On 2/11/26 7:06 PM, James Hilliard wrote:
+static int boot_get_fdt_fit_into_buffer(const void *src, ulong srclen,
+ ulong extra, ulong min_dstlen,
+ void **fdtdstbuf, ulong *fdtdstlenp)
+{
+ const void *fdtsrcbuf;
+ void *tmp = NULL;
+ void *dstbuf, *newdstbuf;
+ ulong dstlen, newdstlen;
+ int err;
+
+ /* Make sure the source FDT/DTO is 8-byte aligned for libfdt. */
+ fdtsrcbuf = src;
+ if (!IS_ALIGNED((uintptr_t)src, 8)) {
+ tmp = memalign(8, srclen);
+ if (!tmp)
+ return -ENOMEM;
+
+ memcpy(tmp, src, srclen);
+ fdtsrcbuf = tmp;
+ }
+
+ newdstlen = ALIGN(fdt_totalsize(fdtsrcbuf) + extra, SZ_4K);
+ min_dstlen = ALIGN(min_dstlen, SZ_4K);
+ if (newdstlen < min_dstlen)
+ newdstlen = min_dstlen;
+
+ dstbuf = *fdtdstbuf;
+ dstlen = dstbuf ? *fdtdstlenp : 0;
+
+ /*
+ * If the caller already provided a large enough writable buffer,
+ * and we're not moving the FDT, nothing to do.
+ */
+ if (dstbuf && dstlen >= newdstlen && dstbuf == fdtsrcbuf) {
Can $dstbuf ever be NULL ?
+ free(tmp);
+ return 0;
You could try something like this here, to reduce the duplicate
free(tmp) in the code:
"
err = 0;
goto exit;
...
exit:
free(tmp);
return err;
"
+ }
+
[...]
- load = (ulong)of_flat_tree;
+ len = fdt_off_dt_strings(base_buf) + fdt_size_dt_strings(base_buf);
How does this new length calculation work, can you please clarify that ?
I don't think this will work for fitImages with external data (generated
using mkimage -E) , but I might be wrong.