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 | |
| 68 | # Default name of u-boot initial env, but enable individual recipes to change |
| 69 | # this value. |
| 70 | UBOOT_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. |
| 74 | UBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux" |
| 75 | UBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf" |
| 76 | UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}" |
| 77 | |
| 78 | # Options for the device tree compiler passed to mkimage '-D' feature: |
| 79 | UBOOT_MKIMAGE_DTCOPTS ??= "" |
| 80 | SPL_MKIMAGE_DTCOPTS ??= "" |
| 81 | |
| 82 | # mkimage command |
| 83 | UBOOT_MKIMAGE ?= "uboot-mkimage" |
| 84 | UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" |
| 85 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 86 | # Signature activation - this requires KERNEL_IMAGETYPE = "fitImage" |
| 87 | UBOOT_SIGN_ENABLE ?= "0" |
| 88 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 89 | # Arguments passed to mkimage for signing |
| 90 | UBOOT_MKIMAGE_SIGN_ARGS ?= "" |
| 91 | SPL_MKIMAGE_SIGN_ARGS ?= "" |
| 92 | |
| 93 | # Options to deploy the u-boot device tree |
| 94 | UBOOT_DTB ?= "" |
| 95 | UBOOT_DTB_BINARY ??= "" |
| 96 | |
| 97 | python () { |
| 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())) |
Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 143 | |
| 144 | if len(ubootconfig) == 1: |
| 145 | d.setVar('KCONFIG_CONFIG_ROOTDIR', os.path.join(d.getVar("B"), d.getVar("UBOOT_MACHINE").strip())) |
| 146 | else: |
| 147 | # Disable menuconfig for multiple configs |
| 148 | d.setVar('KCONFIG_CONFIG_ENABLE_MENUCONFIG', "false") |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 149 | } |