post-image.sh 3.6 KB

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