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