blob: 55d8b478701c6f576f4f76a328c91a377fcc2e39 [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
71# returns all the elements from the src uri that are .cfg files
72def find_cfgs(d):
73 sources=src_patches(d, True)
74 sources_list=[]
75 for s in sources:
76 if s.endswith('.cfg'):
77 sources_list.append(s)
78
79 return sources_list
80
81do_configure () {
82 if [ -z "${UBOOT_CONFIG}" ]; then
83 if [ -n "${UBOOT_MACHINE}" ]; then
84 oe_runmake -C ${S} O=${B} ${UBOOT_MACHINE}
85 else
86 oe_runmake -C ${S} O=${B} oldconfig
87 fi
88 merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
89 cml1_do_configure
90 fi
91}
92
93do_compile () {
94 if [ "${@bb.utils.filter('DISTRO_FEATURES', 'ld-is-gold', d)}" ]; then
95 sed -i 's/$(CROSS_COMPILE)ld$/$(CROSS_COMPILE)ld.bfd/g' ${S}/config.mk
96 fi
97
98 unset LDFLAGS
99 unset CFLAGS
100 unset CPPFLAGS
101
102 if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]
103 then
104 echo ${UBOOT_LOCALVERSION} > ${B}/.scmversion
105 echo ${UBOOT_LOCALVERSION} > ${S}/.scmversion
106 fi
107
108 if [ -n "${UBOOT_CONFIG}" ]
109 then
110 unset i j k
111 for config in ${UBOOT_MACHINE}; do
112 i=$(expr $i + 1);
113 for type in ${UBOOT_CONFIG}; do
114 j=$(expr $j + 1);
115 if [ $j -eq $i ]
116 then
117 oe_runmake -C ${S} O=${B}/${config} ${config}
118 oe_runmake -C ${S} O=${B}/${config} ${UBOOT_MAKE_TARGET}
119 for binary in ${UBOOT_BINARIES}; do
120 k=$(expr $k + 1);
121 if [ $k -eq $i ]; then
122 cp ${B}/${config}/${binary} ${B}/${config}/u-boot-${type}.${UBOOT_SUFFIX}
123 fi
124 done
125 unset k
126 fi
127 done
128 unset j
129 done
130 unset i
131 else
132 oe_runmake -C ${S} O=${B} ${UBOOT_MAKE_TARGET}
133 fi
134
135}
136
137do_install () {
138 if [ -n "${UBOOT_CONFIG}" ]
139 then
140 for config in ${UBOOT_MACHINE}; do
141 i=$(expr $i + 1);
142 for type in ${UBOOT_CONFIG}; do
143 j=$(expr $j + 1);
144 if [ $j -eq $i ]
145 then
146 install -d ${D}/boot
147 install -m 644 ${B}/${config}/u-boot-${type}.${UBOOT_SUFFIX} ${D}/boot/u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX}
148 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${D}/boot/${UBOOT_BINARY}-${type}
149 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${D}/boot/${UBOOT_BINARY}
150 fi
151 done
152 unset j
153 done
154 unset i
155 else
156 install -d ${D}/boot
157 install -m 644 ${B}/${UBOOT_BINARY} ${D}/boot/${UBOOT_IMAGE}
158 ln -sf ${UBOOT_IMAGE} ${D}/boot/${UBOOT_BINARY}
159 fi
160
161 if [ -n "${UBOOT_ELF}" ]
162 then
163 if [ -n "${UBOOT_CONFIG}" ]
164 then
165 for config in ${UBOOT_MACHINE}; do
166 i=$(expr $i + 1);
167 for type in ${UBOOT_CONFIG}; do
168 j=$(expr $j + 1);
169 if [ $j -eq $i ]
170 then
171 install -m 644 ${B}/${config}/${UBOOT_ELF} ${D}/boot/u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}
172 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${D}/boot/${UBOOT_BINARY}-${type}
173 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${D}/boot/${UBOOT_BINARY}
174 fi
175 done
176 unset j
177 done
178 unset i
179 else
180 install -m 644 ${B}/${UBOOT_ELF} ${D}/boot/${UBOOT_ELF_IMAGE}
181 ln -sf ${UBOOT_ELF_IMAGE} ${D}/boot/${UBOOT_ELF_BINARY}
182 fi
183 fi
184
185 if [ -e ${WORKDIR}/fw_env.config ] ; then
186 install -d ${D}${sysconfdir}
187 install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}/fw_env.config
188 fi
189
190 if [ -n "${SPL_BINARY}" ]
191 then
192 if [ -n "${UBOOT_CONFIG}" ]
193 then
194 for config in ${UBOOT_MACHINE}; do
195 i=$(expr $i + 1);
196 for type in ${UBOOT_CONFIG}; do
197 j=$(expr $j + 1);
198 if [ $j -eq $i ]
199 then
200 install -m 644 ${B}/${config}/${SPL_BINARY} ${D}/boot/${SPL_IMAGE}-${type}-${PV}-${PR}
201 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${D}/boot/${SPL_BINARYNAME}-${type}
202 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${D}/boot/${SPL_BINARYNAME}
203 fi
204 done
205 unset j
206 done
207 unset i
208 else
209 install -m 644 ${B}/${SPL_BINARY} ${D}/boot/${SPL_IMAGE}
210 ln -sf ${SPL_IMAGE} ${D}/boot/${SPL_BINARYNAME}
211 fi
212 fi
213
214 if [ -n "${UBOOT_ENV}" ]
215 then
216 install -m 644 ${WORKDIR}/${UBOOT_ENV_BINARY} ${D}/boot/${UBOOT_ENV_IMAGE}
217 ln -sf ${UBOOT_ENV_IMAGE} ${D}/boot/${UBOOT_ENV_BINARY}
218 fi
219
220 if [ "${UBOOT_EXTLINUX}" = "1" ]
221 then
222 install -Dm 0644 ${UBOOT_EXTLINUX_CONFIG} ${D}/${UBOOT_EXTLINUX_INSTALL_DIR}/${UBOOT_EXTLINUX_CONF_NAME}
223 fi
224
225}
226
227FILES_${PN} = "/boot ${sysconfdir} ${datadir}"
228
229do_deploy () {
230 if [ -n "${UBOOT_CONFIG}" ]
231 then
232 for config in ${UBOOT_MACHINE}; do
233 i=$(expr $i + 1);
234 for type in ${UBOOT_CONFIG}; do
235 j=$(expr $j + 1);
236 if [ $j -eq $i ]
237 then
238 install -d ${DEPLOYDIR}
239 install -m 644 ${B}/${config}/u-boot-${type}.${UBOOT_SUFFIX} ${DEPLOYDIR}/u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX}
240 cd ${DEPLOYDIR}
241 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_SYMLINK}-${type}
242 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_SYMLINK}
243 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_BINARY}-${type}
244 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_SUFFIX} ${UBOOT_BINARY}
245 fi
246 done
247 unset j
248 done
249 unset i
250 else
251 install -d ${DEPLOYDIR}
252 install -m 644 ${B}/${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE}
253 cd ${DEPLOYDIR}
254 rm -f ${UBOOT_BINARY} ${UBOOT_SYMLINK}
255 ln -sf ${UBOOT_IMAGE} ${UBOOT_SYMLINK}
256 ln -sf ${UBOOT_IMAGE} ${UBOOT_BINARY}
257 fi
258
259 if [ -n "${UBOOT_ELF}" ]
260 then
261 if [ -n "${UBOOT_CONFIG}" ]
262 then
263 for config in ${UBOOT_MACHINE}; do
264 i=$(expr $i + 1);
265 for type in ${UBOOT_CONFIG}; do
266 j=$(expr $j + 1);
267 if [ $j -eq $i ]
268 then
269 install -m 644 ${B}/${config}/${UBOOT_ELF} ${DEPLOYDIR}/u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}
270 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_BINARY}-${type}
271 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_BINARY}
272 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_SYMLINK}-${type}
273 ln -sf u-boot-${type}-${PV}-${PR}.${UBOOT_ELF_SUFFIX} ${DEPLOYDIR}/${UBOOT_ELF_SYMLINK}
274 fi
275 done
276 unset j
277 done
278 unset i
279 else
280 install -m 644 ${B}/${UBOOT_ELF} ${DEPLOYDIR}/${UBOOT_ELF_IMAGE}
281 ln -sf ${UBOOT_ELF_IMAGE} ${DEPLOYDIR}/${UBOOT_ELF_BINARY}
282 ln -sf ${UBOOT_ELF_IMAGE} ${DEPLOYDIR}/${UBOOT_ELF_SYMLINK}
283 fi
284 fi
285
286
287 if [ -n "${SPL_BINARY}" ]
288 then
289 if [ -n "${UBOOT_CONFIG}" ]
290 then
291 for config in ${UBOOT_MACHINE}; do
292 i=$(expr $i + 1);
293 for type in ${UBOOT_CONFIG}; do
294 j=$(expr $j + 1);
295 if [ $j -eq $i ]
296 then
297 install -m 644 ${B}/${config}/${SPL_BINARY} ${DEPLOYDIR}/${SPL_IMAGE}-${type}-${PV}-${PR}
298 rm -f ${DEPLOYDIR}/${SPL_BINARYNAME} ${DEPLOYDIR}/${SPL_SYMLINK}-${type}
299 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_BINARYNAME}-${type}
300 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_BINARYNAME}
301 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_SYMLINK}-${type}
302 ln -sf ${SPL_IMAGE}-${type}-${PV}-${PR} ${DEPLOYDIR}/${SPL_SYMLINK}
303 fi
304 done
305 unset j
306 done
307 unset i
308 else
309 install -m 644 ${B}/${SPL_BINARY} ${DEPLOYDIR}/${SPL_IMAGE}
310 rm -f ${DEPLOYDIR}/${SPL_BINARYNAME} ${DEPLOYDIR}/${SPL_SYMLINK}
311 ln -sf ${SPL_IMAGE} ${DEPLOYDIR}/${SPL_BINARYNAME}
312 ln -sf ${SPL_IMAGE} ${DEPLOYDIR}/${SPL_SYMLINK}
313 fi
314 fi
315
316
317 if [ -n "${UBOOT_ENV}" ]
318 then
319 install -m 644 ${WORKDIR}/${UBOOT_ENV_BINARY} ${DEPLOYDIR}/${UBOOT_ENV_IMAGE}
320 rm -f ${DEPLOYDIR}/${UBOOT_ENV_BINARY} ${DEPLOYDIR}/${UBOOT_ENV_SYMLINK}
321 ln -sf ${UBOOT_ENV_IMAGE} ${DEPLOYDIR}/${UBOOT_ENV_BINARY}
322 ln -sf ${UBOOT_ENV_IMAGE} ${DEPLOYDIR}/${UBOOT_ENV_SYMLINK}
323 fi
324
325 if [ "${UBOOT_EXTLINUX}" = "1" ]
326 then
327 install -m 644 ${UBOOT_EXTLINUX_CONFIG} ${DEPLOYDIR}/${UBOOT_EXTLINUX_SYMLINK}
328 ln -sf ${UBOOT_EXTLINUX_SYMLINK} ${DEPLOYDIR}/${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}
329 ln -sf ${UBOOT_EXTLINUX_SYMLINK} ${DEPLOYDIR}/${UBOOT_EXTLINUX_CONF_NAME}
330 fi
331}
332
333addtask deploy before do_build after do_compile