From 258be9baad6222d687d9637bef23c1b1d1aa72e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20K=C3=B6hl?= Date: Tue, 21 Nov 2023 16:00:14 +0100 Subject: [PATCH] chore: add files of U-Boot experiment --- boot/uboot/README.md | 12 +++++ boot/uboot/boot.sh | 63 ++++++++++++++++++++++++ boot/uboot/boot_env.py | 13 +++++ boot/uboot/boot_spare_env.py | 12 +++++ boot/uboot/configs/rpi_3_rugpi_defconfig | 61 +++++++++++++++++++++++ boot/uboot/rpi3_config.txt | 12 +++++ 6 files changed, 173 insertions(+) create mode 100644 boot/uboot/README.md create mode 100644 boot/uboot/boot.sh create mode 100644 boot/uboot/boot_env.py create mode 100644 boot/uboot/boot_spare_env.py create mode 100644 boot/uboot/configs/rpi_3_rugpi_defconfig create mode 100755 boot/uboot/rpi3_config.txt diff --git a/boot/uboot/README.md b/boot/uboot/README.md new file mode 100644 index 0000000..7902e23 --- /dev/null +++ b/boot/uboot/README.md @@ -0,0 +1,12 @@ +To build `boot.scr` from `boot.sh`, run: + +```sh +mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Rugpi Boot Script" -d .boot.sh boot.scr +``` + +To build `u-boot.bin`, run: + +```sh +CROSS_COMPILE=aarch64-linux-gnu- make rpi_3_rugpi_defconfig +CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc) +``` \ No newline at end of file diff --git a/boot/uboot/boot.sh b/boot/uboot/boot.sh new file mode 100644 index 0000000..76dc81c --- /dev/null +++ b/boot/uboot/boot.sh @@ -0,0 +1,63 @@ +echo Rugpi Boot Script +echo ================= + + +############################################################################## +# Load Rugpi environment files. +############################################################################## + +if load mmc 0:1 ${loadaddr} default.env; then + env import -c ${loadaddr} ${filesize} +fi +if load mmc 0:1 ${loadaddr} boot_spare.env; then + env import -c ${loadaddr} ${filesize} +fi + + +############################################################################## +# Set `bootpart` to the active partition set (default or spare). +############################################################################## + +if test ${bootpart} = ""; then + # If `bootpart` is not set, boot from the second partition. + setenv bootpart 2 +fi + +# If `boot_spare` is set, boot from the spare partition set. +if test ${boot_spare} = 1; then + setexpr bootpart 5 - ${bootpart} + # Next time, boot from the default partition set again. + setenv boot_spare 0 + env export -c ${loadaddr} boot_spare + save mmc 0:1 ${loadaddr} default.env ${filesize} +fi + + +############################################################################## +# Load environment file `boot.env` from active partition set. +############################################################################## + +if load mmc 0:${bootpart} ${loadaddr} boot.env; then + env import -c ${loadaddr} ${filesize} +fi + + +############################################################################## +# Print information and boot kernel. +############################################################################## + +echo Bootpart: ${bootpart} +echo Cmdline: ${cmdline} + +load mmc 0:${bootpart} ${kernel_addr_r} ${kernel_file} +setenv kernel_comp_addr_r ${loadaddr} +setenv kernel_comp_size 0x4000000 +setenv bootargs ${cmdline} +# Try booting `zImage`. +booti ${kernel_addr_r} - ${fdt_addr} +# Try booting `uImage`. +bootm ${kernel_addr_r} - ${fdt_addr} + +echo "Error loading kernel... Rebooting in 10 seconds." +sleep 10 +reset diff --git a/boot/uboot/boot_env.py b/boot/uboot/boot_env.py new file mode 100644 index 0000000..7b8a9ac --- /dev/null +++ b/boot/uboot/boot_env.py @@ -0,0 +1,13 @@ +import binascii +import struct + +cmdline = "console=serial0,115200 console=tty1 rootfstype=ext4 fsck.repair=yes rootwait panic=60 root=PARTUUID=2ddb0742-05 init=/usr/bin/rugpi-ctrl" +environ = [f"cmdline={cmdline}".encode("ascii")] + +data = b"\0".join(environ) + b"\n" + +crc = binascii.crc32(data) + +with open("boot.env", "wb") as env_file: + env_file.write(struct.pack("