Skip to content

Commit 327e9e3

Browse files
committed
uefi: linuxloader: move to fdt_totalsize for dtbo, as it may contain padding
1 parent 7cea7b6 commit 327e9e3

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

uefi/common_linuxloader/common_linuxloader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ void droidboot_internal_boot_linux_from_ram(void *kernel_raw, off_t kernel_raw_s
104104

105105
// Reallocate DTB
106106
// NOTE: Here we do change dtb size by adding 512 bytes for our extras, 4096 for cmdline, to make sure we have space for cmdline, memory node and initrd addr
107-
dtb_raw_size+=512+dtbo_raw_size+4096;
107+
dtb_raw_size+=512+fdt_totalsize(dtbo_raw)+4096;
108108
mem_pages=EFI_SIZE_TO_PAGES(ALIGN_VALUE(dtb_raw_size,MEM_ALIGN));
109109
mem_size=EFI_PAGES_TO_SIZE(mem_pages);
110110
if(!(dtb_address=AllocateAlignedPages(mem_pages,MEM_ALIGN)))
111111
droidboot_log(DROIDBOOT_LOG_ERROR, "dtb alloc failed\n");
112112
ZeroMem(dtb_address,mem_size);
113-
CopyMem(dtb_address,dtb_raw,dtb_raw_size-512-dtbo_raw_size-4096);
113+
CopyMem(dtb_address,dtb_raw,dtb_raw_size-512-fdt_totalsize(dtbo_raw)-4096);
114114
droidboot_log(DROIDBOOT_LOG_INFO, "dtb reallocation done, old addr: %p new: %p, new size: %llx\n", dtb_raw, dtb_address, dtb_raw_size);
115115

116116
// Update size in dtb itself
@@ -137,7 +137,7 @@ void droidboot_internal_boot_linux_from_ram(void *kernel_raw, off_t kernel_raw_s
137137
// Append dtbo
138138
unsigned char *header_ptr = (unsigned char *)dtbo_raw;
139139
droidboot_dump_hex(DROIDBOOT_LOG_TRACE, dtbo_raw, 16);
140-
if(dtbo_raw_size<=4||dtbo_raw_size>MAX_DTBO_SIZE){
140+
if(fdt_totalsize(dtbo_raw)<=4||fdt_totalsize(dtbo_raw)>MAX_DTBO_SIZE){
141141
droidboot_log(DROIDBOOT_LOG_ERROR, "invalid dtbo size\n");
142142
} else {
143143
const uint32_t magic_dtbo=0xd0dfeed;

0 commit comments

Comments
 (0)