post-image.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. else
  26. echo "\"zImage\""
  27. fi
  28. }
  29. genimage_type()
  30. {
  31. if grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8M=y$" ${BR2_CONFIG}; then
  32. echo "genimage.cfg.template_imx8"
  33. elif grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8X=y$" ${BR2_CONFIG}; then
  34. echo "genimage.cfg.template_imx8"
  35. elif grep -Eq "^BR2_TARGET_UBOOT_SPL=y$" ${BR2_CONFIG}; then
  36. echo "genimage.cfg.template_spl"
  37. else
  38. echo "genimage.cfg.template"
  39. fi
  40. }
  41. imx_offset()
  42. {
  43. if grep -Eq "^BR2_PACKAGE_FREESCALE_IMX_PLATFORM_IMX8M=y$" ${BR2_CONFIG}; then
  44. echo "33K"
  45. else
  46. echo "32K"
  47. fi
  48. }
  49. uboot_image()
  50. {
  51. if grep -Eq "^BR2_TARGET_UBOOT_FORMAT_DTB_IMX=y$" ${BR2_CONFIG}; then
  52. echo "u-boot-dtb.imx"
  53. elif grep -Eq "^BR2_TARGET_UBOOT_FORMAT_IMX=y$" ${BR2_CONFIG}; then
  54. echo "u-boot.imx"
  55. fi
  56. }
  57. main()
  58. {
  59. local FILES="$(dtb_list) $(linux_image)"
  60. local IMXOFFSET="$(imx_offset)"
  61. local UBOOTBIN="$(uboot_image)"
  62. local GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)"
  63. local GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
  64. sed -e "s/%FILES%/${FILES}/" \
  65. -e "s/%IMXOFFSET%/${IMXOFFSET}/" \
  66. -e "s/%UBOOTBIN%/${UBOOTBIN}/" \
  67. board/freescale/common/imx/$(genimage_type) > ${GENIMAGE_CFG}
  68. rm -rf "${GENIMAGE_TMP}"
  69. genimage \
  70. --rootpath "${TARGET_DIR}" \
  71. --tmppath "${GENIMAGE_TMP}" \
  72. --inputpath "${BINARIES_DIR}" \
  73. --outputpath "${BINARIES_DIR}" \
  74. --config "${GENIMAGE_CFG}"
  75. rm -f ${GENIMAGE_CFG}
  76. exit $?
  77. }
  78. main $@