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 27, 2025
1 parent b7c6be8 commit d6d4118
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion meta-balena-common/classes/image-balena.bbclass
Original file line number Diff line number Diff line change
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 @@ -55,7 +55,7 @@ BALENA_BOOT_PARTITION_FILES:append = "${@bb.utils.contains('MACHINE_FEATURES','e
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"
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
2 changes: 1 addition & 1 deletion meta-balena-common/recipes-core/images/balena-image.bb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BALENA_BOOT_PARTITION_FILES:append = "${@oe.utils.conditional('SIGN_API','','','
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"
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 d6d4118

Please sign in to comment.