board/raspberrypi: post-image customisations.
cover board/raspberrypi: post-image customisations.
Hi all.
I wanted to do use u-boot and mainline kernel sources with my raspies but in trying to do so, found that doing it required a lot of changes to the genimage cfg files.
All the files were basically the same, and I found that they, and the post-image script define constants which are no longer correct if the corresponding options are changed in buildroot.
(eg. BR2_LINUX_KERNEL_INTREE_DTS_NAME)
I've improved the situation by first removing the replication in the cfg files (consolidating them into a single generic file). And then parsing the .config file for the board specific pieces; like the device tree files, and the kernel target (zimage vs image).
Then I added some new options;
- Adding files to the boot partition,
Allowing me to include uboot.bin.
- Changing the kernel in the config.txt file,
Allowing me to boot uboot.bin.
- Specifying a different rootfs file,
Since i would like to use btrfs instead of ext4.
- An option to skip creating the full sdimg.
As I'm using btrfs, in some cases I only need the vfat boot blob from genimage.
There are a couple of aspects you might find questionable that I would welcome comments on;
The script now modifies the generic genimage.cfg file and creates a temporary cfg file to be used with genimage. I've chosen to place the file at; ${BUILD_DIR}/genimage.cfg
This might not be the best choice.
I'm using a conbination of grep and eval to pull specific values out of the .config file and get them into the script. That might not be best practice.
Maybe theres a cleaner way of accessing those variables?
Kind regards,
~rob.
Robert J. Heywood (8):
board/raspberrypi: Unify the genimage config files board/raspberrypi: post-image --overlays option. board/raspberrypi: post-image, include .config dfs files. board/raspberrypi: post-image, include .config kernel target. board/raspberrypi: post-image --file option board/raspberrypi: post-image --rootfs option board/raspberrypi: post-image --skip-sdimg option board/raspberrypi: post-image --kernel option
DEVELOPERS | 3 ++
...rrypi2.cfg => genimage-raspberrypi-generic.cfg} | 7 +--
board/raspberrypi/genimage-raspberrypi.cfg | 32 ------------
board/raspberrypi/genimage-raspberrypi0.cfg | 30 ------------
board/raspberrypi/genimage-raspberrypi0w.cfg | 31 ------------
board/raspberrypi/genimage-raspberrypi3-64.cfg | 32 ------------
board/raspberrypi/genimage-raspberrypi3.cfg | 33 -------------
board/raspberrypi/post-image.sh | 57 +++++++++++++++++++++-
8 files changed, 62 insertions(+), 163 deletions(-)
rename board/raspberrypi/{genimage-raspberrypi2.cfg => genimage-raspberrypi-generic.cfg} (85%)
delete mode 100644 board/raspberrypi/genimage-raspberrypi.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi0.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi0w.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi3-64.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi3.cfgSignature · 1 line
2.11.0
PATCH 1/8 board/raspberrypi: Unify the genimage config files
Add a new genimage config file containing all the common elements. The config file contains a marker which post-image.sh replaces with files defined in the board-specific .conf files.
Since I've substantially edited the way the post-image script works, I've added myself to the developers file for board/raspberrypi
---
DEVELOPERS | 3 ++
...rrypi2.cfg => genimage-raspberrypi-generic.cfg} | 3 +-
board/raspberrypi/genimage-raspberrypi.cfg | 32 ---------------------
board/raspberrypi/genimage-raspberrypi0.cfg | 30 --------------------
board/raspberrypi/genimage-raspberrypi0w.cfg | 31 --------------------
board/raspberrypi/genimage-raspberrypi3-64.cfg | 32 ---------------------
board/raspberrypi/genimage-raspberrypi3.cfg | 33 ----------------------
board/raspberrypi/post-image.sh | 17 +++++++++--
board/raspberrypi/raspberrypi.conf | 6 ++++
board/raspberrypi/raspberrypi0.conf | 4 +++
board/raspberrypi/raspberrypi0w.conf | 5 ++++
board/raspberrypi/raspberrypi2.conf | 4 +++
board/raspberrypi/raspberrypi3-64.conf | 6 ++++
board/raspberrypi/raspberrypi3.conf | 7 +++++
14 files changed, 51 insertions(+), 162 deletions(-)
rename board/raspberrypi/{genimage-raspberrypi2.cfg => genimage-raspberrypi-generic.cfg} (90%)
delete mode 100644 board/raspberrypi/genimage-raspberrypi.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi0.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi0w.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi3-64.cfg
delete mode 100644 board/raspberrypi/genimage-raspberrypi3.cfg
create mode 100644 board/raspberrypi/raspberrypi.conf
create mode 100644 board/raspberrypi/raspberrypi0.conf
create mode 100644 board/raspberrypi/raspberrypi0w.conf
create mode 100644 board/raspberrypi/raspberrypi2.conf
create mode 100644 board/raspberrypi/raspberrypi3-64.conf
create mode 100644 board/raspberrypi/raspberrypi3.confDEVELOPERS +3 -0
@@ -1820,6 +1820,9 @@ F: package/subversion/ N: RJ Ascani <[email protected]> F: package/azmq/ +N: Robert Heywood <[email protected]> +F: board/raspberrypi/ + N: Robert Rose <[email protected]> F: package/grpc/
board/raspberrypi/genimage-raspberrypi-generic.cfg renamed from board/raspberrypi/genimage-raspberrypi2.cfg +1 -2
@@ -1,13 +1,12 @@ image boot.vfat { vfat { files = { - "bcm2709-rpi-2-b.dtb", "rpi-firmware/bootcode.bin", "rpi-firmware/cmdline.txt", "rpi-firmware/config.txt", "rpi-firmware/fixup.dat", "rpi-firmware/start.elf", - "zImage" + {BOOT_FILES} } } size = 32M
board/raspberrypi/genimage-raspberrypi.cfg deleted +0 -32
@@ -1,32 +0,0 @@ -image boot.vfat { - vfat { - files = { - "bcm2708-rpi-b.dtb", - "bcm2708-rpi-b-plus.dtb", - "bcm2708-rpi-cm.dtb", - "rpi-firmware/bootcode.bin", - "rpi-firmware/cmdline.txt", - "rpi-firmware/config.txt", - "rpi-firmware/fixup.dat", - "rpi-firmware/start.elf", - "zImage" - } - } - size = 32M -} - -image sdcard.img { - hdimage { - } - - partition boot { - partition-type = 0xC - bootable = "true" - image = "boot.vfat" - } - - partition rootfs { - partition-type = 0x83 - image = "rootfs.ext4" - } -}
board/raspberrypi/genimage-raspberrypi0.cfg deleted +0 -30
@@ -1,30 +0,0 @@ -image boot.vfat { - vfat { - files = { - "bcm2708-rpi-b-plus.dtb", - "rpi-firmware/bootcode.bin", - "rpi-firmware/cmdline.txt", - "rpi-firmware/config.txt", - "rpi-firmware/fixup.dat", - "rpi-firmware/start.elf", - "zImage" - } - } - size = 32M -} - -image sdcard.img { - hdimage { - } - - partition boot { - partition-type = 0xC - bootable = "true" - image = "boot.vfat" - } - - partition rootfs { - partition-type = 0x83 - image = "rootfs.ext4" - } -}
board/raspberrypi/genimage-raspberrypi0w.cfg deleted +0 -31
@@ -1,31 +0,0 @@ -image boot.vfat { - vfat { - files = { - "bcm2708-rpi-0-w.dtb", - "rpi-firmware/bootcode.bin", - "rpi-firmware/cmdline.txt", - "rpi-firmware/config.txt", - "rpi-firmware/fixup.dat", - "rpi-firmware/start.elf", - "rpi-firmware/overlays", - "zImage" - } - } - size = 32M -} - -image sdcard.img { - hdimage { - } - - partition boot { - partition-type = 0xC - bootable = "true" - image = "boot.vfat" - } - - partition rootfs { - partition-type = 0x83 - image = "rootfs.ext4" - } -}
board/raspberrypi/genimage-raspberrypi3-64.cfg deleted +0 -32
@@ -1,32 +0,0 @@ -image boot.vfat { - vfat { - files = { - "bcm2710-rpi-3-b.dtb", - "bcm2710-rpi-3-b-plus.dtb", - "bcm2837-rpi-3-b.dtb", - "rpi-firmware/bootcode.bin", - "rpi-firmware/cmdline.txt", - "rpi-firmware/config.txt", - "rpi-firmware/fixup.dat", - "rpi-firmware/start.elf", - "Image" - } - } - size = 32M -} - -image sdcard.img { - hdimage { - } - - partition boot { - partition-type = 0xC - bootable = "true" - image = "boot.vfat" - } - - partition rootfs { - partition-type = 0x83 - image = "rootfs.ext4" - } -}
board/raspberrypi/genimage-raspberrypi3.cfg deleted +0 -33
@@ -1,33 +0,0 @@ -image boot.vfat { - vfat { - files = { - "bcm2710-rpi-3-b.dtb", - "bcm2710-rpi-3-b-plus.dtb", - "bcm2710-rpi-cm3.dtb", - "rpi-firmware/bootcode.bin", - "rpi-firmware/cmdline.txt", - "rpi-firmware/config.txt", - "rpi-firmware/fixup.dat", - "rpi-firmware/start.elf", - "rpi-firmware/overlays", - "zImage" - } - } - size = 32M -} - -image sdcard.img { - hdimage { - } - - partition boot { - partition-type = 0xC - bootable = "true" - image = "boot.vfat" - } - - partition rootfs { - partition-type = 0x83 - image = "rootfs.ext4" - } -}
board/raspberrypi/post-image.sh +15 -2
@@ -4,9 +4,14 @@ set -e BOARD_DIR="$(dirname $0)" BOARD_NAME="$(basename ${BOARD_DIR})" -GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_NAME}.cfg" +GENIMAGE_CFG="${BOARD_DIR}/genimage-raspberrypi-generic.cfg" GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" +if [ -e ${BOARD_DIR}/${BOARD_NAME}.conf ] +then + . ${BOARD_DIR}/${BOARD_NAME}.conf +fi + for arg in "$@" do case "${arg}" in
@@ -49,6 +54,14 @@ __EOF__ done +for i in ${!FILES[*]} +do + FILES[$i]="\"${FILES[$i]}\"," +done +SEDCMD_BOOTFILES=" -e 's/{BOOT_FILES}/${FILES[*]}/' " + +eval "sed ${SEDCMD_BOOTFILES} ${GENIMAGE_CFG}" > ${BUILD_DIR}/genimage.cfg + rm -rf "${GENIMAGE_TMP}" genimage \
@@ -56,6 +69,6 @@ genimage \ --tmppath "${GENIMAGE_TMP}" \ --inputpath "${BINARIES_DIR}" \ --outputpath "${BINARIES_DIR}" \ - --config "${GENIMAGE_CFG}" + --config "${BUILD_DIR}/genimage.cfg" exit $?
board/raspberrypi/raspberrypi.conf new file +6 -0
@@ -0,0 +1,6 @@ +FILES=( + "bcm2708-rpi-b.dtb" + "bcm2708-rpi-b-plus.dtb" + "bcm2708-rpi-cm.dtb" + "zImage" +)
board/raspberrypi/raspberrypi0.conf new file +4 -0
@@ -0,0 +1,4 @@ +FILES=( + "bcm2708-rpi-b-plus.dtb" + "zImage" +)
board/raspberrypi/raspberrypi0w.conf new file +5 -0
@@ -0,0 +1,5 @@ +FILES=( + "bcm2708-rpi-0-w.dtb" + "rpi-firmware/overlays" + "zImage" +)
board/raspberrypi/raspberrypi2.conf new file +4 -0
@@ -0,0 +1,4 @@ +FILES=( + "bcm2709-rpi-2-b.dtb" + "zImage" +)
board/raspberrypi/raspberrypi3-64.conf new file +6 -0
@@ -0,0 +1,6 @@ +FILES=( + "bcm2710-rpi-3-b.dtb" + "bcm2710-rpi-3-b-plus.dtb" + "bcm2837-rpi-3-b.dtb" + "Image" +)
board/raspberrypi/raspberrypi3.conf new file +7 -0
@@ -0,0 +1,7 @@ +FILES=( + "bcm2710-rpi-3-b.dtb" + "bcm2710-rpi-3-b-plus.dtb" + "bcm2710-rpi-cm3.dtb" + "rpi-firmware/overlays" + "zImage" +)
Signature · 1 line
2.11.0
PATCH 2/8 board/raspberrypi: post-image --overlays option.
In reply to Robert J. HeywoodPull the device tree overlays into the boot partition if the --overlays option is set.
In addition, --add-pi3-miniuart-bt-overlay now implies --overlays.
Since the board conf files no longer need to explicitly declare the overlays, the line including the overlays were removed from raspberrypi0w.conf and raspberrypi3.conf
--- board/raspberrypi/post-image.sh | 9 +++++++++ board/raspberrypi/raspberrypi0w.conf | 1 - board/raspberrypi/raspberrypi3.conf | 1 - 3 files changed, 9 insertions(+), 2 deletions(-)
board/raspberrypi/post-image.sh +9 -0
@@ -6,6 +6,7 @@ BOARD_DIR="$(dirname $0)" BOARD_NAME="$(basename ${BOARD_DIR})" GENIMAGE_CFG="${BOARD_DIR}/genimage-raspberrypi-generic.cfg" GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" +INCLUDE_OVERLAYS=false if [ -e ${BOARD_DIR}/${BOARD_NAME}.conf ] then
@@ -23,8 +24,12 @@ do # fixes rpi3 ttyAMA0 serial console dtoverlay=pi3-miniuart-bt __EOF__ + INCLUDE_OVERLAYS=true fi ;; + --overlays) + INCLUDE_OVERLAYS=true + ;; --aarch64) # Run a 64bits kernel (armv8) sed -e '/^kernel=/s,=.*,=Image,' -i "${BINARIES_DIR}/rpi-firmware/config.txt"
@@ -54,6 +59,10 @@ __EOF__ done +if $INCLUDE_OVERLAYS; then + FILES+=( "rpi-firmware/overlays" ) +fi + for i in ${!FILES[*]} do FILES[$i]="\"${FILES[$i]}\","
board/raspberrypi/raspberrypi0w.conf +0 -1
@@ -1,5 +1,4 @@ FILES=( "bcm2708-rpi-0-w.dtb" - "rpi-firmware/overlays" "zImage" )
board/raspberrypi/raspberrypi3.conf +0 -1
@@ -2,6 +2,5 @@ FILES=( "bcm2710-rpi-3-b.dtb" "bcm2710-rpi-3-b-plus.dtb" "bcm2710-rpi-cm3.dtb" - "rpi-firmware/overlays" "zImage" )
Signature · 1 line
2.11.0
PATCH 3/8 board/raspberrypi: post-image, include .config dfs files.
In reply to Robert J. HeywoodThis change pulls dts filenames from the .config file instead of specifying the required dts files in a board config file. This reduces duplication and makes it possible to specify different dts files in the config file to have it appear in the resultant image. You would want to do so if you were using mainline kernel sources.
The device tree declarations were removed from the board .conf files.
--- board/raspberrypi/post-image.sh | 7 +++++++ board/raspberrypi/raspberrypi.conf | 3 --- board/raspberrypi/raspberrypi0.conf | 1 - board/raspberrypi/raspberrypi0w.conf | 1 - board/raspberrypi/raspberrypi2.conf | 1 - board/raspberrypi/raspberrypi3-64.conf | 3 --- board/raspberrypi/raspberrypi3.conf | 3 --- 7 files changed, 7 insertions(+), 12 deletions(-)
board/raspberrypi/post-image.sh +7 -0
@@ -63,6 +63,13 @@ if $INCLUDE_OVERLAYS; then FILES+=( "rpi-firmware/overlays" ) fi +# Pull device tree names from the .config file. +eval `grep BR2_LINUX_KERNEL_INTREE_DTS_NAME .config` +for dts in $BR2_LINUX_KERNEL_INTREE_DTS_NAME +do + FILES+=( "$(basename $dts).dtb" ) +done + for i in ${!FILES[*]} do FILES[$i]="\"${FILES[$i]}\","
board/raspberrypi/raspberrypi.conf +0 -3
@@ -1,6 +1,3 @@ FILES=( - "bcm2708-rpi-b.dtb" - "bcm2708-rpi-b-plus.dtb" - "bcm2708-rpi-cm.dtb" "zImage" )
board/raspberrypi/raspberrypi0.conf +0 -1
@@ -1,4 +1,3 @@ FILES=( - "bcm2708-rpi-b-plus.dtb" "zImage" )
board/raspberrypi/raspberrypi0w.conf +0 -1
@@ -1,4 +1,3 @@ FILES=( - "bcm2708-rpi-0-w.dtb" "zImage" )
board/raspberrypi/raspberrypi2.conf +0 -1
@@ -1,4 +1,3 @@ FILES=( - "bcm2709-rpi-2-b.dtb" "zImage" )
board/raspberrypi/raspberrypi3-64.conf +0 -3
@@ -1,6 +1,3 @@ FILES=( - "bcm2710-rpi-3-b.dtb" - "bcm2710-rpi-3-b-plus.dtb" - "bcm2837-rpi-3-b.dtb" "Image" )
board/raspberrypi/raspberrypi3.conf +0 -3
@@ -1,6 +1,3 @@ FILES=( - "bcm2710-rpi-3-b.dtb" - "bcm2710-rpi-3-b-plus.dtb" - "bcm2710-rpi-cm3.dtb" "zImage" )
Signature · 1 line
2.11.0
PATCH 4/8 board/raspberrypi: post-image, include .config kernel target.
In reply to Robert J. HeywoodRead the .config file to find if either a zImage or an Image is being built, and include them in the final fat volume if so.
This change means that the config files specific for each version of the pi are now empty. So they are removed.
--- board/raspberrypi/post-image.sh | 9 +++++++++ board/raspberrypi/raspberrypi.conf | 3 --- board/raspberrypi/raspberrypi0.conf | 3 --- board/raspberrypi/raspberrypi0w.conf | 3 --- board/raspberrypi/raspberrypi2.conf | 3 --- board/raspberrypi/raspberrypi3-64.conf | 3 --- board/raspberrypi/raspberrypi3.conf | 3 --- 7 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 board/raspberrypi/raspberrypi.conf delete mode 100644 board/raspberrypi/raspberrypi0.conf delete mode 100644 board/raspberrypi/raspberrypi0w.conf delete mode 100644 board/raspberrypi/raspberrypi2.conf delete mode 100644 board/raspberrypi/raspberrypi3-64.conf delete mode 100644 board/raspberrypi/raspberrypi3.conf
board/raspberrypi/post-image.sh +9 -0
@@ -70,6 +70,15 @@ do FILES+=( "$(basename $dts).dtb" ) done +# Pull the kernel target from the .config file. +eval `egrep '^BR2_LINUX_KERNEL_Z?IMAGE=y$' .config` +if [ "${BR2_LINUX_KERNEL_IMAGE}" = 'y' ]; then + FILES+=( "Image" ) +fi +if [ "${BR2_LINUX_KERNEL_ZIMAGE}" = 'y' ]; then + FILES+=( "zImage" ) +fi + for i in ${!FILES[*]} do FILES[$i]="\"${FILES[$i]}\","
board/raspberrypi/raspberrypi.conf deleted +0 -3
@@ -1,3 +0,0 @@ -FILES=( - "zImage" -)
board/raspberrypi/raspberrypi0.conf deleted +0 -3
@@ -1,3 +0,0 @@ -FILES=( - "zImage" -)
board/raspberrypi/raspberrypi0w.conf deleted +0 -3
@@ -1,3 +0,0 @@ -FILES=( - "zImage" -)
board/raspberrypi/raspberrypi2.conf deleted +0 -3
@@ -1,3 +0,0 @@ -FILES=( - "zImage" -)
board/raspberrypi/raspberrypi3-64.conf deleted +0 -3
@@ -1,3 +0,0 @@ -FILES=( - "Image" -)
board/raspberrypi/raspberrypi3.conf deleted +0 -3
@@ -1,3 +0,0 @@ -FILES=( - "zImage" -)
Signature · 1 line
2.11.0
PATCH 5/8 board/raspberrypi: post-image --file option
In reply to Robert J. HeywoodAdd a mechanism for adding files to the boot partition.
Usage: --file=example.txt
--- board/raspberrypi/post-image.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
board/raspberrypi/post-image.sh +4 -1
@@ -55,6 +55,9 @@ __EOF__ gpu_mem="${arg:2}" sed -e "/^${gpu_mem%=*}=/s,=.*,=${gpu_mem##*=}," -i "${BINARIES_DIR}/rpi-firmware/config.txt" ;; + --file=*) + FILES+=("${arg:7}") + ;; esac done
@@ -81,7 +84,7 @@ fi for i in ${!FILES[*]} do - FILES[$i]="\"${FILES[$i]}\"," + FILES[$i]=$(echo "\"${FILES[$i]}\"," | sed -e 's/[\/&]/\\&/g') done SEDCMD_BOOTFILES=" -e 's/{BOOT_FILES}/${FILES[*]}/' "
Signature · 1 line
2.11.0
PATCH 6/8 board/raspberrypi: post-image --rootfs option
In reply to Robert J. HeywoodAdd an option to change the rootfs. This option is useful if you would like to create an image using something other than ext4.
Usage: --rootfs=example
--- board/raspberrypi/genimage-raspberrypi-generic.cfg | 2 +- board/raspberrypi/post-image.sh | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
board/raspberrypi/genimage-raspberrypi-generic.cfg +1 -1
@@ -24,6 +24,6 @@ image sdcard.img { partition rootfs { partition-type = 0x83 - image = "rootfs.ext4" + image = "{ROOTFS}" } }
board/raspberrypi/post-image.sh +6 -1
@@ -7,6 +7,7 @@ BOARD_NAME="$(basename ${BOARD_DIR})" GENIMAGE_CFG="${BOARD_DIR}/genimage-raspberrypi-generic.cfg" GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" INCLUDE_OVERLAYS=false +ROOTFS="rootfs.ext4" if [ -e ${BOARD_DIR}/${BOARD_NAME}.conf ] then
@@ -58,6 +59,9 @@ __EOF__ --file=*) FILES+=("${arg:7}") ;; + --rootfs=*) + ROOTFS="${arg:9}" + ;; esac done
@@ -87,8 +91,9 @@ do FILES[$i]=$(echo "\"${FILES[$i]}\"," | sed -e 's/[\/&]/\\&/g') done SEDCMD_BOOTFILES=" -e 's/{BOOT_FILES}/${FILES[*]}/' " +SEDCMD_ROOTFS=" -e 's/{ROOTFS}/${ROOTFS}/' " -eval "sed ${SEDCMD_BOOTFILES} ${GENIMAGE_CFG}" > ${BUILD_DIR}/genimage.cfg +eval "sed ${SEDCMD_BOOTFILES} ${SEDCMD_ROOTFS} ${GENIMAGE_CFG}" > ${BUILD_DIR}/genimage.cfg rm -rf "${GENIMAGE_TMP}"
Signature · 1 line
2.11.0
PATCH 7/8 board/raspberrypi: post-image --skip-sdimg option
In reply to Robert J. HeywoodAdd an option to disable the sd-card.img.
This is useful for when youre not building any compatible rootfs.
--- board/raspberrypi/genimage-raspberrypi-generic.cfg | 2 ++ board/raspberrypi/post-image.sh | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)
board/raspberrypi/genimage-raspberrypi-generic.cfg +2 -0
@@ -12,6 +12,7 @@ image boot.vfat { size = 32M } +{SDIMG_START} image sdcard.img { hdimage { }
@@ -27,3 +28,4 @@ image sdcard.img { image = "{ROOTFS}" } } +{SDIMG_END}
board/raspberrypi/post-image.sh +5 -1
@@ -8,6 +8,7 @@ GENIMAGE_CFG="${BOARD_DIR}/genimage-raspberrypi-generic.cfg" GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" INCLUDE_OVERLAYS=false ROOTFS="rootfs.ext4" +SEDCMD_SDIMG=" -e '/{SDIMG_.*}/d' " if [ -e ${BOARD_DIR}/${BOARD_NAME}.conf ] then
@@ -62,6 +63,9 @@ __EOF__ --rootfs=*) ROOTFS="${arg:9}" ;; + --skip-sdimg) + SEDCMD_SDIMG=" -e '/{SDIMG_START}/,/{SDIMG_END}/d' " + ;; esac done
@@ -93,7 +97,7 @@ done SEDCMD_BOOTFILES=" -e 's/{BOOT_FILES}/${FILES[*]}/' " SEDCMD_ROOTFS=" -e 's/{ROOTFS}/${ROOTFS}/' " -eval "sed ${SEDCMD_BOOTFILES} ${SEDCMD_ROOTFS} ${GENIMAGE_CFG}" > ${BUILD_DIR}/genimage.cfg +eval "sed ${SEDCMD_BOOTFILES} ${SEDCMD_ROOTFS} ${SEDCMD_SDIMG} ${GENIMAGE_CFG}" > ${BUILD_DIR}/genimage.cfg rm -rf "${GENIMAGE_TMP}"
Signature · 1 line
2.11.0
PATCH 8/8 board/raspberrypi: post-image --kernel option
In reply to Robert J. HeywoodAdd an option to specify the kernel to boot.
This can be used to enable uboot on the pi.
--- board/raspberrypi/post-image.sh | 3 +++ 1 file changed, 3 insertions(+)
board/raspberrypi/post-image.sh +3 -0
@@ -66,6 +66,9 @@ __EOF__ --skip-sdimg) SEDCMD_SDIMG=" -e '/{SDIMG_START}/,/{SDIMG_END}/d' " ;; + --kernel=*) + sed -e "/^kernel=/s,=.*,=${arg:9}," -i "${BINARIES_DIR}/rpi-firmware/config.txt" + ;; esac done
Signature · 1 line
2.11.0
cover board/raspberrypi: post-image customisations.
In reply to Robert J. HeywoodHi Robert,
Thank you for this work, excellent to see the raspberrypi support improved. We
discussed this at the Buildroot developer meeting.
However, we would like to suggest a slightly different approach that is more
amenable to reuse in other context and also simplifies things in general, we think. See below for our thoughts and suggestions. Thus, the series is marked as Changes Requested in patchwork.
Quoted 5 lines · Robert J. Heywood
Hi all.
I wanted to do use u-boot and mainline kernel sources with my raspies but in trying to do so, found that doing it required a lot of changes to the genimage cfg files.
Note that the intention is actually that when you change the configuration of
your target, you also change the genimage.cfg file. That said, if it is easy to support more use cases with a single genimage.cfg file (especially if there are in-tree use cases as well), that is something we might want to support in the provided genimage.cfg files.
Quoted 9 lines
All the files were basically the same, and I found that they, and the post-image script define constants which are no longer correct if the corresponding options are changed in buildroot.
(eg.BR2_LINUX_KERNEL_INTREE_DTS_NAME)I've improved the situation by first removing the replication in the cfg files (consolidating them into a single generic file). And then parsing the .config file for the board specific pieces; like the device tree files, and the kernel target (zimage vs image).
This .config approach we don't like. Instead, we think it is more appropriate
to add support for wildcards to genimage itself (and send that change upstream to pengutronix as well). That way, you can add "*.dtb" to genimage.cfg instead of the current board-specific names.
This approach can then be reused for other boards as well, like the freescale
boards on which you probably based this approach. Back in the day that approach of a post-image script that autodiscovers things looked like the right thing to do, but it is actually somewhat complicated and confusing.
Quoted 4 lines
Then I added some new options;
- Adding files to the boot partition,
Allowing me to include uboot.bin.
If you want to do something like this, I really think it's more appropriate to
make a custom genimage.cfg and config.txt that includes everything you want. Note that if you make a custom genimage.cfg, you also don't need to use the raspberrypi post-image script. Instead, use support/scripts/genimage.sh as the post-image script.
For the zImage vs. image, you could use "*mage" but I actually think it's more
appropriate to keep separate genimage.cfg files for them.
Quoted 2 lines
- Changing the kernel in the config.txt file,
Allowing me to boot uboot.bin.
Cfr. above.
In fact, I don't really like the way the post-image script is updating the
config.txt. I think it makes much more sense to have a different config.txt for each board instead of SEDing it. There are two options to handle this: either copy the board-specific config.txt in the post-image script, or (more generically) extend support/scripts/genimage.cfg with options that point to directories/files that have to be copied to IMAGES_DIR before running genimage.
Quoted 2 lines
- Specifying a different rootfs file, Since i would like to use btrfs instead of ext4.
This one certainly is better done in a custom genimage.cfg.
Quoted 3 lines
- An option to skip creating the full sdimg.
As I'm using btrfs, in some cases I only need the vfat boot blob from genimage.
Again, make a custom genimage.cfg.
Quoted 7 lines
There are a couple of aspects you might find questionable that I would welcome comments on;
The script now modifies the generic genimage.cfg file and creates a temporary cfg file to be used with genimage. I've chosen to place the file at; ${BUILD_DIR}/genimage.cfg
This might not be the best choice.
The freescale scripts now use mktemp, but actually I prefer your choice of
putting it in BUILD_DIR.
Quoted 3 lines
I'm using a conbination of grep and eval to pull specific values out of the .config file and get them into the script. That might not be best practice.
I personally prefer to use 'make printvars VARS=...' because you can also
extract make-derived variables that way (e.g. LINUX_IMAGE_NAME to get the zImage/image). But either way is fine.
Regards,
Arnout
Quoted 31 lines
Maybe theres a cleaner way of accessing those variables?
Kind regards,
~rob.Robert J. Heywood (8):
board/raspberrypi: Unify the genimage config files board/raspberrypi: post-image --overlays option. board/raspberrypi: post-image, include .config dfs files. board/raspberrypi: post-image, include .config kernel target. board/raspberrypi: post-image --file option board/raspberrypi: post-image --rootfs option board/raspberrypi: post-image --skip-sdimg option board/raspberrypi: post-image --kernel optionDEVELOPERS | 3 ++ ...rrypi2.cfg => genimage-raspberrypi-generic.cfg} | 7 +-- board/raspberrypi/genimage-raspberrypi.cfg | 32 ------------ board/raspberrypi/genimage-raspberrypi0.cfg | 30 ------------ board/raspberrypi/genimage-raspberrypi0w.cfg | 31 ------------ board/raspberrypi/genimage-raspberrypi3-64.cfg | 32 ------------ board/raspberrypi/genimage-raspberrypi3.cfg | 33 ------------- board/raspberrypi/post-image.sh | 57 +++++++++++++++++++++- 8 files changed, 62 insertions(+), 163 deletions(-) rename board/raspberrypi/{genimage-raspberrypi2.cfg => genimage-raspberrypi-generic.cfg} (85%) delete mode 100644 board/raspberrypi/genimage-raspberrypi.cfg delete mode 100644 board/raspberrypi/genimage-raspberrypi0.cfg delete mode 100644 board/raspberrypi/genimage-raspberrypi0w.cfg delete mode 100644 board/raspberrypi/genimage-raspberrypi3-64.cfg delete mode 100644 board/raspberrypi/genimage-raspberrypi3.cfg
cover board/raspberrypi: post-image customisations.
Hi Arnout.
Thanks for your reply.
In retrospect I probably should have reached out and asked if any of this would be wanted prior to submitting it. c?est la vie.
Quoted 11 lines · Arnout Vandecappelle
Hi Robert,
Thank you for this work, excellent to see the raspberrypi support improved. We
discussed this at the Buildroot developer meeting.However, we would like to suggest a slightly different approach that is more
amenable to reuse in other context and also simplifies things in general, we think. See below for our thoughts and suggestions. Thus, the series is marked as Changes Requested in patchwork.On 29/01/2019 14:23, Robert J. Heywood wrote:
Quoted 8 lines
Quoted 5 lines
Hi all.
I wanted to do use u-boot and mainline kernel sources with my raspies but in trying to do so, found that doing it required a lot of changes to the genimage cfg files.
Note that the intention is actually that when you change the configuration of
your target, you also change the genimage.cfg file.
This is something that I found pretty confusing. It seems illogical to have to set the same options in two distinct places.
Quoted 5 lines
That said, if it is easy to
support more use cases with a single genimage.cfg file (especially if there are in-tree use cases as well), that is something we might want to support in the provided genimage.cfg files.
It would be better if the genimage config file could contain a placeholder, such as "devicetree" or "kernel" which could then be specified on the commandline. Then when buildroot calls genimage, it could fill in the relevant parameters.
It would simplify a lot of the cfg files across all of the boards.
Quoted 11 lines
Quoted 5 lines
--snip--
I've improved the situation by first removing the replication in the cfg files (consolidating them into a single generic file). And then parsing the .config file for the board specific pieces; like the device tree files, and the kernel target (zimage vs image).This .config approach we don't like. Instead, we think it is more appropriate
to add support for wildcards to genimage itself (and send that change upstream to pengutronix as well). That way, you can add "*.dtb" to genimage.cfg instead of the current board-specific names.
genimage sort of already has this feature for directories. It's a shame we cant use that feature here, since the pi's bootloader uses device trees in the root of the partition. It would have been nice to have a dtb folder.
Quoted 4 lines
This approach can then be reused for other boards as well, like the freescale
boards on which you probably based this approach. Back in the day that approach of a post-image script that autodiscovers things looked like the right thing to do, but it is actually somewhat complicated and confusing.
I wasn't aware the freescale configs did something similar. That's pretty interesting.
Quoted 7 lines
If you want to do something like this, I really think it's more appropriate to
make a custom genimage.cfg and config.txt that includes everything you want. Note that if you make a custom genimage.cfg, you also don't need to use the raspberrypi post-image script. Instead, usesupport/scripts/genimage.shas the post-image script.
Quoted 7 lines
For the zImage vs. image, you could use "*mage" but I actually think it's more
appropriate to keep separate genimage.cfg files for them.Quoted 2 lines
- Changing the kernel in the config.txt file,
Allowing me to boot uboot.bin.Cfr. above.
I was really hoping I'd be able to get away with not having to maintain a separate set of files outside of buildroot that basically just replicate functionality already inside of it.
But I guess what I could do is setup my CI such that it watches the buildroot genimage.cfg files and alerts me if any incompatible changes happen.
Quoted 7 lines
In fact, I don't really like the way the post-image script is updating the
config.txt. I think it makes much more sense to have a different config.txt for each board instead of SEDing it. There are two options to handle this: either copy the board-specific config.txt in the post-image script, or (more generically) extend support/scripts/genimage.cfg with options that point to directories/files that have to be copied toIMAGES_DIRbefore running genimage.
I enjoy the sed approach. It means buildroot is able to take advantage of upstream changes to the config.txt file, and we're not made to maintain a hoard of copies with minor changes.
Quoted 4 lines
Quoted 3 lines
- Specifying a different rootfs file,
Since i would like to use btrfs instead of ext4.
Quoted 8 lines
This one certainly is better done in a custom genimage.cfg.
Quoted 3 lines
- An option to skip creating the full sdimg.
As I'm using btrfs, in some cases I only need the vfat boot blob from genimage.Again, make a custom genimage.cfg.
very well.
I have a script that configures buildroot as I want it, from defconfigs and fragments. I'll also make it spit out a genimage file.
It'll be easy to do there since that script has access to the devicetree/kernel variables from the defconfig anyway.
Quoted 8 lines
Quoted 4 lines
I'm using a conbination of grep and eval to pull specific values out of the .config file and get them into the script. That might not be best practice.
I personally prefer to use 'make printvars VARS=...' because you can also
extract make-derived variables that way (e.g.LINUX_IMAGE_NAMEto get the zImage/image). But either way is fine.
I think I'll use that from now on. I find the eval approach confusing to look at. :)
kind regards, rob.
cover board/raspberrypi: post-image customisations.
Quoted 25 lines · Robert Heywood
Hi Arnout.
Thanks for your reply.
In retrospect I probably should have reached out and asked if any of this would be wanted prior to submitting it. c?est la vie.Quoted 17 lines · Arnout Vandecappelle
? Hi Robert,
? Thank you for this work, excellent to see the raspberrypi support improved. We discussed this at the Buildroot developer meeting.
? However, we would like to suggest a slightly different approach that is more amenable to reuse in other context and also simplifies things in general, we think. See below for our thoughts and suggestions. Thus, the series is marked as Changes Requested in patchwork.
Quoted 5 lines · Robert J. Heywood
Hi all.
I wanted to do use u-boot and mainline kernel sources with my raspies but in trying to do so, found that doing it required a lot of changes to the genimage cfg files.
Quoted 5 lines
Quoted 2 lines
? Note that the intention is actually that when you change the configuration of your target, you also change the genimage.cfg file.
This is something that I found pretty confusing. It seems illogical to have to set the same options in two distinct places.
True, but this patch series doesn't really change that, does it? E.g. for the
zImage/image kernel, you still have to select both the correct BR2_LINUX_KERNEL_xxIMAGE option and pass --kernel= (rather than updating config.txt).
Quoted 9 lines
Quoted 5 lines
That said, if it is easy to
support more use cases with a single genimage.cfg file (especially if there are in-tree use cases as well), that is something we might want to support in the provided genimage.cfg files.It would be better if the genimage config file could contain a placeholder, such as "devicetree" or "kernel" which could then be specified on the commandline. Then when buildroot calls genimage, it could fill in the relevant parameters.
That is indeed a good idea! Maybe both better and easier to implement than
wildcard support in genimage...
Quoted 56 lines
It would simplify a lot of the cfg files across all of the boards.
Quoted 11 lines
Quoted 5 lines
--snip--
I've improved the situation by first removing the replication in the cfg files (consolidating them into a single generic file). And then parsing the .config file for the board specific pieces; like the device tree files, and the kernel target (zimage vs image).? This .config approach we don't like. Instead, we think it is more appropriate to add support for wildcards to genimage itself (and send that change upstream to pengutronix as well). That way, you can add "*.dtb" to genimage.cfg instead of the current board-specific names.
genimage sort of already has this feature for directories. It's a shame we cant use that feature here, since the pi's bootloader uses device trees in the root of the partition. It would have been nice to have a dtb folder.
Quoted 4 lines
? This approach can then be reused for other boards as well, like the freescale boards on which you probably based this approach. Back in the day that approach of a post-image script that autodiscovers things looked like the right thing to do, but it is actually somewhat complicated and confusing.
I wasn't aware the freescale configs did something similar. That's pretty interesting.
Quoted 7 lines
? If you want to do something like this, I really think it's more appropriate to make a custom genimage.cfg and config.txt that includes everything you want. Note that if you make a custom genimage.cfg, you also don't need to use the raspberrypi post-image script. Instead, use
support/scripts/genimage.shas the post-image script.Quoted 7 lines
? For the zImage vs. image, you could use "*mage" but I actually think it's more appropriate to keep separate genimage.cfg files for them.
Quoted 2 lines
- Changing the kernel in the config.txt file,
?? Allowing me to boot uboot.bin.? Cfr. above.
I was really hoping I'd be able to get away with not having to maintain a separate set of files outside of buildroot that basically just replicate functionality already inside of it.
But I guess what I could do is setup my CI such that it watches the buildroot genimage.cfg files and alerts me if any incompatible changes happen.Quoted 7 lines
? In fact, I don't really like the way the post-image script is updating the config.txt. I think it makes much more sense to have a different config.txt for each board instead of SEDing it. There are two options to handle this: either copy the board-specific config.txt in the post-image script, or (more generically) extend support/scripts/genimage.cfg with options that point to directories/files that have to be copied to
IMAGES_DIRbefore running genimage.
Quoted 3 lines
I enjoy the sed approach. It means buildroot is able to take advantage of upstream changes to the config.txt file, and we're not made to maintain a hoard of copies with minor changes.
Only, config.txt doesn't come from upstream; it comes frompackage/rpi-firmware/config.txt and it says "we recommend you to change it to fit your needs".
Okay, it goes on saying to override it in a post-build script, but that's
because there is no other way to put a file into genimage.cfg.
Regards,
Arnout
Quoted 34 lines
Quoted 11 lines
Quoted 2 lines
- Specifying a different rootfs file,
?? Since i would like to use btrfs instead of ext4.? This one certainly is better done in a custom genimage.cfg.
Quoted 3 lines
- An option to skip creating the full sdimg.
?? As I'm using btrfs, in some cases I only need the vfat boot blob ?? from genimage.? Again, make a custom genimage.cfg.
very well.
I have a script that configures buildroot as I want it, from defconfigs and fragments. I'll also make it spit out a genimage file.
It'll be easy to do there since that script has access to the devicetree/kernel variables from the defconfig anyway.Quoted 8 lines
Quoted 4 lines
I'm using a conbination of grep and eval to pull specific values out of the .config file and get them into the script. That might not be best practice.
? I personally prefer to use 'make printvars VARS=...' because you can also extract make-derived variables that way (e.g.
LINUX_IMAGE_NAMEto get the zImage/image). But either way is fine.I think I'll use that from now on. I find the eval approach confusing to look at. :)
kind regards, rob.
cover board/raspberrypi: post-image customisations.
Quoted 12 lines · Arnout Vandecappelle
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Hi all.
I wanted to do use u-boot and mainline kernel sources with my raspies but in trying to do so, found that doing it required a lot of changes to the genimage cfg files.
? Note that the intention is actually that when you change the configuration of
your target, you also change the genimage.cfg file.
Quoted 8 lines
Quoted 2 lines
This is something that I found pretty confusing. It seems illogical to have to set the same options in two distinct places.
True, but this patch series doesn't really change that, does it? E.g. for the
zImage/image kernel, you still have to select both the correctBR2_LINUX_KERNEL_xxIMAGEoption and pass --kernel= (rather than updating config.txt).
No. Not for the kernel. I could have changed that, but the script already does some level of faffing with the "kernel=" option. And I decided it would be better to not change the script's behaviour for that option, in case anyone were depending on that particular behaviour.
I was referring to the device trees. Which are first defined in the .config, and then have to be redefined in each genimage.cfg.
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
? In fact, I don't really like the way the post-image script is updating the
config.txt. I think it makes much more sense to have a different config.txt for each board instead of SEDing it. There are two options to handle this: either copy the board-specific config.txt in the post-image script, or (more generically) extend support/scripts/genimage.cfg with options that point to directories/files that have to be copied toIMAGES_DIRbefore running genimage.I enjoy the sed approach. It means buildroot is able to take advantage of upstream changes to the config.txt file, and we're not made to maintain a hoard of copies with minor changes.
Quoted 7 lines
Only, config.txt doesn't come from upstream; it comes from
package/rpi-firmware/config.txtand it says "we recommend you to change it to fit your needs".Okay, it goes on saying to override it in a post-build script, but that's
because there is no other way to put a file into genimage.cfg.
The package/rpi-firmware/config.txt file is downloaded from the raspberrypi github. While its true that the file won't change without someone updating the commit in the respective .mk file, its not a file that buildroot maintains or authored. It is being pulled from upstream.
If you really wanted to keep separate versions of config.txt around for each board, genimage does support renaming files as it copies them into the image. You could feasibly add a line such as this to each cfg file;
file config.txt { image = "board/raspberrypi/config_raspberrypi0w.txt" }Quoted 4 lines
Regards,
Arnout
kind regards, rob.
cover board/raspberrypi: post-image customisations.
Robert, All,
On 2019-02-11 11:17 +0000, Robert Heywood spake thusly:
Quoted 11 lines · Arnout Vandecappelle
Quoted 7 lines
Only, config.txt doesn't come from upstream; it comes from
package/rpi-firmware/config.txtand it says "we recommend you to change it to fit your needs".Okay, it goes on saying to override it in a post-build script, but that's
because there is no other way to put a file into genimage.cfg.The
package/rpi-firmware/config.txtfile is downloaded from the raspberrypi github. While its true that the file won't change without someone updating the commit in the respective .mk file,
Absolutely not. The config.txt file *is* bundled in Buildroot.
Quoted 2 lines
its not a file that buildroot
maintains or authored. It is being pulled from upstream.
Yes it is, just do: "git log package/rpi-firmware/config.txt" and you'll see that it is a file we have had since the inception of the rpi-firmware package in Buildroot.
We may have used the upstream one as inspirtion, though.
Quoted 5 lines
If you really wanted to keep separate versions of config.txt around for each board, genimage does support renaming files as it copies them into the image.
You could feasibly add a line such as this to each cfg file;file config.txt { image = "board/raspberrypi/config_raspberrypi0w.txt" }
Actually, I think this is a very good idea. But that is just my position, others may disagree...
Again, you have to recognise that the defconfig files we have in Buildroot are just basic configurations and setups, that are there just to help one bootstrap a local build for a custom project/hobby/...
Again, my position is that, if one's project/hobby/... needs a custom linux/uboot/firmware/etc... config file, then one should handle it locally, using the files in Buildroot as inspiration.
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'