diff --git a/filesystem/android_super.ksy b/filesystem/android_super.ksy new file mode 100644 index 000000000..965fcdf06 --- /dev/null +++ b/filesystem/android_super.ksy @@ -0,0 +1,174 @@ +meta: + id: android_super + title: Android Dynamic Partitions metadata + application: Android + file-extension: img + license: CC0-1.0 + ks-version: 0.8 + endian: le + +doc: | + The metadata stored by Android at the beginning of a "super" partition, which + is what it calls a disk partition that holds one or more Dynamic Partitions. + Dynamic Partitions do more or less the same thing that LVM does on Linux, + allowing Android to map ranges of non-contiguous extents to a single logical + device. This metadata holds that mapping. + +doc-ref: https://source.android.com/devices/tech/ota/dynamic_partitions/implement +doc-ref: https://android.googlesource.com/platform/system/core/+/master/fs_mgr/liblp/include/liblp/metadata_format.h + +seq: + - id: padding + size: 0x1000 + type: dummy + + - id: primary_geometry + size: 0x1000 + type: geometry + + - id: backup_geometry + type: geometry + size: 0x1000 + + - id: primary_metadata + size: primary_geometry.metadata_max_size + type: metadata + repeat: expr + repeat-expr: primary_geometry.metadata_slot_count + + - id: backup_metadata + size: primary_geometry.metadata_max_size + type: metadata + repeat: expr + repeat-expr: primary_geometry.metadata_slot_count + +types: + dummy: {} + + geometry: + seq: + - id: magic + contents: [0x67, 0x44, 0x6c, 0x61] + - id: struct_size + type: u4 + - id: checksum + size: 32 + - id: metadata_max_size + type: u4 + - id: metadata_slot_count + type: u4 + - id: logical_block_size + type: u4 + + metadata: + seq: + - id: magic + contents: [0x30, 0x50, 0x4c, 0x41] + - id: major_version + type: u2 + - id: minor_version + type: u2 + - id: header_size + type: u4 + - id: header_checksum + size: 32 + - id: tables_size + type: u4 + - id: tables_checksum + size: 32 + - id: partitions + type: table_descriptor(0) + - id: extents + type: table_descriptor(1) + - id: groups + type: table_descriptor(2) + - id: block_devices + type: table_descriptor(3) + + types: + table_descriptor: + params: + - id: entry_type + type: u8 + + seq: + - id: offset + type: u4 + - id: num_entries + type: u4 + - id: entry_size + type: u4 + + instances: + table: + pos: _parent.header_size + offset + size: entry_size + type: + switch-on: entry_type + cases: + 0: partition + 1: extent + 2: group + 3: block_device + repeat: expr + repeat-expr: num_entries + + partition: + seq: + - id: name + size: 36 + type: strz + encoding: UTF-8 + - id: attributes + type: u4 + - id: first_extent_index + type: u4 + - id: num_extents + type: u4 + - id: group_index + type: u4 + + extent: + seq: + - id: num_sectors + type: u8 + - id: target_type + type: u4 + enum: target_type + - id: target_data + type: u8 + - id: target_source + type: u4 + + enums: + target_type: + 0: linear + 1: zero + + group: + seq: + - id: name + size: 36 + type: strz + encoding: UTF-8 + - id: flags + type: u4 + - id: maximum_size + type: u8 + + block_device: + seq: + - id: first_logical_sector + type: u8 + - id: alignment + type: u4 + - id: alignment_offset + type: u4 + - id: size + type: u8 + - id: partition_name + size: 36 + type: strz + encoding: UTF-8 + - id: flags + type: u4