Skip to contentSkip to conversation

board/orangepi/orangepi-zero2w: add SPI-NOR image support

PATCH New Vladimir Savelev 1 participant 1 message Sep 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board/orangepi/orangepi-zero2w: add SPI-NOR image support

The board can boot from its 16 MiB SPI-NOR flash (zb25vq128) in addition to the SD card. Add the board files needed to build the SPI-NOR image, leaving the existing SD card image unchanged.

The SPI-NOR image is assembled with genimage, like the other boards do:

- genimage-spi.cfg describes the raw flash layout (U-Boot, FIT kernel and squashfs rootfs at fixed offsets, no partition table) and is fed to the generic genimage wrapper;

- post-image.sh LZMA-compresses the kernel, because the uncompressed Image does not fit the 6400K kernel partition, wraps the kernel and the DTB into a FIT image, and then assembles both the SD card and the SPI-NOR images;

- linux.fragment trims the generic arm64 defconfig so that the

    compressed kernel fits in the 6400K partition;

- uboot.fragment sets CONFIG_BOOTCOMMAND to boot the FIT from SPI and fall back to the default distro boot (SD card), so that the same U-Boot boots both images.

Both images are built by the same defconfig; the SPI-NOR image uses the squashfs rootfs, while the SD card image keeps the ext2 rootfs.

---
 board/orangepi/orangepi-zero2w/fit.its        |  38 ++
 .../orangepi/orangepi-zero2w/genimage-spi.cfg |  38 ++
 board/orangepi/orangepi-zero2w/linux.fragment | 567 ++++++++++++++++++
 board/orangepi/orangepi-zero2w/post-image.sh  |  34 ++
 board/orangepi/orangepi-zero2w/uboot.fragment |   7 +
 configs/orangepi_zero2w_defconfig             |   8 +-
 6 files changed, 690 insertions(+), 2 deletions(-)
 create mode 100644 board/orangepi/orangepi-zero2w/fit.its
 create mode 100644 board/orangepi/orangepi-zero2w/genimage-spi.cfg
 create mode 100644 board/orangepi/orangepi-zero2w/linux.fragment
 create mode 100755 board/orangepi/orangepi-zero2w/post-image.sh
 create mode 100644 board/orangepi/orangepi-zero2w/uboot.fragment
board/orangepi/orangepi-zero2w/fit.its new file +38 -0
new file mode 100644
index 0000000000..8f638f20f6
@@ -0,0 +1,38 @@
+/dts-v1/;
+
+/ {
+	description = "OrangePi Zero 2W - Linux kernel + FDT (SPI-NOR)";
+	#address-cells = <1>;
+
+	images {
+		kernel {
+			description = "Linux kernel";
+			data = /incbin/("kernel.lzma");
+			type = "kernel";
+			arch = "arm64";
+			os = "linux";
+			compression = "lzma";
+			load = <0x41000000>;
+			entry = <0x41000000>;
+		};
+
+		fdt {
+			description = "OrangePi Zero 2W device tree";
+			data = /incbin/("dtb.bin");
+			type = "flat_dt";
+			arch = "arm64";
+			compression = "none";
+			load = <0x43000000>;
+		};
+	};
+
+	configurations {
+		default = "config";
+
+		config {
+			description = "OrangePi Zero 2W";
+			kernel = "kernel";
+			fdt = "fdt";
+		};
+	};
+};
board/orangepi/orangepi-zero2w/genimage-spi.cfg new file +38 -0
new file mode 100644
index 0000000000..3da9cddbd5
@@ -0,0 +1,38 @@
+# OrangePi Zero 2W — SPI-NOR image (16 MiB, zb25vq128).
+#
+# The layout is dictated by the U-Boot environment in
+# board/orangepi/orangepi-zero2w/uboot_env.txt: the mtdparts/bootcmd there use
+# the very same offsets, so both files must be kept in sync.
+#
+#   u-boot @ 0        (896K)
+#   kernel @ 896K     (6400K)   FIT: LZMA-compressed kernel + DTB
+#   rootfs @ 7296K    (9088K)   squashfs (XZ)
+
+flash nor-16M-256 {
+	pebsize = 4K
+	numpebs = 4K
+	minimum-io-unit-size = 256
+}
+
+image spi.img {
+	flash {
+	}
+	flashtype = "nor-16M-256"
+
+	partition u-boot {
+		image = "u-boot-sunxi-with-spl.bin"
+		size = 896K
+	}
+
+	partition kernel {
+		image = "fit.itb"
+		offset = 896K
+		size = 6400K
+	}
+
+	partition rootfs {
+		image = "rootfs.squashfs"
+		offset = 7296K
+		size = 9088K
+	}
+}
board/orangepi/orangepi-zero2w/linux.fragment new file +567 -0

567 lines not on this page · raw message

