Files
2025-07-30 13:34:59 +08:00

164 lines
3.3 KiB
Plaintext

#!/busybox sh
export PATH=/
msc() {
echo mmc0 > /sys/devices/platform/leds/leds/led-user/trigger
# backlight
devmem 0x030010AC 32 0x04 # PINMUX PWM10
blpwm="/sys/class/pwm/pwmchip8/pwm2/"
if [ ! -e "${blpwm}" ]
then
echo 2 > /sys/class/pwm/pwmchip8/export
fi
echo 0 > $blpwm/enable
echo "10000" > ${blpwm}/period # 100KHZ
panel_value=""
if [ -e /boot/board ]
then
panel_value=$(grep '^panel=' /boot/board | cut -d '=' -f 2)
elif [ -e /boot/uEnv.txt ]
then
panel_value=$(grep '^panel=' /boot/uEnv.txt | cut -d '=' -f 2)
fi
if [ "$panel_value" = "st7701_hd228001c31" ] || [ "$panel_value" = "st7701_lct024bsi20" ]
then
echo "2000" > ${blpwm}/duty_cycle # 20%
else
echo "5000" > ${blpwm}/duty_cycle
fi
echo 1 > $blpwm/enable
umount /dev/mmcblk0p1
umount /dev/mmcblk0p2 || true
# usb
mount -t configfs configfs /sys/kernel/config
cd /sys/kernel/config/usb_gadget
mkdir g0
cd g0
if [ -e /boot/usb.idVendor ]
then
cat /boot/usb.idVendor > idVendor
else
echo 0x3346 > idVendor
fi
if [ -e /boot/usb.idProduct ]
then
cat /boot/usb.idProduct > idProduct
else
echo 0x1009 > idProduct
fi
mkdir strings/0x409
if [ -e /boot/usb.serialnumber ]
then
cat /boot/usb.serialnumber > strings/0x409/serialnumber
else
echo '0123456789ABCDEF' > strings/0x409/serialnumber
fi
if [ -e /boot/usb.manufacturer ]
then
cat /boot/usb.manufacturer > strings/0x409/manufacturer
else
echo 'sipeed' > strings/0x409/manufacturer
fi
if [ -e /boot/usb.product ]
then
cat /boot/usb.product > strings/0x409/product
else
echo 'licheervnano' > strings/0x409/product
fi
mkdir configs/c.1/
mkdir functions/mass_storage.disk0
ln -s functions/mass_storage.disk0 configs/c.1/
echo 1 > functions/mass_storage.disk0/lun.0/removable
echo /dev/mmcblk0 > functions/mass_storage.disk0/lun.0/file
ls /sys/class/udc/ | cat > UDC
echo device > /proc/cviusb/otg_role
while true
do
sleep 1
busybox iostat
busybox uptime
busybox uname
sync
done
}
set -x
mkdir -p /dev
mount -t devtmpfs devtmpfs /dev
mkdir -p /proc
mount -t proc proc /proc
mkdir -p /sys
mount -t sysfs sysfs /sys
# mount -t debugfs debugfs /sys/kernel/debug
mkdir -p /boot
# wait ready
i=0
while [ ! -e /dev/mmcblk0p1 ] && [ $i -lt 5 ]; do
echo "Waiting for /dev/mmcblk0p1..."
sleep 1
i=$((i+1))
done
mount -o ro /dev/mmcblk0p1 /boot
ret=$?
if [ $ret -ne 0 ] || [ -e /boot/rec ]; then
echo "Mount boot failed, Entering recovery mode..."
msc
fi
# flashkey0=$(cat /sys/kernel/debug/gpio | grep 'User Key' | grep lo | wc -l)
# if [ "${flashkey0}" -ne 0 ]
# then
# msc
# fi
boot_key=0
for arg in $(cat /proc/cmdline); do
case "$arg" in
boot_key=*)
boot_key="${arg#boot_key=}"
;;
esac
done
if [ "${boot_key}" -eq 1 ] # boot key pressed
then
msc
fi
umount /dev/mmcblk0p1
mkdir /realroot
# parted -s /dev/mmcblk0 "resizepart 2 -0"
# echo "yes
# 100%
# " | parted ---pretend-input-tty /dev/mmcblk0 "resizepart 2 100%"
# #e2fsck -fvp /dev/mmcblk0p2
# resize2fs /dev/mmcblk0p2
mount -o rw /dev/mmcblk0p2 /realroot
mfail="$?"
if [ "${mfail}" -ne 0 ]
then
e2fsck -fvp /dev/mmcblk0p2
mount -o rw /dev/mmcblk0p2 /realroot
mfail="$?"
if [ "${mfail}" -ne 0 ]
then
msc
fi
fi
mount -t proc proc /realroot/proc
mount -t sysfs sysfs /realroot/sys
mount -t devtmpfs devtmpfs /realroot/dev
exec switch_root /realroot /sbin/init