diff --git a/README.md b/README.md index 22011c118cbb662fe02219b35e393c9538a01374..8c28e3588c3cbfe01f87219ab618794e9834ebab 100644 --- a/README.md +++ b/README.md @@ -223,11 +223,18 @@ LINUX_OVERRIDE_SRCDIR指定了一个本地的内核源码目录,这样就不 `$ sudo runtime_replace_bootloader.sh uboot` `$ sudo runtime_replace_bootloader.sh fitImage` 以上三条命令分别实现了更换uboot+Image+dtb、更换uboot和更换Image+dtb的功能,要求当前目录下有fip-all.bin和fitImage文件。 -(5)开发板运行时,如果需要远程升级uboot、Image和dtb,可以在飞腾派上执行对应脚本,用法如下: -`$ sudo phytium_ota all latest` -`$ sudo phytium_ota uboot latest` -`$ sudo phytium_ota fitImage latest` -以上三条命令通过远程分别将uboot+Image+dtb、uboot和Image+dtb升级到最新版本。关于phytium_ota更多信息,可以参考[phytium_ota介绍与使用](https://gitee.com/phytium_embedded/phytium-pi-os/wikis/phytium_ota%E4%BB%8B%E7%BB%8D%E4%B8%8E%E4%BD%BF%E7%94%A8) +(5)开发板运行时,如果需要远程升级uboot、Image和dtb、rootfs,可以在飞腾派上执行对应脚本,用法如下: +`$ sudo get_phytium_ota all` +`$ sudo get_phytium_ota uboot` +`$ sudo get_phytium_ota fitImage` +`$ sudo get_phytium_ota rootfs` +以上四条命令通过远程分别将整个系统、uboot、Image+dtb和根文件系统升级到最新版本。关于phytium_ota更多信息,可以参考[phytium_ota介绍与使用](https://gitee.com/phytium_embedded/phytium-pi-os/wikis/phytium_ota%E4%BB%8B%E7%BB%8D%E4%B8%8E%E4%BD%BF%E7%94%A8) +(6)由于不同的开发板的硬件配置有所不同,对应的固件也有变化。开发板运行时,如果需要更新固件uboot的配置,可以在飞腾派上执行ft-config脚本,用法如下: +`$ sudo ft-config {hw|mem|pcie} {type}` +`$ sudo ft-config hw v3` +`$ sudo ft-config mem 8g` +`$ sudo ft-config pcie usb3` +上面三个例子,分别是配置固件支持硬件v3版本、设置内存为8g和设置pcie为usb3。关于phytium_ota更多信息,可以参考[飞腾派固件配置工具ft-config的介绍与使用](https://gitee.com/phytium_embedded/phytium-pi-os/wikis/%E9%A3%9E%E8%85%BE%E6%B4%BE%E5%9B%BA%E4%BB%B6%E9%85%8D%E7%BD%AE%E5%B7%A5%E5%85%B7ft-config%E7%9A%84%E4%BB%8B%E7%BB%8D%E4%B8%8E%E4%BD%BF%E7%94%A8) # 编译内核模块 关于如何编译内核外部模块,可参考https://www.kernel.org/doc/html/latest/kbuild/modules.html diff --git a/board/phytium/common/debian-package-installer b/board/phytium/common/debian-package-installer index 49d1cde10513f33ee80ac240a7178f2c0f2fe769..c4e7d62d7ec05bcc390d3eff0a3443610a721910 100755 --- a/board/phytium/common/debian-package-installer +++ b/board/phytium/common/debian-package-installer @@ -53,15 +53,11 @@ do_distrorfs_second_stage() { echo installed additional packages. if [ $6 = desktop ]; then - for pkg in task-xfce-desktop ukui-greeter; do + for pkg in task-xfce-desktop; do DEBIAN_FRONTEND=noninteractive apt -y install $pkg || true done rm -f /etc/systemd/system/display-manager.service - sed -i "s/gdm3/lightdm/" /etc/X11/default-display-manager - echo '[SeatDefaults]' >> /etc/lightdm/lightdm.conf - echo 'greeter-session=ukui-greeter' >> /etc/lightdm/lightdm.conf - echo 'user-session=xfce' >> /etc/lightdm/lightdm.conf echo installing desktop packages list packages: $pkglist for pkg in $additional_desktop_packages_list; do @@ -85,6 +81,10 @@ do_distrorfs_second_stage() { if [ -f /etc/cups/cupsd.conf ]; then echo "SSLOptions MinTLS1.2" >> /etc/cups/cupsd.conf fi + + # set the configuration of vim + echo 'set mouse-=a' >> /root/.vimrc + echo 'syntax on' >> /root/.vimrc echo remove packages. DEBIAN_FRONTEND=noninteractive apt-get -y remove --purge parole || exit 1 diff --git a/board/phytium/common/post-build.sh b/board/phytium/common/post-build.sh index 445c0efd7929ee2acef932b166c2b2a9017beec3..165dcbcf1dd33992fa0de8aab2339ba0aab90e37 100755 --- a/board/phytium/common/post-build.sh +++ b/board/phytium/common/post-build.sh @@ -109,16 +109,12 @@ main() ln -sf /lib/systemd/system/phytium-tee-supplicant.service $1/etc/systemd/system/sysinit.target.wants/phytium-tee-supplicant.service fi - # alsa UCM - if grep -Eq "^BR2_PACKAGE_PHYTIUM_DESKTOP_TOOLS=y$" ${BR2_CONFIG}; then - ln -sf ../../Phytium/es8336/es8336.conf $1/usr/share/alsa/ucm2/conf.d/simple-card/phytium,pe220x-i2s-audio.conf - ln -sf ../../Phytium/PMDK-I2S/PMDK-I2S.conf $1/usr/share/alsa/ucm2/conf.d/PMDK-I2S/PMDK-I2S.conf - fi - # zram if grep -Eq "^BR2_PACKAGE_PHYTIUM_ZRAM=y$" ${BR2_CONFIG}; then sudo chroot ${1} systemctl enable phytium-zram-config.service fi + # pwm-fan.service + sudo chroot ${1} systemctl enable pwm-fan.service exit $? } diff --git a/configs/phytiumpi_5g.config b/configs/phytiumpi_5g.config index 4c437959826d68c67fdbd76293c816f09c41da2b..1345041e958520ceddeece669325da71190e6789 100644 --- a/configs/phytiumpi_5g.config +++ b/configs/phytiumpi_5g.config @@ -1,3 +1,2 @@ # kernel patch for linux-5.10 BR2_LINUX_KERNEL_PATCH="$(LINUX_PKGDIR)/kernel-patches/5g/0001-port-Quectel-usb-serial-option-driver.patch" -BR2_PACKAGE_PHYUBOOT_5G=y diff --git a/configs/phytiumpi_defconfig b/configs/phytiumpi_defconfig index ecf5d66e93fd4e00ea01220e6c6b880d4b679b65..63e7caca41507ac2acb8c14b1b57da622abf9f0e 100644 --- a/configs/phytiumpi_defconfig +++ b/configs/phytiumpi_defconfig @@ -73,6 +73,9 @@ BR2_PACKAGE_PHYTIUM_FIRSTLOGIN=y # Phytium_zram BR2_PACKAGE_PHYTIUM_ZRAM=y +# Phytium_ota +BR2_PACKAGE_PHYTIUM_OTA=y + # util-linux BR2_PACKAGE_UTIL_LINUX=y BR2_PACKAGE_UTIL_LINUX_BINARIES=y diff --git a/configs/phytiumpi_desktop_defconfig b/configs/phytiumpi_desktop_defconfig index 8e59894b73e54fdb7c384bf68dca0df545f882e0..59766bc5e98fc999c030b02d23f442c33cd10d5c 100644 --- a/configs/phytiumpi_desktop_defconfig +++ b/configs/phytiumpi_desktop_defconfig @@ -68,6 +68,9 @@ BR2_PACKAGE_PHYTIUM_FIRSTLOGIN=y # Phytium_zram BR2_PACKAGE_PHYTIUM_ZRAM=y +# Phytium_ota +BR2_PACKAGE_PHYTIUM_OTA=y + BR2_PACKAGE_ROOTFS_DESKTOP=y BR2_ROOTFS_DEVICE_TABLE="system/device_table.txt board/phytium/common/desktop_device_table.txt" BR2_PACKAGE_BUSYBOX=n diff --git a/package/Config.in b/package/Config.in index b75455443092e7ab8559d09a8e8ed4d6e9310791..e3ac7afac97600e87f72b8afb5ffea4784855efc 100644 --- a/package/Config.in +++ b/package/Config.in @@ -244,6 +244,7 @@ menu "Filesystem and flash utilities" source "package/phytium-desktop-tools/Config.in" source "package/phytium-firstlogin/Config.in" source "package/phytium-zram/Config.in" + source "package/phytium-ota/Config.in" endmenu menu "Fonts, cursors, icons, sounds and themes" diff --git a/package/phytium-desktop-tools/phytium-desktop-tools.mk b/package/phytium-desktop-tools/phytium-desktop-tools.mk index 01bfa5d22e7a88ce7187c2d0288aa67388b67dd9..fec296f0bc62306ad9dcaab21d598d60cfa20ab2 100644 --- a/package/phytium-desktop-tools/phytium-desktop-tools.mk +++ b/package/phytium-desktop-tools/phytium-desktop-tools.mk @@ -16,6 +16,8 @@ define PHYTIUM_DESKTOP_TOOLS_INSTALL_TARGET_CMDS mkdir -p $(TARGET_DIR)/usr/share/desktop-base/profiles/xdg-config/xfce4/xfconf/xfce-perchannel-xml/ mkdir -p $(TARGET_DIR)/var/lib/alsa/ mkdir -p $(TARGET_DIR)/usr/share/alsa/ucm2/ + mkdir -p $(TARGET_DIR)/usr/local/bin/ + mkdir -p $(TARGET_DIR)/etc/udev/rules.d/ $(INSTALL) -m 777 -D $(@D)/dark.jpg $(TARGET_DIR)/usr/share/images/desktop-base/ $(INSTALL) -m 755 -D $(@D)/01_debian.conf $(TARGET_DIR)/usr/share/lightdm/lightdm-gtk-greeter.conf.d/ $(INSTALL) -m 755 -D $(@D)/xfce4-desktop.xml $(TARGET_DIR)/usr/share/desktop-base/profiles/xdg-config/xfce4/xfconf/xfce-perchannel-xml/ @@ -24,6 +26,8 @@ define PHYTIUM_DESKTOP_TOOLS_INSTALL_TARGET_CMDS cp -rf $(@D)/phytium_pe220x-/ $(TARGET_DIR)/usr/share/alsa/ucm2/ $(INSTALL) -m 755 -D $(@D)/switch_to_headphone.sh $(TARGET_DIR)/usr/bin/ $(INSTALL) -m 644 -D $(@D)/sound_output_device_switching.desktop $(TARGET_DIR)/usr/share/alsa/ucm2/ + $(INSTALL) -m 755 -D $(@D)/auto_resolution.sh $(TARGET_DIR)/usr/local/bin/ + $(INSTALL) -m 644 -D $(@D)/99-monitor-hotplug.rules $(TARGET_DIR)/etc/udev/rules.d/ endef $(eval $(generic-package)) diff --git a/package/phytium-desktop-tools/src/99-monitor-hotplug.rules b/package/phytium-desktop-tools/src/99-monitor-hotplug.rules new file mode 100644 index 0000000000000000000000000000000000000000..bdfa70d3ee9b2d8008e5e10a29fb94a1243e670c --- /dev/null +++ b/package/phytium-desktop-tools/src/99-monitor-hotplug.rules @@ -0,0 +1 @@ +SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/auto_resolution.sh" diff --git a/package/phytium-desktop-tools/src/auto_resolution.sh b/package/phytium-desktop-tools/src/auto_resolution.sh new file mode 100755 index 0000000000000000000000000000000000000000..38dd6ef9a99a8dcd64671fa93c46e46ac9433c65 --- /dev/null +++ b/package/phytium-desktop-tools/src/auto_resolution.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# check if on the greeter interface +IS_GREETER=$(loginctl show-session $(loginctl | grep 'lightdm' | awk '{print $1}') --property=State | grep -q "active" && echo "yes" || echo "no") +if [[ "$IS_GREETER" != "yes" ]]; then + exit 0 +fi + +export DISPLAY=:0 +export XAUTHORITY=$HOME/.Xauthority + +if [[ ! -e "$XAUTHORITY" ]]; then + touch "$XAUTHORITY" +fi + +xauth add $(xauth -f /var/run/lightdm/root/:0 list) + +# check the connection status of the screen +connected_output=$(xrandr --query | grep " connected" | awk '{print $1}') +for output in $connected_output; do + # set the optimal resolution + preferred_mode=$(xrandr --query | grep -A 1 "^$output" | tail -n 1 | awk '{print $1}') + if [ -n "$preferred_mode" ]; then + echo "Setting $output to $preferred_mode" + xrandr --output "$output" --mode "$preferred_mode" + fi +done + diff --git a/package/phytium-firstlogin/src/phytium-firstlogin b/package/phytium-firstlogin/src/phytium-firstlogin index 1e7ea4717b9f965112b48676faaf41c9257b92c5..afa257541f9ea090bbc217030144bed84ddcbb1e 100755 --- a/package/phytium-firstlogin/src/phytium-firstlogin +++ b/package/phytium-firstlogin/src/phytium-firstlogin @@ -475,6 +475,59 @@ add_user() { } +fm_patch_dir="/lib/firmware/uboot-patch" +fm_patch_hash_dir="/lib/firmware/uboot-patch-hash" +fm_patch_check_dd_dir="/lib/firmware/uboot-patch-check-dd" +# check if the dd command was successful. +# $1: the file to be checked. +# $2: the starting position of the file to be checked in the firmware. +# $3: the size of the file to be checked. +check-if-dd-success() { + mkdir -p $fm_patch_check_dd_dir + file=$(basename $1 .bin) + dd if=/dev/mmcblk0 of=$fm_patch_check_dd_dir/recovered_$file.bin bs=$2 skip=1 count=1 + dd if=$fm_patch_check_dd_dir/recovered_$file.bin of=$fm_patch_check_dd_dir/final_$file.bin bs=1 count=$3 + _hash=$(sha256sum $fm_patch_check_dd_dir/final_$file.bin | cut -d ' ' -f 1 ) + _known=$(cat $fm_patch_hash_dir/$1.hash | cut -d ' ' -f 3 ) + # Do the hashes match? + if [ "${_hash}" = "${_known}" ]; then + echo -e "\033[1;32mHash verification succeeded, configuration has been updated.\033[0m" + else + echo -e "\033[1;31mHash verification failed, configuration update encountered an error. You may need to manually update the firmware. See https://gitee.com/phytium_embedded/phytium-pi-os/wikis/phytium_ota%E4%BB%8B%E7%BB%8D%E4%B8%8E%E4%BD%BF%E7%94%A8的启动异常补救措施小节\033[0m" + exit 1 + fi +} +firmware_configure(){ + echo "" + echo -e "Configure firmware." + flag=0 + unset response + while [[ ! "${response}" =~ ^(Y|y|N|n)$ ]]; do + read -r -p "Is the phytiumpi hardware version v2? [Y/n] " response + echo "$response" + done + if [[ "${response}" =~ ^(Y|y)$ ]]; then + check-hash $fm_patch_hash_dir/pad_set_v2.x.bin.hash $fm_patch_dir/pad_set_v2.x.bin pad_set_v2.x.bin + dd if=$fm_patch_dir/pad_set_v2.x.bin of=/dev/mmcblk0 bs=1000k seek=1 && sync + check-if-dd-success pad_set_v2.x.bin 1000k 1088 + flag=1 + systemctl disable pwm-fan.service + fi + echo "" + unset response + while [[ ! "${response}" =~ ^(Y|y|N|n)$ ]]; do + read -r -p "Is the memory size 8GB? [Y/n] " response + echo "$response" + done + if [[ "${response}" =~ ^(Y|y)$ ]]; then + printf "\x11" | dd of=/dev/mmcblk0 bs=1 count=1 conv=notrunc bs=1 count=1 seek=1004390 && sync + flag=1 + fi + if [[ "$flag" == 1 ]]; then + echo "the firmware has change, please power reset after desktop started." + fi + echo "" +} if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then do_firstrun_automated_network_configuration @@ -502,7 +555,7 @@ if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then systemctl is-system-running --wait > /dev/null # enable hiDPI support - if [[ "$(cut -d, -f1 < /sys/class/graphics/fb0/virtual_size 2> /dev/null)" -gt 1920 ]]; then + if [[ "$( (cut -d, -f1 < /sys/class/graphics/fb0/virtual_size) 2> /dev/null)" -gt 1920 ]]; then # lightdm [[ -f /etc/lightdm/slick-greeter.conf ]] && echo "enable-hidpi = on" >> /etc/lightdm/slick-greeter.conf # xfce @@ -609,6 +662,11 @@ if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then rm /root/.desktop_firstlogin fi + # ask user to configure firmware + trap '' 2 + firmware_configure + trap - INT TERM EXIT + if [[ ${USER_SHELL} == zsh ]]; then printf "\nYou selected \e[0;91mZSH\x1B[0m as your default shell. If you want to use it right away, please logout and login! \n\n" fi diff --git a/package/phytium-ota/Config.in b/package/phytium-ota/Config.in new file mode 100644 index 0000000000000000000000000000000000000000..85c7dabdf45d6181f14824ec997f7076b3fe2328 --- /dev/null +++ b/package/phytium-ota/Config.in @@ -0,0 +1,2 @@ +config BR2_PACKAGE_PHYTIUM_OTA + bool "phytium_ota" diff --git a/package/phytium-ota/phytium-ota.mk b/package/phytium-ota/phytium-ota.mk new file mode 100644 index 0000000000000000000000000000000000000000..26a6eb7f1af947c177065d7799bcafac592ff981 --- /dev/null +++ b/package/phytium-ota/phytium-ota.mk @@ -0,0 +1,21 @@ +################################################################################ +# +# phytium-ota +# +################################################################################ + +PHYTIUM_OTA_VERSION = 0.1 +PHYTIUM_OTA_SITE = package/phytium-ota/src +PHYTIUM_OTA_SITE_METHOD = local +PHYTIUM_OTA_INSTALL_TARGET = YES + +define PHYTIUM_OTA_INSTALL_TARGET_CMDS + mkdir -p $(TARGET_DIR)/usr/bin + mkdir -p $(TARGET_DIR)/usr/lib/phytium/ + $(INSTALL) -m 755 -D $(@D)/check-hash $(TARGET_DIR)/usr/bin/ + $(INSTALL) -m 755 -D $(@D)/check-latest $(TARGET_DIR)/usr/bin/ + $(INSTALL) -m 755 -D $(@D)/get_phytium_ota $(TARGET_DIR)/usr/bin/ + cp -rf $(@D)/phytium-ota-latest/ $(TARGET_DIR)/usr/lib/phytium/ +endef + +$(eval $(generic-package)) diff --git a/package/phytium-ota/src/check-hash b/package/phytium-ota/src/check-hash new file mode 100755 index 0000000000000000000000000000000000000000..5a47f49bc302846ff3fdba3d17d0b35143c5052b --- /dev/null +++ b/package/phytium-ota/src/check-hash @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +set -e + +# Helper to check a file matches its known hash +# Call it with: +# $1: the path of the file containing all the expected hashes +# $2: the full path to the temporary file that was downloaded, and +# that is to be checked +# $3: the final basename of the file, to which it will be ultimately +# saved as, to be able to match it to the corresponding hashes +# in the .hash file +# +# Exit codes: +# 0: the hash file exists and the file to check matches all its hashes, +# or the hash file does not exist +# 1: unknown command-line option +# 2: the hash file exists and the file to check does not match at least +# one of its hashes +# 3: the hash file exists and there was no hash to check the file against +# 4: the hash file exists and at least one hash type is unknown + +while getopts :q OPT; do + case "${OPT}" in + q) exec >/dev/null;; + \?) exit 1;; + esac +done +shift $((OPTIND-1)) + +h_file="${1}" +file="${2}" +base="${3}" + +# Bail early if no hash to check +if [ -z "${h_file}" ]; then + exit 0 +fi +# Does the hash-file exist? +if [ ! -f "${h_file}" ]; then + printf "WARNING: no hash file for %s\n" "${base}" >&2 + exit 0 +fi + +# Check one hash for a file +# $1: algo hash +# $2: known hash +# $3: file (full path) +check_one_hash() { + _h="${1}" + _known="${2}" + _file="${3}" + + # Note: md5 is supported, but undocumented on purpose. + # Note: sha3 is not supported, since there is currently no implementation + # (the NIST has yet to publish the parameters). + case "${_h}" in + md5|sha1) ;; + sha224|sha256|sha384|sha512) ;; + *) # Unknown hash, exit with error + printf "ERROR: unknown hash '%s' for '%s'\n" \ + "${_h}" "${base}" >&2 + exit 4 + ;; + esac + + # Do the hashes match? + _hash=$( ${_h}sum "${_file}" |cut -d ' ' -f 1 ) + if [ "${_hash}" = "${_known}" ]; then + printf "%s: OK (%s: %s)\n" "${base}" "${_h}" "${_hash}" + return 0 + fi + + printf "ERROR: %s has wrong %s hash:\n" "${base}" "${_h}" >&2 + printf "ERROR: expected: %s\n" "${_known}" >&2 + printf "ERROR: got : %s\n" "${_hash}" >&2 + printf "ERROR: Incomplete download, or man-in-the-middle (MITM) attack\n" >&2 + + exit 2 +} + +# Do we know one or more hashes for that file? +nb_checks=0 +while read t h f; do + case "${t}" in + ''|'#'*) + # Skip comments and empty lines + continue + ;; + *) + if [ "${f}" = "${base}" ]; then + check_one_hash "${t}" "${h}" "${file}" + : $((nb_checks++)) + fi + ;; + esac +done <"${h_file}" + +if [ ${nb_checks} -eq 0 ]; then + case " ${BR_NO_CHECK_HASH_FOR} " in + *" ${base} "*) + # File explicitly has no hash + exit 0 + ;; + esac + printf "ERROR: No hash found for %s\n" "${base}" >&2 + exit 3 +fi diff --git a/package/phytium-ota/src/check-latest b/package/phytium-ota/src/check-latest new file mode 100755 index 0000000000000000000000000000000000000000..9709bab7039290c1117ad85381130374afeb344f --- /dev/null +++ b/package/phytium-ota/src/check-latest @@ -0,0 +1,38 @@ +#!/bin/bash +set -e + +latest_dir="/usr/lib/phytium/phytium-ota-latest" + +if [ $2 = "uboot" ]; then + _hash=$( sha256sum "$1/$2/fip-all-optee-4GB.bin" |cut -d ' ' -f 1 ) +elif [ $2 = "fitImage" ]; then + _hash=$( sha256sum "$1/$2/5.10/$2.tar" |cut -d ' ' -f 1 ) +elif [ $2 = "rootfs" ]; then + _hash=$( sha256sum "$1/$2/$2.tar" |cut -d ' ' -f 1 ) +fi + +if [ ! -e "$latest_dir/$2/$2_latest.hash" ]; then + mkdir -p $latest_dir/$2 + if [ $2 = "uboot" ]; then + echo "sha256 ${_hash} fip-all-optee-4GB.bin" > $latest_dir/$2/$2_latest.hash + else + echo "sha256 ${_hash} $2.tar" > $latest_dir/$2/$2_latest.hash + fi + echo "no_latest" + exit +else + _known=$(cat $latest_dir/$2/$2_latest.hash | cut -d ' ' -f 3) +fi + +# Do the hashes match? +if [ "${_hash}" = "${_known}" ]; then + echo "latest" +else + mkdir -p $latest_dir/$2 + if [ $2 = "uboot" ]; then + echo "sha256 ${_hash} fip-all-optee-4GB.bin" > $latest_dir/$2/$2_latest.hash + else + echo "sha256 ${_hash} $2.tar" > $latest_dir/$2/$2_latest.hash + fi + echo "no_latest" +fi diff --git a/package/phytium-ota/src/get_phytium_ota b/package/phytium-ota/src/get_phytium_ota new file mode 100755 index 0000000000000000000000000000000000000000..42d14bf01318bd86d8b6bb0e2d84d774703ca8a0 --- /dev/null +++ b/package/phytium-ota/src/get_phytium_ota @@ -0,0 +1,138 @@ +#!/bin/bash + +# Get remote update files. +# +# Copyright (c) 2024-2025 Phytium Technology Co., Ltd. +# +# # This file is licensed under the terms of the GNU General Public +# License version 2. +# +# For the specific function 'detect_and_set_network', the following copyright applies: +# Copyright (c) Authors: https://www.armbian.com/authors +# +# get_phytium_ota - To get remote update files through the network. +# + +download_dir="/usr/local/phytium-libs" +download_site="https://gitee.com/phytium_embedded/phytium-rogue-umlibs.git" +dest_dir="/usr/local/phytium-ota" + +usage() { + echo "Usage: sudo $0 {all|rootfs|fitImage|uboot}" + echo " Example 1: sudo $0 uboot + --update uboot to the latest version" + echo " Example 2: sudo $0 fitImage + --update fitImage to the latest version" + echo " Example 3: sudo $0 rootfs + --update rootfs to the latest version" + echo " Example 4: sudo $0 all + --update uboot,fitImage and rootfs to the latest version" +} + +# check if parameters are provided. +if [ $# -eq 0 ]; then + usage + exit 1 +fi + +check_args() +{ + if [ "$#" -ne 1 ]; then + echo -e "\033[1;31mArgs number error! usage: sudo $0 {all|fitImage|uboot} {latest|v1.x}\033[0m" + exit 1 + fi + if [[ "$1" != "all" ]] && [[ "$1" != "uboot" ]] && [[ "$1" != "fitImage" ]] && [[ "$1" != "rootfs" ]]; then + echo -e "\033[1;31mError: First argument must be 'all', 'uboot', 'fitImage', or 'rootfs'.\033[0m" + exit 1 + fi +} + +while true; do + case $1 in + "-h" | "-help") + usage + exit + ;; + *) + check_args $1 $2 + break + ;; + esac +done + +# get kernel version +kernel_version=$(uname -r) + +# unsupport rt kernel and 4.19 +if [[ $kernel_version =~ ^((5\.10\.[0-9]+))-phytium.* ]]; then + kernel_version="5.10" +elif [[ $kernel_version =~ ^((6\.6\.[0-9]+))-phytium.* ]]; then + kernel_version="6.6" +else + echo -e "\033[31munsupport kernel version: $kernel_version\033[0m" + exit 1 +fi + +detect_and_set_network() { + # Grab this machine's public IP address + PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip) + + # Check if we have wireless adaptor + WIFI_DEVICE=$(LC_ALL=C nmcli dev status | grep " wifi " 2> /dev/null) + + if [ -z "$PUBLIC_IP" ]; then + # ask for connecting to wireless if wifi device is found + if [[ -n "$WIFI_DEVICE" ]]; then + echo -e "Internet connection was \x1B[91mnot detected\x1B[0m." + echo "" + unset response + while [[ ! "${response}" =~ ^(Y|y|N|n)$ ]]; do + if [ -z $PRESET_CONNECT_WIRELESS ];then + read -r -p "Connect via wireless? [Y/n] " response + response=${response:-Y} + else + response=n + fi + echo "$response" + done + if [[ "${response}" =~ ^(Y|y)$ ]]; then + nmtui-connect + fi + echo "" + fi + fi + # Grab IP once again if not found + [[ -z "$PUBLIC_IP" && -n "$WIFI_DEVICE" ]] && PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip) + + if [ -z "$PUBLIC_IP" ]; then + echo -e "Internet connection was \x1B[91mnot detected\x1B[0m." + echo "exit" + exit 1; + fi +} # detect_and_set_network + +# get remote update files from gitee. +get_update_files() { + rm -rf $download_dir + mkdir -p $download_dir + + apt install -y git + + git clone -b develop --depth 1 $download_site $download_dir + if [ "$?" != "0" ]; then + echo -e "\033[1;31mget remote update files failed\033[0m" + exit 1 + fi + echo -e "\033[1;32mget remote update files success\033[0m" + rm -rf $dest_dir + cp -rf $download_dir/phytium-ota /usr/local +} # get_update_files + +main() { + detect_and_set_network + get_update_files + $dest_dir/scripts/run_phytium_ota $1 +} + +main $@ + diff --git a/package/phytium-ota/src/phytium-ota-latest/fitImage/fitImage_latest.hash b/package/phytium-ota/src/phytium-ota-latest/fitImage/fitImage_latest.hash new file mode 100644 index 0000000000000000000000000000000000000000..f386af462fdf3ff751a7b21a0f40c5791736114d --- /dev/null +++ b/package/phytium-ota/src/phytium-ota-latest/fitImage/fitImage_latest.hash @@ -0,0 +1 @@ +sha256 f668e6a510588b93e13514a090c24c84395ca51cf53787185c8e625ddea37175 fitImage.tar diff --git a/package/phytium-ota/src/phytium-ota-latest/rootfs/rootfs_latest.hash b/package/phytium-ota/src/phytium-ota-latest/rootfs/rootfs_latest.hash new file mode 100644 index 0000000000000000000000000000000000000000..4ea19ba170616f426877b5affb170fe3ac801a34 --- /dev/null +++ b/package/phytium-ota/src/phytium-ota-latest/rootfs/rootfs_latest.hash @@ -0,0 +1 @@ +sha256 55d86f2b17bf36d4f622891a256fb72db1532314137479af1b6aa87227b811e2 rootfs.tar diff --git a/package/phytium-ota/src/phytium-ota-latest/uboot/uboot_latest.hash b/package/phytium-ota/src/phytium-ota-latest/uboot/uboot_latest.hash new file mode 100644 index 0000000000000000000000000000000000000000..1b47edc417d2ce13d3dd87bed01e352255ef9845 --- /dev/null +++ b/package/phytium-ota/src/phytium-ota-latest/uboot/uboot_latest.hash @@ -0,0 +1,2 @@ +sha256 07e42417ca8ab699223f321a9dd24ff5b3dbcf5bba8a344ef63bbb2ff0d59e93 fip-all-optee-4GB.bin + diff --git a/package/phytium-tools/phytium-tools.mk b/package/phytium-tools/phytium-tools.mk index b0c71533ec79de3a78f57dabb6c3addeb0369eed..42209dace0c8bf0a56146dd22df6f79d64d44ed8 100644 --- a/package/phytium-tools/phytium-tools.mk +++ b/package/phytium-tools/phytium-tools.mk @@ -16,6 +16,8 @@ define PHYTIUM_TOOLS_INSTALL_TARGET_CMDS mkdir -p $(TARGET_DIR)/lib/firmware/rtw88/ mkdir -p $(TARGET_DIR)/lib/firmware/rtl_bt/ mkdir -p $(TARGET_DIR)/etc/modprobe.d/ + mkdir -p $(TARGET_DIR)/lib/firmware/uboot-patch + mkdir -p $(TARGET_DIR)/lib/firmware/uboot-patch-hash $(INSTALL) -m 755 -D $(@D)/rtlbt/* $(TARGET_DIR)/lib/firmware/rtlbt/ $(INSTALL) -m 755 -D $(@D)/rtk_hciattach $(TARGET_DIR)/usr/bin/ $(INSTALL) -m 755 -D $(@D)/resize.sh $(TARGET_DIR)/usr/bin/ @@ -26,8 +28,13 @@ define PHYTIUM_TOOLS_INSTALL_TARGET_CMDS $(INSTALL) -m 755 -D $(@D)/rtlbt/rtl8821c_config $(TARGET_DIR)/lib/firmware/rtl_bt/rtl8821c_config.bin $(INSTALL) -m 755 -D $(@D)/rtlbt/rtl8821c_fw $(TARGET_DIR)/lib/firmware/rtl_bt/rtl8821c_fw.bin $(INSTALL) -m 755 -D $(@D)/rtw88.conf $(TARGET_DIR)/etc/modprobe.d/ - $(INSTALL) -m 755 -D $(@D)/phytium_ota $(TARGET_DIR)/usr/bin/ $(INSTALL) -m 755 -D $(@D)/quectel-CM $(TARGET_DIR)/usr/bin/ + $(INSTALL) -D -m 644 $(@D)/firmware-configure/* $(TARGET_DIR)/lib/firmware/uboot-patch/ + $(INSTALL) -D -m 644 $(@D)/firmware-configure-hash/* $(TARGET_DIR)/lib/firmware/uboot-patch-hash/ + $(INSTALL) -D -m 755 $(@D)/ft-config $(TARGET_DIR)/usr/bin + $(INSTALL) -m 644 -D $(@D)/pwm-fan.service $(TARGET_DIR)/lib/systemd/system/ + $(INSTALL) -m 755 -D $(@D)/init_pwm_fan.sh $(TARGET_DIR)/usr/bin + $(INSTALL) -m 755 -D $(@D)/pwm_fan.sh $(TARGET_DIR)/usr/bin endef $(eval $(generic-package)) diff --git a/package/phytium-tools/src/firmware-configure-hash/pad_set_v2.x.bin.hash b/package/phytium-tools/src/firmware-configure-hash/pad_set_v2.x.bin.hash new file mode 100644 index 0000000000000000000000000000000000000000..1f5bae731494cb45fc9fc0b992d44612b8f6f1b0 --- /dev/null +++ b/package/phytium-tools/src/firmware-configure-hash/pad_set_v2.x.bin.hash @@ -0,0 +1 @@ +sha256 63201c49e7197a7501af239965be221a161ea89634039a76d76e1cee787da23f pad_set_v2.x.bin diff --git a/package/phytium-tools/src/firmware-configure-hash/pad_set_v3.bin.hash b/package/phytium-tools/src/firmware-configure-hash/pad_set_v3.bin.hash new file mode 100644 index 0000000000000000000000000000000000000000..2ea5f1a05d0a63015ec8b8c72b36115e8a9951e0 --- /dev/null +++ b/package/phytium-tools/src/firmware-configure-hash/pad_set_v3.bin.hash @@ -0,0 +1 @@ +sha256 1165c42d19fe8d9dfcb8836ddbacbbd5e6da1b488bd6c024a9701c8ae0ed7737 pad_set_v3.bin diff --git a/package/phytium-tools/src/firmware-configure-hash/para_5g_usb3.bin.hash b/package/phytium-tools/src/firmware-configure-hash/para_5g_usb3.bin.hash new file mode 100644 index 0000000000000000000000000000000000000000..57f4c8763f708eeb7ead970ffef3d361e250a054 --- /dev/null +++ b/package/phytium-tools/src/firmware-configure-hash/para_5g_usb3.bin.hash @@ -0,0 +1 @@ +sha256 912b81b648134348999087da1cf45a5c482d8f7f3f1107598eef5cfec40b82e7 para_5g_usb3.bin diff --git a/package/phytium-tools/src/firmware-configure-hash/para_msata.bin.hash b/package/phytium-tools/src/firmware-configure-hash/para_msata.bin.hash new file mode 100644 index 0000000000000000000000000000000000000000..f56c587881420c81839ee34d176383bbed70a46f --- /dev/null +++ b/package/phytium-tools/src/firmware-configure-hash/para_msata.bin.hash @@ -0,0 +1 @@ +sha256 9a0ef620ae19a0d4ccff0e23442939e81c52130a81b16eb0306c7ff639511953 para_msata.bin diff --git a/package/phytium-tools/src/firmware-configure-hash/para_nvme_usb2.bin.hash b/package/phytium-tools/src/firmware-configure-hash/para_nvme_usb2.bin.hash new file mode 100644 index 0000000000000000000000000000000000000000..c15fbad4808ada14652ddca50fbd169e951e0dee --- /dev/null +++ b/package/phytium-tools/src/firmware-configure-hash/para_nvme_usb2.bin.hash @@ -0,0 +1 @@ +sha256 1e5e9a5b9f900343cd5d8242d90fc949e231f68e6c939fa0e6f133a5824664d7 para_nvme_usb2.bin diff --git a/package/phytium-tools/src/firmware-configure/pad_set_v2.x.bin b/package/phytium-tools/src/firmware-configure/pad_set_v2.x.bin new file mode 100644 index 0000000000000000000000000000000000000000..caf33a75f98557fadde5da396a965fe0188a625b Binary files /dev/null and b/package/phytium-tools/src/firmware-configure/pad_set_v2.x.bin differ diff --git a/package/phytium-tools/src/firmware-configure/pad_set_v3.bin b/package/phytium-tools/src/firmware-configure/pad_set_v3.bin new file mode 100644 index 0000000000000000000000000000000000000000..831422ce0b043daf68059c1ba9dc9ea9b9fc80e4 Binary files /dev/null and b/package/phytium-tools/src/firmware-configure/pad_set_v3.bin differ diff --git a/package/phytium-tools/src/firmware-configure/para_5g_usb3.bin b/package/phytium-tools/src/firmware-configure/para_5g_usb3.bin new file mode 100644 index 0000000000000000000000000000000000000000..1876b998ba0e6656a75e3711c01189baedabc71c Binary files /dev/null and b/package/phytium-tools/src/firmware-configure/para_5g_usb3.bin differ diff --git a/package/phytium-tools/src/firmware-configure/para_msata.bin b/package/phytium-tools/src/firmware-configure/para_msata.bin new file mode 100644 index 0000000000000000000000000000000000000000..d4c61bafd67ac4358d9b44c85b185adad0f9f241 Binary files /dev/null and b/package/phytium-tools/src/firmware-configure/para_msata.bin differ diff --git a/package/phytium-tools/src/firmware-configure/para_nvme_usb2.bin b/package/phytium-tools/src/firmware-configure/para_nvme_usb2.bin new file mode 100644 index 0000000000000000000000000000000000000000..55cc73c441e7d42ec3d4210a2322feee3ab6716c Binary files /dev/null and b/package/phytium-tools/src/firmware-configure/para_nvme_usb2.bin differ diff --git a/package/phytium-tools/src/ft-config b/package/phytium-tools/src/ft-config new file mode 100755 index 0000000000000000000000000000000000000000..daf9f0d88566ce28e06c2fc56861b43df08f198d --- /dev/null +++ b/package/phytium-tools/src/ft-config @@ -0,0 +1,161 @@ +#!/bin/bash + +# Phytium phytiumpi firmware config script +# +# Copyright (c) 2025 Phytium Technology Co., Ltd. +# +# ft-config - configure the firmware to adapt to different +# hardware configurations on the phytiumpi development board. +# + +fm_patch_dir="/lib/firmware/uboot-patch" +fm_patch_hash_dir="/lib/firmware/uboot-patch-hash" +fm_patch_check_dd_dir="/lib/firmware/uboot-patch-check-dd" + +usage() { + echo -e "Usage: \033[32msudo $0 {hw|mem|pcie} {type}\033[0m" + echo -e " for \033[32mhw\033[0m, {type} can be v2 or v3. + --the phytiumpi development board has v2 and v3 two hardware versions." + echo -e " for \033[32mmem\033[0m, {type} can be 4g or 8g. + --different phytiumpi develpment board has different memory sizes." + echo -e " for \033[32mpcie\033[0m, {type} can be usb2, usb3 or msata. + --pcie can be multiplexed for use as usb2, usb3 or msata." + echo " Example 1: sudo $0 hw v3 + --configure firmware to adapt to v3 phytiumpi hardware." + echo " Example 2: sudo $0 mem 8g + --configure firmware to adapt to 8g mem." + echo " Example 3: sudo $0 pcie usb3 + --configure firmware to repurpose pcie for use as usb3" +} + +# check if parameters are provided. +if [ $# -eq 0 ]; then + usage + exit 1 +fi + +check_args() { + if [ "$#" -ne 2 ]; then + echo -e "\033[1;31mArgs number error! usage: sudo $0 {hw|mem|pcie} {type}\033[0m" + exit 1 + fi + + case "$1" in + "hw") + if [[ "$2" != "v2" && "$2" != "v3" ]]; then + echo -e "\033[1;31mArgs error: when first argument is hw, second argument must be v2 or v3.\033[0m" + exit 1 + fi + ;; + "mem") + if [[ "$2" != "4g" && "$2" != "8g" ]]; then + echo -e "\033[1;31mArgs error: when first argument is mem, second argument must be 4g or 8g.\033[0m" + exit 1 + fi + ;; + "pcie") + if [[ "$2" != "usb2" && "$2" != "usb3" && "$2" != "msata" ]]; then + echo -e "\033[1;31mArgs error: when first argument is pcie, second argument must be usb2, usb3 or msata.\033[0m" + exit 1 + fi + ;; + *) + echo -e "\033[1;31mArgs error: first argument must be 'hw', 'mem', or 'pcie'.\033[0m" + exit 1 + ;; + esac +} + +while true; do + case $1 in + "-h" | "-help") + usage + exit + ;; + *) + check_args $1 $2 $3 + break + ;; + esac +done + +# check if the dd command was successful. +# $1: the file to be checked. +# $2: the starting position of the file to be checked in the firmware. +# $3: the size of the file to be checked. +check-if-dd-success() { + mkdir -p $fm_patch_check_dd_dir + file=$(basename $1 .bin) + dd if=/dev/mmcblk0 of=$fm_patch_check_dd_dir/recovered_$file.bin bs=$2 skip=1 count=1 + dd if=$fm_patch_check_dd_dir/recovered_$file.bin of=$fm_patch_check_dd_dir/final_$file.bin bs=1 count=$3 + _hash=$(sha256sum $fm_patch_check_dd_dir/final_$file.bin | cut -d ' ' -f 1 ) + _known=$(cat $fm_patch_hash_dir/$1.hash | cut -d ' ' -f 3 ) + # Do the hashes match? + if [ "${_hash}" = "${_known}" ]; then + echo -e "\033[1;32mHash verification succeeded, configuration has been updated.\033[0m" + else + echo -e "\033[1;31mHash verification failed, configuration update encountered an error. You may need to manually update the firmware. See https://gitee.com/phytium_embedded/phytium-pi-os/wikis/phytium_ota%E4%BB%8B%E7%BB%8D%E4%B8%8E%E4%BD%BF%E7%94%A8的启动异常补救措施小节\033[0m" + exit 1 + fi +} + +# configure_phytiumpi_firmware +# $1: +# hw, mem or pcie +# $2: +# v2 or v3 when $1 is hw +# 2g, 4g or 8g when $1 is mem +# usb2, usb3 or msata when $1 is pcie +configure_phytiumpi_firmware() { + if [[ "$1" == "hw" ]]; then + if [[ "$2" == "v2" ]]; then + check-hash $fm_patch_hash_dir/pad_set_v2.x.bin.hash $fm_patch_dir/pad_set_v2.x.bin pad_set_v2.x.bin + dd if=$fm_patch_dir/pad_set_v2.x.bin of=/dev/mmcblk0 bs=1000k seek=1 && sync + check-if-dd-success pad_set_v2.x.bin 1000k 1088 + systemctl disable pwm-fan.service + elif [[ "$2" == "v3" ]]; then + check-hash $fm_patch_hash_dir/pad_set_v3.bin.hash $fm_patch_dir/pad_set_v3.bin pad_set_v3.bin + dd if=$fm_patch_dir/pad_set_v3.bin of=/dev/mmcblk0 bs=1000k seek=1 && sync + check-if-dd-success pad_set_v3.bin 1000k 1088 + systemctl enable pwm-fan.service + fi + elif [[ "$1" == "mem" ]]; then + if [[ "$2" == "4g" ]]; then + printf "\x10" | dd of=/dev/mmcblk0 bs=1 count=1 conv=notrunc bs=1 count=1 seek=1004390 && sync + elif [[ "$2" == "8g" ]]; then + printf "\x11" | dd of=/dev/mmcblk0 bs=1 count=1 conv=notrunc bs=1 count=1 seek=1004390 && sync + fi + if [ "$?" != "0" ]; then + echo "\033[1;31mconfigure mem failed\033[0m" + exit 1 + fi + elif [[ "$1" == "pcie" ]]; then + # preserve memory information. + pre_mem=$(dd if=/dev/mmcblk0 bs=1 count=1 skip=1004390 status=none | xxd -p) + if [[ "$2" == "usb2" ]]; then + check-hash $fm_patch_hash_dir/para_nvme_usb2.bin.hash $fm_patch_dir/para_nvme_usb2.bin para_nvme_usb2.bin + dd if=$fm_patch_dir/para_nvme_usb2.bin of=/dev/mmcblk0 bs=980k seek=1 && sync + check-if-dd-success para_nvme_usb2.bin 980k 1568 + elif [[ "$2" == "usb3" ]]; then + check-hash $fm_patch_hash_dir/para_5g_usb3.bin.hash $fm_patch_dir/para_5g_usb3.bin para_5g_usb3.bin + dd if=$fm_patch_dir/para_5g_usb3.bin of=/dev/mmcblk0 bs=980k seek=1 && sync + check-if-dd-success para_5g_usb3.bin 980k 1568 + elif [[ "$2" == "msata" ]]; then + check-hash $fm_patch_hash_dir/para_msata.bin.hash $fm_patch_dir/para_msata.bin para_msata.bin + dd if=$fm_patch_dir/para_msata.bin of=/dev/mmcblk0 bs=980k seek=1 && sync + check-if-dd-success para_msata.bin 980k 1568 + fi + # restore memory information. + printf "\\x$pre_mem" | dd of=/dev/mmcblk0 bs=1 count=1 conv=notrunc bs=1 count=1 seek=1004390 + fi + + echo -e "\033[1;32mConfigure phytiumpi firmware success, please power reset now\033[0m" +} + +main() { + configure_phytiumpi_firmware $1 $2 +} + +main $@ + + diff --git a/package/phytium-tools/src/init_pwm_fan.sh b/package/phytium-tools/src/init_pwm_fan.sh new file mode 100755 index 0000000000000000000000000000000000000000..cfda1b941bde0781e403b812ec76782fd08a38bf --- /dev/null +++ b/package/phytium-tools/src/init_pwm_fan.sh @@ -0,0 +1,10 @@ +#!/bin/bash +#fan +echo 1 > /sys/class/pwm/pwmchip0/export +cd /sys/class/pwm/pwmchip0/pwm1/ +echo 25000 > period +# echo 15000 > duty_cycle #fan slow +echo 24000 > duty_cycle #fan fast +echo normal > polarity +echo 1 > enable +. /usr/bin/pwm_fan.sh & diff --git a/package/phytium-tools/src/phytium_ota b/package/phytium-tools/src/phytium_ota deleted file mode 100755 index 238bd7479659d2b0d129b3d47f4123d0cd0a6793..0000000000000000000000000000000000000000 --- a/package/phytium-tools/src/phytium_ota +++ /dev/null @@ -1,192 +0,0 @@ -#!/bin/bash - -# Phytium phytiumpi ota script -# -# Copyright (c) 2024 Phytium Technology Co., Ltd. -# -# phytium_ota.sh - To replace fip-all.bin and fitImage through the -# network on the phytiumpi development board. -# - -download_dir="/usr/local/phytium-libs" -download_site="https://gitee.com/phytium_embedded/phytium-rogue-umlibs.git" -dest_dir="/usr/local/phytium-ota" - -usage() { - echo "Usage: sudo $0 {all|fitImage|uboot} {version}" - echo -e " for \033[32muboot\033[0m, {version} can be v1.x or latest, etc - for \033[32mfitImage\033[0m and \033[32mall\033[0m, {version} only be latest" - echo " Example 1: sudo $0 uboot v1.x - --update uboot to version v1.x - Example 2: sudo $0 fitImage latest - --update fitImage to the latest - Example 3: sudo $0 all latest - --update uboot and fit Image to the latest" -} - -while true; do - case $1 in - "-h" | "-help") - usage - exit - ;; - *) - break - ;; - esac -done - -check_args() -{ - if [ "$#" -ne 2 ]; then - echo -e "\033[1;31mUsage: sudo $0 {all|fitImage|uboot} {latest|v1.x}\033[0m" - exit 1 - fi - if [ "$1" != "all" ] && [ "$1" != "fitImage" ] && [ "$1" != "uboot" ]; then - echo -e "\033[1;31mError: First argument must be 'all', 'fitImage', or 'uboot'.\033[0m" - exit 1 - fi - - if [[ "$2" != "latest" && "$2" != "msata" && "$2" != "5g" && ! "$2" =~ ^v1\.[0-9]+$ ]]; then - echo -e "\033[1;31mError: Second argument must be 'latest', 'msata', '5g' or 'v1.x'.\033[0m" - exit 1 - fi -} - -mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem") -mem_info=$(echo $mem_info | awk '{print $2}') -memory_total=$(( mem_info * 1024 )) -# compare to 3GB -if [ $memory_total -ge 3221225472 ]; then - mem=4GB -else - mem=2GB -fi -#echo $mem - -# get kernel version -kernel_version=$(uname -r) - -# unsupport rt kernel and 4.19 -if [[ $kernel_version =~ ^((5\.10\.[0-9]+))-phytium.* ]]; then - kernel_version="5.10" -elif [[ $kernel_version =~ ^((6\.6\.[0-9]+))-phytium.* ]]; then - kernel_version="6.6" -else - echo -e "\033[31munsupport kernel version: $kernel_version\033[0m" - exit 1 -fi - -detect_and_set_network() { - # Grab this machine's public IP address - PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip) - - # Check if we have wireless adaptor - WIFI_DEVICE=$(LC_ALL=C nmcli dev status | grep " wifi " 2> /dev/null) - - if [ -z "$PUBLIC_IP" ]; then - - # ask for connecting to wireless if wifi device is found - if [[ -n "$WIFI_DEVICE" ]]; then - echo -e "Internet connection was \x1B[91mnot detected\x1B[0m." - echo "" - unset response - while [[ ! "${response}" =~ ^(Y|y|N|n)$ ]]; do - if [ -z $PRESET_CONNECT_WIRELESS ];then - read -r -p "Connect via wireless? [Y/n] " response - response=${response:-Y} - else - response=n - fi - echo "$response" - done - if [[ "${response}" =~ ^(Y|y)$ ]]; then - nmtui-connect - fi - echo "" - fi - fi - # Grab IP once again if not found - [[ -z "$PUBLIC_IP" && -n "$WIFI_DEVICE" ]] && PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip) - - if [ -z "$PUBLIC_IP" ]; then - echo -e "Internet connection was \x1B[91mnot detected\x1B[0m." - echo "exit" - exit 1; - fi -} # detect_and_set_network - -# get fip-all.bin and fitImage from gitee. -get_uboot_and_fitImage() { - - rm -rf $download_dir - mkdir -p $download_dir - - git clone -b develop --depth 1 $download_site $download_dir - if [ "$?" != "0" ]; then - echo -e "\033[1;33mget uboot and fitImage failed\033[0m" - exit 1 - fi - echo -e "\033[1;32mget uboot and fitImage success\033[0m" - rm -rf $dest_dir - cp -rf $download_dir/phytium-ota /usr/local - -} # get_uboot_and_fitImage - -# replace_uboot_and_fitImage -# $1: can be all\uboot\fitImage -# $2: can be latest\v1.5\msata, etc -replace_uboot_and_fitImage() { - - uboot_type=optee - if [ "$2" == "msata" ]; then - uboot_type=msata - elif [ "$2" == "5g" ]; then - uboot_type=5g - fi - uboot_bin="fip-all-$uboot_type-$mem.bin" - - if [ "$1" == "all" ]; then - echo -e "\033[1;32mupdate uboot...\033[0m" - #to preserve the partition table. - dd if=/dev/mmcblk0 of=start.img bs=512 count=1 >> $dest_dir/uboot/$2/replace.log 2>&1 - dd if=$dest_dir/uboot/$2/$uboot_bin of=/dev/mmcblk0 bs=1M count=4 >> $dest_dir/uboot/$2/replace.log 2>&1 - dd if=start.img of=/dev/mmcblk0 bs=512 count=1 >> $dest_dir/uboot/$2/replace.log 2>&1 - rm -f start.img - echo -e "\033[1;32mupdate fitImage...\033[0m" - dd if=$dest_dir/fitImage/$2/$kernel_version/fitImage of=/dev/mmcblk0 bs=1M seek=4 count=60 >> $dest_dir/fitImage/$2/$kernel_version/replace.log 2>&1 - dpkg -i $dest_dir/fitImage/$2/$kernel_version/linux-headers-$kernel_version.deb - dpkg -i $dest_dir/fitImage/$2/$kernel_version/linux-image-$kernel_version.deb - elif [ "$1" == "uboot" ]; then - echo -e "\033[1;32mupdate uboot...\033[0m" - #to preserve the partition table. - dd if=/dev/mmcblk0 of=start.img bs=512 count=1 >> $dest_dir/$1/$2/replace.log 2>&1 - dd if=$dest_dir/$1/$2/$uboot_bin of=/dev/mmcblk0 bs=1M count=4 >> $dest_dir/$1/$2/replace.log 2>&1 - dd if=start.img of=/dev/mmcblk0 bs=512 count=1 >> $dest_dir/$1/$2/replace.log 2>&1 - rm -f start.img - elif [ "$1" == "fitImage" ]; then - echo -e "\033[1;32mupdate fitImage...\033[0m" - dd if=$dest_dir/$1/$2/$kernel_version/fitImage of=/dev/mmcblk0 bs=1M seek=4 count=60 >> $dest_dir/$1/$2/$kernel_version/replace.log 2>&1 - dpkg -i $dest_dir/$1/$2/$kernel_version/linux-headers-$kernel_version.deb - dpkg -i $dest_dir/$1/$2/$kernel_version/linux-image-$kernel_version.deb - else - echo -e "\033[1;31margs error, exit\033[0m" - fi - - if [ "$?" != "0" ]; then - echo -e "\033[1;31mreplace_uboot_and_fitImage failed\033[0m" - exit 1 - fi - - echo -e "\033[1;32mupdate success, please reboot now\033[0m" -} # replace_uboot_and_fitImage - - -main() { - check_args $1 $2 - detect_and_set_network - get_uboot_and_fitImage $1 $2 - replace_uboot_and_fitImage $1 $2 -} - -main $@ diff --git a/package/phytium-tools/src/pwm-fan.service b/package/phytium-tools/src/pwm-fan.service new file mode 100644 index 0000000000000000000000000000000000000000..d5c0f79d22ff6093e8d25ec57fc43afb0a63cf8c --- /dev/null +++ b/package/phytium-tools/src/pwm-fan.service @@ -0,0 +1,9 @@ +[Unit] +Description=pwm fan process +After=network.target +[Service] +Type=forking +ExecStart=/usr/bin/init_pwm_fan.sh +User=root +[Install] +WantedBy=multi-user.target diff --git a/package/phytium-tools/src/pwm_fan.sh b/package/phytium-tools/src/pwm_fan.sh new file mode 100755 index 0000000000000000000000000000000000000000..cb1886290c3a237c8df6f1843ed91d2944153c40 --- /dev/null +++ b/package/phytium-tools/src/pwm_fan.sh @@ -0,0 +1,16 @@ +#!/bin/bash +THRESHOLD_TEMP=50 +while true; +do + sleep 30s + CPU_TEMP=$(cat /sys/class/thermal/thermal_zone0/temp) + CPU_TEMP_C=$((CPU_TEMP / 1000)) + #echo "$CPU_TEMP_C" + if [ "$CPU_TEMP_C" -gt "$THRESHOLD_TEMP" ]; then + #echo "pwm fast" + echo 24000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle + else + #echo "pwm slow" + echo 12000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle + fi +done diff --git a/package/phyuboot/phyuboot.mk b/package/phyuboot/phyuboot.mk index 5780c6740f816bd792eb03feec4fa41e02083826..648b82e056dd2f244e04d6d25b22b1ef777f14d4 100644 --- a/package/phyuboot/phyuboot.mk +++ b/package/phyuboot/phyuboot.mk @@ -18,7 +18,6 @@ PHYUBOOT_RAMSIZE = $(BR2_PACKAGE_PHYUBOOT_RAMSIZE) define PHYUBOOT_INSTALL_IMAGES_CMDS $(INSTALL) -D -m 0777 $(@D)/phyuboot/fip-all-optee-$(BR2_PACKAGE_PHYUBOOT_RAMSIZE).bin $(BINARIES_DIR)/fip-all.bin - $(if $(BR2_PACKAGE_PHYUBOOT_5G),$(INSTALL) -D -m 0777 $(@D)/phytium-ota/uboot/5g/fip-all-5g-$(BR2_PACKAGE_PHYUBOOT_RAMSIZE).bin $(BINARIES_DIR)/fip-all.bin) $(INSTALL) -D -m 0777 $(PHYUBOOT_PKGDIR)/src/kernel.its $(BINARIES_DIR)/kernel.its $(INSTALL) -D -m 755 $(PHYUBOOT_PKGDIR)/src/mkimage $(HOST_DIR)/bin/mkimage_phypi PATH=$(BR_PATH) $(MKIMAGE_PI) -f $(BINARIES_DIR)/kernel.its $(BINARIES_DIR)/fitImage