post-image.sh 3.6 KB

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