Skip to content

Commit 6237c06

Browse files
authored
Merge pull request #54 from learmj/idp_json_fixups
IDP: updates to provisioning maps and build
2 parents 7c59c68 + fb7bb49 commit 6237c06

21 files changed

+333
-153
lines changed

bin/image2json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ VERSION = "2.0.0"
1515
IMAGE_KEYS = {"IGconf_device_class",
1616
"IGconf_device_variant",
1717
"IGconf_device_storage_type",
18+
"IGconf_device_sector_size",
1819
"IGconf_image_version",
1920
"IGconf_sys_outputdir"}
2021

2122

23+
IMAGE_KEY_TYPES = {
24+
"IGconf_device_sector_size": int,
25+
# add more as needed
26+
}
27+
28+
2229
top_template = {
2330
"IGversion": VERSION,
2431
"IGmeta": [],
2532
"attributes": {
2633
"image-name": "unknown",
27-
"image-size": "0",
34+
"image-size": 0,
35+
"image-palign-bytes": "unknown",
2836
},
2937
"layout": {
3038
"partitiontable": [],
@@ -267,10 +275,11 @@ def parse_genimage_config(config_path):
267275
for img_name, img_data in hdimage_data.items():
268276
hdimage = img_data.get("hdimage")
269277
disk_attr["image-name"] = img_name
270-
disk_attr["image-size"] = img_data.get("size") if img_data.get("size") else "0"
278+
disk_attr["image-size"] = hdimage.get("size") if hdimage.get("size") else 0
279+
disk_attr["image-palign"] = hdimage.get("align") if hdimage.get("align") else "0"
271280
sz = get_artefact_size(img_name)
272281
if sz:
273-
disk_attr["image-size"] = str(sz)
282+
disk_attr["image-size"] = sz
274283

275284
# https://github.com/pengutronix/genimage?tab=readme-ov-file#the-image-configuration-options
276285
gtypes = ["android-sparse", "btrfs", "cpio", "cramfs", "ext2", "ext3",
@@ -301,7 +310,7 @@ def parse_genimage_config(config_path):
301310
# percent). The actual size is required for provisioning purposes.
302311
sz = get_artefact_size(piname)
303312
if sz:
304-
partitions[pname]["size"] = str(sz)
313+
partitions[pname]["size"] = sz
305314

306315
# If this image has a sparse derivative, tag it
307316
for sname, sdata in simgs.items():
@@ -421,8 +430,13 @@ def get_image_meta():
421430
image_vars = {}
422431
for key, value in vars.items():
423432
if key in IMAGE_KEYS:
424-
image_vars[key] = value
425-
433+
if key in IMAGE_KEY_TYPES:
434+
try:
435+
image_vars[key] = IMAGE_KEY_TYPES[key](value)
436+
except ValueError:
437+
image_vars[key] = None # or handle error as needed
438+
else:
439+
image_vars[key] = value
426440
return image_vars
427441

428442

@@ -461,6 +475,7 @@ if __name__ == '__main__':
461475
top_template["IGmeta"] = get_image_meta()
462476
top_template["attributes"]["image-name"] = os.path.basename(attributes.get("image-name"))
463477
top_template["attributes"]["image-size"] = attributes.get("image-size")
478+
top_template["attributes"]["image-palign-bytes"] = attributes.get("image-palign")
464479
top_template["layout"]["partitiontable"] = ptable["partitiontable"]
465480
top_template["layout"]["partitionimages"] = partition_json
466481
if args.provisionmap:

bin/mkslot-helper

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,41 @@ set -u
55
# Read the json provision map from arg1, extract slot info and write the fully
66
# assembled slot helper to stdout with the variables it expects.
77

8-
jq -e '.system_type == "slotted"' $1 > /dev/null || { >&2 echo "Not slotted"; exit 1;}
8+
# Need slotted system type
9+
jq -e '
10+
.[] |
11+
select(.attributes != null) |
12+
.attributes.system_type == "slotted"
13+
' $1 > /dev/null || { >&2 echo "Not slotted"; exit 1;}
914

1015
cat ${RPI_TEMPLATES}/slot-helper.in.head
1116

17+
# Process regular partitions in slots
1218
while read -r role slot id ; do
1319
echo "${role^^}${slot^^}=${id}"
1420
echo "${role^^}${slot^^}_ENCRYPTED=n"
15-
done < <(jq -r '.slots | to_entries[] | .key as $slot | .value.partitions[]? | "\(.role) \($slot) \(.id)"' "$1")
21+
done < <(jq -r '
22+
.[] |
23+
select(.slots != null) |
24+
.slots |
25+
to_entries[] |
26+
.key as $slot |
27+
.value.partitions[]? |
28+
"\(.role) \($slot) \(.id)"
29+
' "$1")
1630

31+
# Process encrypted partitions in slots
1732
while read -r role slot id ; do
1833
echo "${role^^}${slot^^}=${id}"
1934
echo "${role^^}${slot^^}_ENCRYPTED=y"
20-
done < <(jq -r '.slots | to_entries[] | .key as $slot | .value.encrypted.partitions[]? | "\(.role) \($slot) \(.id)"' "$1")
35+
done < <(jq -r '
36+
.[] |
37+
select(.slots != null) |
38+
.slots |
39+
to_entries[] |
40+
.key as $slot |
41+
.value.encrypted.partitions[]? |
42+
"\(.role) \($slot) \(.id)"
43+
' "$1")
2144

2245
cat ${RPI_TEMPLATES}/slot-helper.in.tail

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ done
173173
# Merge defaults for selected device and image
174174
[[ -s ${IGDEVICE}/build.defaults ]] && aggregate_options "device" ${IGDEVICE}/build.defaults
175175
[[ -s ${IGIMAGE}/build.defaults ]] && aggregate_options "image" ${IGIMAGE}/build.defaults
176+
[[ -s ${IGIMAGE}/provision.defaults ]] && aggregate_options "image" ${IGIMAGE}/provision.defaults
176177

177178

178179
# Merge remaining defaults
179180
aggregate_options "device" ${IGTOP_DEVICE}/build.defaults
180181
aggregate_options "image" ${IGTOP_IMAGE}/build.defaults
182+
aggregate_options "image" ${IGTOP_IMAGE}/provision.defaults
181183
aggregate_options "sys" ${IGTOP}/sys-build.defaults
182184
aggregate_options "sbom" ${IGTOP_SBOM}/defaults
183185
aggregate_options "meta" ${META}/defaults
@@ -344,6 +346,7 @@ runh()
344346

345347
# pre-build: hooks - common
346348
runh ${IGTOP_DEVICE}/pre-build.sh
349+
runh ${IGTOP_IMAGE}/pre-build.sh
347350

348351

349352
# pre-build: hooks - image layout then device

config/generic64-apt-ab.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[image]
44
layout=gpt/ab_userdata
5-
name=deb12-arm64-min
5+
name=deb12-arm64-ab
66
boot_part_size=200%
77
system_part_size=300%
88

device/zero2/build.defaults

Lines changed: 0 additions & 3 deletions
This file was deleted.

device/zero2w/build.defaults

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Build defaults for Zero 2 W class devices
2+
class=zero2w
3+
storage_type=sd

image/gpt/ab_userdata/bdebstrap/customize05-rootfs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ set -eu
55
# Install slot rules
66
install -m 0644 -D ../device/slot.rules $1/etc/udev/rules.d/90-rpi-slot.rules
77

8-
# Install provision map - TODO select clear/crypt?
9-
cp ../device/provisionmap.json ${IGconf_sys_outputdir}/provisionmap.json
8+
# Install provision map
9+
if igconf isset image_pmap ; then
10+
cp ../device/provisionmap-${IGconf_image_pmap}.json ${IGconf_sys_outputdir}/provisionmap.json
11+
fi
1012

1113
# Generate slot helper
1214
mkslot-helper ${IGconf_sys_outputdir}/provisionmap.json > $1/usr/bin/rpi-slot
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[
2+
{
3+
"attributes": {
4+
"PMAPversion": "1.0.0",
5+
"system_type": "slotted"
6+
}
7+
},
8+
{
9+
"partitions": [
10+
{
11+
"name": "config",
12+
"id": "1"
13+
}
14+
]
15+
},
16+
{
17+
"slots": {
18+
"A": {
19+
"partitions": [
20+
{
21+
"name": "bootA",
22+
"id": "2",
23+
"role": "boot"
24+
}
25+
]
26+
}
27+
}
28+
},
29+
{
30+
"slots": {
31+
"B": {
32+
"partitions": [
33+
{
34+
"name": "bootB",
35+
"id": "3",
36+
"role": "boot"
37+
}
38+
]
39+
}
40+
}
41+
},
42+
{
43+
"slots": {
44+
"A": {
45+
"partitions": [
46+
{
47+
"name": "systemA",
48+
"id": "4",
49+
"role": "system"
50+
}
51+
]
52+
}
53+
}
54+
},
55+
{
56+
"slots": {
57+
"B": {
58+
"partitions": [
59+
{
60+
"name": "systemB",
61+
"id": "5",
62+
"role": "system"
63+
}
64+
]
65+
}
66+
}
67+
},
68+
{
69+
"partitions": [
70+
{
71+
"name": "data",
72+
"id": "6"
73+
}
74+
]
75+
}
76+
]
Lines changed: 79 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,92 @@
1-
{
2-
"PMAPversion": "1.0.0",
3-
"system_type": "slotted",
4-
"slots": {
5-
"A": {
6-
"partitions": [
7-
{
8-
"name": "bootA",
9-
"id": 2,
10-
"role": "boot"
11-
}
12-
],
13-
"encrypted": {
14-
"luks": {
15-
"version": 2,
16-
"key_size": 512,
17-
"cipher": "aes-xts-plain64",
18-
"hash": "sha256"
19-
},
1+
[
2+
{
3+
"attributes": {
4+
"PMAPversion": "1.0.0",
5+
"system_type": "slotted"
6+
}
7+
},
8+
{
9+
"partitions": [
10+
{
11+
"name": "config",
12+
"id": "1"
13+
}
14+
]
15+
},
16+
{
17+
"slots": {
18+
"A": {
2019
"partitions": [
2120
{
22-
"name": "systemA",
23-
"id": "cryptrootA",
24-
"role": "system"
21+
"name": "bootA",
22+
"id": "2",
23+
"role": "boot"
2524
}
2625
]
2726
}
28-
},
29-
"B": {
30-
"partitions": [
31-
{
32-
"name": "bootB",
33-
"id": 3,
34-
"role": "boot"
35-
}
36-
],
37-
"encrypted": {
38-
"luks": {
39-
"version": 2,
40-
"key_size": 512,
41-
"cipher": "aes-xts-plain64",
42-
"hash": "sha256"
43-
},
27+
}
28+
},
29+
{
30+
"slots": {
31+
"B": {
4432
"partitions": [
4533
{
46-
"name": "systemB",
47-
"id": "cryptrootB",
48-
"role": "system"
34+
"name": "bootB",
35+
"id": "3",
36+
"role": "boot"
4937
}
5038
]
5139
}
5240
}
5341
},
54-
"partitions": [
55-
{
56-
"name": "config",
57-
"id": "1"
58-
},
59-
{
60-
"name": "data",
61-
"id": "6"
42+
{
43+
"slots": {
44+
"A": {
45+
"encrypted": {
46+
"luks": {
47+
"version": 2,
48+
"key_size": 512,
49+
"cipher": "aes-xts-plain64",
50+
"hash": "sha256"
51+
},
52+
"partitions": [
53+
{
54+
"name": "systemA",
55+
"id": "cryptrootA",
56+
"role": "system"
57+
}
58+
]
59+
}
60+
}
61+
}
62+
},
63+
{
64+
"slots": {
65+
"B": {
66+
"encrypted": {
67+
"luks": {
68+
"version": 2,
69+
"key_size": 512,
70+
"cipher": "aes-xts-plain64",
71+
"hash": "sha256"
72+
},
73+
"partitions": [
74+
{
75+
"name": "systemB",
76+
"id": "cryptrootB",
77+
"role": "system"
78+
}
79+
]
80+
}
81+
}
6282
}
63-
]
64-
}
83+
},
84+
{
85+
"partitions": [
86+
{
87+
"name": "data",
88+
"id": "6"
89+
}
90+
]
91+
}
92+
]

0 commit comments

Comments
 (0)