1 # Tabs only for indentation, spaces ok in comments.
3 # jq -f _device_json_transform.jq old.json
4 # Transform from the old schema:
8 # "boardNames": ["..."],
9 # "partition1MTD": "mtdX",
10 # "partition2MTD": "mtdY",
12 # "bootEnv1": "boot_part",
13 # "bootEnv1Partition1Value": 1,
14 # "bootEnv1Partition2Value": 2,
15 # "bootEnv2": "bootcmd",
16 # "bootEnv2Partition1Value": "run nandboot",
17 # "bootEnv2Partition2Value": "run altnandboot",
24 # "device": { "vendor": "...", "model": "...", "board": ["..."] },
25 # "commands": { "params": [...], "get": "fw_printenv", "set": "fw_setenv", "save": null },
27 # { "number": 1, "param_values": [...], "mtd": "mtdX", "labelOffsetBytes": <int|null>, "altMountOptions": {...|null} },
28 # { "number": 2, "param_values": [...], "mtd": "mtdY", "labelOffsetBytes": <int|null>, "altMountOptions": {...|null} }
33 | ([$in.bootEnv1, $in.bootEnv2] | map(select(. != null))) as $params
36 vendor: $in.vendorName,
37 model: $in.deviceName,
38 board: (if ($in.boardNames | type) == "array" then $in.boardNames else [$in.boardNames] end)
47 (if $in.partition1MTD != null then
51 # Align to commands.params: value for param[0], param[1], ...
52 # Only include entries that exist (skip nulls)
54 (if ($params | length) > 0 then $in.bootEnv1Partition1Value else empty end),
55 (if ($params | length) > 1 then $in.bootEnv2Partition1Value else empty end)
56 ] | map(select(. != null))
58 mtd: $in.partition1MTD,
59 labelOffsetBytes: ($in.labelOffset // null)
61 if ($in.opOffset != null or $in.ubiVolume != null) then
62 { altMountOptions: { mtdOffset: ($in.opOffset // null), ubiVolume: ($in.ubiVolume // null) } }
68 (if $in.partition2MTD != null then
73 (if ($params | length) > 0 then $in.bootEnv1Partition2Value else empty end),
74 (if ($params | length) > 1 then $in.bootEnv2Partition2Value else empty end)
75 ] | map(select(. != null))
77 mtd: $in.partition2MTD,
78 labelOffsetBytes: ($in.labelOffset // null)
80 if ($in.opOffset != null or $in.ubiVolume != null) then
81 { altMountOptions: { mtdOffset: ($in.opOffset // null), ubiVolume: ($in.ubiVolume // null) } }