diff --git a/lib/system/api/containers.toit b/lib/system/api/containers.toit index 1aea07f0f..0c6618ee7 100644 --- a/lib/system/api/containers.toit +++ b/lib/system/api/containers.toit @@ -47,9 +47,13 @@ class ContainerServiceClient extends ServiceClient implements ContainerService: list_images -> List: array := invoke_ ContainerService.LIST_IMAGES_INDEX null - return List array.size / 3: - cursor := it * 3 - ContainerImage (uuid.Uuid array[cursor]) array[cursor + 1] array[cursor + 2] + return List array.size / 4: + cursor := it * 4 + ContainerImage + --id=uuid.Uuid array[cursor] + --name=array[cursor + 1] + --flags=array[cursor + 2] + --data=array[cursor + 3] load_image id/uuid.Uuid -> int?: return invoke_ ContainerService.LOAD_IMAGE_INDEX id.to_byte_array diff --git a/lib/system/containers.toit b/lib/system/containers.toit index 1277bf385..25f5aaf4d 100644 --- a/lib/system/containers.toit +++ b/lib/system/containers.toit @@ -36,9 +36,10 @@ uninstall id/uuid.Uuid -> none: class ContainerImage: id/uuid.Uuid + name/string? flags/int data/int - constructor .id .flags .data: + constructor --.id --.name --.flags --.data: class Container extends ServiceResourceProxy: id/uuid.Uuid diff --git a/src/flash_allocation.h b/src/flash_allocation.h index 64a63ef58..7009ae620 100644 --- a/src/flash_allocation.h +++ b/src/flash_allocation.h @@ -94,7 +94,7 @@ class FlashAllocation { memcpy(id_, id, id_size()); } pages_in_flash_ = 0; - memset(_metadata, 0xFF, METADATA_SIZE); + memset(_metadata, 0, METADATA_SIZE); set_uuid(uuid); } diff --git a/system/containers.toit b/system/containers.toit index 854014149..2dc83cd3a 100644 --- a/system/containers.toit +++ b/system/containers.toit @@ -16,8 +16,11 @@ import binary import uuid import monitor -import encoding.base64 as base64 +import encoding.base64 +import encoding.tison + +import system.assets import system.services show ServiceDefinition ServiceResource import system.api.containers show ContainerService @@ -208,10 +211,16 @@ abstract class ContainerServiceDefinition extends ServiceDefinition abstract lookup_image id/uuid.Uuid -> ContainerImage? list_images -> List: + names := {:} + assets.decode.get "images" --if_present=: | encoded | + map := tison.decode encoded + map.do: | name/string id/ByteArray | names[uuid.Uuid id] = name raw := images result := [] raw.do: | image/ContainerImage | - result.add image.id.to_byte_array + id/uuid.Uuid := image.id + result.add id.to_byte_array + result.add (names.get id) result.add image.flags result.add image.data return result diff --git a/tests/negative/gold/illegal_system_call_test.gold b/tests/negative/gold/illegal_system_call_test.gold index 4ce73eb67..ad13afa5c 100644 --- a/tests/negative/gold/illegal_system_call_test.gold +++ b/tests/negative/gold/illegal_system_call_test.gold @@ -1,6 +1,6 @@ As check failed: null is not a ServiceResource. 0: ServiceDefinition.resource /system/services.toit:170:5 - 1: ContainerServiceDefinition.handle <...>/system/containers.toit:198:19 + 1: ContainerServiceDefinition.handle <...>/system/containers.toit:201:19 2: ServiceManager_. /system/services.toit:357:15 3: RpcRequest_.process. /rpc/broker.toit:98:26 4: RpcRequest_.process /rpc/broker.toit:95:3 diff --git a/tools/firmware.toit b/tools/firmware.toit index 392df8272..b6b97f6f2 100644 --- a/tools/firmware.toit +++ b/tools/firmware.toit @@ -566,9 +566,24 @@ extract_binary envelope/Envelope --config_encoded/ByteArray -> ByteArray: system := entries.get SYSTEM_CONTAINER_NAME if system: // TODO(kasper): Take any other system assets into account. - assets_encoded := properties.get "wifi" - --if_present=: assets.encode { "wifi": tison.encode it } - --if_absent=: null + system_assets := {:} + // Encode any WiFi information. + properties.get "wifi" --if_present=: system_assets["wifi"] = tison.encode it + // Encode the list of images with their names. + images := {:} + entries.do: | name/string content/ByteArray | + if not (name == SYSTEM_CONTAINER_NAME or name.starts_with "\$" or name.starts_with "+"): + id/uuid.Uuid := ? + if is_snapshot_bundle content: + bundle := SnapshotBundle name content + id = bundle.uuid + else: + header := decode_image content + id = header.id + images[name] = id.to_byte_array + if not images.is_empty: system_assets["images"] = tison.encode images + // Encode the system assets and add them to the container. + assets_encoded := assets.encode system_assets containers.add (ContainerEntry SYSTEM_CONTAINER_NAME system --assets=assets_encoded) entries.do: | name/string content/ByteArray |