1#!/usr/bin/env bash 2 3# 4# dtb_list extracts the list of DTB files from BR2_LINUX_KERNEL_INTREE_DTS_NAME 5# in ${BR_CONFIG}, then prints the corresponding list of file names for the 6# genimage configuration file 7# 8dtb_list() 9{ 10 local DTB_LIST="$(sed -n 's/^BR2_LINUX_KERNEL_INTREE_DTS_NAME="\([\/a-z0-9 \-]*\)"$/\1/p' ${BR2_CONFIG})" 11 12 for dt in $DTB_LIST; do 13 echo -n "\"`basename $dt`.dtb\", " 14 done 15} 16 17# 18# linux_image extracts the Linux image format from BR2_LINUX_KERNEL_UIMAGE in 19# ${BR_CONFIG}, then prints the corresponding file name for the genimage 20# configuration file 21# 22linux_image() 23{ 24 if grep -Eq "^BR2_LINUX_KERNEL_UIMAGE=y$" ${BR2_CONFIG}; then 25 echo "\"uImage\"" 26 elif grep -Eq "^BR2_LINUX_KERNEL_IMAGE=y$" ${BR2_CONFIG}; then 27 echo "\"Image\"" 28 elif grep -Eq "^BR2_LINUX_KERNEL_IMAGEGZ=y$" ${BR2_CONFIG}; then 29 echo "\"Image.gz\"" 30 else 31 echo "\"zImage\"" 32 fi 33} 34 35genimage_type() 36{ 37 if grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8=y$" ${BR2_CONFIG}; then 38 echo "genimage.cfg.template_imx8" 39 elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8M=y$" ${BR2_CONFIG}; then 40 echo "genimage.cfg.template_imx8" 41 elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8MM=y$" ${BR2_CONFIG}; then 42 echo "genimage.cfg.template_imx8" 43 elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8MN=y$" ${BR2_CONFIG}; then 44 echo "genimage.cfg.template_imx8" 45 elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8MP=y$" ${BR2_CONFIG}; then 46 echo "genimage.cfg.template_imx8" 47 elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8X=y$" ${BR2_CONFIG}; then 48 echo "genimage.cfg.template_imx8" 49 elif grep -Eq "^BR2_LINUX_KERNEL_INSTALL_TARGET=y$" ${BR2_CONFIG}; then 50 if grep -Eq "^BR2_TARGET_UBOOT_SPL=y$" ${BR2_CONFIG}; then 51 echo "genimage.cfg.template_no_boot_part_spl" 52 else 53 echo "genimage.cfg.template_no_boot_part" 54 fi 55 elif grep -Eq "^BR2_TARGET_UBOOT_SPL=y$" ${BR2_CONFIG}; then 56 echo "genimage.cfg.template_spl" 57 else 58 echo "genimage.cfg.template" 59 fi 60} 61 62imx_offset() 63{ 64 if grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8M=y$" ${BR2_CONFIG}; then 65 echo "33K" 66 elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8MM=y$" ${BR2_CONFIG}; then 67 echo "33K" 68 else 69 echo "32K" 70 fi 71} 72 73uboot_image() 74{ 75 if grep -Eq "^BR2_TARGET_UBOOT_FORMAT_DTB_IMX=y$" ${BR2_CONFIG}; then 76 echo "u-boot-dtb.imx" 77 elif grep -Eq "^BR2_TARGET_UBOOT_FORMAT_IMX=y$" ${BR2_CONFIG}; then 78 echo "u-boot.imx" 79 elif grep -Eq "^BR2_TARGET_UBOOT_FORMAT_DTB_IMG=y$" ${BR2_CONFIG}; then 80 echo "u-boot-dtb.img" 81 elif grep -Eq "^BR2_TARGET_UBOOT_FORMAT_IMG=y$" ${BR2_CONFIG}; then 82 echo "u-boot.img" 83 fi 84} 85 86main() 87{ 88 local FILES="$(dtb_list) $(linux_image)" 89 local IMXOFFSET="$(imx_offset)" 90 local UBOOTBIN="$(uboot_image)" 91 local GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)" 92 local GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" 93 94 sed -e "s/%FILES%/${FILES}/" \ 95 -e "s/%IMXOFFSET%/${IMXOFFSET}/" \ 96 -e "s/%UBOOTBIN%/${UBOOTBIN}/" \ 97 board/freescale/common/imx/$(genimage_type) > ${GENIMAGE_CFG} 98 99 rm -rf "${GENIMAGE_TMP}" 100 101 genimage \ 102 --rootpath "${TARGET_DIR}" \ 103 --tmppath "${GENIMAGE_TMP}" \ 104 --inputpath "${BINARIES_DIR}" \ 105 --outputpath "${BINARIES_DIR}" \ 106 --config "${GENIMAGE_CFG}" 107 108 rm -f ${GENIMAGE_CFG} 109 110 exit $? 111} 112 113main $@ 114