Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
darwin wherever the phone has it: at least 20 GiB on LUN 0, not the first phone's place and size
shimoku74c69334edae78
diff --git a/drivers/storage/hakios.ufs.c b/drivers/storage/hakios.ufs.cindex f98f065..abbd0a4 100644--- a/drivers/storage/hakios.ufs.c+++ b/drivers/storage/hakios.ufs.c@@ -83,11 +83,12 @@ extern void FlushPoC_DcacheRegion(vm_offset_t va, size_t length); /* osfmk/arm* Where a write may go, and nowhere else: darwin, the port's own 20 GiB at the end of logical* unit 0, and in it only past what the build puts there from the computer -- the iOS volume* (blocks 0..1374207) and the two cryptexes behind it (..2042367). The loader keeps the same- * bounds and the GUIDs of the partition besides (xnuloader/loader.c, BLOCK_WRITE_FIRST).+ * bounds and checks the partition's type besides (xnuloader/loader.c, BLOCK_WRITE_FIRST). Where darwin+ * begins and its exact size are the phone's (tools/userdata-carve.py puts it after userdata, whatever+ * that is): at least the layout's 20 GiB.*/#define UFS_WRITE_FIRST 2042368ULL /* darwin's blocks of 4096 */-#define UFS_DARWIN_FIRST 25374720ULL /* its first LBA on the unit, as the GPT has it */-#define UFS_DARWIN_BLOCKS 5242875ULL+#define UFS_DARWIN_MIN 5242875ULL /* the first phone's darwin, in blocks of 4096 */struct loader_block_part {char name[36];@@ -1786,10 +1787,8 @@ hakios_ufs_init(void)* has compared with the loader's reads; the device path this firmware gives* says no logical unit number at all, so part[].lun is 0xff for every unit */why = "it is not on the first logical unit";- } else if (ufs_page->part[i].start_lba != UFS_DARWIN_FIRST) {- why = "it does not begin where it did";- } else if (ufs_page->part[i].blocks != UFS_DARWIN_BLOCKS) {- why = "it is not the size it was";+ } else if (ufs_page->part[i].blocks < UFS_DARWIN_MIN) {+ why = "it is smaller than the layout's 20 GiB";} else if (ufs_page->part[i].block_size != 4096) {why = "its blocks are not 4096 bytes";}@@ -1802,7 +1801,7 @@ hakios_ufs_init(void)if (ufs_write_part >= 0) {printf("ufs: /dev/rufs_darwin takes writes, whole blocks from %llu on (%llu MB of it); ""everything else of the storage is read only\n", UFS_WRITE_FIRST,- (UFS_DARWIN_BLOCKS - UFS_WRITE_FIRST) * 4096 >> 20);+ (ufs_page->part[ufs_write_part].blocks - UFS_WRITE_FIRST) * 4096 >> 20);if (devfs_make_node(makedev(ufs_bmajor, UFS_DATA_MINOR), DEVFS_BLOCK, UID_ROOT, GID_OPERATOR, 0640,"ufs_darwin_data") != NULL) {printf("ufs: /dev/ufs_darwin_data: the same %llu MB as a block device, for the data volume; "diff --git a/xnuloader/loader.c b/xnuloader/loader.cindex 55f9da1..23e82cf 100644--- a/xnuloader/loader.c+++ b/xnuloader/loader.c@@ -1529,13 +1529,13 @@ ufs_survey(void)* from the computer (tools/darwin-write.py) is the iOS volume at its start and the two cryptexes* behind it, and nothing of this port reads or writes the rest -- so the data of iOS lives there* and a write is refused before that block. The identity: the partition named darwin, of the APFS- * container type, of the same size, in the same place, on logical unit 0. Not its unique GUID:- * tools/userdata-carve.py gives every phone's darwin a new one (BLOCK_DARWIN_UNIQ was the first- * phone's, made by darwin-write.py, and no write was ever served on another); it is printed instead.+ * container type, on logical unit 0, in blocks of 4096 and at least the 20 GiB the port lays out. Not+ * its place, its exact size or its unique GUID: tools/userdata-carve.py makes darwin at the end of+ * whatever userdata the phone has, with a GUID of its own (BLOCK_DARWIN_FIRST/LAST and _UNIQ were+ * the first phone's, and no write was ever served on another); they are printed instead.*/#define BLOCK_WRITE_FIRST 2042368ULL /* darwin's blocks of 4096: past both cryptexes */-#define BLOCK_DARWIN_FIRST 25374720ULL /* its first and last LBA of unit 0, as the GPT has them */-#define BLOCK_DARWIN_LAST 30617594ULL+#define BLOCK_DARWIN_MIN 5242875ULL /* blocks of 4096: the first phone's darwin, the layout's */#define BLOCK_DARWIN_TYPE { 0x7c3457ef, 0x0000, 0x11aa, { 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } }/*@@ -1888,14 +1888,13 @@ block_is_darwin(const efi_partition_info *info, const efi_block_io *bio, const s}if (memcmp(&info->type_guid, &type, sizeof(type)) != 0) {why = "its type GUID is not the one it had";- } else if (info->start_lba != BLOCK_DARWIN_FIRST || info->end_lba != BLOCK_DARWIN_LAST) {- why = "it does not begin and end where it did";} else if (bp->unit != 0) {/* the first unit UEFI lists: this firmware's device paths say no logical unit number* (device_path_print finds no 3.19 node), so bp->lun is 0xff for every unit */why = "it is not on the first logical unit";- } else if (bp->block_size != 4096 || bp->blocks != BLOCK_DARWIN_LAST - BLOCK_DARWIN_FIRST + 1) {- why = "its blocks are not what they were";+ } else if (bp->block_size != 4096 || bp->blocks < BLOCK_DARWIN_MIN ||+ info->end_lba - info->start_lba + 1 != bp->blocks) {+ why = "it is not 20 GiB in blocks of 4096";} else if (bio->media->read_only) {why = "UEFI gives it out read only";}