Patrick Williams | c124f4f | 2015-09-15 14:41:29 -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> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 6 | # UBOOT_CONFIG[foo] = "config,images,binary" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # |
| 8 | # or |
| 9 | # |
| 10 | # UBOOT_MACHINE = "config" |
| 11 | # |
| 12 | # Copyright 2013, 2014 (C) O.S. Systems Software LTDA. |
| 13 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 14 | def removesuffix(s, suffix): |
| 15 | if suffix and s.endswith(suffix): |
| 16 | return s[:-len(suffix)] |
| 17 | return s |
| 18 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 19 | # Some versions of u-boot use .bin and others use .img. By default use .bin |
| 20 | # but enable individual recipes to change this value. |
| 21 | UBOOT_SUFFIX ??= "bin" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 22 | UBOOT_BINARY ?= "u-boot.${UBOOT_SUFFIX}" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 23 | UBOOT_BINARYNAME ?= "${@os.path.splitext(d.getVar("UBOOT_BINARY"))[0]}" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 24 | UBOOT_IMAGE ?= "${UBOOT_BINARYNAME}-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}" |
| 25 | UBOOT_SYMLINK ?= "${UBOOT_BINARYNAME}-${MACHINE}.${UBOOT_SUFFIX}" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 26 | UBOOT_MAKE_TARGET ?= "all" |
| 27 | |
| 28 | # Output the ELF generated. Some platforms can use the ELF file and directly |
| 29 | # load it (JTAG booting, QEMU) additionally the ELF can be used for debugging |
| 30 | # purposes. |
| 31 | UBOOT_ELF ?= "" |
| 32 | UBOOT_ELF_SUFFIX ?= "elf" |
| 33 | UBOOT_ELF_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}" |
| 34 | UBOOT_ELF_BINARY ?= "u-boot.${UBOOT_ELF_SUFFIX}" |
| 35 | UBOOT_ELF_SYMLINK ?= "u-boot-${MACHINE}.${UBOOT_ELF_SUFFIX}" |
| 36 | |
| 37 | # Some versions of u-boot build an SPL (Second Program Loader) image that |
| 38 | # should be packaged along with the u-boot binary as well as placed in the |
| 39 | # deploy directory. For those versions they can set the following variables |
| 40 | # to allow packaging the SPL. |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 41 | SPL_SUFFIX ?= "" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 42 | SPL_BINARY ?= "" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 43 | SPL_DELIMITER ?= "${@'.' if d.getVar("SPL_SUFFIX") else ''}" |
| 44 | SPL_BINARYFILE ?= "${@os.path.basename(d.getVar("SPL_BINARY"))}" |
| 45 | SPL_BINARYNAME ?= "${@removesuffix(d.getVar("SPL_BINARYFILE"), "." + d.getVar("SPL_SUFFIX"))}" |
| 46 | SPL_IMAGE ?= "${SPL_BINARYNAME}-${MACHINE}-${PV}-${PR}${SPL_DELIMITER}${SPL_SUFFIX}" |
| 47 | SPL_SYMLINK ?= "${SPL_BINARYNAME}-${MACHINE}${SPL_DELIMITER}${SPL_SUFFIX}" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 48 | |
| 49 | # Additional environment variables or a script can be installed alongside |
| 50 | # u-boot to be used automatically on boot. This file, typically 'uEnv.txt' |
| 51 | # or 'boot.scr', should be packaged along with u-boot as well as placed in the |
| 52 | # deploy directory. Machine configurations needing one of these files should |
| 53 | # include it in the SRC_URI and set the UBOOT_ENV parameter. |
| 54 | UBOOT_ENV_SUFFIX ?= "txt" |
| 55 | UBOOT_ENV ?= "" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 56 | UBOOT_ENV_SRC_SUFFIX ?= "cmd" |
| 57 | UBOOT_ENV_SRC ?= "${UBOOT_ENV}.${UBOOT_ENV_SRC_SUFFIX}" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 58 | UBOOT_ENV_BINARY ?= "${UBOOT_ENV}.${UBOOT_ENV_SUFFIX}" |
| 59 | UBOOT_ENV_IMAGE ?= "${UBOOT_ENV}-${MACHINE}-${PV}-${PR}.${UBOOT_ENV_SUFFIX}" |
| 60 | UBOOT_ENV_SYMLINK ?= "${UBOOT_ENV}-${MACHINE}.${UBOOT_ENV_SUFFIX}" |
| 61 | |
| 62 | # Default name of u-boot initial env, but enable individual recipes to change |
| 63 | # this value. |
| 64 | UBOOT_INITIAL_ENV ?= "${PN}-initial-env" |
| 65 | |
| 66 | # U-Boot EXTLINUX variables. U-Boot searches for /boot/extlinux/extlinux.conf |
| 67 | # to find EXTLINUX conf file. |
| 68 | UBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux" |
| 69 | UBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf" |
| 70 | UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}" |
| 71 | |
| 72 | # Options for the device tree compiler passed to mkimage '-D' feature: |
| 73 | UBOOT_MKIMAGE_DTCOPTS ??= "" |
| 74 | SPL_MKIMAGE_DTCOPTS ??= "" |
| 75 | |
| 76 | # mkimage command |
| 77 | UBOOT_MKIMAGE ?= "uboot-mkimage" |
| 78 | UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" |
| 79 | |
| 80 | # Arguments passed to mkimage for signing |
| 81 | UBOOT_MKIMAGE_SIGN_ARGS ?= "" |
| 82 | SPL_MKIMAGE_SIGN_ARGS ?= "" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 84 | # Options to deploy the u-boot device tree |
| 85 | UBOOT_DTB ?= "" |
| 86 | UBOOT_DTB_BINARY ??= "" |
| 87 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 89 | ubootmachine = d.getVar("UBOOT_MACHINE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | ubootconfigflags = d.getVarFlags('UBOOT_CONFIG') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 91 | ubootbinary = d.getVar('UBOOT_BINARY') |
| 92 | ubootbinaries = d.getVar('UBOOT_BINARIES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 93 | # The "doc" varflag is special, we don't want to see it here |
| 94 | ubootconfigflags.pop('doc', None) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | ubootconfig = (d.getVar('UBOOT_CONFIG') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 97 | if not ubootmachine and not ubootconfig: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | PN = d.getVar("PN") |
| 99 | FILE = os.path.basename(d.getVar("FILE")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | bb.debug(1, "To build %s, see %s for instructions on \ |
| 101 | setting up your machine config" % (PN, FILE)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 102 | raise bb.parse.SkipRecipe("Either UBOOT_MACHINE or UBOOT_CONFIG must be set in the %s machine configuration." % d.getVar("MACHINE")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 104 | if ubootmachine and ubootconfig: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 105 | raise bb.parse.SkipRecipe("You cannot use UBOOT_MACHINE and UBOOT_CONFIG at the same time.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 107 | if ubootconfigflags and ubootbinaries: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 108 | raise bb.parse.SkipRecipe("You cannot use UBOOT_BINARIES as it is internal to uboot_config.bbclass.") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 109 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | if len(ubootconfig) > 0: |
| 111 | for config in ubootconfig: |
| 112 | for f, v in ubootconfigflags.items(): |
| 113 | if config == f: |
| 114 | items = v.split(',') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 115 | if items[0] and len(items) > 3: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 116 | raise bb.parse.SkipRecipe('Only config,images,binary can be specified!') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | d.appendVar('UBOOT_MACHINE', ' ' + items[0]) |
| 118 | # IMAGE_FSTYPES appending |
| 119 | if len(items) > 1 and items[1]: |
| 120 | bb.debug(1, "Appending '%s' to IMAGE_FSTYPES." % items[1]) |
| 121 | d.appendVar('IMAGE_FSTYPES', ' ' + items[1]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 122 | if len(items) > 2 and items[2]: |
| 123 | bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % items[2]) |
| 124 | d.appendVar('UBOOT_BINARIES', ' ' + items[2]) |
| 125 | else: |
| 126 | bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % ubootbinary) |
| 127 | d.appendVar('UBOOT_BINARIES', ' ' + ubootbinary) |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame^] | 128 | return |
| 129 | raise bb.parse.SkipRecipe("The selected UBOOT_CONFIG key %s has no match in %s." % (ubootconfig, ubootconfigflags.keys())) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | } |