blob: fb7a4bc4988be733c109566dc3a8e50897f2a60b [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
97python () {
98 ubootmachine = d.getVar("UBOOT_MACHINE")
99 ubootconfigflags = d.getVarFlags('UBOOT_CONFIG')
100 ubootbinary = d.getVar('UBOOT_BINARY')
101 ubootbinaries = d.getVar('UBOOT_BINARIES')
102 # The "doc" varflag is special, we don't want to see it here
103 ubootconfigflags.pop('doc', None)
104 ubootconfig = (d.getVar('UBOOT_CONFIG') or "").split()
105
106 if not ubootmachine and not ubootconfig:
107 PN = d.getVar("PN")
108 FILE = os.path.basename(d.getVar("FILE"))
109 bb.debug(1, "To build %s, see %s for instructions on \
110 setting up your machine config" % (PN, FILE))
111 raise bb.parse.SkipRecipe("Either UBOOT_MACHINE or UBOOT_CONFIG must be set in the %s machine configuration." % d.getVar("MACHINE"))
112
113 if ubootmachine and ubootconfig:
114 raise bb.parse.SkipRecipe("You cannot use UBOOT_MACHINE and UBOOT_CONFIG at the same time.")
115
116 if ubootconfigflags and ubootbinaries:
117 raise bb.parse.SkipRecipe("You cannot use UBOOT_BINARIES as it is internal to uboot_config.bbclass.")
118
119 if len(ubootconfig) > 0:
120 for config in ubootconfig:
121 found = False
122 for f, v in ubootconfigflags.items():
123 if config == f:
124 found = True
125 items = v.split(',')
126 if items[0] and len(items) > 3:
127 raise bb.parse.SkipRecipe('Only config,images,binary can be specified!')
128 d.appendVar('UBOOT_MACHINE', ' ' + items[0])
129 # IMAGE_FSTYPES appending
130 if len(items) > 1 and items[1]:
131 bb.debug(1, "Appending '%s' to IMAGE_FSTYPES." % items[1])
132 d.appendVar('IMAGE_FSTYPES', ' ' + items[1])
133 if len(items) > 2 and items[2]:
134 bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % items[2])
135 d.appendVar('UBOOT_BINARIES', ' ' + items[2])
136 else:
137 bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % ubootbinary)
138 d.appendVar('UBOOT_BINARIES', ' ' + ubootbinary)
139 break
140
141 if not found:
142 raise bb.parse.SkipRecipe("The selected UBOOT_CONFIG key %s has no match in %s." % (ubootconfig, ubootconfigflags.keys()))
143}