From f9f2e2a794d43ad145703fe58f9869e8f131a45a Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 19 May 2019 19:00:19 +0300 Subject: Modularise platform handling Signed-off-by: Laurent Pinchart --- kbuild.sh | 168 ++++++++++++++++++++------------------------------- platforms/gen3.sh | 9 +++ platforms/imx7.sh | 8 +++ platforms/omap3.sh | 6 ++ platforms/omap4+.sh | 7 +++ platforms/scarlet.sh | 8 +++ platforms/soraka.sh | 7 +++ platforms/x86.sh | 5 ++ platforms/zynqmp.sh | 9 +++ 9 files changed, 124 insertions(+), 103 deletions(-) create mode 100644 platforms/gen3.sh create mode 100644 platforms/imx7.sh create mode 100644 platforms/omap3.sh create mode 100644 platforms/omap4+.sh create mode 100644 platforms/scarlet.sh create mode 100644 platforms/soraka.sh create mode 100644 platforms/x86.sh create mode 100644 platforms/zynqmp.sh diff --git a/kbuild.sh b/kbuild.sh index b979b36..9bd2274 100755 --- a/kbuild.sh +++ b/kbuild.sh @@ -1,7 +1,10 @@ #!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ set -e +kbuild_root=$(dirname $(readlink -f "$0")) + #OPTIONS='CONFIG_DEBUG_SECTION_MISMATCH=y' #OPTIONS='C=1' OPTIONS="KALLSYMS_EXTRA_PASS=0" @@ -10,12 +13,9 @@ KCFLAGS="-Werror -Wno-error=cpp" NFS_ROOT=$HOME/src/netboot TFTP_ROOT=$HOME/tftpboot -echo $PWD | grep -q libcamera && PLATFORM=x86 -echo $PWD | grep -q media && PLATFORM=omap3 -echo $PWD | grep -q omap && PLATFORM=omap4+ -echo $PWD | grep -q plusoptix && PLATFORM=imx7 -echo $PWD | grep -q renesas && PLATFORM=gen3 -echo $PWD | grep -q xilinx && PLATFORM=zynqmp +# +# Options parsing +# do_compile_doc=0 do_menu_config=0 @@ -67,80 +67,42 @@ while [[ $# != 0 ]] ; do exit 1 ;; *) - PLATFORM=$option + platform=$option ;; esac done -case $PLATFORM in - gen3) - ARCH=arm64 - 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 - LOADADDR=0x48080000 - ;; - imx7) - 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 - LOADADDR=0x80008000 - ;; - omap3) - ARCH=arm - BOOT_DIR=$TFTP_ROOT/omap3 - DTBS="omap3-beagle-xm.dtb omap3-overo-storm-tobi.dtb" - IMAGE=zImage - ;; - omap4+) - 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 - LOADADDR=0x80008000 - ;; - scarlet) - ARCH=arm64 - 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 - LOADADDR=0 - ;; - soraka) - 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 - KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than=" - ;; - x86) - ARCH=x86 - BOOT_DIR=$TFTP_ROOT/x86 - IMAGE=bzImage - KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than=" - ;; - zynqmp) - ARCH=arm64 - BOOT_DIR=$TFTP_ROOT/xilinx - DTBS="xilinx/zynqmp-zcu106-revA.dtb" - 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 - ;; - *) - echo "Invalid platform $PLATFORM" - exit 1 - ;; -esac +# +# Platform handling +# + +if [[ -z "$platform" ]] ; then + for f in $kbuild_root/platforms/*.sh ; do + pattern=$(cat $f | grep "dir_pattern=" | head -1) + pattern=${pattern/#dir_pattern=/} + if [[ -n "$pattern" ]] ; then + echo $PWD | grep -q "$pattern" || continue + platform=$(basename -s .sh $f) + break + fi + done +fi + +if [[ ! -r "$kbuild_root/platforms/$platform.sh" ]] ; then + echo "Unknown platform '$platform'. Available platforms are" + for f in $kbuild_root/platforms/*.sh ; do + echo "- $(basename -s .sh $f)" + done + exit 1 +fi + +source "${kbuild_root}/platforms/$platform.sh" || exit 1 + +# +# Architecture handling +# -case $ARCH in +case $arch in arm) arch_dir=arm32 cross_compile=arm-buildroot-linux-uclibcgnueabihf- @@ -170,19 +132,19 @@ pmake="make -j$((num_cpus*2))" OPTIONS="KALLSYMS_EXTRA_PASS=0 KCFLAGS='$KCFLAGS'" -echo "Compiling for platform $PLATFORM with $num_cpus CPUs" +echo "Compiling for platform $platform with $num_cpus CPUs" mkdir -p $output_dir/ if [[ -n "$opt_defconfig" ]] ; then - mkdir -p $output_dir/arch/$ARCH/configs/ - cp $opt_defconfig $output_dir/arch/$ARCH/configs/build_defconfig - make ARCH=$ARCH O=$output_dir build_defconfig - rm $output_dir/arch/$ARCH/configs/build_defconfig + mkdir -p $output_dir/arch/$arch/configs/ + cp $opt_defconfig $output_dir/arch/$arch/configs/build_defconfig + make ARCH=$arch O=$output_dir build_defconfig + rm $output_dir/arch/$arch/configs/build_defconfig fi if [[ $do_menu_config = 1 ]] ; then - make ARCH=$ARCH O=$output_dir menuconfig + make ARCH=$arch O=$output_dir menuconfig exit 0 fi @@ -191,7 +153,7 @@ fi # if [[ $do_compile_doc = 1 ]] ; then - $pmake ARCH=$ARCH O=$output_dir DOCBOOKS='' htmldocs + $pmake ARCH=$arch O=$output_dir DOCBOOKS='' htmldocs fi # @@ -204,12 +166,12 @@ for dtb in $DTBS ; do dtbs="$dtbs $dtb" done -eval $pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile $OPTIONS \ +eval $pmake ARCH=$arch O=$output_dir CROSS_COMPILE=$cross_compile $OPTIONS \ $image_kernel $dtbs grep 'CONFIG_MODULES=y' $output_dir/.config > /dev/null && modules=modules if [[ x$modules == xmodules ]] ; then - eval $pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile $OPTIONS \ + eval $pmake ARCH=$arch O=$output_dir CROSS_COMPILE=$cross_compile $OPTIONS \ $modules fi @@ -220,7 +182,7 @@ version=$(cat $output_dir/include/generated/utsrelease.h | cut -d '"' -f 2) # make_fit_image() { - local kernel_its=$output_dir/arch/$ARCH/boot/kernel_fdt.its + local kernel_its=$output_dir/arch/$arch/boot/kernel_fdt.its cat < $kernel_its /dts-v1/; @@ -231,9 +193,9 @@ make_fit_image() { images { kernel { description = "Linux kernel"; - data = /incbin/("$output_dir/arch/$ARCH/boot/$image_kernel"); + data = /incbin/("$output_dir/arch/$arch/boot/$image_kernel"); type = "kernel"; - arch = "$ARCH"; + arch = "$arch"; os = "linux"; compression = "none"; load = <$LOADADDR>; @@ -257,9 +219,9 @@ EOF cat <> $kernel_its fdt-$dst { description = "Flattened Device Tree blob $dst"; - data = /incbin/("$output_dir/arch/$ARCH/boot/dts/$src"); + data = /incbin/("$output_dir/arch/$arch/boot/dts/$src"); type = "flat_dt"; - arch = "$ARCH"; + arch = "$arch"; compression = "none"; hash-1 { algo = "crc32"; @@ -300,7 +262,7 @@ EOF } make_srec_image() { - local image=$output_dir/arch/$ARCH/boot/$image_kernel + 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 \ @@ -315,13 +277,13 @@ make_srec_image() { } 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 + 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 boot_dir=$output_dir/arch/$arch/boot local vmlinuz=$boot_dir/$1 local bootloader local config @@ -344,7 +306,7 @@ make_cros_image() { --pack $boot_dir/vmlinuz.image \ --version 1 \ --vmlinuz $vmlinuz \ - --arch $ARCH \ + --arch $arch \ --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ --config $config \ @@ -354,28 +316,28 @@ make_cros_image() { case $IMAGE in FIT) make_fit_image - image_file=$output_dir/arch/$ARCH/boot/kernel_fdt.itb + 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 + 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 + image_file=$output_dir/arch/$arch/boot/vmlinuz.image ;; srec) make_srec_image - image_file=$output_dir/arch/$ARCH/boot/$kernel_image.xz.srec + 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/uImage ;; *) - image_file=$output_dir/arch/$ARCH/boot/$IMAGE + image_file=$output_dir/arch/$arch/boot/$IMAGE ;; esac @@ -404,12 +366,12 @@ if [[ $IMAGE != FIT && $IMAGE != cros-arm && $IMAGE != cros-x86 ]] ; then fi if [[ x$modules = xmodules ]] ; then - $pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile INSTALL_MOD_PATH=$target_dir modules_install + $pmake ARCH=$arch O=$output_dir CROSS_COMPILE=$cross_compile INSTALL_MOD_PATH=$target_dir modules_install echo "Kernel modules installed to $target_dir/lib/modules/$version" fi if [[ $do_package_deb = 1 ]] ; then - $pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile bindeb-pkg + $pmake ARCH=$arch O=$output_dir CROSS_COMPILE=$cross_compile bindeb-pkg fi echo "Kernel image available in $image_file" diff --git a/platforms/gen3.sh b/platforms/gen3.sh new file mode 100644 index 0000000..73a51a7 --- /dev/null +++ b/platforms/gen3.sh @@ -0,0 +1,9 @@ +platform=gen3 +dir_pattern=renesas +arch=arm64 +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 +LOADADDR=0x48080000 diff --git a/platforms/imx7.sh b/platforms/imx7.sh new file mode 100644 index 0000000..6e4d3cc --- /dev/null +++ b/platforms/imx7.sh @@ -0,0 +1,8 @@ +platform=imx7 +dir_pattern=plusoptix +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 +LOADADDR=0x80008000 diff --git a/platforms/omap3.sh b/platforms/omap3.sh new file mode 100644 index 0000000..a0afae6 --- /dev/null +++ b/platforms/omap3.sh @@ -0,0 +1,6 @@ +platform=omap3 +dir_pattern=media +arch=arm +BOOT_DIR=$TFTP_ROOT/omap3 +DTBS="omap3-beagle-xm.dtb omap3-overo-storm-tobi.dtb" +IMAGE=zImage diff --git a/platforms/omap4+.sh b/platforms/omap4+.sh new file mode 100644 index 0000000..59e3441 --- /dev/null +++ b/platforms/omap4+.sh @@ -0,0 +1,7 @@ +platform=omap4+ +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 +LOADADDR=0x80008000 diff --git a/platforms/scarlet.sh b/platforms/scarlet.sh new file mode 100644 index 0000000..530748d --- /dev/null +++ b/platforms/scarlet.sh @@ -0,0 +1,8 @@ +platform=scarlet +arch=arm64 +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 +LOADADDR=0 diff --git a/platforms/soraka.sh b/platforms/soraka.sh new file mode 100644 index 0000000..571fce1 --- /dev/null +++ b/platforms/soraka.sh @@ -0,0 +1,7 @@ +platform=soraka +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 +KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than=" diff --git a/platforms/x86.sh b/platforms/x86.sh new file mode 100644 index 0000000..97d3358 --- /dev/null +++ b/platforms/x86.sh @@ -0,0 +1,5 @@ +platform=x86 +arch=x86 +BOOT_DIR=$TFTP_ROOT/x86 +IMAGE=bzImage +KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than=" diff --git a/platforms/zynqmp.sh b/platforms/zynqmp.sh new file mode 100644 index 0000000..cc936e7 --- /dev/null +++ b/platforms/zynqmp.sh @@ -0,0 +1,9 @@ +platform=zynqmp +dir_pattern=xilinx +arch=arm64 +BOOT_DIR=$TFTP_ROOT/xilinx +DTBS="xilinx/zynqmp-zcu106-revA.dtb" +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