Skip to content

Commit

Permalink
west/sign: Move from using partition label property
Browse files Browse the repository at this point in the history
MCUmgr no longer uses DTS node property label to identify
slots for image upload and running application. It now uses DTS node
labels for that purpose.
This commit moves `west sign` from using label properties
to DTS node labels, same way the MCUmgr does.

(cherry picked from commit 86c4b4c)

Original-Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
GitOrigin-RevId: 86c4b4c
Change-Id: I2fda6d5d37eee0908526c13f5360ed945296901f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4287510
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
Tested-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Tested-by: CopyBot Service Account <copybot.service@gmail.com>
Commit-Queue: Al Semjonovs <asemjonovs@google.com>
Tested-by: Al Semjonovs <asemjonovs@google.com>
  • Loading branch information
de-nordic authored and Chromeos LUCI committed Feb 24, 2023
1 parent 8eca31e commit ec0738a
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions scripts/west_commands/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,34 +333,35 @@ def edt_flash_node(b, quiet=False):
flash = edt.chosen_node('zephyr,flash')
if not flash:
log.die('devicetree has no chosen zephyr,flash node;',
"can't infer flash write block or image-0 slot sizes")
"can't infer flash write block or slot0_partition slot sizes")

return flash

@staticmethod
def edt_flash_params(flash):
# Get the flash device's write alignment and offset from the
# image-0 partition and the size from image-1 partition, out of the
# build directory's devicetree. image-1 partition size is used,
# slot0_partition and the size from slot1_partition , out of the
# build directory's devicetree. slot1_partition size is used,
# when available, because in swap-move mode it can be one sector
# smaller. When not available, fallback to image-0 (single image dfu).
# smaller. When not available, fallback to slot0_partition (single slot dfu).

# The node must have a "partitions" child node, which in turn
# must have child node labeled "image-0" and may have a child node
# named "image-1". By convention, the slots for consumption by
# must have child nodes with label slot0_partition and may have a child node
# with label slot1_partition. By convention, the slots for consumption by
# imgtool are linked into these partitions.
if 'partitions' not in flash.children:
log.die("DT zephyr,flash chosen node has no partitions,",
"can't find partitions for MCUboot slots")

partitions = flash.children['partitions']
images = {
node.label: node for node in partitions.children.values()
if node.label in set(['image-0', 'image-1'])
slots = {
label: node for node in partitions.children.values()
for label in node.labels
if label in set(['slot0_partition', 'slot1_partition'])
}

if 'image-0' not in images:
log.die("DT zephyr,flash chosen node has no image-0 partition,",
if 'slot0_partition' not in slots:
log.die("DT zephyr,flash chosen node has no slot0_partition partition,",
"can't determine its address")

# Die on missing or zero alignment or slot_size.
Expand All @@ -373,18 +374,18 @@ def edt_flash_params(flash):
'DT flash device write-block-size {}'.format(align))

# The partitions node, and its subnode, must provide
# the size of image-1 or image-0 partition via the regs property.
image_key = 'image-1' if 'image-1' in images else 'image-0'
if not images[image_key].regs:
log.die(f'{image_key} flash partition has no regs property;',
"can't determine size of image")
# the size of slot1_partition or slot0_partition partition via the regs property.
slot_key = 'slot0_partition' if 'slot1_partition' in slots else 'slot0_partition'
if not slots[slot_key].regs:
log.die(f'{slot_key} flash partition has no regs property;',
"can't determine size of slot")

# always use addr of image-0, which is where images are run
addr = images['image-0'].regs[0].addr
# always use addr of slot0_partition, which is where slots are run
addr = slots['slot0_partition'].regs[0].addr

size = images[image_key].regs[0].size
size = slots[slot_key].regs[0].size
if size == 0:
log.die('expected nonzero slot size for {}'.format(image_key))
log.die('expected nonzero slot size for {}'.format(slot_key))

return (align, addr, size)

Expand Down

0 comments on commit ec0738a

Please sign in to comment.