From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F376C3DA6E for ; Thu, 15 Dec 2022 11:58:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0956985405; Thu, 15 Dec 2022 12:58:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="CdEajLcg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A97DE852FA; Thu, 15 Dec 2022 12:58:38 +0100 (CET) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BB2A78545C for ; Thu, 15 Dec 2022 12:58:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Eugen.Hristev@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1671105514; x=1702641514; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4uDqeto1NE1P63MANAcB7buhCfhoaQhNAk07YEDG3/s=; b=CdEajLcgs43sTqc6yNPLTUAX1YaF+6o36NwDM7gTSJO64/N0LDvJzgko mVFREPjdgFKTnq05JZwYtENSu5QsqdY9sk8M1Yk2aqdUksEXyBj+MrUCd nWus//L61Qg0s6DWoVtQJMj+qmfUhh9DzakS1U5hmgLLsdr+JaJJOTQji 5s0/hWtJ5ZdIXKuoiwsDWeK9aw0AByEcd8sVgWFzakysUEdx4K/FRRQ6/ wFbzYsoDTM+CdR9szILxNXvpsN8wLJyDCfG+1kvaVjGyK/seu8DeZoaFb QgLYu8IrTdEjJsfoTRiS21JlDmTetfWaNDZJB3ppDgIZJcrByRhhowsaQ g==; X-IronPort-AV: E=Sophos;i="5.96,247,1665471600"; d="scan'208";a="193172773" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 15 Dec 2022 04:58:31 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 15 Dec 2022 04:58:31 -0700 Received: from ROB-ULT-M18282.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Thu, 15 Dec 2022 04:58:28 -0700 From: Eugen Hristev To: , CC: , , , , , , Eugen Hristev Subject: [PATCH] lds: align u-boot-nodtb with 8 bytes boundary Date: Thu, 15 Dec 2022 13:58:25 +0200 Message-ID: <20221215115825.827111-1-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Newer DTC require that the DTB start address is aligned at 8 bytes. In the u-boot.bin case, the u-boot-nodtb.bin is concatenated with the DTB, but there is no alignment/padding to the next 8byte aligned address. This causes the board to fail booting, because the FDT will claim that the DTB inside u-boot.bin is not a valid DTB, it will fail with -FDT_ERR_ALIGNMENT. To solve this, have the u-boot binary `_end` aligned with 8 bytes. The objcopy in the Makefile will create the u-boot-nodtb.bin and it has to be truncated to 8 bytes to correspond to the u-boot.map file which will have the `_end` aligned to 8 bytes. The lds files which use devicetrees have been changed to align the `_end` tag with 8 bytes. This patch is also a prerequisite to have the possibility to update the dtc inside u-boot to newer versions (1.6.1+) Signed-off-by: Eugen Hristev --- Hi, I could not test all affected boards, it's an impossible task. I tried this on at91 boards which I have, and ran the CI on denx. I cannot guarantee that no other boards are affected, so this patch is a bit of an RFC. If the u-boot-nodtb.bin does not have the size equal with the corresponding one in u-boot.map, the binary_size_check will fail at build time with something like this: u-boot.map shows a binary size of 502684 but u-boot-nodtb.bin shows 502688 Thanks, Eugen Makefile | 2 ++ arch/arm/cpu/armv8/u-boot.lds | 4 ++-- arch/arm/cpu/u-boot-spl.lds | 1 + arch/arm/cpu/u-boot.lds | 1 + arch/arm/lib/elf_arm_efi.lds | 5 +++++ arch/arm/mach-at91/arm926ejs/u-boot-spl.lds | 2 +- arch/arm/mach-at91/armv7/u-boot-spl.lds | 2 +- arch/arm/mach-zynq/u-boot-spl.lds | 2 +- arch/mips/cpu/u-boot.lds | 2 +- arch/sandbox/cpu/u-boot.lds | 6 ++++++ arch/sh/cpu/u-boot.lds | 2 ++ board/ti/am335x/u-boot.lds | 1 + tools/binman/test/u_boot_binman_embed.lds | 2 +- 13 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9d84f96481..b4d387bcce 100644 --- a/Makefile +++ b/Makefile @@ -1317,6 +1317,8 @@ endif u-boot-nodtb.bin: u-boot FORCE $(call if_changed,objcopy_uboot) +# Make sure the size is 8 byte-aligned. + @truncate -s %8 $@ $(BOARD_SIZE_CHECK) u-boot.ldr: u-boot diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds index 8fe4682dd2..e5fa4ef95c 100644 --- a/arch/arm/cpu/armv8/u-boot.lds +++ b/arch/arm/cpu/armv8/u-boot.lds @@ -145,10 +145,10 @@ SECTIONS *(.__rel_dyn_end) } - _end = .; - . = ALIGN(8); + _end = .; + .bss_start : { KEEP(*(.__bss_start)); } diff --git a/arch/arm/cpu/u-boot-spl.lds b/arch/arm/cpu/u-boot-spl.lds index fb2189d50d..732ed42db1 100644 --- a/arch/arm/cpu/u-boot-spl.lds +++ b/arch/arm/cpu/u-boot-spl.lds @@ -55,6 +55,7 @@ SECTIONS .end : { + . = ALIGN(8); *(.__end) } diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds index f25f72b2e0..274e1a7d30 100644 --- a/arch/arm/cpu/u-boot.lds +++ b/arch/arm/cpu/u-boot.lds @@ -193,6 +193,7 @@ SECTIONS .end : { + . = ALIGN(8); *(.__end) } diff --git a/arch/arm/lib/elf_arm_efi.lds b/arch/arm/lib/elf_arm_efi.lds index 767ebda635..f3867021d3 100644 --- a/arch/arm/lib/elf_arm_efi.lds +++ b/arch/arm/lib/elf_arm_efi.lds @@ -54,6 +54,11 @@ SECTIONS .rel.data : { *(.rel.data) *(.rel.data*) } _data_size = . - _etext; + .end : { + . = ALIGN(8); + *(.__end) + } + /DISCARD/ : { *(.rel.reloc) *(.eh_frame) diff --git a/arch/arm/mach-at91/arm926ejs/u-boot-spl.lds b/arch/arm/mach-at91/arm926ejs/u-boot-spl.lds index 1a8bf94dee..d7e5d81ecc 100644 --- a/arch/arm/mach-at91/arm926ejs/u-boot-spl.lds +++ b/arch/arm/mach-at91/arm926ejs/u-boot-spl.lds @@ -31,7 +31,7 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram - . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; .end : diff --git a/arch/arm/mach-at91/armv7/u-boot-spl.lds b/arch/arm/mach-at91/armv7/u-boot-spl.lds index 6ca725fc4c..2a0a1b4b86 100644 --- a/arch/arm/mach-at91/armv7/u-boot-spl.lds +++ b/arch/arm/mach-at91/armv7/u-boot-spl.lds @@ -38,7 +38,7 @@ SECTIONS . = ALIGN(4); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))) } > .sram - . = ALIGN(4); + . = ALIGN(8); __image_copy_end = .; .end : diff --git a/arch/arm/mach-zynq/u-boot-spl.lds b/arch/arm/mach-zynq/u-boot-spl.lds index 8c18d3f91f..c0320dbe1e 100644 --- a/arch/arm/mach-zynq/u-boot-spl.lds +++ b/arch/arm/mach-zynq/u-boot-spl.lds @@ -41,7 +41,7 @@ SECTIONS KEEP(*(SORT(__u_boot_list*))); } > .sram - . = ALIGN(4); + . = ALIGN(8); _image_binary_end = .; diff --git a/arch/mips/cpu/u-boot.lds b/arch/mips/cpu/u-boot.lds index 9a4ebcd151..182e9bc6e5 100644 --- a/arch/mips/cpu/u-boot.lds +++ b/arch/mips/cpu/u-boot.lds @@ -56,7 +56,7 @@ SECTIONS . += CONFIG_MIPS_RELOCATION_TABLE_SIZE - 4; } - . = ALIGN(4); + . = ALIGN(8); _end = .; .bss __rel_start (OVERLAY) : { diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds index ba8dee50c7..3fbca6d248 100644 --- a/arch/sandbox/cpu/u-boot.lds +++ b/arch/sandbox/cpu/u-boot.lds @@ -51,6 +51,12 @@ SECTIONS *(.dynsym) __dyn_sym_end = .; } + + .end : + { + . = ALIGN(8); + *(.__end) + } } INSERT BEFORE .data; diff --git a/arch/sh/cpu/u-boot.lds b/arch/sh/cpu/u-boot.lds index d360eea7eb..226f50b19c 100644 --- a/arch/sh/cpu/u-boot.lds +++ b/arch/sh/cpu/u-boot.lds @@ -74,6 +74,8 @@ SECTIONS KEEP(*(SORT(__u_boot_list*))); } >ram + . = ALIGN(8); + PROVIDE (__init_end = .); PROVIDE (reloc_dst_end = .); PROVIDE (_end = .); diff --git a/board/ti/am335x/u-boot.lds b/board/ti/am335x/u-boot.lds index 087dee8bb2..deb9098a90 100644 --- a/board/ti/am335x/u-boot.lds +++ b/board/ti/am335x/u-boot.lds @@ -118,6 +118,7 @@ SECTIONS .end : { + . = ALIGN(8); *(.__end) } diff --git a/tools/binman/test/u_boot_binman_embed.lds b/tools/binman/test/u_boot_binman_embed.lds index e213fa8a84..93c0ae6aed 100644 --- a/tools/binman/test/u_boot_binman_embed.lds +++ b/tools/binman/test/u_boot_binman_embed.lds @@ -18,7 +18,7 @@ SECTIONS *(.text*) } - . = ALIGN(4); + . = ALIGN(8); .data : { dtb_embed_begin = .; KEEP(*(.mydtb)); -- 2.25.1