board/orangepi/orangepi-zero2w/post-image.sh new file +34 -0
new file mode 100755
index 0000000000..214b88af8b
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# OrangePi Zero 2W — build the FIT image, then assemble the SD card and the
+# SPI-NOR images.
+#
+# The kernel is LZMA-compressed so that it fits the 6400K kernel partition.
+# A FIT image is a device tree, so fit.its is compiled with dtc (as mkimage
+# would do internally — but Buildroot's host-uboot-tools is built with an empty
+# CONFIG_MKIMAGE_DTC_PATH, so mkimage cannot invoke dtc here).
+#
+# The raw 16 MiB flash layout is described in genimage-spi.cfg; both images are
+# assembled by the generic genimage wrapper (support/scripts/genimage.sh).
+
+set -e
+
+BOARD_DIR="$(dirname "$0")"
+
+# FIT: LZMA-compressed kernel + DTB.
+xz --format=lzma -9 -c "${BINARIES_DIR}/Image" > "${BINARIES_DIR}/kernel.lzma"
+
+DTB="${BINARIES_DIR}/allwinner/sun50i-h618-orangepi-zero2w.dtb"
+[ -f "${DTB}" ] || { echo "ERROR: DTB not found: ${DTB}" >&2; exit 1; }
+cp "${DTB}" "${BINARIES_DIR}/dtb.bin"
+
+# The /incbin/ paths in fit.its are relative to the working directory.
+cp "${BOARD_DIR}/fit.its" "${BINARIES_DIR}/fit.its"
+(cd "${BINARIES_DIR}" && \
+	"${HOST_DIR}/bin/dtc" -I dts -O dtb -p 500 -o fit.itb fit.its)
+
+# SD card image (genimage.cfg is generated by the common OrangePi post-build).
+support/scripts/genimage.sh -c "${BINARIES_DIR}/genimage.cfg"
+
+# SPI-NOR image.
+support/scripts/genimage.sh -c "${BOARD_DIR}/genimage-spi.cfg"
board/orangepi/orangepi-zero2w/uboot.fragment new file +7 -0
new file mode 100644
index 0000000000..d047504835
@@ -0,0 +1,7 @@
+# Boot the SPI-NOR image first: read the FIT from offset 0xE0000 and bootm it.
+# If that fails, fall back to the default boot flow (distro boot: SD card, USB,
+# network).  Setting CONFIG_BOOTCOMMAND only replaces the default 'bootcmd',
+# while keeping distro_bootcmd, so the same U-Boot can boot both sdcard.img
+# (SD) and spi.img (SPI-NOR).
+CONFIG_BOOTCOMMAND="sf probe; if sf read 0x48000000 0xE0000 0x640000; then setenv bootargs console=ttyS0,115200 root=/dev/mtdblock2 rootfstype=squashfs mtdparts=spi0.0:896k(u-boot),6400k(kernel),9088k(rootfs); bootm 0x48000000; fi; run distro_bootcmd"
+CONFIG_BOOTDELAY=2
configs/orangepi_zero2w_defconfig +6 -2
index c2030b05c2..2da4372fdb 100644
@@ -6,12 +6,13 @@ BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
 BR2_TARGET_GENERIC_ISSUE="Welcome to Orangepi Zero2W"
 BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
 BR2_ROOTFS_POST_BUILD_SCRIPT="board/orangepi/common/post-build.sh"
-BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
-BR2_ROOTFS_POST_SCRIPT_ARGS="-c $(BINARIES_DIR)/genimage.cfg"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/orangepi/orangepi-zero2w/post-image.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS=""
 BR2_LINUX_KERNEL=y
 BR2_LINUX_KERNEL_CUSTOM_VERSION=y
 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.3"
 BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
+BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/orangepi/orangepi-zero2w/linux.fragment"
 BR2_LINUX_KERNEL_DTS_SUPPORT=y
 BR2_LINUX_KERNEL_INTREE_DTS_NAME="allwinner/sun50i-h618-orangepi-zero2w"
 BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME=y
@@ -20,6 +21,8 @@ BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
 BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_ROOTFS_EXT2_SIZE="256M"
+BR2_TARGET_ROOTFS_SQUASHFS=y
+BR2_TARGET_ROOTFS_SQUASHFS4_XZ=y
 # BR2_TARGET_ROOTFS_TAR is not set
 BR2_TARGET_ARM_TRUSTED_FIRMWARE=y
 BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION=y
@@ -30,6 +33,7 @@ BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
 BR2_TARGET_UBOOT_CUSTOM_VERSION=y
 BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2024.10"
 BR2_TARGET_UBOOT_BOARD_DEFCONFIG="orangepi_zero2w"
+BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="board/orangepi/orangepi-zero2w/uboot.fragment"
 BR2_TARGET_UBOOT_NEEDS_DTC=y
 BR2_TARGET_UBOOT_NEEDS_PYLIBFDT=y
 BR2_TARGET_UBOOT_NEEDS_OPENSSL=y
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot