From: Simon Glass Date: Mon, 18 Jun 2018 08:08:25 -0600 Subject: [U-Boot] [PATCH v8 20/30] efi: Tidy up device-tree-size calculation in copy_fdt() In-Reply-To: <20180618140835.195901-1-sjg@chromium.org> References: <20180618140835.195901-1-sjg@chromium.org> Message-ID: <20180618140835.195901-21-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This is a bit confusing at present since it adds 4KB to the pointer, then rounds it up. It looks like a bug, but is not. Move the 4KB addition into a separate statement and expand the comment. Signed-off-by: Simon Glass --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None cmd/bootefi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index d2458e2397..c89f83fb33 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -137,8 +137,12 @@ static void *copy_fdt(void *fdt) fdt_ram_start = ram_start; } - /* Give us at least 4kb breathing room */ - fdt_size = ALIGN(fdt_size + 4096, EFI_PAGE_SIZE); + /* + * Give us at least 4KB of breathing room in case the device tree needs + * to be expanded later. Round up to the nearest EFI page boundary. + */ + fdt_size += 4096; + fdt_size = ALIGN(fdt_size + EFI_PAGE_SIZE - 1, EFI_PAGE_SIZE); fdt_pages = fdt_size >> EFI_PAGE_SHIFT; /* Safe fdt location is at 127MB */ -- 2.18.0.rc1.244.gcf134e6275-goog