2021-05-13 14:23:23 +00:00
|
|
|
# Microdroid Payload
|
2021-04-14 06:34:24 +00:00
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
Payload disk is a composite disk image referencing host APEXes and an APK so that microdroid
|
|
|
|
mounts/activates APK/APEXes and executes a binary within the APK.
|
2021-04-14 06:34:24 +00:00
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
## Partitions
|
2021-04-14 06:34:24 +00:00
|
|
|
|
2021-05-13 14:23:23 +00:00
|
|
|
Payload disk has 1 + N(number of APEX/APK payloads) partitions.
|
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
The first partition is a "metadata" partition which describes other partitions.
|
2021-05-13 14:23:23 +00:00
|
|
|
And APEXes and an APK are following as separate partitions.
|
|
|
|
|
|
|
|
For now, the order of partitions are important.
|
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
* partition 1: Metadata partition
|
2021-05-13 14:23:23 +00:00
|
|
|
* partition 2 ~ n: APEX payloads
|
|
|
|
* partition n + 1: APK payload
|
|
|
|
|
|
|
|
It's subject to change in the future, though.
|
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
### Metadata partition
|
2021-05-13 14:23:23 +00:00
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
Metadata partition provides description of the other partitions and the location for VM payload
|
|
|
|
configuration.
|
2021-05-13 14:23:23 +00:00
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
The partition is a protobuf message prefixed with the size of the message.
|
2021-04-14 06:34:24 +00:00
|
|
|
|
|
|
|
| offset | size | description |
|
|
|
|
|--------|------|----------------------------------------------------------------|
|
|
|
|
| 0 | 4 | Header. unsigned int32: body length(L) in big endian |
|
2021-06-08 08:10:21 +00:00
|
|
|
| 4 | L | Body. A protobuf message. [schema](metadata.proto) |
|
2021-04-14 09:46:14 +00:00
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
### Payload partitions
|
|
|
|
|
|
|
|
Each payload partition presents APEX or APK passed from the host.
|
2021-04-19 18:57:19 +00:00
|
|
|
|
2021-05-13 14:23:23 +00:00
|
|
|
At the end of each payload partition the size of the original payload file (APEX or APK) is stored
|
|
|
|
in 4-byte big endian.
|
2021-04-14 09:46:14 +00:00
|
|
|
|
2021-05-13 14:23:23 +00:00
|
|
|
For example, the following code shows how to get the original size of host apex file
|
|
|
|
when the apex is read in microdroid as /dev/block/vdc2,
|
2021-04-14 09:46:14 +00:00
|
|
|
|
2021-05-13 14:23:23 +00:00
|
|
|
int fd = open("/dev/block/vdc2", O_RDONLY | O_BINARY | O_CLOEXEC);
|
|
|
|
uint32_t size;
|
|
|
|
lseek(fd, -sizeof(size), SEEK_END);
|
|
|
|
read(fd, &size, sizeof(size));
|
|
|
|
size = betoh32(size);
|
2021-04-14 09:46:14 +00:00
|
|
|
|
2021-05-13 14:23:23 +00:00
|
|
|
## How to Create
|
2021-04-14 09:46:14 +00:00
|
|
|
|
2021-04-19 18:57:19 +00:00
|
|
|
### `mk_payload`
|
|
|
|
|
2021-06-08 08:10:21 +00:00
|
|
|
`mk_payload` creates a payload composite disk image as described in a JSON which is intentionlly
|
|
|
|
similar to the schema of VM payload config.
|
2021-05-21 12:41:13 +00:00
|
|
|
|
2021-04-19 18:57:19 +00:00
|
|
|
```
|
|
|
|
$ cat payload_config.json
|
|
|
|
{
|
|
|
|
"system_apexes": [
|
|
|
|
"com.android.adbd",
|
|
|
|
],
|
|
|
|
"apexes": [
|
|
|
|
{
|
|
|
|
"name": "com.my.hello",
|
|
|
|
"path": "hello.apex"
|
|
|
|
}
|
2021-05-13 14:23:23 +00:00
|
|
|
],
|
|
|
|
"apk": {
|
|
|
|
"name": "com.my.world",
|
|
|
|
"path": "/path/to/world.apk"
|
|
|
|
}
|
2021-04-19 18:57:19 +00:00
|
|
|
}
|
|
|
|
$ adb push payload_config.json hello.apex /data/local/tmp/
|
|
|
|
$ adb shell 'cd /data/local/tmp; /apex/com.android.virt/bin/mk_payload payload_config.json payload.img
|
|
|
|
$ adb shell ls /data/local/tmp/*.img
|
2021-05-13 14:23:23 +00:00
|
|
|
payload.img
|
2021-04-19 18:57:19 +00:00
|
|
|
payload-footer.img
|
|
|
|
payload-header.img
|
2021-06-08 08:10:21 +00:00
|
|
|
payload-metadata.img
|
2021-05-13 14:23:23 +00:00
|
|
|
payload.img.0 # fillers
|
|
|
|
payload.img.1
|
|
|
|
...
|
2021-04-19 18:57:19 +00:00
|
|
|
```
|
|
|
|
|
2021-05-21 12:41:13 +00:00
|
|
|
In the future, [VirtualizationService](../../virtualizationservice) will handle this.
|