Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # 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 | |
| 17 | def removesuffix(s, suffix): |
| 18 | if suffix and s.endswith(suffix): |
| 19 | return s[:-len(suffix)] |
| 20 | return s |
| 21 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 22 | UBOOT_ENTRYPOINT ?= "20008000" |
| 23 | UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}" |
| 24 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 25 | # Some versions of u-boot use .bin and others use .img. By default use .bin |
| 26 | # but enable individual recipes to change this value. |
| 27 | UBOOT_SUFFIX ??= "bin" |
| 28 | UBOOT_BINARY ?= "u-boot.${UBOOT_SUFFIX}" |
| 29 | UBOOT_BINARYNAME ?= "${@os.path.splitext(d.getVar("UBOOT_BINARY"))[0]}" |
| 30 | UBOOT_IMAGE ?= "${UBOOT_BINARYNAME}-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}" |
| 31 | UBOOT_SYMLINK ?= "${UBOOT_BINARYNAME}-${MACHINE}.${UBOOT_SUFFIX}" |
| 32 | UBOOT_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. |
| 37 | UBOOT_ELF ?= "" |
| 38 | UBOOT_ELF_SUFFIX ?= "elf" |
| 39 | UBOOT_ELF_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}" |
| 40 | UBOOT_ELF_BINARY ?= "u-boot.${UBOOT_ELF_SUFFIX}" |
| 41 | UBOOT_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. |
| 47 | SPL_SUFFIX ?= "" |
| 48 | SPL_BINARY ?= "" |
| 49 | SPL_DELIMITER ?= "${@'.' if d.getVar("SPL_SUFFIX") else ''}" |
| 50 | SPL_BINARYFILE ?= "${@os.path.basename(d.getVar("SPL_BINARY"))}" |
| 51 | SPL_BINARYNAME ?= "${@removesuffix(d.getVar("SPL_BINARYFILE"), "." + d.getVar("SPL_SUFFIX"))}" |
| 52 | SPL_IMAGE ?= "${SPL_BINARYNAME}-${MACHINE}-${PV}-${PR}${SPL_DELIMITER}${SPL_SUFFIX}" |
| 53 | SPL_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. |
| 60 | UBOOT_ENV_SUFFIX ?= "txt" |
| 61 | UBOOT_ENV ?= "" |
| 62 | UBOOT_ENV_SRC_SUFFIX ?= "cmd" |
| 63 | UBOOT_ENV_SRC ?= "${UBOOT_ENV}.${UBOOT_ENV_SRC_SUFFIX}" |
| 64 | UBOOT_ENV_BINARY ?= "${UBOOT_ENV}.${UBOOT_ENV_SUFFIX}" |
| 65 | UBOOT_ENV_IMAGE ?= "${UBOOT_ENV}-${MACHINE}-${PV}-${PR}.${UBOOT_ENV_SUFFIX}" |
| 66 | UBOOT_ENV_SYMLINK ?= "${UBOOT_ENV}-${MACHINE}.${UBOOT_ENV_SUFFIX}" |
| 67 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 68 | # U-Boot EXTLINUX variables. U-Boot searches for /boot/extlinux/extlinux.conf |
| 69 | # to find EXTLINUX conf file. |
| 70 | UBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux" |
| 71 | UBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf" |
| 72 | UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}" |
| 73 | |
| 74 | # Options for the device tree compiler passed to mkimage '-D' feature: |
| 75 | UBOOT_MKIMAGE_DTCOPTS ??= "" |
| 76 | SPL_MKIMAGE_DTCOPTS ??= "" |
| 77 | |
| 78 | # mkimage command |
| 79 | UBOOT_MKIMAGE ?= "uboot-mkimage" |
| 80 | UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" |
| 81 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 82 | # Signature activation - this requires KERNEL_IMAGETYPE = "fitImage" |
| 83 | UBOOT_SIGN_ENABLE ?= "0" |
| 84 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 85 | # Arguments passed to mkimage for signing |
| 86 | UBOOT_MKIMAGE_SIGN_ARGS ?= "" |
| 87 | SPL_MKIMAGE_SIGN_ARGS ?= "" |
| 88 | |
| 89 | # Options to deploy the u-boot device tree |
| 90 | UBOOT_DTB ?= "" |
| 91 | UBOOT_DTB_BINARY ??= "" |
| 92 | |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 93 | # uboot-fit_check_sign command |
| 94 | UBOOT_FIT_CHECK_SIGN ?= "uboot-fit_check_sign" |
| 95 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 96 | python () { |
| 97 | ubootmachine = d.getVar("UBOOT_MACHINE") |
| 98 | ubootconfigflags = d.getVarFlags('UBOOT_CONFIG') |
| 99 | ubootbinary = d.getVar('UBOOT_BINARY') |
| 100 | ubootbinaries = d.getVar('UBOOT_BINARIES') |
| 101 | # The "doc" varflag is special, we don't want to see it here |
| 102 | ubootconfigflags.pop('doc', None) |
| 103 | ubootconfig = (d.getVar('UBOOT_CONFIG') or "").split() |
| 104 | |
| 105 | if not ubootmachine and not ubootconfig: |
| 106 | PN = d.getVar("PN") |
| 107 | FILE = os.path.basename(d.getVar("FILE")) |
| 108 | bb.debug(1, "To build %s, see %s for instructions on \ |
| 109 | setting up your machine config" % (PN, FILE)) |
| 110 | raise bb.parse.SkipRecipe("Either UBOOT_MACHINE or UBOOT_CONFIG must be set in the %s machine configuration." % d.getVar("MACHINE")) |
| 111 | |
| 112 | if ubootmachine and ubootconfig: |
| 113 | raise bb.parse.SkipRecipe("You cannot use UBOOT_MACHINE and UBOOT_CONFIG at the same time.") |
| 114 | |
| 115 | if ubootconfigflags and ubootbinaries: |
| 116 | raise bb.parse.SkipRecipe("You cannot use UBOOT_BINARIES as it is internal to uboot_config.bbclass.") |
| 117 | |
| 118 | if len(ubootconfig) > 0: |
| 119 | for config in ubootconfig: |
| 120 | found = False |
| 121 | for f, v in ubootconfigflags.items(): |
| 122 | if config == f: |
| 123 | found = True |
| 124 | items = v.split(',') |
| 125 | if items[0] and len(items) > 3: |
| 126 | raise bb.parse.SkipRecipe('Only config,images,binary can be specified!') |
| 127 | d.appendVar('UBOOT_MACHINE', ' ' + items[0]) |
| 128 | # IMAGE_FSTYPES appending |
| 129 | if len(items) > 1 and items[1]: |
| 130 | bb.debug(1, "Appending '%s' to IMAGE_FSTYPES." % items[1]) |
| 131 | d.appendVar('IMAGE_FSTYPES', ' ' + items[1]) |
| 132 | if len(items) > 2 and items[2]: |
| 133 | bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % items[2]) |
| 134 | d.appendVar('UBOOT_BINARIES', ' ' + items[2]) |
| 135 | else: |
| 136 | bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % ubootbinary) |
| 137 | d.appendVar('UBOOT_BINARIES', ' ' + ubootbinary) |
| 138 | break |
| 139 | |
| 140 | if not found: |
| 141 | raise bb.parse.SkipRecipe("The selected UBOOT_CONFIG key %s has no match in %s." % (ubootconfig, ubootconfigflags.keys())) |
Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 142 | |
| 143 | if len(ubootconfig) == 1: |
| 144 | d.setVar('KCONFIG_CONFIG_ROOTDIR', os.path.join(d.getVar("B"), d.getVar("UBOOT_MACHINE").strip())) |
| 145 | else: |
| 146 | # Disable menuconfig for multiple configs |
| 147 | d.setVar('KCONFIG_CONFIG_ENABLE_MENUCONFIG', "false") |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 148 | } |