post-image.sh 3.2 KB

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