Skip to content

Commit b3ad8dc

Browse files
committed
Adapt Agilex 5 DTS fixup to the fdt context API
1 parent 19563bb commit b3ad8dc

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

‎hal/agilex5.c‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,34 @@ void *hal_get_dts_update_address(void)
153153
}
154154

155155
#ifdef __WOLFBOOT
156-
int hal_dts_fixup(void *dts_addr)
156+
int hal_dts_fixup(void *dts_addr, uint32_t capacity)
157157
{
158-
struct fdt_header *fdt = (struct fdt_header *)dts_addr;
158+
fdt_ctx ctx;
159159
int off;
160-
int ret = fdt_check_header(dts_addr);
160+
int ret;
161161

162+
/* Validate the blob against the window it actually occupies. */
163+
ret = fdt_open(&ctx, dts_addr, capacity);
162164
if (ret != 0) {
163165
wolfBoot_printf("FDT: invalid header (%d)\n", ret);
164166
return ret;
165167
}
166-
fdt_set_totalsize(fdt,
167-
fdt_totalsize(fdt) + WOLFBOOT_FDT_FIXUP_HEADROOM);
168+
ret = fdt_grow(&ctx, WOLFBOOT_FDT_FIXUP_HEADROOM);
169+
if (ret != 0) {
170+
wolfBoot_printf("FDT: no headroom for fixups (%d)\n", ret);
171+
return ret;
172+
}
168173

169174
/* U-Boot normally patches the memory node after SPL has measured the
170175
* LPDDR4. wolfBoot bypasses U-Boot and passes this DTB directly to
171176
* Linux, so preserve the board's 1792 MiB memory map explicitly. */
172-
off = fdt_find_devtype(fdt, -1, "memory");
177+
off = fdt_find_devtype(&ctx, -1, "memory");
173178
if (off >= 0) {
174179
uint64_t reg[2];
175180

176181
reg[0] = cpu_to_fdt64(AGILEX5_DDR_BASE);
177182
reg[1] = cpu_to_fdt64(AGILEX5_DDR_SIZE);
178-
ret = fdt_setprop(fdt, off, "reg", reg, sizeof(reg));
183+
ret = fdt_setprop(&ctx, off, "reg", reg, sizeof(reg));
179184
if (ret != 0) {
180185
wolfBoot_printf("FDT: failed to set memory (%d)\n", ret);
181186
return ret;
@@ -190,21 +195,21 @@ int hal_dts_fixup(void *dts_addr)
190195
* direct wolfBoot handoff does not yet program that optional design.
191196
* Keep Linux from touching an unconfigured fabric register while the
192197
* HPS, FCS and storage paths remain available. */
193-
off = fdt_find_node_offset(fdt, -1, "leds");
198+
off = fdt_find_node_offset(&ctx, -1, "leds");
194199
if (off >= 0) {
195-
ret = fdt_fixup_str(fdt, off, "leds", "status", "disabled");
200+
ret = fdt_fixup_str(&ctx, off, "leds", "status", "disabled");
196201
if (ret != 0) {
197202
wolfBoot_printf("FDT: failed to disable FPGA LEDs (%d)\n", ret);
198203
return ret;
199204
}
200205
}
201206

202-
off = fdt_find_node_offset(fdt, -1, "chosen");
207+
off = fdt_subnode_offset(&ctx, 0, "chosen");
203208
if (off == -FDT_ERR_NOTFOUND)
204-
off = fdt_add_subnode(fdt, 0, "chosen");
209+
off = fdt_add_subnode(&ctx, 0, "chosen");
205210
if (off < 0)
206211
return off;
207-
return fdt_fixup_str(fdt, off, "chosen", "bootargs", LINUX_BOOTARGS);
212+
return fdt_fixup_str(&ctx, off, "chosen", "bootargs", LINUX_BOOTARGS);
208213
}
209214
#endif
210215
#endif

0 commit comments

Comments
 (0)