Index: stand/fdt/fdt_loader_cmd.c =================================================================== --- stand/fdt/fdt_loader_cmd.c +++ stand/fdt/fdt_loader_cmd.c @@ -431,7 +431,10 @@ return (1); } -void +/* + * Returns the number of overlays successfully applied + */ +int fdt_apply_overlays() { struct preloaded_file *fp; @@ -440,10 +443,11 @@ void *current_fdtp; void *next_fdtp; void *overlay; + int overlays_applied; int rv; if ((fdtp == NULL) || (fdtp_size == 0)) - return; + return (0); max_overlay_size = 0; for (fp = file_findfile(NULL, "dtbo"); fp != NULL; fp = fp->f_next) { @@ -453,15 +457,16 @@ /* Nothing to apply */ if (max_overlay_size == 0) - return; + return (0); overlay = malloc(max_overlay_size); if (overlay == NULL) { printf("failed to allocate memory for DTB blob with overlays\n"); - return; + return (0); } current_fdtp = fdtp; current_fdtp_size = fdtp_size; + overlays_applied = 0; for (fp = file_findfile(NULL, "dtbo"); fp != NULL; fp = fp->f_next) { COPYOUT(fp->f_addr, overlay, fp->f_size); /* Check compatible first to avoid unnecessary allocation */ @@ -494,7 +499,9 @@ if (current_fdtp != fdtp) free(current_fdtp); current_fdtp = next_fdtp; - current_fdtp_size = next_fdtp_size; + fdt_pack(current_fdtp); + current_fdtp_size = fdt_totalsize(current_fdtp); + overlays_applied++; } else { /* * Assume here that the base we tried to apply on is @@ -513,6 +520,26 @@ fdtp_size = current_fdtp_size; } free(overlay); + return (overlays_applied); +} + +int +fdt_pad_dtb(size_t padding) +{ + void *padded_fdtp; + size_t padded_fdtp_size; + + padded_fdtp_size = fdtp_size + padding; + padded_fdtp = malloc(padded_fdtp_size); + if (padded_fdtp == NULL) + return (1); + if (fdt_open_into(fdtp, padded_fdtp, padded_fdtp_size) != 0) { + free(padded_fdtp); + return (1); + } + fdtp = padded_fdtp; + fdtp_size = padded_fdtp_size; + return (0); } int Index: stand/fdt/fdt_platform.h =================================================================== --- stand/fdt/fdt_platform.h +++ stand/fdt/fdt_platform.h @@ -43,7 +43,8 @@ void fdt_fixup_ethernet(const char *, char *, int); void fdt_fixup_memory(struct fdt_mem_region *, size_t); void fdt_fixup_stdout(const char *); -void fdt_apply_overlays(void); +int fdt_apply_overlays(void); +int fdt_pad_dtb(size_t); int fdt_load_dtb_addr(struct fdt_header *); int fdt_load_dtb_file(const char *); void fdt_load_dtb_overlays(const char *); Index: stand/uboot/fdt/uboot_fdt.c =================================================================== --- stand/uboot/fdt/uboot_fdt.c +++ stand/uboot/fdt/uboot_fdt.c @@ -39,6 +39,8 @@ #define STR(number) #number #define STRINGIFY(number) STR(number) +#define FDT_DTB_PADSZ 1024 + int fdt_platform_load_dtb(void) { @@ -108,7 +110,8 @@ ethstr = NULL; /* Apply overlays before anything else */ - fdt_apply_overlays(); + if (fdt_apply_overlays() > 0) + fdt_pad_dtb(FDT_DTB_PADSZ); /* Acquire sys_info */ si = ub_get_sys_info();