From bcd880c8e4085c943a055bcb2e2dc78feda33bea Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 19 May 2019 19:04:07 +0300 Subject: Modularise image handling Signed-off-by: Laurent Pinchart --- images/CrOS.sh | 48 +++++++++++++++ images/FIT.sh | 83 +++++++++++++++++++++++++ images/srec.sh | 18 ++++++ images/uImage.sh | 9 +++ kbuild.sh | 167 +++------------------------------------------------ platforms/gen3.sh | 2 +- platforms/imx7.sh | 2 +- platforms/omap3.sh | 2 +- platforms/omap4+.sh | 2 +- platforms/scarlet.sh | 2 +- platforms/soraka.sh | 2 +- platforms/x86.sh | 2 +- platforms/zynqmp.sh | 2 +- 13 files changed, 173 insertions(+), 168 deletions(-) create mode 100644 images/CrOS.sh create mode 100644 images/FIT.sh create mode 100644 images/srec.sh create mode 100644 images/uImage.sh diff --git a/images/CrOS.sh b/images/CrOS.sh new file mode 100644 index 0000000..eb9ff05 --- /dev/null +++ b/images/CrOS.sh @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: GPL-2.0+ + +if [[ $arch != arm64 && $arch != x86 ]] ; then + echo "CrOS image unsupported on architecture $arch" + exit 1 +fi + +source "${kbuild_root}/images/FIT.sh" || exit 1 + +make_CrOS_image() { + local boot_dir=$output_dir/arch/$arch/boot + local bootloader + local config + local vmlinuz + + if [[ $arch == arm64 ]] ; then + make_FIT_image + vmlinuz=$boot_dir/kernel_fdt.itb + elif [[ $arch == x86 ]] ; then + vmlinuz=$boot_dir/bzImage + fi + + if [[ -f $opt_bootloader ]] ; then + bootloader=$opt_bootloader + else + dd if=/dev/zero of=$boot_dir/bootloader bs=512 count=1 + bootloader=$boot_dir/bootloader + fi + + if [[ -f $opt_cmdline_file ]] ; then + config=$opt_cmdline_file + else + echo "$CMDLINE" > $boot_dir/cmdline + config=$boot_dir/cmdline + fi + + vbutil_kernel \ + --pack $boot_dir/vmlinuz.image \ + --version 1 \ + --vmlinuz $vmlinuz \ + --arch $arch \ + --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ + --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ + --config $config \ + --bootloader $bootloader +} + +image_file=$output_dir/arch/$arch/boot/vmlinuz.image diff --git a/images/FIT.sh b/images/FIT.sh new file mode 100644 index 0000000..0ed5482 --- /dev/null +++ b/images/FIT.sh @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: GPL-2.0+ + +make_FIT_image() { + local kernel_its=$output_dir/arch/$arch/boot/kernel_fdt.its + + cat < $kernel_its +/dts-v1/; +/ { + description = "Kernel + FDT image for $board board"; + #address-cells = <1>; + + images { + kernel { + description = "Linux kernel"; + data = /incbin/("$output_dir/arch/$arch/boot/$image_kernel"); + type = "kernel"; + arch = "$arch"; + os = "linux"; + compression = "none"; + load = <$LOADADDR>; + entry = <$LOADADDR>; + hash-1 { + algo = "crc32"; + }; + hash-2 { + algo = "sha1"; + }; + }; +EOF + + local dtb + + for dtb in $DTBS ; do + local src=${dtb/:*/} + local dst=${dtb/*:/} + dst=${dst/*\//} + + cat <> $kernel_its + fdt-$dst { + description = "Flattened Device Tree blob $dst"; + data = /incbin/("$output_dir/arch/$arch/boot/dts/$src"); + type = "flat_dt"; + arch = "$arch"; + compression = "none"; + hash-1 { + algo = "crc32"; + }; + hash-2 { + algo = "sha1"; + }; + }; +EOF + done + + local config=$(echo $DTBS | sed 's/.*[:/]//') + cat <> $kernel_its + }; + + configurations { + default = "conf-$config"; +EOF + for dtb in $DTBS ; do + local dst=${dtb/*:/} + dst=${dst/*\//} + + cat <> $kernel_its + conf-$dst { + description = "Boot Linux kernel with $dst blob"; + kernel = "kernel"; + fdt = "fdt-$dst"; + }; +EOF + done + + cat <> $kernel_its + }; +}; +EOF + + PATH="$output_dir/scripts/dtc:$PATH" mkimage -f $kernel_its ${kernel_its/its/itb} +} + +image_file=$output_dir/arch/$arch/boot/kernel_fdt.itb diff --git a/images/srec.sh b/images/srec.sh new file mode 100644 index 0000000..6f89b92 --- /dev/null +++ b/images/srec.sh @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0+ + +make_srec_image() { + local image=$output_dir/arch/$arch/boot/$image_kernel + + cat $image | lzma -z -e > $image.xz + objcopy -I binary -O srec --srec-forceS3 --srec-len 516 \ + $image.xz $image.xz.srec + + for dtb in $DTBS ; do + local src=${dtb/:*/} + + objcopy -I binary -O srec --srec-forceS3 --srec-len 516 \ + $src $src.srec + done +} + +image_file=$output_dir/arch/$arch/boot/$kernel_image.xz.srec diff --git a/images/uImage.sh b/images/uImage.sh new file mode 100644 index 0000000..40e7cf3 --- /dev/null +++ b/images/uImage.sh @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0+ + +make_uImage_image() { + mkimage -A $arch -O linux -T kernel -C none -a $LOADADDR -e $LOADADDR \ + -n "Linux-${version}" -d $output_dir/arch/$arch/boot/$kernel_image \ + $output_dir/arch/$arch/boot/uImage +} + +image_file=$output_dir/arch/$arch/boot/uImage diff --git a/kbuild.sh b/kbuild.sh index 50f8d21..d91e67b 100755 --- a/kbuild.sh +++ b/kbuild.sh @@ -173,165 +173,12 @@ version=$(cat $output_dir/include/generated/utsrelease.h | cut -d '"' -f 2) # Create the image # -make_fit_image() { - local kernel_its=$output_dir/arch/$arch/boot/kernel_fdt.its - - cat < $kernel_its -/dts-v1/; -/ { - description = "Kernel + FDT image for $board board"; - #address-cells = <1>; - - images { - kernel { - description = "Linux kernel"; - data = /incbin/("$output_dir/arch/$arch/boot/$image_kernel"); - type = "kernel"; - arch = "$arch"; - os = "linux"; - compression = "none"; - load = <$LOADADDR>; - entry = <$LOADADDR>; - hash-1 { - algo = "crc32"; - }; - hash-2 { - algo = "sha1"; - }; - }; -EOF - - local dtb - - for dtb in $DTBS ; do - local src=${dtb/:*/} - local dst=${dtb/*:/} - dst=${dst/*\//} - - cat <> $kernel_its - fdt-$dst { - description = "Flattened Device Tree blob $dst"; - data = /incbin/("$output_dir/arch/$arch/boot/dts/$src"); - type = "flat_dt"; - arch = "$arch"; - compression = "none"; - hash-1 { - algo = "crc32"; - }; - hash-2 { - algo = "sha1"; - }; - }; -EOF - done - - local config=$(echo $DTBS | sed 's/.*[:/]//') - cat <> $kernel_its - }; - - configurations { - default = "conf-$config"; -EOF - for dtb in $DTBS ; do - local dst=${dtb/*:/} - dst=${dst/*\//} - - cat <> $kernel_its - conf-$dst { - description = "Boot Linux kernel with $dst blob"; - kernel = "kernel"; - fdt = "fdt-$dst"; - }; -EOF - done - - cat <> $kernel_its - }; -}; -EOF - - PATH="$output_dir/scripts/dtc:$PATH" mkimage -f $kernel_its ${kernel_its/its/itb} -} - -make_srec_image() { - local image=$output_dir/arch/$arch/boot/$image_kernel - - cat $image | lzma -z -e > $image.xz - objcopy -I binary -O srec --srec-forceS3 --srec-len 516 \ - $image.xz $image.xz.srec - - for dtb in $DTBS ; do - local src=${dtb/:*/} - - objcopy -I binary -O srec --srec-forceS3 --srec-len 516 \ - $src $src.srec - done -} - -make_uboot_image() { - mkimage -A $arch -O linux -T kernel -C none -a $LOADADDR -e $LOADADDR \ - -n "Linux-${version}" -d $output_dir/arch/$arch/boot/$kernel_image \ - $output_dir/arch/$arch/boot/uImage -} - -make_cros_image() { - local boot_dir=$output_dir/arch/$arch/boot - local vmlinuz=$boot_dir/$1 - local bootloader - local config - - if [[ -f $opt_bootloader ]] ; then - bootloader=$opt_bootloader - else - dd if=/dev/zero of=$boot_dir/bootloader bs=512 count=1 - bootloader=$boot_dir/bootloader - fi - - if [[ -f $opt_cmdline_file ]] ; then - config=$opt_cmdline_file - else - echo "$CMDLINE" > $boot_dir/cmdline - config=$boot_dir/cmdline - fi - - vbutil_kernel \ - --pack $boot_dir/vmlinuz.image \ - --version 1 \ - --vmlinuz $vmlinuz \ - --arch $arch \ - --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ - --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ - --config $config \ - --bootloader $bootloader -} - -case $IMAGE in -FIT) - make_fit_image - image_file=$output_dir/arch/$arch/boot/kernel_fdt.itb - ;; -cros-arm) - make_fit_image - make_cros_image kernel_fdt.itb - image_file=$output_dir/arch/$arch/boot/vmlinuz.image - ;; -cros-x86) - make_fit_image - make_cros_image bzImage - image_file=$output_dir/arch/$arch/boot/vmlinuz.image - ;; -srec) - make_srec_image - image_file=$output_dir/arch/$arch/boot/$kernel_image.xz.srec - ;; -uImage) - make_uboot_image - image_file=$output_dir/arch/$arch/boot/uImage - ;; -*) - image_file=$output_dir/arch/$arch/boot/$IMAGE - ;; -esac +if [[ -r "$kbuild_root/images/$image.sh" ]] ; then + source "${kbuild_root}/images/$image.sh" || exit 1 + eval make_${image}_image +else + image_file=$output_dir/arch/$arch/boot/$image +fi # # Copy the files to their destination directories @@ -353,7 +200,7 @@ copy_dtbs() { mkdir -p $BOOT_DIR cp $image_file $BOOT_DIR/ -if [[ $IMAGE != FIT && $IMAGE != cros-arm && $IMAGE != cros-x86 ]] ; then +if [[ $image != FIT && $image != CrOS ]] ; then copy_dtbs $BOOT_DIR/ fi diff --git a/platforms/gen3.sh b/platforms/gen3.sh index 73a51a7..7b7ae6d 100644 --- a/platforms/gen3.sh +++ b/platforms/gen3.sh @@ -5,5 +5,5 @@ BOOT_DIR=$TFTP_ROOT/gen3 DTBS="renesas/r8a7795-es1-h3ulcb.dtb renesas/r8a7795-es1-salvator-x.dtb renesas/r8a7795-h3ulcb.dtb renesas/r8a7795-h3ulcb-kf.dtb renesas/r8a7795-salvator-x.dtb renesas/r8a7795-salvator-xs.dtb renesas/r8a7796-m3ulcb.dtb renesas/r8a7796-salvator-x.dtb renesas/r8a77995-draak.dtb" DTBS=$(cd arch/arm64/boot/dts ; ls renesas/*.dts | sed 's/\.dts/.dtb/') #DTBS="renesas/r8a77965-salvator-xs.dtb" -IMAGE=FIT +image=FIT LOADADDR=0x48080000 diff --git a/platforms/imx7.sh b/platforms/imx7.sh index 6e4d3cc..736e5ae 100644 --- a/platforms/imx7.sh +++ b/platforms/imx7.sh @@ -4,5 +4,5 @@ arch=arm #BOOT_DIR=$TFTP_ROOT/imx7 BOOT_DIR=$NFS_ROOT/arm32/boot DTBS="imx7d-sx-pl-emar.dtb imx7d-sx-pl-test.dtb" -IMAGE=zImage +image=zImage LOADADDR=0x80008000 diff --git a/platforms/omap3.sh b/platforms/omap3.sh index a0afae6..b6d7e2d 100644 --- a/platforms/omap3.sh +++ b/platforms/omap3.sh @@ -3,4 +3,4 @@ dir_pattern=media arch=arm BOOT_DIR=$TFTP_ROOT/omap3 DTBS="omap3-beagle-xm.dtb omap3-overo-storm-tobi.dtb" -IMAGE=zImage +image=zImage diff --git a/platforms/omap4+.sh b/platforms/omap4+.sh index 59e3441..646518b 100644 --- a/platforms/omap4+.sh +++ b/platforms/omap4+.sh @@ -3,5 +3,5 @@ dir_pattern=omap arch=arm BOOT_DIR=$TFTP_ROOT/omap4 DTBS="omap4-panda.dtb omap4-panda-es.dtb am57xx-evm-reva3.dtb:am57xx-beagle-x15.dtb" -IMAGE=FIT +image=FIT LOADADDR=0x80008000 diff --git a/platforms/scarlet.sh b/platforms/scarlet.sh index 530748d..4702900 100644 --- a/platforms/scarlet.sh +++ b/platforms/scarlet.sh @@ -4,5 +4,5 @@ BOOT_DIR=$NFS_ROOT/arm64/boot CMDLINE="console=ttyS2,115200n8 earlyprintk=ttyS2,115200n8 console=tty1 init=/sbin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd ignore_loglevel" CMDLINE="console=ttyS2,115200n8 earlyprintk=ttyS2,115200n8 console=tty1 ip=dhcp root=/dev/nfs rootwait rw noinitrd ignore_loglevel" DTBS="rockchip/rk3399-gru-scarlet-inx.dtb" -IMAGE=cros-arm +image=CrOS LOADADDR=0 diff --git a/platforms/soraka.sh b/platforms/soraka.sh index 571fce1..d278b34 100644 --- a/platforms/soraka.sh +++ b/platforms/soraka.sh @@ -3,5 +3,5 @@ dir_pattern=libcamera arch=x86 BOOT_DIR=$TFTP_ROOT/x86 CMDLINE="console=ttyS0,115200n8 earlyprintk=ttyS0,115200n8 console=tty1 ip=dhcp root=/dev/nfs rootwait rw noinitrd ignore_loglevel" -IMAGE=cros-x86 +image=CrOS KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than=" diff --git a/platforms/x86.sh b/platforms/x86.sh index 97d3358..5c61998 100644 --- a/platforms/x86.sh +++ b/platforms/x86.sh @@ -1,5 +1,5 @@ platform=x86 arch=x86 BOOT_DIR=$TFTP_ROOT/x86 -IMAGE=bzImage +image=bzImage KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than=" diff --git a/platforms/zynqmp.sh b/platforms/zynqmp.sh index cc936e7..3f9b302 100644 --- a/platforms/zynqmp.sh +++ b/platforms/zynqmp.sh @@ -3,7 +3,7 @@ dir_pattern=xilinx arch=arm64 BOOT_DIR=$TFTP_ROOT/xilinx DTBS="xilinx/zynqmp-zcu106-revA.dtb" -IMAGE=Image +image=Image LOADADDR=0x10000000 KCFLAGS="$KCFLAGS -Wno-error=packed-not-aligned -Wno-error=sizeof-pointer-memaccess -Wno-error=stringop-truncation -Wno-error=stringop-overflow" target_dir=$NFS_ROOT/zynqmp -- cgit v1.2.3