1*4882a593Smuzhiyun# Handle U-Boot config for a machine 2*4882a593Smuzhiyun# 3*4882a593Smuzhiyun# The format to specify it, in the machine, is: 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# UBOOT_CONFIG ??= <default> 6*4882a593Smuzhiyun# UBOOT_CONFIG[foo] = "config,images,binary" 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# or 9*4882a593Smuzhiyun# 10*4882a593Smuzhiyun# UBOOT_MACHINE = "config" 11*4882a593Smuzhiyun# 12*4882a593Smuzhiyun# Copyright 2013, 2014 (C) O.S. Systems Software LTDA. 13*4882a593Smuzhiyun 14*4882a593Smuzhiyundef removesuffix(s, suffix): 15*4882a593Smuzhiyun if suffix and s.endswith(suffix): 16*4882a593Smuzhiyun return s[:-len(suffix)] 17*4882a593Smuzhiyun return s 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun# Some versions of u-boot use .bin and others use .img. By default use .bin 20*4882a593Smuzhiyun# but enable individual recipes to change this value. 21*4882a593SmuzhiyunUBOOT_SUFFIX ??= "bin" 22*4882a593SmuzhiyunUBOOT_BINARY ?= "u-boot.${UBOOT_SUFFIX}" 23*4882a593SmuzhiyunUBOOT_BINARYNAME ?= "${@os.path.splitext(d.getVar("UBOOT_BINARY"))[0]}" 24*4882a593SmuzhiyunUBOOT_IMAGE ?= "${UBOOT_BINARYNAME}-${MACHINE}-${PV}-${PR}.${UBOOT_SUFFIX}" 25*4882a593SmuzhiyunUBOOT_SYMLINK ?= "${UBOOT_BINARYNAME}-${MACHINE}.${UBOOT_SUFFIX}" 26*4882a593SmuzhiyunUBOOT_MAKE_TARGET ?= "all" 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun# Output the ELF generated. Some platforms can use the ELF file and directly 29*4882a593Smuzhiyun# load it (JTAG booting, QEMU) additionally the ELF can be used for debugging 30*4882a593Smuzhiyun# purposes. 31*4882a593SmuzhiyunUBOOT_ELF ?= "" 32*4882a593SmuzhiyunUBOOT_ELF_SUFFIX ?= "elf" 33*4882a593SmuzhiyunUBOOT_ELF_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.${UBOOT_ELF_SUFFIX}" 34*4882a593SmuzhiyunUBOOT_ELF_BINARY ?= "u-boot.${UBOOT_ELF_SUFFIX}" 35*4882a593SmuzhiyunUBOOT_ELF_SYMLINK ?= "u-boot-${MACHINE}.${UBOOT_ELF_SUFFIX}" 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun# Some versions of u-boot build an SPL (Second Program Loader) image that 38*4882a593Smuzhiyun# should be packaged along with the u-boot binary as well as placed in the 39*4882a593Smuzhiyun# deploy directory. For those versions they can set the following variables 40*4882a593Smuzhiyun# to allow packaging the SPL. 41*4882a593SmuzhiyunSPL_SUFFIX ?= "" 42*4882a593SmuzhiyunSPL_BINARY ?= "" 43*4882a593SmuzhiyunSPL_DELIMITER ?= "${@'.' if d.getVar("SPL_SUFFIX") else ''}" 44*4882a593SmuzhiyunSPL_BINARYFILE ?= "${@os.path.basename(d.getVar("SPL_BINARY"))}" 45*4882a593SmuzhiyunSPL_BINARYNAME ?= "${@removesuffix(d.getVar("SPL_BINARYFILE"), "." + d.getVar("SPL_SUFFIX"))}" 46*4882a593SmuzhiyunSPL_IMAGE ?= "${SPL_BINARYNAME}-${MACHINE}-${PV}-${PR}${SPL_DELIMITER}${SPL_SUFFIX}" 47*4882a593SmuzhiyunSPL_SYMLINK ?= "${SPL_BINARYNAME}-${MACHINE}${SPL_DELIMITER}${SPL_SUFFIX}" 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun# Additional environment variables or a script can be installed alongside 50*4882a593Smuzhiyun# u-boot to be used automatically on boot. This file, typically 'uEnv.txt' 51*4882a593Smuzhiyun# or 'boot.scr', should be packaged along with u-boot as well as placed in the 52*4882a593Smuzhiyun# deploy directory. Machine configurations needing one of these files should 53*4882a593Smuzhiyun# include it in the SRC_URI and set the UBOOT_ENV parameter. 54*4882a593SmuzhiyunUBOOT_ENV_SUFFIX ?= "txt" 55*4882a593SmuzhiyunUBOOT_ENV ?= "" 56*4882a593SmuzhiyunUBOOT_ENV_SRC_SUFFIX ?= "cmd" 57*4882a593SmuzhiyunUBOOT_ENV_SRC ?= "${UBOOT_ENV}.${UBOOT_ENV_SRC_SUFFIX}" 58*4882a593SmuzhiyunUBOOT_ENV_BINARY ?= "${UBOOT_ENV}.${UBOOT_ENV_SUFFIX}" 59*4882a593SmuzhiyunUBOOT_ENV_IMAGE ?= "${UBOOT_ENV}-${MACHINE}-${PV}-${PR}.${UBOOT_ENV_SUFFIX}" 60*4882a593SmuzhiyunUBOOT_ENV_SYMLINK ?= "${UBOOT_ENV}-${MACHINE}.${UBOOT_ENV_SUFFIX}" 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun# Default name of u-boot initial env, but enable individual recipes to change 63*4882a593Smuzhiyun# this value. 64*4882a593SmuzhiyunUBOOT_INITIAL_ENV ?= "${PN}-initial-env" 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun# U-Boot EXTLINUX variables. U-Boot searches for /boot/extlinux/extlinux.conf 67*4882a593Smuzhiyun# to find EXTLINUX conf file. 68*4882a593SmuzhiyunUBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux" 69*4882a593SmuzhiyunUBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf" 70*4882a593SmuzhiyunUBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}" 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun# Options for the device tree compiler passed to mkimage '-D' feature: 73*4882a593SmuzhiyunUBOOT_MKIMAGE_DTCOPTS ??= "" 74*4882a593SmuzhiyunSPL_MKIMAGE_DTCOPTS ??= "" 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun# mkimage command 77*4882a593SmuzhiyunUBOOT_MKIMAGE ?= "uboot-mkimage" 78*4882a593SmuzhiyunUBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun# Arguments passed to mkimage for signing 81*4882a593SmuzhiyunUBOOT_MKIMAGE_SIGN_ARGS ?= "" 82*4882a593SmuzhiyunSPL_MKIMAGE_SIGN_ARGS ?= "" 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun# Options to deploy the u-boot device tree 85*4882a593SmuzhiyunUBOOT_DTB ?= "" 86*4882a593SmuzhiyunUBOOT_DTB_BINARY ??= "" 87*4882a593Smuzhiyun 88*4882a593Smuzhiyunpython () { 89*4882a593Smuzhiyun ubootmachine = d.getVar("UBOOT_MACHINE") 90*4882a593Smuzhiyun ubootconfigflags = d.getVarFlags('UBOOT_CONFIG') 91*4882a593Smuzhiyun ubootbinary = d.getVar('UBOOT_BINARY') 92*4882a593Smuzhiyun ubootbinaries = d.getVar('UBOOT_BINARIES') 93*4882a593Smuzhiyun # The "doc" varflag is special, we don't want to see it here 94*4882a593Smuzhiyun ubootconfigflags.pop('doc', None) 95*4882a593Smuzhiyun ubootconfig = (d.getVar('UBOOT_CONFIG') or "").split() 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun if not ubootmachine and not ubootconfig: 98*4882a593Smuzhiyun PN = d.getVar("PN") 99*4882a593Smuzhiyun FILE = os.path.basename(d.getVar("FILE")) 100*4882a593Smuzhiyun bb.debug(1, "To build %s, see %s for instructions on \ 101*4882a593Smuzhiyun setting up your machine config" % (PN, FILE)) 102*4882a593Smuzhiyun raise bb.parse.SkipRecipe("Either UBOOT_MACHINE or UBOOT_CONFIG must be set in the %s machine configuration." % d.getVar("MACHINE")) 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun if ubootmachine and ubootconfig: 105*4882a593Smuzhiyun raise bb.parse.SkipRecipe("You cannot use UBOOT_MACHINE and UBOOT_CONFIG at the same time.") 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun if ubootconfigflags and ubootbinaries: 108*4882a593Smuzhiyun raise bb.parse.SkipRecipe("You cannot use UBOOT_BINARIES as it is internal to uboot_config.bbclass.") 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun if len(ubootconfig) > 0: 111*4882a593Smuzhiyun for config in ubootconfig: 112*4882a593Smuzhiyun for f, v in ubootconfigflags.items(): 113*4882a593Smuzhiyun if config == f: 114*4882a593Smuzhiyun items = v.split(',') 115*4882a593Smuzhiyun if items[0] and len(items) > 3: 116*4882a593Smuzhiyun raise bb.parse.SkipRecipe('Only config,images,binary can be specified!') 117*4882a593Smuzhiyun d.appendVar('UBOOT_MACHINE', ' ' + items[0]) 118*4882a593Smuzhiyun # IMAGE_FSTYPES appending 119*4882a593Smuzhiyun if len(items) > 1 and items[1]: 120*4882a593Smuzhiyun bb.debug(1, "Appending '%s' to IMAGE_FSTYPES." % items[1]) 121*4882a593Smuzhiyun d.appendVar('IMAGE_FSTYPES', ' ' + items[1]) 122*4882a593Smuzhiyun if len(items) > 2 and items[2]: 123*4882a593Smuzhiyun bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % items[2]) 124*4882a593Smuzhiyun d.appendVar('UBOOT_BINARIES', ' ' + items[2]) 125*4882a593Smuzhiyun else: 126*4882a593Smuzhiyun bb.debug(1, "Appending '%s' to UBOOT_BINARIES." % ubootbinary) 127*4882a593Smuzhiyun d.appendVar('UBOOT_BINARIES', ' ' + ubootbinary) 128*4882a593Smuzhiyun break 129*4882a593Smuzhiyun} 130