efi/dtb: Fix dtb malloc failed for kernel args

kernel_args_malloc should be used after heap_init, or it will failed
when we new some region instance.

Change-Id: I457057b1e0ff6d4def9e101485e38fec1848d8de
Signed-off-by: Han Pengfei <pengphei@qq.com>
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3912
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Han Pengfei 2021-05-15 02:00:41 +08:00 committed by Adrien Destugues
parent 4a6c01c33f
commit cd9b0eed94
3 changed files with 23 additions and 6 deletions

View File

@ -21,6 +21,10 @@
#define ERROR(x...) dprintf("efi/fdt: " x)
static void* sDtbTable = NULL;
static uint32 sDtbSize = 0;
static bool
fdt_valid(void* fdt, uint32* size)
{
@ -56,16 +60,27 @@ dtb_init()
if (!fdt_valid(dtbPtr, &fdtSize)) {
ERROR("Invalid FDT from UEFI table %d\n", i);
break;
} else {
INFO("Valid FDT from UEFI table %d (%d)\n", i, fdtSize);
sDtbTable = dtbPtr;
sDtbSize = fdtSize;
break;
}
}
}
INFO("Valid FDT from UEFI table %d (%d)\n", i, fdtSize);
// pack into proper location if the architecture cares
void
dtb_set_kernel_args()
{
// pack into proper location if the architecture cares
if (sDtbTable != NULL) {
#ifdef __ARM__
gKernelArgs.arch_args.fdt = kernel_args_malloc(fdtSize);
if (gKernelArgs.arch_args.fdt != NULL) {
memcpy(gKernelArgs.arch_args.fdt, dtbPtr, fdtSize);
} else
gKernelArgs.arch_args.fdt = kernel_args_malloc(sDtbSize);
if (gKernelArgs.arch_args.fdt != NULL)
memcpy(gKernelArgs.arch_args.fdt, sDtbTable, sDtbSize);
else
ERROR("unable to malloc for fdt!\n");
#endif
}

View File

@ -13,6 +13,7 @@
extern void dtb_init();
extern void dtb_set_kernel_args();
#endif /* !_ASSEMBLER */

View File

@ -146,6 +146,7 @@ extern "C" void
platform_start_kernel(void)
{
smp_init_other_cpus();
dtb_set_kernel_args();
addr_t kernelEntry = get_kernel_entry();