blob: 40fb5ad4ae6ebc20631eb452a168bd688a2fdb49 [file] [log] [blame]
Benjamin Fair18e3d812020-05-01 10:47:23 -07001SUMMARY = "Universal Boot Loader for embedded devices"
2PROVIDES = "virtual/bootloader"
3
4B = "${WORKDIR}/build"
5
6PACKAGE_ARCH = "${MACHINE_ARCH}"
7
8DEPENDS += "kern-tools-native"
9
10inherit uboot-config uboot-extlinux-config uboot-sign deploy cml1 python3native
11
12DEPENDS += "swig-native"
13
14EXTRA_OEMAKE = 'CROSS_COMPILE=${TARGET_PREFIX} CC="${TARGET_PREFIX}gcc ${TOOLCHAIN_OPTIONS}" V=1'
15EXTRA_OEMAKE += 'HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}"'
16EXTRA_OEMAKE += 'STAGING_INCDIR=${STAGING_INCDIR_NATIVE} STAGING_LIBDIR=${STAGING_LIBDIR_NATIVE}'
17
18PACKAGECONFIG ??= "openssl"
19# u-boot will compile its own tools during the build, with specific
20# configurations (aka when CONFIG_FIT_SIGNATURE is enabled) openssl is needed as
21# a host build dependency.
22PACKAGECONFIG[openssl] = ",,openssl-native"
23
24# Allow setting an additional version string that will be picked up by the
25# u-boot build system and appended to the u-boot version. If the .scmversion
26# file already exists it will not be overwritten.
27UBOOT_LOCALVERSION ?= ""
28
29# Some versions of u-boot use .bin and others use .img. By default use .bin
30# but enable individual recipes to change this value.
31UBOOT_SUFFIX ??= "bin"
32UBOOT_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}"
33UBOOT_SYMLINK ?= "u-boot-${MACHINE}.${UBOOT_SUFFIX}"
34UBOOT_MAKE_TARGET ?= "all"
35
36# Output the ELF generated. Some platforms can use the ELF file and directly
37# load it (JTAG booting, QEMU) additionally the ELF can be used for debugging
38# purposes.
39UBOOT_ELF ?= ""
40UBOOT_ELF_SUFFIX ?= "elf"
41UBOOT_ELF_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}"
42UBOOT_ELF_BINARY ?= "u-boot.${UBOOT_ELF_SUFFIX}"
43UBOOT_ELF_SYMLINK ?= "u-boot-${MACHINE}.${UBOOT_ELF_SUFFIX}"
44
45# Some versions of u-boot build an SPL (Second Program Loader) image that
46# should be packaged along with the u-boot binary as well as placed in the
47# deploy directory. For those versions they can set the following variables
48# to allow packaging the SPL.
49SPL_BINARY ?= ""
50SPL_BINARYNAME ?= "${@os.path.basename(d.getVar("SPL_BINARY"))}"
51SPL_IMAGE ?= "${SPL_BINARYNAME}-${MACHINE}-${PV}-${PR}"
52SPL_SYMLINK ?= "${SPL_BINARYNAME}-${MACHINE}"
53
54# Additional environment variables or a script can be installed alongside
55# u-boot to be used automatically on boot. This file, typically 'uEnv.txt'
56# or 'boot.scr', should be packaged along with u-boot as well as placed in the
57# deploy directory. Machine configurations needing one of these files should
58# include it in the SRC_URI and set the UBOOT_ENV parameter.
59UBOOT_ENV_SUFFIX ?= "txt"
60UBOOT_ENV ?= ""
61UBOOT_ENV_BINARY ?= "${UBOOT_ENV}.${UBOOT_ENV_SUFFIX}"
62UBOOT_ENV_IMAGE ?= "${UBOOT_ENV}-${MACHINE}-${PV}-${PR}.${UBOOT_ENV_SUFFIX}"
63UBOOT_ENV_SYMLINK ?= "${UBOOT_ENV}-${MACHINE}.${UBOOT_ENV_SUFFIX}"
64
65# U-Boot EXTLINUX variables. U-Boot searches for /boot/extlinux/extlinux.conf
66# to find EXTLINUX conf file.
67UBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux"
68UBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf"
69UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}"
70
George Hungd09ea352020-07-15 17:15:46 +080071# Set Device tree from the machine config automatically
72UBOOT_MAKE_TARGET += '${@"" if d.getVar("UBOOT_DEVICETREE") is None \
73 else " DEVICE_TREE=" + d.getVar("UBOOT_DEVICETREE")}'
74
Benjamin Fair18e3d812020-05-01 10:47:23 -070075# returns all the elements from the src uri that are .cfg files
76def find_cfgs(d):
77 sources=src_patches(d, True)
78 sources_list=[]
79 for s in sources:
80 if s.endswith('.cfg'):
81 sources_list.append(s)
82
83 return sources_list
84
85do_configure () {
86 if [ -z "${UBOOT_CONFIG}" ]; then
87 if [ -n "${UBOOT_MACHINE}" ]; then
88 oe_runmake -C ${S} O=${B} ${UBOOT_MACHINE}
89 else
90 oe_runmake -C ${S} O=${B} oldconfig
91 fi
92 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
93 cml1_do_configure
94 fi
95}
96
97do_compile () {
98 if [ "${@bb.utils.filter('DISTRO_FEATURES', 'ld-is-gold', d)}" ]; then
99 sed -i 's/$(CROSS_COMPILE)ld$/$(CROSS_COMPILE)ld.bfd/g' ${S}/config.mk
100 fi
101
102 unset LDFLAGS
103 unset CFLAGS
104 unset CPPFLAGS
105
106 if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]
107 then
108 echo ${UBOOT_LOCALVERSION} > ${B}/.scmversion
109 echo ${UBOOT_LOCALVERSION} > ${S}/.scmversion
110 fi
111
112 if [ -n "${UBOOT_CONFIG}" ]
113 then
114 unset i j k
115 for config in ${UBOOT_MACHINE}; do
116 i=$(expr $i + 1);
117 for type in ${UBOOT_CONFIG}; do
118 j=$(expr $j + 1);
119 if [ $j -eq $i ]
120 then
121 oe_runmake -C ${S} O=${B}/${config} ${config}
122 oe_runmake -C ${S} O=${B}/${config} ${UBOOT_MAKE_TARGET}
123 for binary in ${UBOOT_BINARIES}; do
124 k=$(expr $k + 1);
125 if [ $k -eq $i ]; then
126 cp ${B}/${config}/${binary} ${B}/${config}/u-boot-${type}.${UBOOT_SUFFIX}
127 fi
128 done
129 unset k
130 fi
131 done
132 unset j
133 done
134 unset i
135 else
136 oe_runmake -C ${S} O=${B} ${UBOOT_MAKE_TARGET}
137 fi
138
139}
140
141do_install () {
142 if [ -n "${UBOOT_CONFIG}" ]
143 then
144 for config in ${UBOOT_MACHINE}; do
145 i=$(expr $i + 1);
146 for type in ${UBOOT_CONFIG}; do
147 j=$(expr $j + 1);
148 if [ $j -eq $i ]
149 then
150 install -d ${D}/boot
151 install -m 644 ${B}/${config}/u-boot-${type}.${UBOOT_SUFFIX} ${D}/boot/u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX}
152 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${D}/boot/${UBOOT_BINARY}-${type}
153 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${D}/boot/${UBOOT_BINARY}
154 fi
155 done
156 unset j
157 done
158 unset i
159 else
160 install -d ${D}/boot
161 install -m 644 ${B}/${UBOOT_BINARY} ${D}/boot/${UBOOT_IMAGE}
162 ln -sf ${UBOOT_IMAGE} ${D}/boot/${UBOOT_BINARY}
163 fi
164
165 if [ -n "${UBOOT_ELF}" ]
166 then
167 if [ -n "${UBOOT_CONFIG}" ]
168 then
169 for config in ${UBOOT_MACHINE}; do
170 i=$(expr $i + 1);
171 for type in ${UBOOT_CONFIG}; do
172 j=$(expr $j + 1);
173 if [ $j -eq $i ]
174 then
175 install -m 644 ${B}/${config}/${UBOOT_ELF} ${D}/boot/u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}
176 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${D}/boot/${UBOOT_BINARY}-${type}
177 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${D}/boot/${UBOOT_BINARY}
178 fi
179 done
180 unset j
181 done
182 unset i
183 else
184 install -m 644 ${B}/${UBOOT_ELF} ${D}/boot/${UBOOT_ELF_IMAGE}
185 ln -sf ${UBOOT_ELF_IMAGE} ${D}/boot/${UBOOT_ELF_BINARY}
186 fi
187 fi
188
189 if [ -e ${WORKDIR}/fw_env.config ] ; then
190 install -d ${D}${sysconfdir}
191 install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}/fw_env.config
192 fi
193
194 if [ -n "${SPL_BINARY}" ]
195 then
196 if [ -n "${UBOOT_CONFIG}" ]
197 then
198 for config in ${UBOOT_MACHINE}; do
199 i=$(expr $i + 1);
200 for type in ${UBOOT_CONFIG}; do
201 j=$(expr $j + 1);
202 if [ $j -eq $i ]
203 then
204 install -m 644 ${B}/${config}/${SPL_BINARY} ${D}/boot/${SPL_IMAGE}-${type}-${PV}-${PR}
205 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${D}/boot/${SPL_BINARYNAME}-${type}
206 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${D}/boot/${SPL_BINARYNAME}
207 fi
208 done
209 unset j
210 done
211 unset i
212 else
213 install -m 644 ${B}/${SPL_BINARY} ${D}/boot/${SPL_IMAGE}
214 ln -sf ${SPL_IMAGE} ${D}/boot/${SPL_BINARYNAME}
215 fi
216 fi
217
218 if [ -n "${UBOOT_ENV}" ]
219 then
220 install -m 644 ${WORKDIR}/${UBOOT_ENV_BINARY} ${D}/boot/${UBOOT_ENV_IMAGE}
221 ln -sf ${UBOOT_ENV_IMAGE} ${D}/boot/${UBOOT_ENV_BINARY}
222 fi
223
224 if [ "${UBOOT_EXTLINUX}" = "1" ]
225 then
226 install -Dm 0644 ${UBOOT_EXTLINUX_CONFIG} ${D}/${UBOOT_EXTLINUX_INSTALL_DIR}/${UBOOT_EXTLINUX_CONF_NAME}
227 fi
228
229}
230
Willy Tuce3cb2c2021-08-10 15:28:25 -0700231FILES:${PN} = "/boot ${sysconfdir} ${datadir}"
Benjamin Fair18e3d812020-05-01 10:47:23 -0700232
233do_deploy () {
234 if [ -n "${UBOOT_CONFIG}" ]
235 then
236 for config in ${UBOOT_MACHINE}; do
237 i=$(expr $i + 1);
238 for type in ${UBOOT_CONFIG}; do
239 j=$(expr $j + 1);
240 if [ $j -eq $i ]
241 then
242 install -d ${DEPLOYDIR}
243 install -m 644 ${B}/${config}/u-boot-${type}.${UBOOT_SUFFIX} ${DEPLOYDIR}/u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX}
244 cd ${DEPLOYDIR}
245 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_SYMLINK}-${type}
246 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_SYMLINK}
247 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_BINARY}-${type}
248 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_BINARY}
249 fi
250 done
251 unset j
252 done
253 unset i
254 else
255 install -d ${DEPLOYDIR}
256 install -m 644 ${B}/${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE}
257 cd ${DEPLOYDIR}
258 rm -f ${UBOOT_BINARY} ${UBOOT_SYMLINK}
259 ln -sf ${UBOOT_IMAGE} ${UBOOT_SYMLINK}
260 ln -sf ${UBOOT_IMAGE} ${UBOOT_BINARY}
261 fi
262
263 if [ -n "${UBOOT_ELF}" ]
264 then
265 if [ -n "${UBOOT_CONFIG}" ]
266 then
267 for config in ${UBOOT_MACHINE}; do
268 i=$(expr $i + 1);
269 for type in ${UBOOT_CONFIG}; do
270 j=$(expr $j + 1);
271 if [ $j -eq $i ]
272 then
273 install -m 644 ${B}/${config}/${UBOOT_ELF} ${DEPLOYDIR}/u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}
274 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_BINARY}-${type}
275 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_BINARY}
276 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_SYMLINK}-${type}
277 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_SYMLINK}
278 fi
279 done
280 unset j
281 done
282 unset i
283 else
284 install -m 644 ${B}/${UBOOT_ELF} ${DEPLOYDIR}/${UBOOT_ELF_IMAGE}
285 ln -sf ${UBOOT_ELF_IMAGE} ${DEPLOYDIR}/${UBOOT_ELF_BINARY}
286 ln -sf ${UBOOT_ELF_IMAGE} ${DEPLOYDIR}/${UBOOT_ELF_SYMLINK}
287 fi
288 fi
289
290
291 if [ -n "${SPL_BINARY}" ]
292 then
293 if [ -n "${UBOOT_CONFIG}" ]
294 then
295 for config in ${UBOOT_MACHINE}; do
296 i=$(expr $i + 1);
297 for type in ${UBOOT_CONFIG}; do
298 j=$(expr $j + 1);
299 if [ $j -eq $i ]
300 then
301 install -m 644 ${B}/${config}/${SPL_BINARY} ${DEPLOYDIR}/${SPL_IMAGE}-${type}-${PV}-${PR}
302 rm -f ${DEPLOYDIR}/${SPL_BINARYNAME} ${DEPLOYDIR}/${SPL_SYMLINK}-${type}
303 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_BINARYNAME}-${type}
304 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_BINARYNAME}
305 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_SYMLINK}-${type}
306 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_SYMLINK}
307 fi
308 done
309 unset j
310 done
311 unset i
312 else
313 install -m 644 ${B}/${SPL_BINARY} ${DEPLOYDIR}/${SPL_IMAGE}
314 rm -f ${DEPLOYDIR}/${SPL_BINARYNAME} ${DEPLOYDIR}/${SPL_SYMLINK}
315 ln -sf ${SPL_IMAGE} ${DEPLOYDIR}/${SPL_BINARYNAME}
316 ln -sf ${SPL_IMAGE} ${DEPLOYDIR}/${SPL_SYMLINK}
317 fi
318 fi
319
320
321 if [ -n "${UBOOT_ENV}" ]
322 then
323 install -m 644 ${WORKDIR}/${UBOOT_ENV_BINARY} ${DEPLOYDIR}/${UBOOT_ENV_IMAGE}
324 rm -f ${DEPLOYDIR}/${UBOOT_ENV_BINARY} ${DEPLOYDIR}/${UBOOT_ENV_SYMLINK}
325 ln -sf ${UBOOT_ENV_IMAGE} ${DEPLOYDIR}/${UBOOT_ENV_BINARY}
326 ln -sf ${UBOOT_ENV_IMAGE} ${DEPLOYDIR}/${UBOOT_ENV_SYMLINK}
327 fi
328
329 if [ "${UBOOT_EXTLINUX}" = "1" ]
330 then
331 install -m 644 ${UBOOT_EXTLINUX_CONFIG} ${DEPLOYDIR}/${UBOOT_EXTLINUX_SYMLINK}
332 ln -sf ${UBOOT_EXTLINUX_SYMLINK} ${DEPLOYDIR}/${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}
333 ln -sf ${UBOOT_EXTLINUX_SYMLINK} ${DEPLOYDIR}/${UBOOT_EXTLINUX_CONF_NAME}
334 fi
335}
336
337addtask deploy before do_build after do_compile