blob: 0c579e8861bbd02b6eabaf315e8f339dfbc1d285 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001# Handle U-Boot config for a machine
2#
3# The format to specify it, in the machine, is:
4#
5# UBOOT_CONFIG ??= <default>
6# UBOOT_CONFIG[foo] = "config,images,binary"
7#
8# or
9#
10# UBOOT_MACHINE = "config"
11#
12# Copyright 2013, 2014 (C) O.S. Systems Software LTDA.
13#
14# SPDX-License-Identifier: MIT
15
16
17def removesuffix(s, suffix):
18 if suffix and s.endswith(suffix):
19 return s[:-len(suffix)]
20 return s
21
Patrick Williams2390b1b2022-11-03 13:47:49 -050022UBOOT_ENTRYPOINT ?= "20008000"
23UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
24
Patrick Williams92b42cb2022-09-03 06:53:57 -050025# Some versions of u-boot use .bin and others use .img. By default use .bin
26# but enable individual recipes to change this value.
27UBOOT_SUFFIX ??= "bin"
28UBOOT_BINARY ?= "u-boot.${UBOOT_SUFFIX}"
29UBOOT_BINARYNAME ?= "${@os.path.splitext(d.getVar("UBOOT_BINARY"))[0]}"
30UBOOT_IMAGE ?= "${UBOOT_BINARYNAME}-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}"
31UBOOT_SYMLINK ?= "${UBOOT_BINARYNAME}-${MACHINE}.${UBOOT_SUFFIX}"
32UBOOT_MAKE_TARGET ?= "all"
33
34# Output the ELF generated. Some platforms can use the ELF file and directly
35# load it (JTAG booting, QEMU) additionally the ELF can be used for debugging
36# purposes.
37UBOOT_ELF ?= ""
38UBOOT_ELF_SUFFIX ?= "elf"
39UBOOT_ELF_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}"
40UBOOT_ELF_BINARY ?= "u-boot.${UBOOT_ELF_SUFFIX}"
41UBOOT_ELF_SYMLINK ?= "u-boot-${MACHINE}.${UBOOT_ELF_SUFFIX}"
42
43# Some versions of u-boot build an SPL (Second Program Loader) image that
44# should be packaged along with the u-boot binary as well as placed in the
45# deploy directory. For those versions they can set the following variables
46# to allow packaging the SPL.
47SPL_SUFFIX ?= ""
48SPL_BINARY ?= ""
49SPL_DELIMITER ?= "${@'.' if d.getVar("SPL_SUFFIX") else ''}"
50SPL_BINARYFILE ?= "${@os.path.basename(d.getVar("SPL_BINARY"))}"
51SPL_BINARYNAME ?= "${@removesuffix(d.getVar("SPL_BINARYFILE"), "." + d.getVar("SPL_SUFFIX"))}"
52SPL_IMAGE ?= "${SPL_BINARYNAME}-${MACHINE}-${PV}-${PR}${SPL_DELIMITER}${SPL_SUFFIX}"
53SPL_SYMLINK ?= "${SPL_BINARYNAME}-${MACHINE}${SPL_DELIMITER}${SPL_SUFFIX}"
54
55# Additional environment variables or a script can be installed alongside
56# u-boot to be used automatically on boot. This file, typically 'uEnv.txt'
57# or 'boot.scr', should be packaged along with u-boot as well as placed in the
58# deploy directory. Machine configurations needing one of these files should
59# include it in the SRC_URI and set the UBOOT_ENV parameter.
60UBOOT_ENV_SUFFIX ?= "txt"
61UBOOT_ENV ?= ""
62UBOOT_ENV_SRC_SUFFIX ?= "cmd"
63UBOOT_ENV_SRC ?= "${UBOOT_ENV}.${UBOOT_ENV_SRC_SUFFIX}"
64UBOOT_ENV_BINARY ?= "${UBOOT_ENV}.${UBOOT_ENV_SUFFIX}"
65UBOOT_ENV_IMAGE ?= "${UBOOT_ENV}-${MACHINE}-${PV}-${PR}.${UBOOT_ENV_SUFFIX}"
66UBOOT_ENV_SYMLINK ?= "${UBOOT_ENV}-${MACHINE}.${UBOOT_ENV_SUFFIX}"
67
68# Default name of u-boot initial env, but enable individual recipes to change
69# this value.
70UBOOT_INITIAL_ENV ?= "${PN}-initial-env"
71
72# U-Boot EXTLINUX variables. U-Boot searches for /boot/extlinux/extlinux.conf
73# to find EXTLINUX conf file.
74UBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux"
75UBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf"
76UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}"
77
78# Options for the device tree compiler passed to mkimage '-D' feature:
79UBOOT_MKIMAGE_DTCOPTS ??= ""
80SPL_MKIMAGE_DTCOPTS ??= ""
81
82# mkimage command
83UBOOT_MKIMAGE ?= "uboot-mkimage"
84UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}"
85
Patrick Williams2390b1b2022-11-03 13:47:49 -050086# Signature activation - this requires KERNEL_IMAGETYPE = "fitImage"
87UBOOT_SIGN_ENABLE ?= "0"
88
Patrick Williams92b42cb2022-09-03 06:53:57 -050089# Arguments passed to mkimage for signing
90UBOOT_MKIMAGE_SIGN_ARGS ?= ""
91SPL_MKIMAGE_SIGN_ARGS ?= ""
92
93# Options to deploy the u-boot device tree
94UBOOT_DTB ?= ""
95UBOOT_DTB_BINARY ??= ""
96
Patrick Williams73bd93f2024-02-20 08:07:48 -060097# uboot-fit_check_sign command
98UBOOT_FIT_CHECK_SIGN ?= "uboot-fit_check_sign"
99
Patrick Williams92b42cb2022-09-03 06:53:57 -0500100python () {
101 ubootmachine = d.getVar("UBOOT_MACHINE")
102 ubootconfigflags = d.getVarFlags('UBOOT_CONFIG')
103 ubootbinary = d.getVar('UBOOT_BINARY')
104 ubootbinaries = d.getVar('UBOOT_BINARIES')
105 # The "doc" varflag is special, we don't want to see it here
106 ubootconfigflags.pop('doc', None)
107 ubootconfig = (d.getVar('UBOOT_CONFIG') or "").split()
108
109 if not ubootmachine and not ubootconfig:
110 PN = d.getVar("PN")
111 FILE = os.path.basename(d.getVar("FILE"))
112 bb.debug(1, "To build %s, see %s for instructions on \
113 setting up your machine config" % (PN, FILE))
114 raise bb.parse.SkipRecipe("Either UBOOT_MACHINE or UBOOT_CONFIG must be set in the %s machine configuration." % d.getVar("MACHINE"))
115
116 if ubootmachine and ubootconfig:
117 raise bb.parse.SkipRecipe("You cannot use UBOOT_MACHINE and UBOOT_CONFIG at the same time.")
118
119 if ubootconfigflags and ubootbinaries:
120 raise bb.parse.SkipRecipe("You cannot use UBOOT_BINARIES as it is internal to uboot_config.bbclass.")
121
122 if len(ubootconfig) > 0:
123 for config in ubootconfig:
124 found = False
125 for f, v in ubootconfigflags.items():
126 if config == f:
127 found = True
128 items = v.split(',')
129 if items[0] and len(items) > 3:
130 raise bb.parse.SkipRecipe('Only config,images,binary can be specified!')
131 d.appendVar('UBOOT_MACHINE', ' ' + items[0])
132 # IMAGE_FSTYPES appending
133 if len(items) > 1 and items[1]:
134 bb.debug(1, "Appending '%s' to IMAGE_FSTYPES." % items[1])
135 d.appendVar('IMAGE_FSTYPES', ' ' + items[1])
136 if len(items) > 2 and items[2]:
137 bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % items[2])
138 d.appendVar('UBOOT_BINARIES', ' ' + items[2])
139 else:
140 bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % ubootbinary)
141 d.appendVar('UBOOT_BINARIES', ' ' + ubootbinary)
142 break
143
144 if not found:
145 raise bb.parse.SkipRecipe("The selected UBOOT_CONFIG key %s has no match in %s." % (ubootconfig, ubootconfigflags.keys()))
Patrick Williams520786c2023-06-25 16:20:36 -0500146
147 if len(ubootconfig) == 1:
148 d.setVar('KCONFIG_CONFIG_ROOTDIR', os.path.join(d.getVar("B"), d.getVar("UBOOT_MACHINE").strip()))
149 else:
150 # Disable menuconfig for multiple configs
151 d.setVar('KCONFIG_CONFIG_ENABLE_MENUCONFIG', "false")
Patrick Williams92b42cb2022-09-03 06:53:57 -0500152}