Skip to content

Commit

Permalink
Add DEVICE_TYPE
Browse files Browse the repository at this point in the history
Allow for device type names and machine to differ. Until know, the
device type contract had to be named `$MACHINE.json`, and then the
slug in it could be something else.

The DEVICE_TYPE variable that defaults to MACHINE for backwards
compatibility allows for the same MACHINE to build several device types
by passing a different DEVICE_TYPE to the build.

Change-type: patch
Signed-off-by: Alex Gonzalez <alexg@balena.io>
  • Loading branch information
alexgg committed Feb 28, 2025
1 parent b7c6be8 commit 955d169
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions meta-balena-common/classes/image-balena.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ init_config_json() {
echo "$(cat ${1}/config.json | jq -S ".persistentLogging=false")" > ${1}/config.json

# Find board json and extract slug
json_path=${BALENA_COREBASE}/../../../${MACHINE}.json
json_path=${BALENA_COREBASE}/../../../${DEVICE_TYPE}.json
slug=$(jq .slug $json_path)

# Set deviceType for supervisor
Expand Down Expand Up @@ -321,11 +321,12 @@ def get_rel_path(layers, rel, d):
def get_slug(d):
import json
slug = "unknown"
device_type = d.getVar("DEVICE_TYPE", True)
machine = d.getVar("MACHINE", True)
resinboardpath = get_rel_path(['meta-resin-common','meta-balena-common'], '../../../', d)
if not resinboardpath:
return slug
jsonfile = os.path.normpath(os.path.join(resinboardpath, machine + ".json"))
jsonfile = os.path.normpath(os.path.join(resinboardpath, device_type + ".json"))
try:
with open(jsonfile, 'r') as fd:
machinejson = json.load(fd)
Expand Down
3 changes: 3 additions & 0 deletions meta-balena-common/conf/distro/include/balena-os.inc
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,6 @@ BALENA_USE_LUKS ?= "1"
# This is the docker API version for v20.10
# balena version --format '{{.Server.APIVersion}}'
BALENA_API_VERSION ?= "1.41"

# Override if the device-type.json file is not named as the machine
DEVICE_TYPE ?= "${MACHINE}"
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ do_compile[noexec] = "1"

api_fetch_supervisor_image() {
_version=$1
_arch=$(jq --raw-output '.arch' "${TOPDIR}/../${MACHINE}.json")
_arch=$(jq --raw-output '.arch' "${TOPDIR}/../${DEVICE_TYPE}.json")
_api_env="${BALENA_API_ENV}"
_token="${BALENA_API_TOKEN}"
[ -z "${_token}" ] && [ -f "~/.balena/token" ] && _token=$(cat "~/.balena/token") || true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ BALENA_BOOT_PARTITION_FILES:append = "${@bb.utils.contains('MACHINE_FEATURES','e
# Put the resin logo, uEnv.txt files inside the boot partition
BALENA_BOOT_PARTITION_FILES:append = " balena-logo.png:/splash/balena-logo.png"

# add the generated <machine-name>.json to the flash-boot partition, renamed as device-type.json
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_COREBASE}/../../../${MACHINE}.json:/device-type.json"
# add the generated <devicetype-name>.json to the flash-boot partition, renamed as device-type.json
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_COREBASE}/../../../${DEVICE_TYPE}.json:/device-type.json"

# Put balena-image in the flasher rootfs
add_resin_image_to_flasher_rootfs() {
Expand Down
4 changes: 2 additions & 2 deletions meta-balena-common/recipes-core/images/balena-image.bb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ BALENA_BOOT_PARTITION_FILES:append = "${@oe.utils.conditional('SIGN_API','','','
# add the LUKS variant of GRUB config if needed
BALENA_BOOT_PARTITION_FILES:append = "${@bb.utils.contains('MACHINE_FEATURES','efi',' grub.cfg_internal_luks:/EFI/BOOT/grub-luks.cfg','',d)}"

# add the generated <machine-name>.json to the resin-boot partition, renamed as device-type.json
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_COREBASE}/../../../${MACHINE}.json:/device-type.json"
# add the generated <devicetype-name>.json to the resin-boot partition, renamed as device-type.json
BALENA_BOOT_PARTITION_FILES:append = " ${BALENA_COREBASE}/../../../${DEVICE_TYPE}.json:/device-type.json"

# example NetworkManager config file
BALENA_BOOT_PARTITION_FILES:append = " \
Expand Down

0 comments on commit 955d169

Please sign in to comment.