powerpc: Enable LTO on mpc85xx
Subsystems (4)
v2 cover powerpc: Enable LTO on mpc85xx
This series allows LTO on mpc85xx and enables it for the CZ.NIC Turris 1.x. The Turris NOR image is limited to 768 KiB. LTO, together with dropping NVMe and SCSI from the NOR build, makes room for the ubi command and the BCH ECC code required by the NAND.
The series depends on two generic LTO fixes sent separately, as requested in the v1 review [1]:
- "Makefile: Pass -static to the LTO link" [2], which fixes the LTO link with default-PIE toolchains such as Debian's GCC.
- "Makefile: Set LTO_ENABLE before including config.mk" (2/2 of [3]), which makes patch 7 effective.
The series consists of:
1-2. PowerPC global data:
- Drop an unused SPL copy of gd.
- Make the global data pointer LTO-safe.
3-5. PowerPC private libgcc:
- Add GCC's out-of-line register save and restore routines from Linux.
- Add 64-bit division routines.
- Select the private libgcc for mpc85xx LTO builds, as the LTO link puts it inside --whole-archive, where a toolchain libgcc does not link.
6-9. mpc85xx LTO support:
- Discard the LTO keep-syms section and its fixups.
- Drop -ffunction-sections and -fdata-sections with LTO, as ARM does.
- Allow CONFIG_LTO=y on mpc85xx.
- Pass the make jobserver to xPL links, as GCC 12's lto-wrapper requires.
10-14. Turris 1.x:
- Enable LTO.
- Select the BCH ECC code required by the NAND.
- Make the NVMe and SCSI boot targets conditional.
- Add the ubi command to the NOR build.
- Put the OTP MAC addresses and serial number into the kernel device tree also after the environment has been reset.
Since v2026.10, main's turris_1x_sdcard u-boot.bin has grown from 1046491 to 1049419 bytes, exceeding the 1 MiB that its SPL loads from the card. The build does not catch this. Patch 10 brings the image back below the limit. Patch 11 fixes a separate problem:
without it, NAND probing hits BUG().
With Debian's GCC 14.2 and the two generic fixes, turris_1x_nor's u-boot-nodtb.bin shrinks from 757336 to 752000 bytes while gaining LTO, BCH ECC and the ubi command and dropping NVMe and SCSI. The turris_1x_sdcard u-boot.bin shrinks from 1049419 to 997059 bytes.
All 83 PowerPC defconfigs build, and all 71 mpc85xx defconfigs link with CONFIG_LTO=y. No .discard* section or zero fixup entry remains. test.py on qemu-ppce500 gives the same results as on main, with and without LTO. The single failing timing test also fails on main. With the kernel.org GCC 14.2 used by CI, both Turris LTO builds fit. With Debian's GCC 12.2 and make 4.3, the Turris SD card SPL links at -j8 only with patch 9.
Boot-tested on a Turris 1.1 from NOR and SD card. The NOR build also booted OpenWrt from a kernel in a UBI volume on NAND. Linux received the OTP MAC addresses and serial number even after "env default -a". With the SD card build, ethaddr and serial# values set in the environment were preserved. Other boards were build-tested only.
Changes in v2:
- Based on main.
- Replace "Makefile: Link a toolchain libgcc outside --whole-archive with LTO" with patches 3-5, which make the private libgcc work for mpc85xx LTO builds.
- Add patch 7 to drop -ffunction-sections and -fdata-sections with LTO.
- Send "Makefile: Skip undefined symbols in keep-syms-lto.c" [4] and "Makefile: Pass -static to the LTO link" separately.
- Explain in patch 10 that the SD card image already exceeds 1 MiB without BCH ECC.
- Shorten the commit messages of patches 6 and 9.
- Keep Marek Mojík's Reviewed-by from v1. His Tested-by is not carried over because the images have changed.
[1] https://lore.kernel.org/u-boot/20261012190720.GF3722450@bill-the-cat/
[2] https://lore.kernel.org/u-boot/[email protected]/
[3] https://lore.kernel.org/u-boot/[email protected]/
[4] https://lore.kernel.org/u-boot/[email protected]/
v1: https://lore.kernel.org/u-boot/[email protected]/
Josef Schlehofer (14):
board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy
powerpc: Make the global data pointer LTO safe
powerpc: lib: Add GPR save and restore routines to the private libgcc
powerpc: lib: Add 64-bit division to the private libgcc
powerpc: mpc85xx: Use the private libgcc with LTO
powerpc: mpc85xx: Discard LTO keep-syms sections
powerpc: Drop -ffunction-sections and -fdata-sections with LTO
powerpc: mpc85xx: Allow LTO
xpl: Pass the make jobserver to the xPL link
configs: turris_1x: Enable LTO
mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH
board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional
configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI
board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP
arch/powerpc/Kconfig | 2 + arch/powerpc/config.mk | 8 +- arch/powerpc/cpu/mpc83xx/cpu_init.c | 3 +- arch/powerpc/cpu/mpc83xx/spl_minimal.c | 3 +- arch/powerpc/cpu/mpc85xx/cpu_init_early.c | 3 +- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 11 +- arch/powerpc/cpu/mpc85xx/u-boot.lds | 11 +- arch/powerpc/include/asm/global_data.h | 30 +++ arch/powerpc/lib/Makefile | 5 +- arch/powerpc/lib/crtsavres.S | 213 ++++++++++++++++++++++ arch/powerpc/lib/gd.c | 14 ++ arch/powerpc/lib/udivdi3.c | 82 +++++++++ board/CZ.NIC/turris_1x/turris_1x.c | 20 ++ board/nxp/p1010rdb/spl.c | 9 +- board/nxp/p1010rdb/spl_minimal.c | 2 +- board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c | 3 + board/nxp/p1_p2_rdb_pc/spl.c | 9 +- board/nxp/p1_p2_rdb_pc/spl_minimal.c | 2 +- board/nxp/t102xrdb/spl.c | 4 +- board/nxp/t104xrdb/spl.c | 4 +- board/nxp/t208xqds/spl.c | 4 +- board/nxp/t208xrdb/spl.c | 4 +- board/nxp/t4rdb/spl.c | 4 +- common/board_r.c | 2 +- common/init/board_init.c | 9 +- common/spl/spl.c | 4 +- configs/kmcoge5ne_defconfig | 1 - configs/turris_1x_nor_defconfig | 10 +- configs/turris_1x_sdcard_defconfig | 2 +- doc/build/gcc.rst | 6 +- drivers/mtd/nand/raw/Kconfig | 2 + include/configs/turris_1x.h | 20 +- scripts/Makefile.xpl | 2 +- 33 files changed, 446 insertions(+), 62 deletions(-) create mode 100644 arch/powerpc/lib/crtsavres.S create mode 100644 arch/powerpc/lib/gd.c create mode 100644 arch/powerpc/lib/udivdi3.c
base-commit: 5e3b01c8466dbe45cd6a06299f8f4c7e8c1c2363
prerequisite-patch-id: dd05ac311e66ce2e58bee21495f7a8ec9deb09f8
prerequisite-patch-id: 272fe84ac4b6e21b07a782eeb57a58a4953afa1c
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v2 1/14 board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy
The SPL board_init_r() of these boards points its gd parameter, which shadows the global gd, at CONFIG_VAL(GD_ADDR), clears that area and stores bd, the full malloc flag and, in the NAND TPLs, the location of the loaded environment there. The SPL keeps running on the global data that cpu_init_early_f() set up in the initial RAM, so nothing reads this copy.
The next patch makes gd LTO safe, and gd can then no longer be the name of a parameter. Drop the copy and the stores to it instead of moving the global data to CONFIG_VAL(GD_ADDR): on the P1/P2 RDB SD card SPLs that address is 4 KiB below the stack top, and the 8 KiB environment buffer of env_mmc_load_singular() would overwrite it.
No functional change: the SPLs and TPLs lose only the stores to the copy.
Tested on CZ.NIC Turris 1.1 (SD boot, with the LTO build of this series).
---
(no changes since v1)
--- board/nxp/p1010rdb/spl.c | 9 +-------- board/nxp/p1_p2_rdb_pc/spl.c | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-)
board/nxp/p1010rdb/spl.c +1 -8
@@ -60,22 +60,17 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_VAL (RELOC_STACK ),0 ,CONFIG_SPL_RELOC_TEXT_BASE ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) { -/* Pointer is writable since we allocated a register for it */ - gd = (gd_t *)CONFIG_VAL (GD_ADDR );struct bd_info *bd; -memset (gd,0 ,sizeof (gd_t)); bd = (struct bd_info *)(CONFIG_VAL (GD_ADDR ) +sizeof (gd_t));memset (bd,0 ,sizeof (struct bd_info )); - gd->bd = bd;arch_cpu_init ();get_clocks ();mem_malloc_init (CONFIG_VAL (RELOC_MALLOC_ADDR ),CONFIG_VAL (RELOC_MALLOC_SIZE )); - gd->flags |=GD_FLG_FULL_MALLOC_INIT ;#ifndef CONFIG_SPL_NAND_BOOT env_init ();
@@ -88,8 +83,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)#ifdef CONFIG_SPL_NAND_BOOT nand_spl_load_image (CONFIG_ENV_OFFSET ,CONFIG_ENV_SIZE , (uchar *)SPL_ENV_ADDR ); - gd->env_addr = (ulong)(SPL_ENV_ADDR ); - gd->env_valid =ENV_VALID ;#else env_relocate ();#endif
board/nxp/p1_p2_rdb_pc/spl.c +1 -8
@@ -72,22 +72,17 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_VAL (RELOC_STACK ),0 ,CONFIG_SPL_RELOC_TEXT_BASE ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) { -/* Pointer is writable since we allocated a register for it */ - gd = (gd_t *)CONFIG_VAL (GD_ADDR );struct bd_info *bd; -memset (gd,0 ,sizeof (gd_t)); bd = (struct bd_info *)(CONFIG_VAL (GD_ADDR ) +sizeof (gd_t));memset (bd,0 ,sizeof (struct bd_info )); - gd->bd = bd;arch_cpu_init ();get_clocks ();mem_malloc_init (CONFIG_VAL (RELOC_MALLOC_ADDR ),CONFIG_VAL (RELOC_MALLOC_SIZE )); - gd->flags |=GD_FLG_FULL_MALLOC_INIT ;#ifdef CONFIG_SPL_ENV_SUPPORT #ifndef CONFIG_SPL_NAND_BOOT
@@ -102,8 +97,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)#ifdef CONFIG_SPL_NAND_BOOT nand_spl_load_image (CONFIG_ENV_OFFSET ,CONFIG_ENV_SIZE , (uchar *)SPL_ENV_ADDR ); - gd->env_addr = (ulong)(SPL_ENV_ADDR ); - gd->env_valid =ENV_VALID ;#else env_relocate ();#endif
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v2 2/14 powerpc: Make the global data pointer LTO safe
In reply to Josef SchlehoferThe register variable form of gd cannot be used with LTO (GCC bug 68384). The LTO link fails with "multiple definition of `r2'". In LTO builds define gd through inline assembly accessors that read and write r2, following ARM and RISC-V. Other builds keep the register variable, and set_gd() assigns it.
Every assignment to gd has to go through set_gd() for that to work, so convert all PowerPC ones, including those in common code, and give PowerPC its own arch_setup_gd() in the new arch/powerpc/lib/gd.c instead of the weak one, which assigns gd. Rename the gd parameter of the SPL board_init_r() functions, which the gd macro would otherwise replace.
---
(no changes since v1)
The mpc83xx and common/spl/spl.c hunks change no build: mpc83xx cannot enable LTO and no PowerPC board builds common/spl/spl.c. They are converted so that no PowerPC code assigns gd directly.
Unlike on ARM and RISC-V, set_gd() assigns the register variable in builds without LTO. GCC requires inline assembly that accesses a global register variable to declare that access through constraints.
In the T-series SPLs, the board_init_r() bodies now use the global gd instead of the parameter. relocate_code() passes the CONFIG_SPL_GD_ADDR that board_init_f() has already set as gd and leaves r2 alone, so the pointer is the same.
checkpatch asks for IS_ENABLED() on the #if lines in common/board_r.c, common/init/board_init.c and common/spl/spl.c. They choose how gd is set per architecture: set_gd() exists only on ARM, RISC-V and PowerPC, so IS_ENABLED() cannot replace them. The new arch/powerpc/lib/gd.c is covered by the POWERPC entry in MAINTAINERS.
--- arch/powerpc/cpu/mpc83xx/cpu_init.c | 3 +-- arch/powerpc/cpu/mpc83xx/spl_minimal.c | 3 +-- arch/powerpc/cpu/mpc85xx/cpu_init_early.c | 3 +-- arch/powerpc/include/asm/global_data.h | 30 +++++++++++++++++++++++ arch/powerpc/lib/Makefile | 1 + arch/powerpc/lib/gd.c | 14 +++++++++++ board/nxp/p1010rdb/spl_minimal.c | 2 +- board/nxp/p1_p2_rdb_pc/spl_minimal.c | 2 +- board/nxp/t102xrdb/spl.c | 4 +-- board/nxp/t104xrdb/spl.c | 4 +-- board/nxp/t208xqds/spl.c | 4 +-- board/nxp/t208xrdb/spl.c | 4 +-- board/nxp/t4rdb/spl.c | 4 +-- common/board_r.c | 2 +- common/init/board_init.c | 9 ++++--- common/spl/spl.c | 4 ++- 16 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 arch/powerpc/lib/gd.c
arch/powerpc/cpu/mpc83xx/cpu_init.c +1 -2
@@ -139,8 +139,7 @@ void cpu_init_f (volatile immap_t * im)#endif 0 ; -/* Pointer is writable since we allocated a register for it */ - gd = (gd_t *)SYS_INIT_SP_ADDR ; +set_gd ((gd_t *)SYS_INIT_SP_ADDR );/* global data region was cleared in start.S */
arch/powerpc/cpu/mpc83xx/spl_minimal.c +1 -2
@@ -25,8 +25,7 @@ DECLARE_GLOBAL_DATA_PTR;*/ void cpu_init_f (volatile immap_t * im) { -/* Pointer is writable since we allocated a register for it */ - gd = (gd_t *)SYS_INIT_SP_ADDR ; +set_gd ((gd_t *)SYS_INIT_SP_ADDR );/* global data region was cleared in start.S */
arch/powerpc/cpu/mpc85xx/cpu_init_early.c +1 -2
@@ -95,8 +95,7 @@ void cpu_init_early_f(void *fdt)int i;#endif -/* Pointer is writable since we allocated a register for it */ - gd = (gd_t *)SYS_INIT_SP_ADDR ; +set_gd ((gd_t *)SYS_INIT_SP_ADDR );/* gd area was zeroed during startup */
arch/powerpc/include/asm/global_data.h +30 -0
@@ -93,8 +93,38 @@ struct arch_global_data {#include <asm-generic/global_data.h> +#ifdef LTO_ENABLE + +#define DECLARE_GLOBAL_DATA_PTR +#define gd get_gd() + +static inline gd_t *get_gd (void ) +{ +gd_t *gd_ptr; + + __asm__volatile ("mr %0, 2\n" :"=r" (gd_ptr)); + +return gd_ptr; +} + +static inline void set_gd (gd_t *gd_ptr) +{ + __asm__volatile ("mr 2, %0\n" : :"r" (gd_ptr)); +} + +#else +#define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("r2") +/* +* GCC does not see an asm statement write r2 and assumes that the +* register variable is unchanged, so it may move gd accesses across the +* write. Assign the variable itself. +*/ +#define set_gd (gd_ptr) (gd = (gd_ptr)) + +#endif +#include <asm/u-boot.h> #endif /* __ASM_GBL_DATA_H */
arch/powerpc/lib/Makefile +1 -0
@@ -18,6 +18,7 @@ endif endif obj-y += bdinfo.o +obj-y += gd.o ifdef MINIMAL obj-y += cache.o time.o
arch/powerpc/lib/gd.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2026 Josef Schlehofer <[email protected]> +*/ + +#include <init.h> +#include <asm/global_data.h> + +DECLARE_GLOBAL_DATA_PTR ; + +void arch_setup_gd (gd_t *new_gd) +{ +set_gd (new_gd); +}
board/nxp/p1010rdb/spl_minimal.c +1 -1
@@ -45,7 +45,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK ,0 ,CONFIG_SPL_RELOC_TEXT_BASE ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {puts ("\nSecond program loader running in sram..." );nand_boot ();
board/nxp/p1_p2_rdb_pc/spl_minimal.c +1 -1
@@ -43,7 +43,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK ,0 ,CONFIG_SPL_RELOC_TEXT_BASE ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {puts ("\nSecond program loader running in sram..." );nand_boot ();
board/nxp/t102xrdb/spl.c +2 -2
@@ -58,7 +58,7 @@ void board_init_f(ulong bootflag)memcpy ((void *)CONFIG_SPL_GD_ADDR , (void *)gd,sizeof (gd_t));/* Update GD pointer */ - gd = (gd_t *)(CONFIG_SPL_GD_ADDR ); +set_gd ((gd_t *)(CONFIG_SPL_GD_ADDR ));console_init_f ();
@@ -87,7 +87,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK , (gd_t *)CONFIG_SPL_GD_ADDR ,0x0 ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {struct bd_info *bd;
board/nxp/t104xrdb/spl.c +2 -2
@@ -55,7 +55,7 @@ void board_init_f(ulong bootflag)memcpy ((void *)CONFIG_SPL_GD_ADDR , (void *)gd,sizeof (gd_t));/* Update GD pointer */ - gd = (gd_t *)(CONFIG_SPL_GD_ADDR ); +set_gd ((gd_t *)(CONFIG_SPL_GD_ADDR ));#ifdef CONFIG_DEEP_SLEEP /* disable the console if boot from deep sleep */
@@ -78,7 +78,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK , (gd_t *)CONFIG_SPL_GD_ADDR ,0x0 ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {struct bd_info *bd;
board/nxp/t208xqds/spl.c +2 -2
@@ -73,7 +73,7 @@ void board_init_f(ulong bootflag)memcpy ((void *)CONFIG_SPL_GD_ADDR , (void *)gd,sizeof (gd_t));/* Update GD pointer */ - gd = (gd_t *)(CONFIG_SPL_GD_ADDR ); +set_gd ((gd_t *)(CONFIG_SPL_GD_ADDR ));console_init_f ();
@@ -96,7 +96,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK , (gd_t *)CONFIG_SPL_GD_ADDR ,0x0 ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {struct bd_info *bd;
board/nxp/t208xrdb/spl.c +2 -2
@@ -33,7 +33,7 @@ void board_init_f(ulong bootflag)memcpy ((void *)CONFIG_SPL_GD_ADDR , (void *)gd,sizeof (gd_t));/* Update GD pointer */ - gd = (gd_t *)(CONFIG_SPL_GD_ADDR ); +set_gd ((gd_t *)(CONFIG_SPL_GD_ADDR ));console_init_f ();
@@ -56,7 +56,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK , (gd_t *)CONFIG_SPL_GD_ADDR ,0x0 ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {struct bd_info *bd;
board/nxp/t4rdb/spl.c +2 -2
@@ -39,7 +39,7 @@ void board_init_f(ulong bootflag)memcpy ((void *)CONFIG_SPL_GD_ADDR , (void *)gd,sizeof (gd_t));/* Update GD pointer */ - gd = (gd_t *)(CONFIG_SPL_GD_ADDR ); +set_gd ((gd_t *)(CONFIG_SPL_GD_ADDR ));/* compiler optimization barrier needed for GCC >= 3.4 */ __asm__ __volatile__("" : : :"memory" );
@@ -59,7 +59,7 @@ void board_init_f(ulong bootflag)relocate_code (CONFIG_SPL_RELOC_STACK , (gd_t *)CONFIG_SPL_GD_ADDR ,0x0 ); } -void board_init_r (gd_t *gd,ulong dest_addr) +void board_init_r (gd_t *dummy,ulong dest_addr) {struct bd_info *bd;
common/board_r.c +1 -1
@@ -796,7 +796,7 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)if (CONFIG_IS_ENABLED (X86_64 ) && !IS_ENABLED (CONFIG_EFI_APP ))arch_setup_gd (new_gd); -#if defined(CONFIG_RISCV ) +#if defined(CONFIG_RISCV ) || defined(CONFIG_PPC )set_gd (new_gd);#elif !defined(CONFIG_X86 ) && !defined(CONFIG_ARM ) && !defined(CONFIG_ARM64 ) gd = new_gd;
common/init/board_init.c +5 -4
@@ -14,15 +14,16 @@DECLARE_GLOBAL_DATA_PTR ;/* -* Unfortunately x86, ARM and RISC-V can't compile this code as gd is defined -* as macro and cannot be assigned. +* x86, RISC-V and PowerPC provide their own arch_setup_gd(), and ARM does +* not call it. */ -#if !defined(CONFIG_X86 ) && !defined(CONFIG_ARM ) && !defined(CONFIG_RISCV ) +#if !defined(CONFIG_X86 ) && !defined(CONFIG_ARM ) && !defined(CONFIG_RISCV ) && \ + !defined(CONFIG_PPC )__weak void arch_setup_gd (struct global_data *gd_ptr) { gd = gd_ptr; } -#endif /* !CONFIG_X86 && !CONFIG_ARM */ +#endif /* !CONFIG_X86 && !CONFIG_ARM && !CONFIG_RISCV && !CONFIG_PPC */ /** * This function is called from board_init_f_init_reserve to set up
common/spl/spl.c +3 -1
@@ -956,7 +956,9 @@ ulong spl_relocate_stack_gd(void)#if CONFIG_IS_ENABLED (LOG )log_fixup_for_gd_move (new_gd);#endif -#if !defined(CONFIG_ARM ) && !defined(CONFIG_RISCV ) +#if defined(CONFIG_PPC ) +set_gd (new_gd); +#elif !defined(CONFIG_ARM ) && !defined(CONFIG_RISCV ) gd = new_gd;#endif return ptr;
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v2 3/14 powerpc: lib: Add GPR save and restore routines to the private libgcc
In reply to Josef SchlehoferWhen GCC optimizes for size, it branches to libgcc's _restgpr_N_x routines to restore non-volatile registers. U-Boot's private libgcc lacks these routines, so builds with CONFIG_USE_PRIVATE_LIBGCC=y fail to link with Debian's GCC 14.2, for example qemu-ppce500:
undefined reference to `_restgpr_31_x'
Copy the 32-bit integer register save and restore routines from Linux's arch/powerpc/lib/crtsavres.S (v7.3-rc5), following the private libgcc's existing approach for shift routines. Put each group of routines in its own section so --gc-sections can discard unused groups. Linux's CONFIG_CC_OPTIMIZE_FOR_SIZE condition is then not needed.
---
Changes in v2:
- new patch
The routines assemble to the same code as crtsavgpr.o, crtresgpr.o and crtresxgpr.o in Debian's libgcc 14.2.
--- arch/powerpc/lib/Makefile | 3 +- arch/powerpc/lib/crtsavres.S | 213 +++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/lib/crtsavres.S
arch/powerpc/lib/Makefile +2 -1
@@ -5,7 +5,8 @@ ## Build a couple of necessary functions into a private libgcc ## if the user asked for it -lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _ashldi3.o _ashrdi3.o _lshrdi3.o +lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _ashldi3.o _ashrdi3.o _lshrdi3.o \ + crtsavres.o MINIMAL=
arch/powerpc/lib/crtsavres.S new file +213 -0
213 lines not on this page · raw message
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 03/14] powerpc: lib: Add GPR save and restore routines to the private libgcc
Quoted 22 lines · Josef Schlehofer
When GCC optimizes for size, it branches to libgcc's
_restgpr_N_xroutines to restore non-volatile registers. U-Boot's private libgcc lacks these routines, so builds withCONFIG_USE_PRIVATE_LIBGCC=yfail to link with Debian's GCC 14.2, for example qemu-ppce500:undefined reference to `_restgpr_31_x'
Copy the 32-bit integer register save and restore routines from Linux's
arch/powerpc/lib/crtsavres.S(v7.3-rc5), following the private libgcc's existing approach for shift routines. Put each group of routines in its own section so --gc-sections can discard unused groups. Linux'sCONFIG_CC_OPTIMIZE_FOR_SIZEcondition is then not needed.Signed-off-by Josef Schlehofer <[email protected]>Cc Tom Rini <[email protected]>Cc Christophe Leroy <[email protected]>Cc Marek Behún <[email protected]>---
Changes in v2:
- new patch
Quoted 7 lines
The routines assemble to the same code as crtsavgpr.o, crtresgpr.o and crtresxgpr.o in Debian's libgcc 14.2.
---arch/powerpc/lib/Makefile| 3 +-arch/powerpc/lib/crtsavres.S| 213 +++++++++++++++++++++++++++++++++++2 files changed, 215 insertions(+), 1 deletion(-)create mode 100644
arch/powerpc/lib/crtsavres.S
I feel a maintainers entry for this would be good, or could it be covered under me? (If I end up getting maintainers patch merged)
Quoted 225 lines
arch/powerpc/lib/Makefile +2
-1@@ -5,7 +5,8 @@ ## Build a couple of necessary functions into a private libgcc ## if the user asked for it -lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _ashldi3.o _ashrdi3.o _lshrdi3.o +lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _ashldi3.o _ashrdi3.o _lshrdi3.o \ + crtsavres.oMINIMAL=
arch/powerpc/lib/crtsavres.S new file +203
-0@@ -0,0 +1,213 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Out-of-line integer register save and restore routines, which GCC calls + * from function prologues and epilogues when it optimizes for size. + * + * This code was copied from crtsavres.S in arch/powerpc/lib of the Linux + * kernel sources (v7.3-rc5, last changed by commit 699d53f04829 + * ("powerpc/vdso32: Fix use of crtsavres for PPC64")): the 32-bit integer + * register routines, without the CONFIG_CC_OPTIMIZE_FOR_SIZE condition. + * Each group of routines is in a section of its own, so that --gc-sections + * drops the groups that nothing calls. The source file copyrights are as + * follows: + * + * Copyright (C) 1995, 1996, 1998, 2000, 2001 Free Software Foundation, Inc. + * Copyright 2008 Freescale Semiconductor, Inc. + * Written By Michael Meissner + * + * Based on gcc/config/rs6000/crtsavres.asm from gcc + */ + +#include <asm/processor.h> + +/* Routines for saving integer registers, called by the compiler. */ +/* Called with r11 pointing to the stack header word of the caller of the */ +/* function, just beyond the end of the integer save area. */ + + .section ".text._savegpr_14","ax",@progbits + .align 2 + +_GLOBAL(_savegpr_14) +_GLOBAL(_save32gpr_14) + stw 14,-72(11) /* save gp registers */ +_GLOBAL(_savegpr_15) +_GLOBAL(_save32gpr_15) + stw 15,-68(11) +_GLOBAL(_savegpr_16) +_GLOBAL(_save32gpr_16) + stw 16,-64(11) +_GLOBAL(_savegpr_17) +_GLOBAL(_save32gpr_17) + stw 17,-60(11) +_GLOBAL(_savegpr_18) +_GLOBAL(_save32gpr_18) + stw 18,-56(11) +_GLOBAL(_savegpr_19) +_GLOBAL(_save32gpr_19) + stw 19,-52(11) +_GLOBAL(_savegpr_20) +_GLOBAL(_save32gpr_20) + stw 20,-48(11) +_GLOBAL(_savegpr_21) +_GLOBAL(_save32gpr_21) + stw 21,-44(11) +_GLOBAL(_savegpr_22) +_GLOBAL(_save32gpr_22) + stw 22,-40(11) +_GLOBAL(_savegpr_23) +_GLOBAL(_save32gpr_23) + stw 23,-36(11) +_GLOBAL(_savegpr_24) +_GLOBAL(_save32gpr_24) + stw 24,-32(11) +_GLOBAL(_savegpr_25) +_GLOBAL(_save32gpr_25) + stw 25,-28(11) +_GLOBAL(_savegpr_26) +_GLOBAL(_save32gpr_26) + stw 26,-24(11) +_GLOBAL(_savegpr_27) +_GLOBAL(_save32gpr_27) + stw 27,-20(11) +_GLOBAL(_savegpr_28) +_GLOBAL(_save32gpr_28) + stw 28,-16(11) +_GLOBAL(_savegpr_29) +_GLOBAL(_save32gpr_29) + stw 29,-12(11) +_GLOBAL(_savegpr_30) +_GLOBAL(_save32gpr_30) + stw 30,-8(11) +_GLOBAL(_savegpr_31) +_GLOBAL(_save32gpr_31) + stw 31,-4(11) + blr + +/* Routines for restoring integer registers, called by the compiler. */ +/* Called with r11 pointing to the stack header word of the caller of the */ +/* function, just beyond the end of the integer restore area. */ + + .section ".text._restgpr_14","ax",@progbits + .align 2 + +_GLOBAL(_restgpr_14) +_GLOBAL(_rest32gpr_14) + lwz 14,-72(11) /* restore gp registers */ +_GLOBAL(_restgpr_15) +_GLOBAL(_rest32gpr_15) + lwz 15,-68(11) +_GLOBAL(_restgpr_16) +_GLOBAL(_rest32gpr_16) + lwz 16,-64(11) +_GLOBAL(_restgpr_17) +_GLOBAL(_rest32gpr_17) + lwz 17,-60(11) +_GLOBAL(_restgpr_18) +_GLOBAL(_rest32gpr_18) + lwz 18,-56(11) +_GLOBAL(_restgpr_19) +_GLOBAL(_rest32gpr_19) + lwz 19,-52(11) +_GLOBAL(_restgpr_20) +_GLOBAL(_rest32gpr_20) + lwz 20,-48(11) +_GLOBAL(_restgpr_21) +_GLOBAL(_rest32gpr_21) + lwz 21,-44(11) +_GLOBAL(_restgpr_22) +_GLOBAL(_rest32gpr_22) + lwz 22,-40(11) +_GLOBAL(_restgpr_23) +_GLOBAL(_rest32gpr_23) + lwz 23,-36(11) +_GLOBAL(_restgpr_24) +_GLOBAL(_rest32gpr_24) + lwz 24,-32(11) +_GLOBAL(_restgpr_25) +_GLOBAL(_rest32gpr_25) + lwz 25,-28(11) +_GLOBAL(_restgpr_26) +_GLOBAL(_rest32gpr_26) + lwz 26,-24(11) +_GLOBAL(_restgpr_27) +_GLOBAL(_rest32gpr_27) + lwz 27,-20(11) +_GLOBAL(_restgpr_28) +_GLOBAL(_rest32gpr_28) + lwz 28,-16(11) +_GLOBAL(_restgpr_29) +_GLOBAL(_rest32gpr_29) + lwz 29,-12(11) +_GLOBAL(_restgpr_30) +_GLOBAL(_rest32gpr_30) + lwz 30,-8(11) +_GLOBAL(_restgpr_31) +_GLOBAL(_rest32gpr_31) + lwz 31,-4(11) + blr + +/* Routines for restoring integer registers, called by the compiler. */ +/* Called with r11 pointing to the stack header word of the caller of the */ +/* function, just beyond the end of the integer restore area. */ + + .section ".text._restgpr_14_x","ax",@progbits + .align 2 + +_GLOBAL(_restgpr_14_x) +_GLOBAL(_rest32gpr_14_x) + lwz 14,-72(11) /* restore gp registers */ +_GLOBAL(_restgpr_15_x) +_GLOBAL(_rest32gpr_15_x) + lwz 15,-68(11) +_GLOBAL(_restgpr_16_x) +_GLOBAL(_rest32gpr_16_x) + lwz 16,-64(11) +_GLOBAL(_restgpr_17_x) +_GLOBAL(_rest32gpr_17_x) + lwz 17,-60(11) +_GLOBAL(_restgpr_18_x) +_GLOBAL(_rest32gpr_18_x) + lwz 18,-56(11) +_GLOBAL(_restgpr_19_x) +_GLOBAL(_rest32gpr_19_x) + lwz 19,-52(11) +_GLOBAL(_restgpr_20_x) +_GLOBAL(_rest32gpr_20_x) + lwz 20,-48(11) +_GLOBAL(_restgpr_21_x) +_GLOBAL(_rest32gpr_21_x) + lwz 21,-44(11) +_GLOBAL(_restgpr_22_x) +_GLOBAL(_rest32gpr_22_x) + lwz 22,-40(11) +_GLOBAL(_restgpr_23_x) +_GLOBAL(_rest32gpr_23_x) + lwz 23,-36(11) +_GLOBAL(_restgpr_24_x) +_GLOBAL(_rest32gpr_24_x) + lwz 24,-32(11) +_GLOBAL(_restgpr_25_x) +_GLOBAL(_rest32gpr_25_x) + lwz 25,-28(11) +_GLOBAL(_restgpr_26_x) +_GLOBAL(_rest32gpr_26_x) + lwz 26,-24(11) +_GLOBAL(_restgpr_27_x) +_GLOBAL(_rest32gpr_27_x) + lwz 27,-20(11) +_GLOBAL(_restgpr_28_x) +_GLOBAL(_rest32gpr_28_x) + lwz 28,-16(11) +_GLOBAL(_restgpr_29_x) +_GLOBAL(_rest32gpr_29_x) + lwz 29,-12(11)
arch/powerpc/lib/crtsavres.S line 213
Quoted 10 lines
arch/powerpc/lib/crtsavres.S new file +10
-0+_GLOBAL(_restgpr_30_x) +_GLOBAL(_rest32gpr_30_x) + lwz 30,-8(11) +_GLOBAL(_restgpr_31_x) +_GLOBAL(_rest32gpr_31_x) + lwz 0,4(11) + lwz 31,-4(11) + mtlr 0 + mr 1,11 + blr
Hmm. Makes sense.
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 4/14 powerpc: lib: Add 64-bit division to the private libgcc
In reply to Josef SchlehoferOn 32-bit PowerPC, GCC lowers '/' and '%' on unsigned 64-bit operands to calls to __udivdi3() and __umoddi3(). U-Boot's private libgcc lacks these routines, so turris_1x_sdcard fails to link with CONFIG_USE_PRIVATE_LIBGCC=y:
undefined reference to `__udivdi3'
Implement both with a copy of __div64_32() from lib/div64.c whose divisor is widened to 64 bits. The copy keeps the private libgcc independent of lib/, which not every xPL phase links.
Build the file without LTO, as ARM does for eabi_compat.o: LTO can drop these functions before GCC generates the calls that need them.
---
Changes in v2:
- new patch
At -Os the two take 300 bytes, against 1036 and 992 bytes of _udivdi3.o and _umoddi3.o in Debian's libgcc 14.2.
--- arch/powerpc/lib/Makefile | 3 +- arch/powerpc/lib/udivdi3.c | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/lib/udivdi3.c
arch/powerpc/lib/Makefile +2 -1
@@ -6,7 +6,8 @@ ## Build a couple of necessary functions into a private libgcc ## if the user asked for it lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _ashldi3.o _ashrdi3.o _lshrdi3.o \ - crtsavres.o + crtsavres.o udivdi3.o +CFLAGS_REMOVE_udivdi3.o := $(LTO_CFLAGS) MINIMAL=
arch/powerpc/lib/udivdi3.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 04/14] powerpc: lib: Add 64-bit division to the private libgcc
Quoted 11 lines · Josef Schlehofer
On 32-bit PowerPC, GCC lowers '/' and '%' on unsigned 64-bit operands to calls to
__udivdi3()and__umoddi3(). U-Boot's private libgcc lacks these routines, soturris_1x_sdcardfails to link withCONFIG_USE_PRIVATE_LIBGCC=y:undefined reference to `__udivdi3'
Implement both with a copy of
__div64_32()fromlib/div64.cwhose divisor is widened to 64 bits. The copy keeps the private libgcc independent oflib/, which not every xPL phase links.
Quoted 6 lines
Build the file without LTO, as ARM does for eabi_compat.o: LTO can drop these functions before GCC generates the calls that need them.
Signed-off-by Josef Schlehofer <[email protected]>Cc Tom Rini <[email protected]>Cc Marek Behún <[email protected]>
I see. Let's crack on and review thid
Quoted 35 lines
---
Changes in v2:
- new patchAt -Os the two take 300 bytes, against 1036 and 992 bytes of _udivdi3.o and _umoddi3.o in Debian's libgcc 14.2.
---arch/powerpc/lib/Makefile| 3 +-arch/powerpc/lib/udivdi3.c| 82 ++++++++++++++++++++++++++++++++++++++2 files changed, 84 insertions(+), 1 deletion(-)create mode 100644
arch/powerpc/lib/udivdi3.carch/powerpc/lib/Makefile +2
-1@@ -6,7 +6,8 @@ ## Build a couple of necessary functions into a private libgcc ## if the user asked for it lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _ashldi3.o _ashrdi3.o _lshrdi3.o \ - crtsavres.o + crtsavres.o udivdi3.o +CFLAGS_REMOVE_udivdi3.o := $(LTO_CFLAGS)MINIMAL=
arch/powerpc/lib/udivdi3.c new file +3
-0@@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* 64-bit unsigned division and modulo for the private libgcc
arch/powerpc/lib/udivdi3.c line 13
Quoted 10 lines
arch/powerpc/lib/udivdi3.c new file +10
-0+* +* GCC calls __udivdi3() and __umoddi3() for '/' and '%' on unsigned 64-bit +* operands on 32-bit PowerPC. udivmod64() is __div64_32() from lib/div64.c +* with a 64-bit divisor: its shift-and-subtract loop already works on one, +* and the step that first divides the high word now only runs when the +* divisor fits into 32 bits. Like __div64_32(), the functions are not +* instrumented, as tracing code may divide. The source file copyrights are +* as follows: +* +* Copyright (C) 2003 Bernardo Innocenti <[email protected]>
What's your source? Maybe cite it?
Quoted 5 lines
arch/powerpc/lib/udivdi3.c new file +5
-0+* +* Based on former do_div() implementation from asm-parisc/div64.h: +* Copyright (C) 1999 Hewlett-Packard Co +* Copyright (C) 1999 David Mosberger-Tang <[email protected]> +*/
arch/powerpc/lib/udivdi3.c line 28
Quoted 10 lines
arch/powerpc/lib/udivdi3.c new file +10
-0+ +#include <linux/types.h> + +static notrace u64 udivmod64(u64 n, u64 base, u64 *rem) +{ +u64 b = base; +u64 res, d =1 ; +u32 high = n >>32 ; + +/* Reduce the thing a bit first */
Could we clarify that better?
Quoted 45 lines
arch/powerpc/lib/udivdi3.c new file +44
-0+ res =0 ; +if (!(base >>32 ) && high >= base) { + high /= (u32 )base; + res = (u64 )high <<32 ; + n -= (u64)(high * (u32 )base) <<32 ; + } + +while ((s64 )b >0 && b < n) { + b = b + b; + d = d + d; + } + +do { +if (n >= b) { + n -= b; + res += d; + } + b >>=1 ; + d >>=1 ; + }while (d); + + *rem = n; +return res; +} + +/** +* __udivdi3() - divide two 64-bit unsigned integers +* +* @n: dividend +* @d: divisor +* Return: quotient +*/ +notrace u64 __udivdi3(u64 n, u64 d) +{ +u64 rem; + +return udivmod64 (n, d, &rem); +} + +/** +* __umoddi3() - remainder of the division of two 64-bit unsigned integers +* +* @n: dividend +* @d: divisor
arch/powerpc/lib/udivdi3.c line 82
Quoted 10 lines
arch/powerpc/lib/udivdi3.c new file +10
-0+* Return: remainder +*/ +notrace u64 __umoddi3(u64 n, u64 d) +{ +u64 rem; + +udivmod64 (n, d, &rem); + +return rem; +}
Ok, the code looks *sane* to me, I'd be comfortable adding
/shrug
--- Thanks!
"I'm not a very positive person" - Linus torvalds
Re: [PATCH v2 04/14] powerpc: lib: Add 64-bit division to the private libgcc
Hi Bradley,
thanks for the review, and apologies for the delayed reply.
Quoted 1 line
What's your source? Maybe cite it?
The implementation is based on __div64_32() from U-Boot's lib/div64.c, and the copyright notices are taken from the same file. The comment above them already mentions the source, but I'll make the attribution more explicit.
Quoted 1 line
Could we clarify that better?
Sure. That comment also comes from lib/div64.c. The algorithm first divides the high 32-bit word, so this step is only valid when the divisor fits into 32 bits.
Regarding 03/14, I don't think a separate MAINTAINERS entry is needed. Your POWERPC entry already covers arch/powerpc/.
I can send a v3 with these two updates and the tags I've collected, or you can make the changes when applying the series. Either works for me.
Best,
Josef
Re: [PATCH v2 04/14] powerpc: lib: Add 64-bit division to the private libgcc
Quoted 3 lines · Josef Schlehofer
Hi Bradley,
thanks for the review, and apologies for the delayed reply.
That's ok.
Quoted 7 lines
Quoted 2 lines
What's your source? Maybe cite it?
The implementation is based on
__div64_32()from U-Boot'slib/div64.c, and the copyright notices are taken from the same file. The comment above them already mentions the source, but I'll make the attribution more explicit.
Thanks.
Quoted 9 lines
Quoted 2 lines
Could we clarify that better?
Sure. That comment also comes from
lib/div64.c. The algorithm first divides the high 32-bit word, so this step is only valid when the divisor fits into 32 bits.Regarding 03/14, I don't think a separate
MAINTAINERSentry is needed. Your POWERPC entry already coversarch/powerpc/.
Hmm. Okay, if you end up not getting CCed, I'll CC you in patches to that.
Quoted 3 lines
I can send a v3 with these two updates and the tags I've collected, or you can make the changes when applying the series. Either works for me.
Hey, could you do the V3 cc'ing me? If that doesn't kill you.
Quoted 4 lines
Best,
Josef
--- Thanks!
PATCH v2 5/14 powerpc: mpc85xx: Use the private libgcc with LTO
In reply to Josef SchlehoferThe LTO link rules put $(PLATFORM_LIBS) inside --whole-archive. This works with U-Boot's private libgcc, but pulls every member of a toolchain libgcc into the link. With Debian's GCC 14.2, turris_1x_nor fails to link with CONFIG_LTO=y: ld rejects the hard-float members in this soft-float build, while other members reference __morestack_fail, __tls_get_addr or __SDATA_START__.
Select USE_PRIVATE_LIBGCC for mpc85xx LTO builds. The previous two patches add the routines it was missing. This has no effect until a later patch allows LTO on mpc85xx.
---
Changes in v2:
- new patch, instead of "Makefile: Link a toolchain libgcc outside --whole-archive with LTO"
With the whole series, all 71 mpc85xx defconfigs link with CONFIG_LTO=y.
--- arch/powerpc/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/Kconfig +1 -0
@@ -21,6 +21,7 @@ config MPC85xx select SYS_FSL_DDR select SYS_FSL_DDR_BE select SYS_FSL_IFC_BE + select USE_PRIVATE_LIBGCC if LTO select BINMAN if MPC85XX_HAVE_RESET_VECTOR && OF_SEPARATE imply CMD_HASH imply CMD_IRQ
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 05/14] powerpc: mpc85xx: Use the private libgcc with LTO
Quoted 7 lines · Josef Schlehofer
The LTO link rules put $(PLATFORM_LIBS) inside --whole-archive. This works with U-Boot's private libgcc, but pulls every member of a toolchain libgcc into the link. With Debian's GCC 14.2,
turris_1x_norfails to link withCONFIG_LTO=y: ld rejects the hard-float members in this soft-float build, while other members reference__morestack_fail,__tls_get_addror__SDATA_START__.
Quoted 5 lines
Select
USE_PRIVATE_LIBGCCfor mpc85xx LTO builds. The previous two patches add the routines it was missing. This has no effect until a later patch allows LTO on mpc85xx.Signed-off-by Josef Schlehofer <[email protected]>
Quoted 20 lines
Cc Tom Rini <[email protected]>Cc Marek Behún <[email protected]>Cc Priyanka Jain <[email protected]>---
Changes in v2:
- new patch, instead of "Makefile: Link a toolchain libgcc outside --whole-archive with LTO"With the whole series, all 71 mpc85xx defconfigs link with
CONFIG_LTO=y.
---arch/powerpc/Kconfig| 1 +1 file changed, 1 insertion(+)arch/powerpc/Kconfig +0
-0
arch/powerpc/Kconfig config MPC85xx · line 27
Quoted 7 lines
arch/powerpc/Kconfig +1
-0@@ -21,6 +21,7 @@ config MPC85xx select SYS_FSL_DDR select SYS_FSL_DDR_BE select SYS_FSL_IFC_BE + select USE_PRIVATE_LIBGCC if LTO select BINMAN if MPC85XX_HAVE_RESET_VECTOR && OF_SEPARATE imply CMD_HASH imply CMD_IRQ
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 6/14 powerpc: mpc85xx: Discard LTO keep-syms sections
In reply to Josef SchlehoferWith LTO, keep-syms-lto.o puts pointers to linker list entries in .discard.addressable to prevent the entries from being removed. On mpc85xx, -mrelocatable creates .fixup entries for these pointers, and the linker scripts keep all .fixup input sections, leaving .discard.addressable in the image.
Discard .discard* sections and the .fixup entries of keep-syms-lto.o, which point into them. Otherwise, ld leaves zero words in the fixup table, which start.S treats as addresses to relocate. With them, the Turris NOR build with LTO hung after the DRAM message.
---
Changes in v2:
- shorter commit message
--- arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 11 ++++++++++- arch/powerpc/cpu/mpc85xx/u-boot.lds | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-)
arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +10 -1
@@ -35,7 +35,7 @@ SECTIONS KEEP(*(.got2)) KEEP(*(.got)) _FIXUP_TABLE_ = .; - KEEP(*(.fixup)) + KEEP(*(EXCLUDE_FILE(*keep-syms-lto.o) .fixup)) } __got2_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT2_TABLE_) >> 2) - 1; __fixup_entries = (. - _FIXUP_TABLE_) >> 2;
@@ -63,6 +63,15 @@ SECTIONS __init_end = .; _end = .; + /* + * .discard.addressable of keep-syms-lto.o only keeps the linker lists + * alive during an LTO link. Drop it, and its fixups with it. + */ + /DISCARD/ : { + *(.discard*) + *keep-syms-lto.o(.fixup) + } + #if CONFIG_IS_ENABLED(SYS_MPC85XX_NO_RESETVEC) #if defined(CONFIG_SDCARD) && !defined(CFG_SYS_MMC_U_BOOT_OFFS) mmc_u_boot_offs = .;
arch/powerpc/cpu/mpc85xx/u-boot.lds +10 -1
@@ -49,7 +49,7 @@ SECTIONS KEEP(*(.got2)) KEEP(*(.got)) _FIXUP_TABLE_ = .; - KEEP(*(.fixup)) + KEEP(*(EXCLUDE_FILE(*keep-syms-lto.o) .fixup)) } __got2_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT2_TABLE_) >> 2) - 1; __fixup_entries = (. - _FIXUP_TABLE_) >> 2;
@@ -107,6 +107,15 @@ SECTIONS #endif #endif + /* + * .discard.addressable of keep-syms-lto.o only keeps the linker lists + * alive during an LTO link. Drop it, and its fixups with it. + */ + /DISCARD/ : { + *(.discard*) + *keep-syms-lto.o(.fixup) + } + __bss_start = .; .bss (NOLOAD) : {
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 06/14] powerpc: mpc85xx: Discard LTO keep-syms sections
Quoted 11 lines · Josef Schlehofer
With LTO, keep-syms-lto.o puts pointers to linker list entries in .discard.addressable to prevent the entries from being removed. On mpc85xx, -mrelocatable creates .fixup entries for these pointers, and the linker scripts keep all .fixup input sections, leaving .discard.addressable in the image.
Discard .discard* sections and the .fixup entries of keep-syms-lto.o, which point into them. Otherwise, ld leaves zero words in the fixup table, which
start.Streats as addresses to relocate. With them, the Turris NOR build with LTO hung after the DRAM message.
I don't see any wrong with this ;)
Quoted 59 lines
Signed-off-by Josef Schlehofer <[email protected]>Cc Marek Behún <[email protected]>---
Changes in v2:
- shorter commit message
---arch/powerpc/cpu/mpc85xx/u-boot-spl.lds| 11 ++++++++++-arch/powerpc/cpu/mpc85xx/u-boot.lds| 11 ++++++++++-2 files changed, 20 insertions(+), 2 deletions(-)arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +10
-1@@ -35,7 +35,7 @@ SECTIONS KEEP(*(.got2)) KEEP(*(.got)) _FIXUP_TABLE_ = .; - KEEP(*(.fixup)) + KEEP(*(EXCLUDE_FILE(*keep-syms-lto.o) .fixup)) } __got2_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT2_TABLE_) >> 2) - 1; __fixup_entries = (. - _FIXUP_TABLE_) >> 2;@@ -63,6 +63,15 @@ SECTIONS __init_end = .; _end = .; + /* + * .discard.addressable of keep-syms-lto.o only keeps the linker lists + * alive during an LTO link. Drop it, and its fixups with it. + */ + /DISCARD/ : { + *(.discard*) + *keep-syms-lto.o(.fixup) + } + #if CONFIG_IS_ENABLED(SYS_MPC85XX_NO_RESETVEC) #if defined(CONFIG_SDCARD) && !defined(CFG_SYS_MMC_U_BOOT_OFFS) mmc_u_boot_offs = .;arch/powerpc/cpu/mpc85xx/u-boot.lds +3
-1@@ -49,7 +49,7 @@ SECTIONS KEEP(*(.got2)) KEEP(*(.got)) _FIXUP_TABLE_ = .; - KEEP(*(.fixup)) + KEEP(*(EXCLUDE_FILE(*keep-syms-lto.o) .fixup)) } __got2_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT2_TABLE_) >> 2) - 1; __fixup_entries = (. - _FIXUP_TABLE_) >> 2;@@ -107,6 +107,15 @@ SECTIONS #endif #endif + /* + * .discard.addressable of keep-syms-lto.o only keeps the linker lists
arch/powerpc/cpu/mpc85xx/u-boot.lds SECTIONS · line 121
Quoted 10 lines
arch/powerpc/cpu/mpc85xx/u-boot.lds +7
-0+ * alive during an LTO link. Drop it, and its fixups with it. + */ + /DISCARD/ : { + *(.discard*) + *keep-syms-lto.o(.fixup) + } + __bss_start = .; .bss (NOLOAD) : {
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 7/14 powerpc: Drop -ffunction-sections and -fdata-sections with LTO
In reply to Josef SchlehoferWhen LTO is enabled, omit -ffunction-sections and -fdata-sections, as ARM does. This affects U-Boot proper only, as scripts/Makefile.xpl adds both flags for xPL builds anyway.
The change takes effect only once LTO_ENABLE is set before arch/$(ARCH)/config.mk is included. Keep --gc-sections: it drops the .eh_frame sections, which the linker scripts do not place.
---
Changes in v2:
- new patch
Depends on "Makefile: Set LTO_ENABLE before including config.mk" and follows "arm: Keep --gc-sections with LTO":
https://lore.kernel.org/u-boot/[email protected]/
With Debian's GCC 14.2, U-Boot proper of the 71 mpc85xx LTO builds changes by -5302 to +5588 bytes of text and data, and 69 of them shrink. SPL/TPL sizes and builds without LTO are unchanged.
--- arch/powerpc/config.mk | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/config.mk +6 -2
@@ -3,10 +3,14 @@ # (C) Copyright 2000-2010 # Wolfgang Denk, DENX Software Engineering, [email protected]. +# Keep --gc-sections with LTO: it drops the .eh_frame sections, which the +# linker scripts do not place. LDFLAGS_FINAL += --gc-sections LDFLAGS_FINAL += --bss-plt -PLATFORM_RELFLAGS += -fpic -mrelocatable -ffunction-sections \ --fdata-sections -mcall-linux +PLATFORM_RELFLAGS += -fpic -mrelocatable -mcall-linux +ifneq ($(LTO_ENABLE),y) +PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections +endif PF_CPPFLAGS_POWERPC := $(call cc-option,-fno-ira-hoist-pressure,) $(call cc-option,-Xassembler --fatal-warnings,) PLATFORM_CPPFLAGS += -D__powerpc__ -ffixed-r2 -m32 $(PF_CPPFLAGS_POWERPC)
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v2 8/14 powerpc: mpc85xx: Allow LTO
In reply to Josef SchlehoferSelect ARCH_SUPPORTS_LTO from MPC85xx, so that boards can set CONFIG_LTO=y, and name mpc85xx next to ARM in doc/build/gcc.rst. This does not turn LTO on for any board by itself.
Only mpc85xx is covered: it is the PowerPC family whose linker scripts discard the LTO keep-syms sections, and the one that was built and booted with LTO.
---
(no changes since v1)
--- arch/powerpc/Kconfig | 1 + doc/build/gcc.rst | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -17,6 +17,7 @@ config MPC83xx config MPC85xx bool "MPC85xx" + select ARCH_SUPPORTS_LTO select CREATE_ARCH_SYMLINK select SYS_FSL_DDR select SYS_FSL_DDR_BE
doc/build/gcc.rst +3 -3
@@ -193,9 +193,9 @@ Link-time optimisation (LTO) U-Boot supports link-time optimisation which can reduce the size of the final U-Boot binaries, particularly with SPL. -At present this can be enabled by ARM boards by adding `CONFIG_LTO=y` into the -defconfig file. Other architectures are not supported. LTO is enabled by default -for sandbox. +At present this can be enabled by ARM boards and by PowerPC mpc85xx boards by +adding `CONFIG_LTO=y` into the defconfig file. Other architectures are not +supported. LTO is enabled by default for sandbox. This does incur a link-time penalty of several seconds. For faster incremental builds during development, you can disable it by setting `NO_LTO` to `1`.
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v2 9/14 xpl: Pass the make jobserver to the xPL link
In reply to Josef SchlehoferWith LTO, SPL, TPL and VPL are linked through the compiler driver, and GCC's lto-wrapper runs code generation through make. The link recipe is not marked recursive, so make does not pass its jobserver to that command.
With Debian's GCC 12.2 and make 4.3, the SPL link of turris_1x_sdcard, which the next patch switches to LTO, therefore fails at -j8:
make[3]: *** write jobserver: Bad file descriptor. Stop.
lto-wrapper: fatal error: make returned 2 exit status
Prefix the recipe with '+', as the top-level U-Boot link rule does.
Tested with Debian's GCC 12.2, where the link now succeeds, and GCC 14.2, where '+' does not change the images of three mpc85xx LTO builds.
---
Changes in v2:
- shorter commit message
With Debian's GCC 14.2.0-19, the link also succeeds without '+' at -j8. The LTO images of turris_1x_sdcard, P2020RDB-PC_NAND and T2080RDB_NAND are identical with and without it.
--- scripts/Makefile.xpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.xpl +1 -1
@@ -544,7 +544,7 @@ endif $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \ $(u-boot-spl-main) $(u-boot-spl-keep-syms-lto) \ $(obj)/u-boot-spl.lds FORCE - $(call if_changed,u-boot-spl) + +$(call if_changed,u-boot-spl) $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 09/14] xpl: Pass the make jobserver to the xPL link
Quoted 8 lines · Josef Schlehofer
With LTO, SPL, TPL and VPL are linked through the compiler driver, and GCC's lto-wrapper runs code generation through make. The link recipe is not marked recursive, so make does not pass its jobserver to that command.
With Debian's GCC 12.2 and make 4.3, the SPL link of
turris_1x_sdcard, which the next patch switches to LTO, therefore fails at -j8:
Quoted 8 lines
make[3]: *** write jobserver: Bad file descriptor. Stop.
lto-wrapper: fatal error: make returned 2 exit statusPrefix the recipe with '+', as the top-level U-Boot link rule does.
Tested with Debian's GCC 12.2, where the link now succeeds, and GCC 14.2, where '+' does not change the images of three mpc85xx LTO builds.
I guess
Quoted 22 lines
Signed-off-by Josef Schlehofer <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Marek Behún <[email protected]>---
Changes in v2:
- shorter commit messageWith Debian's GCC 14.2.0-19, the link also succeeds without '+' at -j8. The LTO images of
turris_1x_sdcard, P2020RDB-PC_NAND andT2080RDB_NANDare identical with and without it.
---scripts/Makefile.xpl| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.xpl +0
-0
scripts/Makefile.xpl endif · line 550
Quoted 8 lines
scripts/Makefile.xpl +1
-1@@ -544,7 +544,7 @@ endif $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \ $(u-boot-spl-main) $(u-boot-spl-keep-syms-lto) \ $(obj)/u-boot-spl.lds FORCE - $(call if_changed,u-boot-spl) + +$(call if_changed,u-boot-spl) $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 10/14 configs: turris_1x: Enable LTO
In reply to Josef SchlehoferEnable LTO in both Turris 1.x builds. The NOR build needs the space for the ubi command next to the BCH code. The SD card build needs it even without the BCH code: with Debian's GCC 14.2, its u-boot.bin, device tree included, is 1049419 bytes, more than the 1 MiB (CFG_SYS_MMC_U_BOOT_SIZE) that its SPL loads from the card. With LTO, it is 984523 bytes.
---
Changes in v2:
- give the size of the SD card build, which is too large already without the BCH code
The Reviewed-by of v1 is kept: the diff is the same, only the commit message changed.
The build does not catch an SD card image that is too large: here BOARD_SIZE_CHECK covers only u-boot-nodtb.bin, while the SPL loads u-boot.bin, device tree included. That is left for a follow-up.
--- configs/turris_1x_nor_defconfig | 1 + configs/turris_1x_sdcard_defconfig | 1 + 2 files changed, 2 insertions(+)
configs/turris_1x_nor_defconfig +1 -0
@@ -19,6 +19,7 @@ CONFIG_PCIE1=y CONFIG_PCIE2=y CONFIG_PCIE3=y CONFIG_OPTIMIZE_INLINING=y +CONFIG_LTO=y CONFIG_ENV_VARS_UBOOT_CONFIG=y CONFIG_HAS_BOARD_SIZE_LIMIT=y CONFIG_BOARD_SIZE_LIMIT=786432
configs/turris_1x_sdcard_defconfig +1 -0
@@ -29,6 +29,7 @@ CONFIG_OF_BOARD_FIXUP=y CONFIG_PCIE1=y CONFIG_PCIE2=y CONFIG_PCIE3=y +CONFIG_LTO=y CONFIG_HAS_BOARD_SIZE_LIMIT=y CONFIG_BOARD_SIZE_LIMIT=1048576 CONFIG_MP=y
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 10/14] configs: turris_1x: Enable LTO
Quoted 8 lines · Josef Schlehofer
Enable LTO in both Turris 1.x builds. The NOR build needs the space for the ubi command next to the BCH code. The SD card build needs it even without the BCH code: with Debian's GCC 14.2, its u-boot.bin, device tree included, is 1049419 bytes, more than the 1 MiB (
CFG_SYS_MMC_U_BOOT_SIZE) that its SPL loads from the card. With LTO, it is 984523 bytes.Signed-off-by Josef Schlehofer <[email protected]>
Quoted 35 lines
Reviewed-by Marek Mojík <[email protected]>Cc Marek Mojík <[email protected]>---
Changes in v2:
- give the size of the SD card build, which is too large already without the BCH codeThe Reviewed-by of v1 is kept: the diff is the same, only the commit message changed.
The build does not catch an SD card image that is too large: here
BOARD_SIZE_CHECKcovers only u-boot-nodtb.bin, while the SPL loads u-boot.bin, device tree included. That is left for a follow-up.
---
configs/turris_1x_nor_defconfig | 1 +
configs/turris_1x_sdcard_defconfig | 1 +2 files changed, 2 insertions(+)configs/turris_1x_nor_defconfig +0
-0@@ -19,6 +19,7 @@ CONFIG_PCIE1=y
CONFIG_PCIE2=yCONFIG_PCIE3=yCONFIG_OPTIMIZE_INLINING=y
+CONFIG_LTO=yCONFIG_ENV_VARS_UBOOT_CONFIG=yCONFIG_HAS_BOARD_SIZE_LIMIT=yCONFIG_BOARD_SIZE_LIMIT=786432configs/turris_1x_sdcard_defconfig +0
-0@@ -29,6 +29,7 @@ CONFIG_OF_BOARD_FIXUP=y
Quoted 8 lines
CONFIG_PCIE1=yCONFIG_PCIE2=yCONFIG_PCIE3=y
+CONFIG_LTO=yCONFIG_HAS_BOARD_SIZE_LIMIT=yCONFIG_BOARD_SIZE_LIMIT=1048576CONFIG_MP=y
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 11/14 mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH
In reply to Josef SchlehoferThe CZ.NIC Turris 1.x device tree asks the eLBC FCM NAND driver for software BCH. Without CONFIG_NAND_ECC_BCH, nand_scan_tail() reaches BUG() while probing the NAND chip and the board resets:
BUG at drivers/mtd/nand/raw/nand_base.c:5074/nand_scan_tail()!
This broke with commit b182816c1fb4 ("turris_1x: Normalize Kconfig usage"), which moved the board Kconfig defaults to the defconfigs. NAND_ECC_BCH has no prompt, so a defconfig cannot set it.
Make NAND_FSL_ELBC_DT select NAND_ECC_BCH and NAND_ECC_BCH select BCH, and drop the now redundant CONFIG_BCH=y from the turris_1x and kmcoge5ne defconfigs. This comes after enabling LTO on the Turris 1.x, without which the turris_1x_sdcard u-boot.bin does not fit into the 1 MiB its SPL loads from the card.
Tested on CZ.NIC Turris 1.1.
---
Changes in v2:
- reword why this comes after enabling LTO
- move the note on BOARD_SIZE_CHECK to "configs: turris_1x: Enable LTO"
The Reviewed-by of v1 is kept: the diff is the same, only the commit message changed.
Only the two Turris 1.x defconfigs enable NAND_FSL_ELBC_DT, so the ECC of no other board changes.
--- configs/kmcoge5ne_defconfig | 1 - configs/turris_1x_nor_defconfig | 1 - configs/turris_1x_sdcard_defconfig | 1 - drivers/mtd/nand/raw/Kconfig | 2 ++ 4 files changed, 2 insertions(+), 3 deletions(-)
configs/kmcoge5ne_defconfig +0 -1
@@ -200,5 +200,4 @@ CONFIG_QE_UEC=y # CONFIG_PINCTRL_FULL is not set CONFIG_QE=y CONFIG_SYS_NS16550=y -CONFIG_BCH=y CONFIG_POST=y
configs/turris_1x_nor_defconfig +0 -1
@@ -119,5 +119,4 @@ CONFIG_USB_EHCI_FSL=y CONFIG_USB_STORAGE=y CONFIG_WDT=y CONFIG_WDT_MAX6370=y -CONFIG_BCH=y # CONFIG_BINMAN_FDT is not set
configs/turris_1x_sdcard_defconfig +0 -1
@@ -151,4 +151,3 @@ CONFIG_USB_EHCI_FSL=y CONFIG_WDT=y CONFIG_WDT_MAX6370=y CONFIG_FAT_WRITE=y -CONFIG_BCH=y
drivers/mtd/nand/raw/Kconfig +2 -0
@@ -240,6 +240,7 @@ config NAND_FSL_ELBC config NAND_FSL_ELBC_DT bool "Support Freescale Enhanced Local Bus Controller FCM NAND driver (DT mode)" depends on NAND_FSL_ELBC + select NAND_ECC_BCH config NAND_FSL_IFC bool "Support Freescale Integrated Flash Controller NAND driver"
@@ -259,6 +260,7 @@ config NAND_KIRKWOOD config NAND_ECC_BCH bool + select BCH config NAND_KMETER1 bool "Support KMETER1 NAND controller"
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v2 12/14 board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional
In reply to Josef SchlehoferA Turris 1.x configuration without CONFIG_NVME or CONFIG_SCSI does not build. The NVMe and SCSI distroboot targets are listed unconditionally, and config_distro_bootcmd.h turns a target whose support is disabled into a build error such as:
error: expected '}' before 'BOOT_TARGET_DEVICES_references_NVME_without_CONFIG_NVME'
List the NVMe target only when CONFIG_NVME is enabled and the SCSI target only when CONFIG_SCSI is enabled, so that the NOR build can drop NVMe and SCSI to make room for the ubi command. Both defconfigs enable NVMe and SCSI, so nothing changes yet.
---
(no changes since v1)
u-boot.bin of turris_1x_nor and turris_1x_sdcard has the same size and md5 before and after this patch (Debian GCC 14.2).
--- include/configs/turris_1x.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
include/configs/turris_1x.h +16 -4
@@ -71,6 +71,18 @@* define CONFIG_SPL_MAX_SIZE = CONFIG_SYS_L2_SIZE */ +#ifdef CONFIG_NVME +#define BOOT_TARGET_NVME (func) func(NVME, nvme, 0) +#else +#define BOOT_TARGET_NVME (func) +#endif + +#ifdef CONFIG_SCSI +#define BOOT_TARGET_SCSI (func) func(SCSI, scsi, 0) +#else +#define BOOT_TARGET_SCSI (func) +#endif +#ifdef CONFIG_SDCARD #define CFG_SYS_MMC_U_BOOT_SIZE CONFIG_BOARD_SIZE_LIMIT#define CFG_SYS_MMC_U_BOOT_DST CONFIG_TEXT_BASE
@@ -266,8 +278,8 @@#ifdef CONFIG_SDCARD #define BOOT_TARGET_DEVICES (func) \ func(MMC, mmc, 0) \ - func(NVME, nvme, 0) \ - func(SCSI, scsi, 0) \ + BOOT_TARGET_NVME(func) \ + BOOT_TARGET_SCSI(func) \ func(USB, usb, 0) \ func(USB, usb, 1) \ func(USB, usb, 2) \
@@ -279,8 +291,8 @@#else #define BOOT_TARGET_DEVICES (func) \ func(MMC, mmc, 0) \ - func(NVME, nvme, 0) \ - func(SCSI, scsi, 0) \ + BOOT_TARGET_NVME(func) \ + BOOT_TARGET_SCSI(func) \ func(USB, usb, 0) \ func(USB, usb, 1) \ func(USB, usb, 2) \
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 12/14] board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional
Quoted 8 lines · Josef Schlehofer
A Turris 1.x configuration without
CONFIG_NVMEorCONFIG_SCSIdoes not build. The NVMe and SCSI distroboot targets are listed unconditionally, andconfig_distro_bootcmd.hturns a target whose support is disabled into a build error such as:error: expected '}' before '
BOOT_TARGET_DEVICES_references_NVME_without_CONFIG_NVME'
Quoted 6 lines
List the NVMe target only when
CONFIG_NVMEis enabled and the SCSI target only whenCONFIG_SCSIis enabled, so that the NOR build can drop NVMe and SCSI to make room for the ubi command. Both defconfigs enable NVMe and SCSI, so nothing changes yet.Signed-off-by Josef Schlehofer <[email protected]>
Quoted 47 lines
Reviewed-by Marek Mojík <[email protected]>Cc Marek Mojík <[email protected]>---
(no changes since v1)u-boot.bin of
turris_1x_norandturris_1x_sdcardhas the same size and md5 before and after this patch (Debian GCC 14.2).
---include/configs/turris_1x.h| 20 ++++++++++++++++----1 file changed, 16 insertions(+), 4 deletions(-)include/configs/turris_1x.h +14
-2@@ -71,6 +71,18 @@* define CONFIG_SPL_MAX_SIZE = CONFIG_SYS_L2_SIZE */ +#ifdef CONFIG_NVME +#define BOOT_TARGET_NVME (func) func(NVME, nvme, 0) +#else +#define BOOT_TARGET_NVME (func) +#endif + +#ifdef CONFIG_SCSI +#define BOOT_TARGET_SCSI (func) func(SCSI, scsi, 0) +#else +#define BOOT_TARGET_SCSI (func) +#endif +#ifdef CONFIG_SDCARD #define CFG_SYS_MMC_U_BOOT_SIZE CONFIG_BOARD_SIZE_LIMIT#define CFG_SYS_MMC_U_BOOT_DST CONFIG_TEXT_BASE@@ -266,8 +278,8 @@#ifdef CONFIG_SDCARD #define BOOT_TARGET_DEVICES (func) \ func(MMC, mmc, 0) \ - func(NVME, nvme, 0) \ - func(SCSI, scsi, 0) \ + BOOT_TARGET_NVME(func) \ + BOOT_TARGET_SCSI(func) \ func(USB, usb, 0) \ func(USB, usb, 1) \ func(USB, usb, 2) \
include/configs/turris_1x.h line 298
Quoted 10 lines
include/configs/turris_1x.h +2
-2@@ -279,8 +291,8 @@#else #define BOOT_TARGET_DEVICES (func) \ func(MMC, mmc, 0) \ - func(NVME, nvme, 0) \ - func(SCSI, scsi, 0) \ + BOOT_TARGET_NVME(func) \ + BOOT_TARGET_SCSI(func) \ func(USB, usb, 0) \ func(USB, usb, 1) \ func(USB, usb, 2) \
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 13/14 configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI
In reply to Josef SchlehoferEnable CMD_UBI so that the NOR build can boot a kernel from a UBI volume on the NAND. CMD_UBIFS, which defaults to y with it, stays off. A kernel inside a UBIFS volume would need it.
Even with LTO, the ubi command does not fit into the 768 KiB NOR image next to NVMe and SCSI, so drop those from the NOR build. The SD card build keeps both boot targets.
Tested on CZ.NIC Turris 1.1: with the MAX6370 watchdog stopped first, the NOR build read the OpenWrt kernel from its UBI volume on the NAND and booted OpenWrt.
---
(no changes since v1)
The default environment does not call ubi. The boot above used:
setenv bootargs ubi.mtd=nand_ubi,2048 rootwait console=ttyS0,115200 wdt dev watchdog@2; wdt stop
ubi part rootfs 2048; ubi read $kernel_addr_r kernel bootm $kernel_addr_r
--- configs/turris_1x_nor_defconfig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
configs/turris_1x_nor_defconfig +2 -6
@@ -55,6 +55,8 @@ CONFIG_CMD_EXT4=y CONFIG_CMD_FAT=y CONFIG_CMD_FS_GENERIC=y CONFIG_CMD_FS_UUID=y +CONFIG_CMD_UBI=y +# CONFIG_CMD_UBIFS is not set CONFIG_OF_CONTROL=y CONFIG_OF_INITIAL_DTB_READONLY=y CONFIG_ENV_OVERWRITE=y
@@ -63,9 +65,6 @@ CONFIG_ENV_RELOC_GD_ENV_ADDR=y CONFIG_USE_ETHPRIME=y CONFIG_ETHPRIME="eth2" # CONFIG_DM_DEVICE_REMOVE is not set -CONFIG_AHCI=y -CONFIG_SCSI_AHCI=y -CONFIG_AHCI_PCI=y CONFIG_LBA48=y CONFIG_SYS_64BIT_LBA=y CONFIG_DDR_CLK_FREQ=66666666
@@ -101,14 +100,11 @@ CONFIG_SYS_MAX_FLASH_SECT=128 CONFIG_MTD_RAW_NAND=y CONFIG_NAND_FSL_ELBC=y CONFIG_NAND_FSL_ELBC_DT=y -CONFIG_MTD_UBI=y CONFIG_DM_MDIO=y CONFIG_MII=y CONFIG_TSEC_ENET=y CONFIG_PHY_FIXED=y -CONFIG_NVME_PCI=y CONFIG_PCIE_FSL=y -CONFIG_SCSI=y CONFIG_SPECIFY_CONSOLE_INDEX=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH v2 13/14] configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI
Quoted 8 lines · Josef Schlehofer
Enable
CMD_UBIso that the NOR build can boot a kernel from a UBI volume on the NAND.CMD_UBIFS, which defaults to y with it, stays off. A kernel inside a UBIFS volume would need it.Even with LTO, the ubi command does not fit into the 768 KiB NOR image next to NVMe and SCSI, so drop those from the NOR build. The SD card build keeps both boot targets.
Quoted 5 lines
Tested on CZ.NIC Turris 1.1: with the MAX6370 watchdog stopped first, the NOR build read the OpenWrt kernel from its UBI volume on the NAND and booted OpenWrt.
Signed-off-by Josef Schlehofer <[email protected]>
Good!
Quoted 45 lines
Reviewed-by Marek Mojík <[email protected]>Cc Marek Mojík <[email protected]>---
(no changes since v1)The default environment does not call ubi. The boot above used:
setenv bootargs ubi.mtd=nand_ubi,2048 rootwait console=ttyS0,115200 wdt dev watchdog@2; wdt stop
ubi part rootfs 2048; ubi read $kernel_addr_r kernel bootm $kernel_addr_r
---
configs/turris_1x_nor_defconfig | 8 ++------1 file changed, 2 insertions(+), 6 deletions(-)configs/turris_1x_nor_defconfig +0
-0@@ -55,6 +55,8 @@ CONFIG_CMD_EXT4=y
CONFIG_CMD_FAT=yCONFIG_CMD_FS_GENERIC=yCONFIG_CMD_FS_UUID=yconfigs/turris_1x_nor_defconfig +2
-0+CONFIG_CMD_UBI=y +# CONFIG_CMD_UBIFS is not set
CONFIG_OF_CONTROL=yCONFIG_OF_INITIAL_DTB_READONLY=yCONFIG_ENV_OVERWRITE=yconfigs/turris_1x_nor_defconfig +0
-0@@ -63,9 +65,6 @@ CONFIG_ENV_RELOC_GD_ENV_ADDR=y
CONFIG_USE_ETHPRIME=yCONFIG_ETHPRIME="eth2"
#CONFIG_DM_DEVICE_REMOVEis not setconfigs/turris_1x_nor_defconfig +0
-3-CONFIG_AHCI=y -CONFIG_SCSI_AHCI=y -CONFIG_AHCI_PCI=y
CONFIG_LBA48=yCONFIG_SYS_64BIT_LBA=yCONFIG_DDR_CLK_FREQ=66666666configs/turris_1x_nor_defconfig +0
-0@@ -101,14 +100,11 @@ CONFIG_SYS_MAX_FLASH_SECT=128
CONFIG_MTD_RAW_NAND=yCONFIG_NAND_FSL_ELBC=yCONFIG_NAND_FSL_ELBC_DT=y
-CONFIG_MTD_UBI=yCONFIG_DM_MDIO=yCONFIG_MII=y
Quoted 9 lines
CONFIG_TSEC_ENET=yCONFIG_PHY_FIXED=y
-CONFIG_NVME_PCI=yCONFIG_PCIE_FSL=y
-CONFIG_SCSI=yCONFIG_SPECIFY_CONSOLE_INDEX=yCONFIG_DM_SERIAL=yCONFIG_SYS_NS16550=y
--- Thanks!
"I'm not a very positive person" - Linus torvalds
PATCH v2 14/14 board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP
In reply to Josef SchlehoferWhen the environment is reset with "env default -a" before booting, the kernel device tree gets no /serial-number and keeps its all-zero MAC addresses, so Linux reports "Using random MAC address". misc_init_r() reads both values from the ATSHA204A into the environment at startup, and the device tree fixups take them from there, so the reset loses them.
Read the OTP again in ft_board_setup() and repeat these fixups, through a new weak hook in the shared P1/P2 RDB code next to p1_p2_rdb_pc_fix_fdt_model(). As in misc_init_r(), a valid MAC address or a 16-character serial# already in the environment is kept. An EVT_FT_FIXUP spy would not be called: without OFNODE_MULTI_TREE, which Turris 1.x does not enable, image_setup_libfdt() sends that event only for the control device tree.
Tested on CZ.NIC Turris 1.1 with the NOR and the SD card build after "env default -a".
---
(no changes since v1)
--- board/CZ.NIC/turris_1x/turris_1x.c | 20 ++++++++++++++++++++ board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c | 3 +++ 2 files changed, 23 insertions(+)
board/CZ.NIC/turris_1x/turris_1x.c +20 -0
@@ -315,6 +315,26 @@ int misc_init_r(void)return 0 ; } +/* +* The generic fixups copy the MAC addresses and the serial number from the +* environment into the kernel device tree. misc_init_r() puts them there, but +* if the environment is reset before booting, e.g. by "env default -a", they +* are gone. Read them from the OTP again and repeat these fixups. Valid MAC +* addresses and a 16-character serial# set in the environment are kept. +*/ +void p1_p2_rdb_pc_fix_fdt_env (void *blob) +{ +int ret; + + ret =turris_atsha_otp_init_mac_addresses (0 ); +if (ret) +printf ("Cannot read MAC addresses from OTP: %d\n" , ret); +turris_atsha_otp_init_serial_number (); + +fdt_fixup_ethernet (blob); +fdt_root (blob); +} +/* This comes from ../../nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c */ extern int checkboard_p1_p2 (void );
board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c +3 -0
@@ -373,6 +373,8 @@ int board_early_init_r(void)__weak void p1_p2_rdb_pc_fix_fdt_model (void *blob) {} +__weak void p1_p2_rdb_pc_fix_fdt_env (void *blob) {} +#if defined(CONFIG_OF_BOARD_SETUP ) || defined(CONFIG_OF_BOARD_FIXUP )static void fix_max6370_watchdog (void *blob) {
@@ -418,6 +420,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)p1_p2_rdb_pc_fix_fdt_model (blob);fix_max6370_watchdog (blob); +p1_p2_rdb_pc_fix_fdt_env (blob);#if defined(CONFIG_HAS_FSL_DR_USB )fsl_fdt_fixup_dr_usb (blob, bd);
Signature · 1 line
2.54.0 (Apple Git-157)