diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ccdad51..385ccda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: build-system: strategy: matrix: - device: [ pico-mini-b, pico-plus, pico-pro-max ] + device: [ pico-ultra-flash ] # runs-on: "cirun-aws-amd64--${{ github.run_id }}" runs-on: ubuntu-latest needs: build-rootfs @@ -44,9 +44,9 @@ jobs: python-is-python3 passwd openssl openssh-server \ openssh-client vim file cpio rsync" - name: build system - run: ./system.sh -f rootfs-alpine.tar.gz -d ${{ matrix.device }} + run: sudo ./system.sh -f rootfs-alpine.tar.gz -d ${{ matrix.device }} - name: upload update.img uses: actions/upload-artifact@v4 with: - name: ${{ matrix.device }}-sysupgrade - path: output/${{ matrix.device }}-sysupgrade.img + name: ${{ matrix.device }} + path: output/* diff --git a/.gitmodules b/.gitmodules index 639e721..9c4572b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "sdk"] path = sdk - url = https://github.com/soyflourbread/luckfox-pico-sdk.git + url = https://github.com/bcarrella/luckfox-pico-sdk.git diff --git a/README.md b/README.md index 263fbb4..11a7d1a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Linux systems for LuckFox Pico series, including Pico Mini b, Pico Plus and Pico Pro Max (all models with SPI flash). +Pico Ultra, Pico Ultra W (with EMMC) Currently only [Alpine Linux](https://alpinelinux.org/) is available. @@ -57,3 +58,4 @@ Just fork this repo and trigger Github Actions after you made your changes! For example, * To add software packages, edit `bootstrap.sh`. * To change files in the system image, edit `overlay/`. +* To load Dynamic Kernel Modules, first use scripts in sdk submodule to configure and build the Linux Kernel, then edit `/oem/usr/ko/insmod_ko.sh` to load resulting .ko modules at runtime. diff --git a/bootstrap.sh b/bootstrap.sh index 781987a..53b6183 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -22,15 +22,49 @@ apk del -r shadow # Install SSH apk add openssh rc-update add sshd default +chown 0:0 /var/empty # Extra stuff apk add mtd-utils-ubi apk add bottom -apk add neofetch +#apk add neofetch +apk add e2fsprogs-extra + +# Install iptables-legacy +apk add iptables-legacy +rc-update add iptables-legacy +ln -s /usr/sbin/iptables-legacy /usr/sbin/iptables + +# Install tailscale +apk add tailscale +rc-update add tailscale default + +# install wireguard +apk add wireguard-tools + +# Install Chrony +apk add chrony +rc-update add chrony default + +# install curl +apk add curl + +# install nano +apk add nano + +# install ca-certificates +apk add ca-certificates +update-ca-certificates + +# install staticroute +rc-update add staticroute + +# install ethtool +apk add ehtool # Clear apk cache rm -rf /var/cache/apk/* # Packaging rootfs -for d in bin etc lib sbin usr; do tar c "$d" | tar x -C /extrootfs; done -for dir in dev proc root run sys var oem userdata; do mkdir /extrootfs/${dir}; done +for d in bin etc lib sbin usr var; do tar c "$d" | tar x -C /extrootfs; done +for dir in dev proc root run sys oem userdata; do mkdir /extrootfs/${dir}; done diff --git a/overlay/etc/local.d/load_modules.start b/overlay/etc/local.d/load_modules.start new file mode 100755 index 0000000..bcec351 --- /dev/null +++ b/overlay/etc/local.d/load_modules.start @@ -0,0 +1,6 @@ +#!/bin/bash + +if [ -f /oem/usr/ko/insmod_ko.sh ]; then + chmod a+x /oem/usr/ko/insmod_ko.sh + /oem/usr/ko/insmod_ko.sh +fi \ No newline at end of file diff --git a/overlay/etc/local.d/load_sysctl.start b/overlay/etc/local.d/load_sysctl.start new file mode 100644 index 0000000..12967c8 --- /dev/null +++ b/overlay/etc/local.d/load_sysctl.start @@ -0,0 +1,3 @@ +#!/bin/bash + +sysctl -p /etc/sysctl.d/*.conf diff --git a/overlay/etc/motd b/overlay/etc/motd new file mode 100644 index 0000000..562b5d9 --- /dev/null +++ b/overlay/etc/motd @@ -0,0 +1,39 @@ +Welcome to Alpine! + +The Alpine Wiki contains a large amount of how-to guides and general +information about administrating Alpine systems. +See . + +You can setup the system with the command: setup-alpine + +You may change this message by editing /etc/motd. + + + + ==== ==== + ======== ======== + =========== =========== + ==== =============== ==== + ==== ========= ==== + ==== ==== + = = + ============ ============ + ================================ + ====== ========== ======= + ===== ======= ===== + ========== === =========== + ============ ============ + ======= ====== + ====== ===== + ============ + ======== + ==== + + + === === === ======= === === ========= ====== === === + === === === === === === === === === === === === + === === === === ====== === === === ===== + === === === === ====== ========= === === ===== + === === === === === === === === === === === === + ========= ====== ======= === === === ====== === === + diff --git a/overlay/etc/network/interfaces b/overlay/etc/network/interfaces index 2b9e5c1..a6ef8ad 100644 --- a/overlay/etc/network/interfaces +++ b/overlay/etc/network/interfaces @@ -1,10 +1,14 @@ auto lo iface lo inet loopback auto eth0 -iface eth0 inet dhcp - udhcpc_opts -t 1 +iface eth0 inet static + address 192.168.199.100 + netmask 255.255.255.0 + up ip route add 192.168.15.0/24 via 192.168.199.59 + gateway 192.168.199.1 + auto usb0 iface usb0 inet static address 172.32.0.93 netmask 255.255.255.0 - gateway 172.32.0.1 + \ No newline at end of file diff --git a/overlay/etc/sysctl.d/99-tailscale.conf b/overlay/etc/sysctl.d/99-tailscale.conf new file mode 100644 index 0000000..4234b54 --- /dev/null +++ b/overlay/etc/sysctl.d/99-tailscale.conf @@ -0,0 +1 @@ +net.ipv4.ip_forward = 1 diff --git a/overlay/usr/bin/link_mount b/overlay/usr/bin/link_mount index caf02f2..5173993 100755 --- a/overlay/usr/bin/link_mount +++ b/overlay/usr/bin/link_mount @@ -1,17 +1,42 @@ #!/bin/sh -bootmedium=spi_nand +eval $(cat /proc/cmdline | grep -o ' storagemedia=[^ ]*') +bootmedium=$storagemedia linkdev(){ -if [ ! -d "/dev/block/by-name" ];then -mkdir -p /dev/block/by-name -cd /dev/block/by-name -ln -sf /dev/mtd0 env -ln -sf /dev/mtd1 idblock -ln -sf /dev/mtd2 uboot -ln -sf /dev/mtd3 boot -ln -sf /dev/mtd4 oem -ln -sf /dev/mtd5 userdata -ln -sf /dev/mtd6 rootfs -fi } + if [ ! -d "/dev/block/by-name" ];then + mkdir -p /dev/block/by-name + cd /dev/block/by-name + case $storagemedia in + mtd|spi_nand|slc_nand) + ln -sf /dev/mtd0 env + ln -sf /dev/mtd1 idblock + ln -sf /dev/mtd2 uboot + ln -sf /dev/mtd3 boot + ln -sf /dev/mtd4 oem + ln -sf /dev/mtd5 userdata + ln -sf /dev/mtd6 rootfs + ;; + sd) + ln -sf /dev/mmcblk1p1 env + ln -sf /dev/mmcblk1p2 idblock + ln -sf /dev/mmcblk1p3 uboot + ln -sf /dev/mmcblk1p4 boot + ln -sf /dev/mmcblk1p5 oem + ln -sf /dev/mmcblk1p6 userdata + ln -sf /dev/mmcblk1p7 rootfs + ;; + emmc) + ln -sf /dev/mmcblk0p1 env + ln -sf /dev/mmcblk0p2 idblock + ln -sf /dev/mmcblk0p3 uboot + ln -sf /dev/mmcblk0p4 boot + ln -sf /dev/mmcblk0p5 oem + ln -sf /dev/mmcblk0p6 userdata + ln -sf /dev/mmcblk0p7 rootfs + ;; + + esac + fi +} mount_part(){ if [ -z "$1" -o -z "$2" -o -z "$3" ];then echo "Invalid paramter, exit !!!" @@ -25,8 +50,15 @@ mountpt=$2 part_fstype=$3 part_realdev=$(realpath $part_dev) if [ ! -d $mountpt ]; then - if [ "$mountpt" = "IGNORE" -a "emmc" = "$bootmedium" ];then + if [ "$mountpt" = "IGNORE" -a "sd" = "$bootmedium" ];then + if [ "$root_dev" = "$part_realdev" ];then + mount -o remount,rw / + resize2fs $part_dev + fi + return 0; + elif [ "$mountpt" = "IGNORE" -a "emmc" = "$bootmedium" ];then if [ "$root_dev" = "$part_realdev" ];then + mount -o remount,rw / resize2fs $part_dev fi return 0; @@ -37,6 +69,21 @@ if [ ! -d $mountpt ]; then fi if test -h $part_dev; then case $bootmedium in + sd) + if [ "$root_dev" = "$part_realdev" ];then + resize2fs $part_dev + else + e2fsck -y $part_dev + mount -t $part_fstype $part_dev $mountpt + if [ $? -eq 0 ]; then + resize2fs $part_dev + tune2fs $part_dev -L $partname + else + echo "mount $partname error, try to format..." + mke2fs -F -L $partname $part_dev && tune2fs -c 0 -i 0 $part_dev && mount -t $part_fstype $part_dev $mountpt + fi + fi + ;; emmc) if [ "$root_dev" = "$part_realdev" ];then resize2fs $part_dev @@ -52,7 +99,7 @@ case $bootmedium in fi fi ;; - spi_nand|slc_nand) + mtd|spi_nand|slc_nand) if [ $partname = "rootfs" ];then echo "rootfs mount on $root_dev" elif [ "$part_fstype" = "ubifs" ]; then @@ -153,9 +200,14 @@ case $bootmedium in esac fi } +case $bootmedium in + sd) fstype=ext4 ;; + emmc) fstype=ext4 ;; + mtd|spi_nand|slc_nand) fstype=ubifs ;; +esac case $1 in start) linkdev; -mount_part rootfs IGNORE ubifs ; -mount_part oem /oem ubifs ; -mount_part userdata /userdata ubifs ; +mount_part rootfs IGNORE $fstype ; +mount_part oem /oem $fstype ; +mount_part userdata /userdata $fstype ; ;; linkdev) linkdev ; ;; stop) printf stop $0 finished\n ;; *) echo Usage: $0 {start|stop} exit 1 ;; esac diff --git a/rootfs.sh b/rootfs.sh index 4019943..e711ee0 100755 --- a/rootfs.sh +++ b/rootfs.sh @@ -27,6 +27,7 @@ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # Create docker docker container rm -f armv7alpine docker run \ + --platform=linux/arm/v7 \ --name armv7alpine \ --net host \ --mount type=bind,source=./bootstrap.sh,target=/bootstrap.sh \ @@ -47,9 +48,13 @@ overlay() { sed -i -e "s/{TTY_PORT}/$TTY_PORT/g" "$OVERLAY_WORKSPACE/etc/securetty" sed -i -e "s/{TTY_PORT}/$TTY_PORT/g" "$OVERLAY_WORKSPACE/etc/inittab" + chown -R 0:0 $OVERLAY_WORKSPACE + echo "ARH DEBUG: ls -la $OVERLAY_WORKSPACE" + ls -la $OVERLAY_WORKSPACE rsync -a "$OVERLAY_WORKSPACE/" "$ROOTFS_WORKSPACE_MNT/" rm -rf "$OVERLAY_WORKSPACE" - + echo "ARH DEBUG: ls -la $ROOTFS_WORKSPACE_MNT" + ls -la $ROOTFS_WORKSPACE_MNT echo "Include /etc/ssh/sshd_config.d/*.conf" >> \ "$ROOTFS_WORKSPACE_MNT/etc/ssh/sshd_config" diff --git a/sdk b/sdk index 8dde6a3..63c6675 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 8dde6a3209dffdaedf4c3fe0d5367ee413987951 +Subproject commit 63c66750b218d1cb32160764b2a99f8eeffadcf5 diff --git a/system.sh b/system.sh index 7ed64b2..6b1d32b 100755 --- a/system.sh +++ b/system.sh @@ -1,7 +1,7 @@ #!/bin/bash ROOTFS_NAME="rootfs-alpine.tar.gz" -DEVICE_NAME="pico-mini-b" +DEVICE_NAME="pico-ultra-flash" while getopts ":f:d:" opt; do case ${opt} in @@ -14,16 +14,6 @@ while getopts ":f:d:" opt; do esac done -DEVICE_ID="6" -case $DEVICE_NAME in - pico-mini-b) DEVICE_ID="6" ;; - pico-plus) DEVICE_ID="7" ;; - pico-pro-max) DEVICE_ID="8" ;; - *) - echo "Invalid device: ${DEVICE_NAME}." - exit 1 - ;; -esac rm -rf sdk/sysdrv/custom_rootfs/ mkdir -p sdk/sysdrv/custom_rootfs/ @@ -36,9 +26,31 @@ source env_install_toolchain.sh popd || exit rm -rf .BoardConfig.mk -echo "$DEVICE_ID" | ./build.sh lunch +case $DEVICE_NAME in + pico-mini-sd) ln -s project/cfg/BoardConfig_IPC/BoardConfig-SD_CARD-Buildroot-RV1103_Luckfox_Pico_Mini-IPC.mk .BoardConfig.mk ;; + pico-mini-flash) ln -s project/cfg/BoardCnfig_IPC/BoardConfig-SPI_NAND-Buildroot-RV1103_Luckfox_Pico_Mini-IPC.mk .BoardConfig.mk ;; + pico-plus-sd) ln -s project/cfg/BoardConfig_IPC/BoardConfig-SD_CARD-Buildroot-RV1103_Luckfox_Pico_Plus-IPC.mk .BoardConfig.mk ;; + pico-plus-flash) ln -s project/cfg/BoardConfig_IPC/BoardConfig-SPI_NAND-Buildroot-RV1103_Luckfox_Pico_Plus-IPC.mk .BoardConfig.mk ;; + pico-ultra-flash) ln -s project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_Ultra-IPC.mk .BoardConfig.mk ;; + pico-ultra-w-flash) ln -s project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_Ultra_W-IPC.mk .BoardConfig.mk ;; + pico-pro-max-flash) ln -s project/cfg/BoardConfig_IPC/BoardConfig-SPI_NAND-Busybox-RV1106_Luckfox_Pico_Pro_Max-IPC_FASTBOOT.mk .BoardConfig.mk ;; + pico-pro-max-sd) ln -s project/cfg/BoardConfig_IPC/BoardConfig-SD_CARD-Buildroot-RV1106_Luckfox_Pico_Pro_Max-IPC.mk .BoardConfig.mk ;; + *) + echo "Invalid device: ${DEVICE_NAME}." + exit 1 + ;; +esac + +#echo "$DEVICE_ID" | ./build.sh lunch echo "export RK_CUSTOM_ROOTFS=../sysdrv/custom_rootfs/$ROOTFS_NAME" >> .BoardConfig.mk -echo "export RK_BOOTARGS_CMA_SIZE=\"1M\"" >> .BoardConfig.mk +#echo "export RK_BOOTARGS_CMA_SIZE=\"1M\"" >> .BoardConfig.mk + +#change size on SD +if echo "$DEVICE_NAME" | grep -q "\-sd"; then + echo "export RK_PARTITION_CMD_IN_ENV=\"32K(env),512K@32K(idblock),256K(uboot),32M(boot),512M(oem),256M(userdata),30G(rootfs)\"" >> .BoardConfig.mk +fi + +#cat .BoardConfig.mk # build sysdrv - rootfs ./build.sh uboot @@ -54,4 +66,4 @@ popd || exit rm -rf output mkdir -p output -cp sdk/output/image/update.img "output/$DEVICE_NAME-sysupgrade.img" +cp sdk/output/image/* "output/"