Skip to content

Commit 84ee2ac

Browse files
committed
read fakefs device from nvram
1 parent 492abab commit 84ee2ac

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

checkra1n/kpf/ramdisk.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,32 @@ static void kpf_ramdisk_bootprep(struct mach_header_64 *hdr, palerain_option_t p
169169
uint32_t partid = 1;
170170
/* have SSV and rootful */
171171
if ((palera1n_flags & (palerain_option_rootful | palerain_option_ssv)) == (palerain_option_rootful | palerain_option_ssv)) {
172-
dt_node_t* fstab = dt_find(gDeviceTree, "fstab");
173-
if (!fstab) panic("invalid devicetree: no fstab!"); /* iOS 12 and below should not have SSV */
174-
size_t max_fs_entries_len = 0;
175-
size_t root_matching_len = 0;
176-
uint32_t* max_fs_entries = dt_prop(fstab, "max_fs_entries", &max_fs_entries_len);
177-
if (!max_fs_entries) panic("invalid devicetree: no prop!");
178-
uint32_t* patch = (uint32_t*)max_fs_entries;
179-
printf("fstab max_fs_entries: %016" PRIx64 ": %08x\n", (uint64_t)max_fs_entries, patch[0]);
180-
dt_node_t* baseband = dt_find(gDeviceTree, "baseband");
181-
if (baseband) partid = patch[0] + 1U;
182-
else partid = patch[0];
183-
if (socnum == 0x7000 || socnum == 0x7001) partid--;
184-
partid += fakefs_offset;
185172
dt_node_t* chosen = dt_find(gDeviceTree, "chosen");
186173
if (!chosen) panic("invalid devicetree: no device!");
174+
size_t nvram_proxy_data_len = 0;
175+
char* nvram_proxy_data = dt_prop(chosen, "nvram-proxy-data", &nvram_proxy_data_len);
176+
if (!nvram_proxy_data) panic("invalid devicetree: no /chosen/nvram-proxy-data!");
177+
char* nvram_rootdev = memmem(nvram_proxy_data, nvram_proxy_data_len, "p1-fakefs-rootdev=", 18);
178+
if (nvram_rootdev) snprintf(BSDName, 16, "%s", &nvram_rootdev[18]);
179+
180+
size_t root_matching_len = 0;
187181
char* root_matching = dt_prop(chosen, "root-matching", &root_matching_len);
188182
if (!root_matching) panic("invalid devicetree: no prop!");
189-
snprintf(BSDName, 16, "%s%" PRIu32, disk_prefix(), partid);
183+
if (!nvram_rootdev) {
184+
dt_node_t* fstab = dt_find(gDeviceTree, "fstab");
185+
if (!fstab) panic("invalid devicetree: no fstab!"); /* iOS 12 and below should not have SSV */
186+
size_t max_fs_entries_len = 0;
187+
uint32_t* max_fs_entries = dt_prop(fstab, "max_fs_entries", &max_fs_entries_len);
188+
if (!max_fs_entries) panic("invalid devicetree: no prop!");
189+
uint32_t* patch = (uint32_t*)max_fs_entries;
190+
printf("fstab max_fs_entries: %016" PRIx64 ": %08x\n", (uint64_t)max_fs_entries, patch[0]);
191+
dt_node_t* baseband = dt_find(gDeviceTree, "baseband");
192+
if (baseband) partid = patch[0] + 1U;
193+
else partid = patch[0];
194+
if (socnum == 0x7000 || socnum == 0x7001) partid--;
195+
partid += fakefs_offset;
196+
snprintf(BSDName, 16, "%s%" PRIu32, disk_prefix(), partid);
197+
}
190198
/* Don't root from fakefs during fakefs setup or force revert */
191199
if ((palera1n_flags & (palerain_option_setup_rootful | palerain_option_force_revert)) == 0)
192200
snprintf(root_matching, root_matching_len,

0 commit comments

Comments
 (0)