Skip to content

Commit

Permalink
kboot: Parse "anvram" partition start and size from ADT
Browse files Browse the repository at this point in the history
"nvram" size depends on the iboot version. Monterey (12.3) and earlier
used 128k nvram partition but Ventura since at least 13.2 increased the
size to 1M. Parse the values from the ADT and fill and enable the node
in the device tree.

Signed-off-by: Janne Grunau <[email protected]>
  • Loading branch information
jannau authored and marcan committed Oct 5, 2023
1 parent 0cf2302 commit fecfa13
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,57 @@ static int dt_set_ipd(void)
return 0;
}

#define NVRAM_START 0x700000
#define NVRAM_MAX_SIZE SZ_1M

static int dt_set_nvram(void)
{
int adt_path[8];
u64 start, size;

int anode = adt_path_offset_trace(adt, "/arm-io/spi1/spinor/anvram", adt_path);
if (anode < 0) {
printf("ADT: nvram partition not found\n");
return 0;
}

int pp = 0;
while (adt_path[pp])
pp++;
adt_path[pp + 1] = 0;

int ret = adt_get_reg(adt, adt_path, "reg", 0, &start, &size);
if (ret < 0) {
printf("ADT: could not read nvram partition start/size\n");
return 0;
}

if (start != NVRAM_START || size > NVRAM_MAX_SIZE) {

printf("ADT: unexpected nvram partition start (0x%lx) size (0x%lx)\n", start, size);
return 0;
}

int node = fdt_path_offset(dt, "nvram");
if (node < 0) {
printf("DT: nvram alias/partition not found\n");
return 0;
}

fdt32_t reg[2];
fdt32_st(reg + 0, start);
fdt32_st(reg + 1, size);
if (fdt_setprop(dt, node, "reg", reg, sizeof(reg))) {
printf("FDT: couldn't set nvram.reg\n");
return 0;
}

if (fdt_setprop_string(dt, node, "status", "okay") < 0)
printf("FDT: failed to enable nvram partition node\n");

return 0;
}

static int dt_set_wifi(void)
{
int anode = adt_path_offset(adt, "/arm-io/wlan");
Expand Down Expand Up @@ -2096,6 +2147,8 @@ int kboot_prepare_dt(void *fdt)
return -1;
if (dt_set_multitouch())
return -1;
if (dt_set_nvram())
return -1;
if (dt_set_ipd())
return -1;
if (dt_disable_missing_devs("usb-drd", "usb@", 8))
Expand Down

0 comments on commit fecfa13

Please sign in to comment.