Skip to contentSkip to conversation

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

PATCH Applied Vladimir Savelev 2 participants 3 messages Sep 25 – Oct 11

lore
Share & tools
lore
#0 lore raw

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

The board can boot from its 16 MiB SPI-NOR flash 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 Zero 2W does:

- 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 5376K 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 5376K partition, and linux-net.fragment enables the board's on-board Gigabit Ethernet (emac0 + Motorcomm PHY);

- 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-zero3/fit.its         |  38 ++
 .../orangepi/orangepi-zero3/genimage-spi.cfg  |  42 ++
 .../orangepi-zero3/linux-net.fragment         |   8 +
 board/orangepi/orangepi-zero3/linux.fragment  | 567 ++++++++++++++++++
 board/orangepi/orangepi-zero3/post-image.sh   |  34 ++
 board/orangepi/orangepi-zero3/uboot.fragment  |   6 +
 configs/orangepi_zero3_defconfig              |   8 +-
 7 files changed, 701 insertions(+), 2 deletions(-)
 create mode 100644 board/orangepi/orangepi-zero3/fit.its
 create mode 100644 board/orangepi/orangepi-zero3/genimage-spi.cfg
 create mode 100644 board/orangepi/orangepi-zero3/linux-net.fragment
 create mode 100644 board/orangepi/orangepi-zero3/linux.fragment
 create mode 100755 board/orangepi/orangepi-zero3/post-image.sh
 create mode 100644 board/orangepi/orangepi-zero3/uboot.fragment
board/orangepi/orangepi-zero3/fit.its new file +38 -0
new file mode 100644
index 0000000000..cdd5afe05c
@@ -0,0 +1,38 @@
+/dts-v1/;
+
+/ {
+	description = "OrangePi Zero 3 - 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 3 device tree";
+			data = /incbin/("dtb.bin");
+			type = "flat_dt";
+			arch = "arm64";
+			compression = "none";
+			load = <0x43000000>;
+		};
+	};
+
+	configurations {
+		default = "config";
+
+		config {
+			description = "OrangePi Zero 3";
+			kernel = "kernel";
+			fdt = "fdt";
+		};
+	};
+};
board/orangepi/orangepi-zero3/genimage-spi.cfg new file +42 -0

42 lines not on this page · raw message

board/orangepi/orangepi-zero3/linux-net.fragment new file +8 -0
new file mode 100644
index 0000000000..7d1c59c943
@@ -0,0 +1,8 @@
+# Zero 3 networking on top of the trimmed kernel (linux.fragment disables
+# Ethernet): the board has an on-board Gigabit PHY (Motorcomm YT8531) on emac0.
+CONFIG_ETHERNET=y
+CONFIG_NET_VENDOR_STMICRO=y
+CONFIG_STMMAC_ETH=y
+CONFIG_STMMAC_PLATFORM=y
+CONFIG_DWMAC_SUN8I=y
+CONFIG_MOTORCOMM_PHY=y
board/orangepi/orangepi-zero3/linux.fragment new file +567 -0

567 lines not on this page · raw message

board/orangepi/orangepi-zero3/post-image.sh new file +34 -0
new file mode 100755
index 0000000000..588e25bbb7
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# OrangePi Zero 3 — build the FIT image, then assemble the SD card and the
+# SPI-NOR images.
+#
+# The kernel is LZMA-compressed so that it fits the 5376K 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-zero3.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-zero3/uboot.fragment new file +6 -0
new file mode 100644
index 0000000000..070a0b7fbb
@@ -0,0 +1,6 @@
+# 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 available.
+CONFIG_BOOTCOMMAND="sf probe; if sf read 0x48000000 0xE0000 0x540000; then setenv bootargs console=ttyS0,115200 root=/dev/mtdblock2 rootfstype=squashfs mtdparts=spi0.0:896k(u-boot),5376k(kernel),10112k(rootfs); bootm 0x48000000; fi; run distro_bootcmd"
+CONFIG_BOOTDELAY=2
configs/orangepi_zero3_defconfig +6 -2
index c6aa9c991a..bfaec7ebd5 100644
@@ -7,8 +7,8 @@ BR2_TARGET_GENERIC_ISSUE="Welcome to Orangepi Zero3"
 BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
 BR2_SYSTEM_DHCP="eth0"
 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-zero3/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.6"
@@ -18,9 +18,12 @@ BR2_LINUX_KERNEL_INTREE_DTS_NAME="allwinner/sun50i-h618-orangepi-zero3"
 BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME=y
 BR2_LINUX_KERNEL_INSTALL_TARGET=y
 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
+BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/orangepi/orangepi-zero3/linux.fragment board/orangepi/orangepi-zero3/linux-net.fragment"
 BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_ROOTFS_EXT2_SIZE="130M"
+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
@@ -39,5 +42,6 @@ BR2_TARGET_UBOOT_NEEDS_ATF_BL31=y
 BR2_TARGET_UBOOT_SPL=y
 BR2_TARGET_UBOOT_SPL_NAME="u-boot-sunxi-with-spl.bin"
 BR2_TARGET_UBOOT_CUSTOM_MAKEOPTS="SCP=/dev/null"
+BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="board/orangepi/orangepi-zero3/uboot.fragment"
 BR2_PACKAGE_HOST_GENIMAGE=y
 BR2_PACKAGE_HOST_UBOOT_TOOLS=y
Signature · 6 lines
2.53.0

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

PATCH 2/2 board/orangepi/orangepi-zero2w, orangepi-zero3: set the hostname

Give both boards a recognizable hostname instead of the generic "buildroot". The name is used for the login banner and sent as the DHCP hostname (option 12), so the board is easy to identify on the network.

---
 configs/orangepi_zero2w_defconfig | 1 +
 configs/orangepi_zero3_defconfig  | 1 +
 2 files changed, 2 insertions(+)
configs/orangepi_zero2w_defconfig +1 -0
index 2da4372fdb..c815028405 100644
@@ -4,6 +4,7 @@ BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_12=y
 BR2_GLOBAL_PATCH_DIR="board/orangepi/orangepi-zero2w/patches"
 BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
 BR2_TARGET_GENERIC_ISSUE="Welcome to Orangepi Zero2W"
+BR2_TARGET_GENERIC_HOSTNAME="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="board/orangepi/orangepi-zero2w/post-image.sh"
configs/orangepi_zero3_defconfig +1 -0
index bfaec7ebd5..61a4f3855b 100644
@@ -4,6 +4,7 @@ BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_12=y
 BR2_GLOBAL_PATCH_DIR="board/orangepi/orangepi-zero3/patches"
 BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
 BR2_TARGET_GENERIC_ISSUE="Welcome to Orangepi Zero3"
+BR2_TARGET_GENERIC_HOSTNAME="orangepi-zero3"
 BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
 BR2_SYSTEM_DHCP="eth0"
 BR2_ROOTFS_POST_BUILD_SCRIPT="board/orangepi/common/post-build.sh"
Signature · 6 lines
2.53.0

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

Re: [Buildroot] [PATCH 2/2] board/orangepi/orangepi-zero2w, orangepi-zero3: set the hostname

Quoted 5 lines · Vladimir Savelev

Give both boards a recognizable hostname instead of the generic "buildroot". The name is used for the login banner and sent as the DHCP hostname (option 12), so the board is easy to identify on the network.

Applied to master, thanks!

Best regards,

Thomas Petazzoni

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot