All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx
@ 2026-11-19 13:32 Josef Schlehofer
  2026-11-19 13:32 ` [PATCH v3 01/14] board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy Josef Schlehofer
                   ` (13 more replies)
  0 siblings, 14 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:32 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

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.

v3 is based on next, which has "Makefile: Set LTO_ENABLE before
including config.mk" [1], needed by patch 7. On u-boot-ppc next,
patch 2 conflicts in board/nxp/t104xrdb/spl.c, which that branch
removes. Dropping that hunk resolves it.

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 32-bit 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.

On next, the turris_1x_sdcard u-boot.bin is 1052227 bytes, 3651 bytes
more than 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, turris_1x_nor's u-boot-nodtb.bin shrinks from
759880 to 752752 bytes while gaining LTO, BCH ECC and the ubi command
and dropping NVMe and SCSI. The turris_1x_sdcard u-boot.bin shrinks
from 1052227 to 998051 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 next, with and
without LTO. 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 in a Debian bookworm
container, the Turris SD card SPL links at -j8 only with patch 9.

v2 was boot-tested on a Turris 1.1 from NOR and SD card. Its NOR build
also booted OpenWrt from a kernel in a UBI volume on NAND, and 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. Against v2, the code of v3
changes only in two comments of patch 4. v3 was rebased onto next and
build-tested only, as were the other boards.

Changes in v3:
- Based on next, which has the generic LTO fixes v2 depended on.
- Patch 4: name lib/div64.c as the source more clearly and explain why
  the high word is only divided first when the divisor fits into
  32 bits, as Bradley Morgan asked.
- Patch 7: compare with 32-bit ARM, as ARM64 keeps both flags with LTO.
- Collect Bradley's Reviewed-by tags.
- Measure the sizes again on next.

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" 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] commit 5f3bcac3f7f9 ("Makefile: Set LTO_ENABLE before including config.mk")
v2: https://lore.kernel.org/u-boot/20261018083516.49229-1-pepe.schlehofer@gmail.com/
v1: https://lore.kernel.org/u-boot/20260928110434.70686-1-pepe.schlehofer@gmail.com/

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                |  85 +++++++++
 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, 449 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: e6fa1282975af50acf44be7aa678b89e187f0860
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v3 01/14] board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
@ 2026-11-19 13:32 ` Josef Schlehofer
  2026-11-19 13:32 ` [PATCH v3 02/14] powerpc: Make the global data pointer LTO safe Josef Schlehofer
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:32 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

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).

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
Cc: Qiang Zhao <qiang.zhao@nxp.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Marek Behún <kabel@kernel.org>
Cc: Marek Mojík <marek.mojik@nic.cz>
---
(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(-)

diff --git a/board/nxp/p1010rdb/spl.c b/board/nxp/p1010rdb/spl.c
index fc26cef2cc8..7c36026a55a 100644
--- a/board/nxp/p1010rdb/spl.c
+++ b/board/nxp/p1010rdb/spl.c
@@ -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
diff --git a/board/nxp/p1_p2_rdb_pc/spl.c b/board/nxp/p1_p2_rdb_pc/spl.c
index b07f481fbf9..6db77682e3c 100644
--- a/board/nxp/p1_p2_rdb_pc/spl.c
+++ b/board/nxp/p1_p2_rdb_pc/spl.c
@@ -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
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 02/14] powerpc: Make the global data pointer LTO safe
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
  2026-11-19 13:32 ` [PATCH v3 01/14] board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy Josef Schlehofer
@ 2026-11-19 13:32 ` Josef Schlehofer
  2026-11-19 13:32 ` [PATCH v3 03/14] powerpc: lib: Add GPR save and restore routines to the private libgcc Josef Schlehofer
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:32 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

The 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Cc: Bradley Morgan <bradley.morgan@linux.dev>
Cc: Marek Behún <kabel@kernel.org>
Cc: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Cc: Mario Six <mario.six@gdsys.cc>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
Cc: Qiang Zhao <qiang.zhao@nxp.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Shengzhou Liu <Shengzhou.Liu@nxp.com>
Cc: Marek Mojík <marek.mojik@nic.cz>
---
(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

diff --git a/arch/powerpc/cpu/mpc83xx/cpu_init.c b/arch/powerpc/cpu/mpc83xx/cpu_init.c
index 340f9a0da56..5618b79a78b 100644
--- a/arch/powerpc/cpu/mpc83xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc83xx/cpu_init.c
@@ -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 */
 
diff --git a/arch/powerpc/cpu/mpc83xx/spl_minimal.c b/arch/powerpc/cpu/mpc83xx/spl_minimal.c
index 7036e3fae0c..1d48428573d 100644
--- a/arch/powerpc/cpu/mpc83xx/spl_minimal.c
+++ b/arch/powerpc/cpu/mpc83xx/spl_minimal.c
@@ -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 */
 
diff --git a/arch/powerpc/cpu/mpc85xx/cpu_init_early.c b/arch/powerpc/cpu/mpc85xx/cpu_init_early.c
index 75bfc07fe97..fb3d662c9d3 100644
--- a/arch/powerpc/cpu/mpc85xx/cpu_init_early.c
+++ b/arch/powerpc/cpu/mpc85xx/cpu_init_early.c
@@ -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 */
 
diff --git a/arch/powerpc/include/asm/global_data.h b/arch/powerpc/include/asm/global_data.h
index 26cbc7854d9..d8aefd2ca0a 100644
--- a/arch/powerpc/include/asm/global_data.h
+++ b/arch/powerpc/include/asm/global_data.h
@@ -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 */
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index c0caa703caa..a3048975ae7 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -18,6 +18,7 @@ endif
 endif
 
 obj-y	+= bdinfo.o
+obj-y	+= gd.o
 
 ifdef MINIMAL
 obj-y += cache.o time.o
diff --git a/arch/powerpc/lib/gd.c b/arch/powerpc/lib/gd.c
new file mode 100644
index 00000000000..d36f784fbf7
--- /dev/null
+++ b/arch/powerpc/lib/gd.c
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Josef Schlehofer <pepe.schlehofer@gmail.com>
+ */
+
+#include <init.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void arch_setup_gd(gd_t *new_gd)
+{
+	set_gd(new_gd);
+}
diff --git a/board/nxp/p1010rdb/spl_minimal.c b/board/nxp/p1010rdb/spl_minimal.c
index 8cd79c6fb5f..33930fef8d9 100644
--- a/board/nxp/p1010rdb/spl_minimal.c
+++ b/board/nxp/p1010rdb/spl_minimal.c
@@ -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();
diff --git a/board/nxp/p1_p2_rdb_pc/spl_minimal.c b/board/nxp/p1_p2_rdb_pc/spl_minimal.c
index 511bcf5506b..960b2c41457 100644
--- a/board/nxp/p1_p2_rdb_pc/spl_minimal.c
+++ b/board/nxp/p1_p2_rdb_pc/spl_minimal.c
@@ -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();
diff --git a/board/nxp/t102xrdb/spl.c b/board/nxp/t102xrdb/spl.c
index de6cdda194e..f527f62a5dd 100644
--- a/board/nxp/t102xrdb/spl.c
+++ b/board/nxp/t102xrdb/spl.c
@@ -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;
 
diff --git a/board/nxp/t104xrdb/spl.c b/board/nxp/t104xrdb/spl.c
index e02a1f95d4c..0310baa381c 100644
--- a/board/nxp/t104xrdb/spl.c
+++ b/board/nxp/t104xrdb/spl.c
@@ -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;
 
diff --git a/board/nxp/t208xqds/spl.c b/board/nxp/t208xqds/spl.c
index 44ad4e68d9f..f8c641a9c64 100644
--- a/board/nxp/t208xqds/spl.c
+++ b/board/nxp/t208xqds/spl.c
@@ -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;
 
diff --git a/board/nxp/t208xrdb/spl.c b/board/nxp/t208xrdb/spl.c
index df3b9c6fe40..4b1ab3618c3 100644
--- a/board/nxp/t208xrdb/spl.c
+++ b/board/nxp/t208xrdb/spl.c
@@ -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;
 
diff --git a/board/nxp/t4rdb/spl.c b/board/nxp/t4rdb/spl.c
index 9d2472dec25..441015bf5a4 100644
--- a/board/nxp/t4rdb/spl.c
+++ b/board/nxp/t4rdb/spl.c
@@ -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;
 
diff --git a/common/board_r.c b/common/board_r.c
index a397e20959d..7a9de6ba5f3 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -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;
diff --git a/common/init/board_init.c b/common/init/board_init.c
index 2a6f39f51ad..2faea5432c0 100644
--- a/common/init/board_init.c
+++ b/common/init/board_init.c
@@ -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
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 6c9a1a1cbcc..81aec2b1108 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -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;
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 03/14] powerpc: lib: Add GPR save and restore routines to the private libgcc
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
  2026-11-19 13:32 ` [PATCH v3 01/14] board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy Josef Schlehofer
  2026-11-19 13:32 ` [PATCH v3 02/14] powerpc: Make the global data pointer LTO safe Josef Schlehofer
@ 2026-11-19 13:32 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 04/14] powerpc: lib: Add 64-bit division " Josef Schlehofer
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:32 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

When 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Bradley Morgan <bradley.morgan@linux.dev>
Cc: Tom Rini <trini@konsulko.com>
Cc: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Cc: Marek Behún <kabel@kernel.org>
---
(no changes since v2)

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

diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index a3048975ae7..90f0e1e5fa9 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -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=
 
diff --git a/arch/powerpc/lib/crtsavres.S b/arch/powerpc/lib/crtsavres.S
new file mode 100644
index 00000000000..8c35eedecb6
--- /dev/null
+++ b/arch/powerpc/lib/crtsavres.S
@@ -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)
+_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
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (2 preceding siblings ...)
  2026-11-19 13:32 ` [PATCH v3 03/14] powerpc: lib: Add GPR save and restore routines to the private libgcc Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 14:21   ` Christophe Leroy (CS GROUP)
  2026-11-19 13:33 ` [PATCH v3 05/14] powerpc: mpc85xx: Use the private libgcc with LTO Josef Schlehofer
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

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, 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Tom Rini <trini@konsulko.com>
Cc: Marek Behún <kabel@kernel.org>
---
Changes in v3:
- name lib/div64.c as the source of udivmod64() more clearly
- explain in the comment why the high word is only divided first when
  the divisor fits into 32 bits

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 | 85 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/lib/udivdi3.c

diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 90f0e1e5fa9..23e62996701 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -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=
 
diff --git a/arch/powerpc/lib/udivdi3.c b/arch/powerpc/lib/udivdi3.c
new file mode 100644
index 00000000000..4b02c61bcba
--- /dev/null
+++ b/arch/powerpc/lib/udivdi3.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * 64-bit unsigned division and modulo for the private libgcc
+ *
+ * GCC calls __udivdi3() and __umoddi3() for '/' and '%' on unsigned 64-bit
+ * operands on 32-bit PowerPC.
+ *
+ * udivmod64() is a copy of __div64_32() from lib/div64.c, changed to take a
+ * 64-bit divisor. Its shift-and-subtract loop already works with one. Like
+ * __div64_32(), the functions are not instrumented, as tracing code may
+ * divide. The copyright notices below are those of lib/div64.c.
+ *
+ *   Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
+ *
+ *   Based on former do_div() implementation from asm-parisc/div64.h:
+ *	Copyright (C) 1999 Hewlett-Packard Co
+ *	Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
+ */
+
+#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;
+
+	/*
+	 * Divide the high word first, as __div64_32() does. This is a 32-bit
+	 * division, so it is only valid when the divisor fits into 32 bits.
+	 */
+	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
+ * Return:	remainder
+ */
+notrace u64 __umoddi3(u64 n, u64 d)
+{
+	u64 rem;
+
+	udivmod64(n, d, &rem);
+
+	return rem;
+}
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 05/14] powerpc: mpc85xx: Use the private libgcc with LTO
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (3 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 04/14] powerpc: lib: Add 64-bit division " Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 06/14] powerpc: mpc85xx: Discard LTO keep-syms sections Josef Schlehofer
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

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_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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Tom Rini <trini@konsulko.com>
Cc: Marek Behún <kabel@kernel.org>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
---
(no changes since v2)

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(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index f20d58b4de6..b4883e00458 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 06/14] powerpc: mpc85xx: Discard LTO keep-syms sections
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (4 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 05/14] powerpc: mpc85xx: Use the private libgcc with LTO Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 07/14] powerpc: Drop -ffunction-sections and -fdata-sections with LTO Josef Schlehofer
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

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.S treats as addresses to relocate. With them, the
Turris NOR build with LTO hung after the DRAM message.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Marek Behún <kabel@kernel.org>
---
(no changes since v2)

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(-)

diff --git a/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds b/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
index d918b4395bf..dd4d18bc24b 100644
--- a/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
+++ b/arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
@@ -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 = .;
diff --git a/arch/powerpc/cpu/mpc85xx/u-boot.lds b/arch/powerpc/cpu/mpc85xx/u-boot.lds
index bedd2d47472..4bb9b4ecfb2 100644
--- a/arch/powerpc/cpu/mpc85xx/u-boot.lds
+++ b/arch/powerpc/cpu/mpc85xx/u-boot.lds
@@ -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)       :
   {
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 07/14] powerpc: Drop -ffunction-sections and -fdata-sections with LTO
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (5 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 06/14] powerpc: mpc85xx: Discard LTO keep-syms sections Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 08/14] powerpc: mpc85xx: Allow LTO Josef Schlehofer
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

When LTO is enabled, omit -ffunction-sections and -fdata-sections, as
32-bit ARM does. This affects U-Boot proper only, as
scripts/Makefile.xpl adds both flags for xPL builds anyway.

Keep --gc-sections, as ARM does. It drops the .eh_frame sections, which
the linker scripts do not place.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Cc: Bradley Morgan <bradley.morgan@linux.dev>
Cc: Tom Rini <trini@konsulko.com>
Cc: Marek Behún <kabel@kernel.org>
---
Changes in v3:
- compare with 32-bit ARM, as ARM64 keeps both flags with LTO
- drop the sentence and the note on "Makefile: Set LTO_ENABLE before
  including config.mk", which is in next now

Changes in v2:
- new patch

With Debian's GCC 14.2, U-Boot proper of the 71 mpc85xx LTO builds
changes by -2211 to +5628 bytes of text and data, and 70 of them
shrink. SPL/TPL sizes and builds without LTO are unchanged.
---
 arch/powerpc/config.mk | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/config.mk b/arch/powerpc/config.mk
index 32e86d84a12..557d9360e3b 100644
--- a/arch/powerpc/config.mk
+++ b/arch/powerpc/config.mk
@@ -3,10 +3,14 @@
 # (C) Copyright 2000-2010
 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 
+# 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)
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 08/14] powerpc: mpc85xx: Allow LTO
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (6 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 07/14] powerpc: Drop -ffunction-sections and -fdata-sections with LTO Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 09/14] xpl: Pass the make jobserver to the xPL link Josef Schlehofer
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

Select 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Cc: Bradley Morgan <bradley.morgan@linux.dev>
Cc: Marek Behún <kabel@kernel.org>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
---
(no changes since v1)
---
 arch/powerpc/Kconfig | 1 +
 doc/build/gcc.rst    | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index b4883e00458..20716135cd5 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst
index 16afe292899..5e81b2e6661 100644
--- a/doc/build/gcc.rst
+++ b/doc/build/gcc.rst
@@ -196,9 +196,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`.
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 09/14] xpl: Pass the make jobserver to the xPL link
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (7 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 08/14] powerpc: mpc85xx: Allow LTO Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 10/14] configs: turris_1x: Enable LTO Josef Schlehofer
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

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 in a Debian bookworm container, 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Marek Behún <kabel@kernel.org>
---
Changes in v3:
- name the container in which the link fails

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.

The GCC 12.2 failure was seen with the bookworm container emulated on
an arm64 host, for v2 and again for v3. On a native amd64 GitHub
Actions runner, the same build linked without the '+'.
---
 scripts/Makefile.xpl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.xpl b/scripts/Makefile.xpl
index 77746ec07cd..cfc1ad17822 100644
--- a/scripts/Makefile.xpl
+++ b/scripts/Makefile.xpl
@@ -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) ;
 
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 10/14] configs: turris_1x: Enable LTO
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (8 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 09/14] xpl: Pass the make jobserver to the xPL link Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 11/14] mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH Josef Schlehofer
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

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 1052227 bytes, more than the 1 MiB
(CFG_SYS_MMC_U_BOOT_SIZE) that its SPL loads from the card. With LTO,
it is 989355 bytes.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Marek Mojík <marek.mojik@nic.cz>
---
Changes in v3:
- sizes measured again on next

Changes in v2:
- give the size of the SD card build, which is too large already
  without the BCH code

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(+)

diff --git a/configs/turris_1x_nor_defconfig b/configs/turris_1x_nor_defconfig
index 070428ae25e..d8ce4aed4a7 100644
--- a/configs/turris_1x_nor_defconfig
+++ b/configs/turris_1x_nor_defconfig
@@ -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
diff --git a/configs/turris_1x_sdcard_defconfig b/configs/turris_1x_sdcard_defconfig
index dbeb34dacfb..982a6cb0703 100644
--- a/configs/turris_1x_sdcard_defconfig
+++ b/configs/turris_1x_sdcard_defconfig
@@ -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
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 11/14] mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (9 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 10/14] configs: turris_1x: Enable LTO Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 12/14] board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional Josef Schlehofer
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

The 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.

Fixes: b182816c1fb4 ("turris_1x: Normalize Kconfig usage")
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Cc: Tom Rini <trini@konsulko.com>
Cc: Heiko Schocher <hs@nabladev.com>
Cc: Michael Trimarchi <michael@amarulasolutions.com>
Cc: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Cc: Holger Brunck <holger.brunck@hitachienergy.com>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
Cc: Marek Mojík <marek.mojik@nic.cz>
---
(no changes since v2)

Changes in v2:
- reword why this comes after enabling LTO
- move the note on BOARD_SIZE_CHECK to "configs: turris_1x: Enable LTO"

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(-)

diff --git a/configs/kmcoge5ne_defconfig b/configs/kmcoge5ne_defconfig
index 69ef6cf3b9b..ef03f02d1e5 100644
--- a/configs/kmcoge5ne_defconfig
+++ b/configs/kmcoge5ne_defconfig
@@ -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
diff --git a/configs/turris_1x_nor_defconfig b/configs/turris_1x_nor_defconfig
index d8ce4aed4a7..35df37fbc70 100644
--- a/configs/turris_1x_nor_defconfig
+++ b/configs/turris_1x_nor_defconfig
@@ -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
diff --git a/configs/turris_1x_sdcard_defconfig b/configs/turris_1x_sdcard_defconfig
index 982a6cb0703..5e99d895b2f 100644
--- a/configs/turris_1x_sdcard_defconfig
+++ b/configs/turris_1x_sdcard_defconfig
@@ -151,4 +151,3 @@ CONFIG_USB_EHCI_FSL=y
 CONFIG_WDT=y
 CONFIG_WDT_MAX6370=y
 CONFIG_FAT_WRITE=y
-CONFIG_BCH=y
diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index 6084b614358..b0ae441900b 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -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"
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 12/14] board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (10 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 11/14] mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 13/14] configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 14/14] board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP Josef Schlehofer
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

A 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Marek Mojík <marek.mojik@nic.cz>
---
(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(-)

diff --git a/include/configs/turris_1x.h b/include/configs/turris_1x.h
index c05614950c7..3a2818d1904 100644
--- a/include/configs/turris_1x.h
+++ b/include/configs/turris_1x.h
@@ -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) \
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 13/14] configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (11 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 12/14] board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  2026-11-19 13:33 ` [PATCH v3 14/14] board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP Josef Schlehofer
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

Enable 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.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Cc: Marek Mojík <marek.mojik@nic.cz>
---
(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(-)

diff --git a/configs/turris_1x_nor_defconfig b/configs/turris_1x_nor_defconfig
index 35df37fbc70..c5aaf55a75c 100644
--- a/configs/turris_1x_nor_defconfig
+++ b/configs/turris_1x_nor_defconfig
@@ -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
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 14/14] board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP
  2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
                   ` (12 preceding siblings ...)
  2026-11-19 13:33 ` [PATCH v3 13/14] configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI Josef Schlehofer
@ 2026-11-19 13:33 ` Josef Schlehofer
  13 siblings, 0 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 13:33 UTC (permalink / raw)
  To: u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu,
	Christophe Leroy (CS GROUP), Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass

When 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".

Fixes: f41582035cf7 ("powerpc: Add support for CZ.NIC Turris 1.x routers")
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Reviewed-by: Marek Mojík <marek.mojik@nic.cz>
Cc: Marek Mojík <marek.mojik@nic.cz>
Cc: Marek Behún <kabel@kernel.org>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
---
(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(+)

diff --git a/board/CZ.NIC/turris_1x/turris_1x.c b/board/CZ.NIC/turris_1x/turris_1x.c
index 32535ed6ee0..8173e021f11 100644
--- a/board/CZ.NIC/turris_1x/turris_1x.c
+++ b/board/CZ.NIC/turris_1x/turris_1x.c
@@ -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);
 
diff --git a/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c b/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c
index a19a98dd0d1..07c18117cbe 100644
--- a/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c
+++ b/board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c
@@ -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);
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 13:33 ` [PATCH v3 04/14] powerpc: lib: Add 64-bit division " Josef Schlehofer
@ 2026-11-19 14:21   ` Christophe Leroy (CS GROUP)
  2026-11-19 16:01     ` Bradley Morgan
  0 siblings, 1 reply; 24+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-11-19 14:21 UTC (permalink / raw)
  To: Josef Schlehofer, u-boot, Bradley Morgan
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu, Mario Six,
	Dario Binacchi, Michael Trimarchi, Heiko Schocher, Holger Brunck,
	Simon Glass, Bradley Morgan



Le 19/11/2026 à 14:33, Josef Schlehofer a écrit :
> 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, so turris_1x_sdcard fails to link with
> CONFIG_USE_PRIVATE_LIBGCC=y:
> 
>    undefined reference to `__udivdi3'

Why do we need __udivdi3() at all ? Can't we just avoid / and % on 
64-bit operands and use __div64_32() or equivalent instead ?

Christophe


> 
> 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.
> 
> Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
> Reviewed-by: Bradley Morgan <brads@mainlining.org>
> Cc: Tom Rini <trini@konsulko.com>
> Cc: Marek Behún <kabel@kernel.org>
> ---
> Changes in v3:
> - name lib/div64.c as the source of udivmod64() more clearly
> - explain in the comment why the high word is only divided first when
>    the divisor fits into 32 bits
> 
> 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 | 85 ++++++++++++++++++++++++++++++++++++++
>   2 files changed, 87 insertions(+), 1 deletion(-)
>   create mode 100644 arch/powerpc/lib/udivdi3.c
> 
> diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
> index 90f0e1e5fa9..23e62996701 100644
> --- a/arch/powerpc/lib/Makefile
> +++ b/arch/powerpc/lib/Makefile
> @@ -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=
>   
> diff --git a/arch/powerpc/lib/udivdi3.c b/arch/powerpc/lib/udivdi3.c
> new file mode 100644
> index 00000000000..4b02c61bcba
> --- /dev/null
> +++ b/arch/powerpc/lib/udivdi3.c
> @@ -0,0 +1,85 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * 64-bit unsigned division and modulo for the private libgcc
> + *
> + * GCC calls __udivdi3() and __umoddi3() for '/' and '%' on unsigned 64-bit
> + * operands on 32-bit PowerPC.
> + *
> + * udivmod64() is a copy of __div64_32() from lib/div64.c, changed to take a
> + * 64-bit divisor. Its shift-and-subtract loop already works with one. Like
> + * __div64_32(), the functions are not instrumented, as tracing code may
> + * divide. The copyright notices below are those of lib/div64.c.
> + *
> + *   Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
> + *
> + *   Based on former do_div() implementation from asm-parisc/div64.h:
> + *	Copyright (C) 1999 Hewlett-Packard Co
> + *	Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
> + */
> +
> +#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;
> +
> +	/*
> +	 * Divide the high word first, as __div64_32() does. This is a 32-bit
> +	 * division, so it is only valid when the divisor fits into 32 bits.
> +	 */
> +	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
> + * Return:	remainder
> + */
> +notrace u64 __umoddi3(u64 n, u64 d)
> +{
> +	u64 rem;
> +
> +	udivmod64(n, d, &rem);
> +
> +	return rem;
> +}


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 14:21   ` Christophe Leroy (CS GROUP)
@ 2026-11-19 16:01     ` Bradley Morgan
  2026-11-19 18:42       ` Josef Schlehofer
  0 siblings, 1 reply; 24+ messages in thread
From: Bradley Morgan @ 2026-11-19 16:01 UTC (permalink / raw)
  To: Christophe Leroy (CS GROUP), Josef Schlehofer, u-boot
  Cc: Tom Rini, Marek Behún, Marek Mojík, Peng Fan,
	Priyanka Jain, Qiang Zhao, Shengzhou Liu, Mario Six,
	Dario Binacchi, Michael Trimarchi, Heiko Schocher, Holger Brunck,
	Simon Glass, Bradley Morgan

On 19 November 2026 14:21:14 GMT, "Christophe Leroy (CS GROUP)"
<chleroy@kernel.org> wrote:
>
>
>Le 19/11/2026 à 14:33, Josef Schlehofer a écrit :
>> 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, so turris_1x_sdcard fails to link with
>> CONFIG_USE_PRIVATE_LIBGCC=y:
>> 
>>    undefined reference to `__udivdi3'
>
>Why do we need __udivdi3() at all ? Can't we just avoid / and % on 64-bit
>operands and use __div64_32() or equivalent instead ?

Oh yes. That's right. What's the point OF using __udivdi3()..

Also, a potential user of this file is the arch/powerpc/lib/time.c file.

It's a pain to do the dividing maths, and we need a "fast(er)" non
overflowy way to do usec2ticks(), see the comment.

/*
 * This function is intended for SHORT delays only.
 * It will overflow at around 10 seconds @ 400MHz,
 * or 20 seconds @ 200MHz.
 */

A patch I self-naked did 64 bit div math but it was slowww..

From a look of this. This looks slightly feasibler as a option, well, this
just came into my head.

>
>Christophe
>
>
>> 
>> 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.
>> 
>> Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
>> Reviewed-by: Bradley Morgan <brads@mainlining.org>
>> Cc: Tom Rini <trini@konsulko.com>
>> Cc: Marek Behún <kabel@kernel.org>
>> ---
>> Changes in v3:
>> - name lib/div64.c as the source of udivmod64() more clearly
>> - explain in the comment why the high word is only divided first when
>>    the divisor fits into 32 bits
>> 
>> 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 | 85 ++++++++++++++++++++++++++++++++++++++
>>   2 files changed, 87 insertions(+), 1 deletion(-)
>>   create mode 100644 arch/powerpc/lib/udivdi3.c
>> 
>> diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
>> index 90f0e1e5fa9..23e62996701 100644
>> --- a/arch/powerpc/lib/Makefile
>> +++ b/arch/powerpc/lib/Makefile
>> @@ -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=
>>   diff --git a/arch/powerpc/lib/udivdi3.c b/arch/powerpc/lib/udivdi3.c
>> new file mode 100644
>> index 00000000000..4b02c61bcba
>> --- /dev/null
>> +++ b/arch/powerpc/lib/udivdi3.c
>> @@ -0,0 +1,85 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * 64-bit unsigned division and modulo for the private libgcc
>> + *
>> + * GCC calls __udivdi3() and __umoddi3() for '/' and '%' on unsigned
>64-bit
>> + * operands on 32-bit PowerPC.
>> + *
>> + * udivmod64() is a copy of __div64_32() from lib/div64.c, changed to
>take a
>> + * 64-bit divisor. Its shift-and-subtract loop already works with one.
>Like
>> + * __div64_32(), the functions are not instrumented, as tracing code
>may
>> + * divide. The copyright notices below are those of lib/div64.c.
>> + *
>> + *   Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
>> + *
>> + *   Based on former do_div() implementation from asm-parisc/div64.h:
>> + *	Copyright (C) 1999 Hewlett-Packard Co
>> + *	Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
>> + */
>> +
>> +#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;
>> +
>> +	/*
>> +	 * Divide the high word first, as __div64_32() does. This is a 32-bit
>> +	 * division, so it is only valid when the divisor fits into 32 bits.
>> +	 */
>> +	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
>> + * Return:	remainder
>> + */
>> +notrace u64 __umoddi3(u64 n, u64 d)
>> +{
>> +	u64 rem;
>> +
>> +	udivmod64(n, d, &rem);
>> +
>> +	return rem;
>> +}

Other than that, this file really looks good!

>
>

--- Thanks!

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 16:01     ` Bradley Morgan
@ 2026-11-19 18:42       ` Josef Schlehofer
  2026-11-19 18:55         ` Bradley Morgan
  2026-11-19 20:09         ` Tom Rini
  0 siblings, 2 replies; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-19 18:42 UTC (permalink / raw)
  To: Bradley Morgan
  Cc: u-boot, Christophe Leroy (CS GROUP), Tom Rini, Marek Behún,
	Marek Mojík, Peng Fan, Priyanka Jain, Qiang Zhao,
	Shengzhou Liu, Mario Six, Dario Binacchi, Michael Trimarchi,
	Heiko Schocher, Holger Brunck, Simon Glass, Bradley Morgan

Hi Christophe, Bradley,

On 19. 11. 26 17:01, Bradley Morgan wrote:
> On 19 November 2026 14:21:14 GMT, "Christophe Leroy (CS GROUP)"
> <chleroy@kernel.org> wrote:
>> Why do we need __udivdi3() at all ? Can't we just avoid / and % on
>> 64-bit operands and use __div64_32() or equivalent instead ?
>
> Oh yes. That's right. What's the point OF using __udivdi3()..

The division operations originate in common code, for example in btrfs,
squashfs, and mmc_berase() in turris_1x_sdcard. All the instances I
found use 32-bit divisors, so do_div() should work for them.

I can drop this patch and convert those divisions in v4 instead, if you
both prefer. The downside is that another such division added to common
code would break the mpc85xx LTO builds again, because patch 5 replaces
the toolchain-provided libgcc for those builds.

Josef

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 18:42       ` Josef Schlehofer
@ 2026-11-19 18:55         ` Bradley Morgan
  2026-11-20  9:08           ` Josef Schlehofer
  2026-11-19 20:09         ` Tom Rini
  1 sibling, 1 reply; 24+ messages in thread
From: Bradley Morgan @ 2026-11-19 18:55 UTC (permalink / raw)
  To: Josef Schlehofer
  Cc: u-boot, Christophe Leroy (CS GROUP), Tom Rini, Marek Behún,
	Marek Mojík, Peng Fan, Priyanka Jain, Qiang Zhao,
	Shengzhou Liu, Mario Six, Dario Binacchi, Michael Trimarchi,
	Heiko Schocher, Holger Brunck, Simon Glass, Bradley Morgan

On 19 November 2026 18:42:44 GMT, Josef Schlehofer
<pepe.schlehofer@gmail.com> wrote:
>Hi Christophe, Bradley,
>
>On 19. 11. 26 17:01, Bradley Morgan wrote:
>> On 19 November 2026 14:21:14 GMT, "Christophe Leroy (CS GROUP)"
>> <chleroy@kernel.org> wrote:
>>> Why do we need __udivdi3() at all ? Can't we just avoid / and % on
>>> 64-bit operands and use __div64_32() or equivalent instead ?
>>
>> Oh yes. That's right. What's the point OF using __udivdi3()..
>
>The division operations originate in common code, for example in btrfs,
>squashfs, and mmc_berase() in turris_1x_sdcard. All the instances I
>found use 32-bit divisors, so do_div() should work for them.

Listening...

>
>I can drop this patch and convert those divisions in v4 instead, if you
>both prefer. The downside is that another such division added to common
>code would break the mpc85xx LTO builds again, because patch 5 replaces
>the toolchain-provided libgcc for those builds.

Well, Christophe has the concern, he can assess, also mind answering my
question about the user?

>
>Josef
>

--- Thanks!

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 18:42       ` Josef Schlehofer
  2026-11-19 18:55         ` Bradley Morgan
@ 2026-11-19 20:09         ` Tom Rini
  1 sibling, 0 replies; 24+ messages in thread
From: Tom Rini @ 2026-11-19 20:09 UTC (permalink / raw)
  To: Josef Schlehofer
  Cc: Bradley Morgan, u-boot, Christophe Leroy (CS GROUP),
	Marek Behún, Marek Mojík, Peng Fan, Priyanka Jain,
	Qiang Zhao, Shengzhou Liu, Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

[-- Attachment #1: Type: text/plain, Size: 1090 bytes --]

On Thu, Nov 19, 2026 at 07:42:44PM +0100, Josef Schlehofer wrote:
> Hi Christophe, Bradley,
> 
> On 19. 11. 26 17:01, Bradley Morgan wrote:
> > On 19 November 2026 14:21:14 GMT, "Christophe Leroy (CS GROUP)"
> > <chleroy@kernel.org> wrote:
> >> Why do we need __udivdi3() at all ? Can't we just avoid / and % on
> >> 64-bit operands and use __div64_32() or equivalent instead ?
> >
> > Oh yes. That's right. What's the point OF using __udivdi3()..
> 
> The division operations originate in common code, for example in btrfs,
> squashfs, and mmc_berase() in turris_1x_sdcard. All the instances I
> found use 32-bit divisors, so do_div() should work for them.
> 
> I can drop this patch and convert those divisions in v4 instead, if you
> both prefer. The downside is that another such division added to common
> code would break the mpc85xx LTO builds again, because patch 5 replaces
> the toolchain-provided libgcc for those builds.

Please update the common code. New breakage would trip CI and so that
new code would need to be corrected prior to merge.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-19 18:55         ` Bradley Morgan
@ 2026-11-20  9:08           ` Josef Schlehofer
  2026-11-20 16:04             ` Bradley Morgan
  0 siblings, 1 reply; 24+ messages in thread
From: Josef Schlehofer @ 2026-11-20  9:08 UTC (permalink / raw)
  To: Bradley Morgan
  Cc: u-boot, Christophe Leroy (CS GROUP), Tom Rini, Marek Behún,
	Marek Mojík, Peng Fan, Priyanka Jain, Qiang Zhao,
	Shengzhou Liu, Mario Six, Dario Binacchi, Michael Trimarchi,
	Heiko Schocher, Holger Brunck, Simon Glass, Bradley Morgan

Hi Bradley,

On 19. 11. 26 19:55, Bradley Morgan wrote:
> Well, Christophe has the concern, he can assess, also mind answering my
> question about the user?

Tom asked to update the common code, so v4 will convert the callers and
drop this patch.

As for usec2ticks() in arch/powerpc/lib/time.c, a 64-bit implementation
would divide by the constant 1000000. With a constant divisor, do_div()
uses reciprocal multiplication, and lldiv() relies on the same
implementation, as does usec_to_tick() in lib/time.c. GCC 14 at -Os
compiles this without any call to a division helper.

However, the overflow described in the comment is in the 32-bit tick
count itself, not in an intermediate calculation. Fixing it would
therefore require usec2ticks() to return 64-bit tick counts and
wait_ticks() to accept them as well.

Josef

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-20  9:08           ` Josef Schlehofer
@ 2026-11-20 16:04             ` Bradley Morgan
  2026-11-20 16:16               ` Tom Rini
  0 siblings, 1 reply; 24+ messages in thread
From: Bradley Morgan @ 2026-11-20 16:04 UTC (permalink / raw)
  To: Josef Schlehofer
  Cc: u-boot, Christophe Leroy (CS GROUP), Tom Rini, Marek Behún,
	Marek Mojík, Peng Fan, Priyanka Jain, Qiang Zhao,
	Shengzhou Liu, Mario Six, Dario Binacchi, Michael Trimarchi,
	Heiko Schocher, Holger Brunck, Simon Glass, Bradley Morgan

On 20 November 2026 09:08:54 GMT, Josef Schlehofer
<pepe.schlehofer@gmail.com> wrote:
>Hi Bradley,
>
>On 19. 11. 26 19:55, Bradley Morgan wrote:
>> Well, Christophe has the concern, he can assess, also mind answering my
>> question about the user?
>
>Tom asked to update the common code, so v4 will convert the callers and
>drop this patch.

Oof.. (also please don't keep doing new threads, it's a pain)

>
>As for usec2ticks() in arch/powerpc/lib/time.c, a 64-bit implementation
>would divide by the constant 1000000. With a constant divisor, do_div()
>uses reciprocal multiplication, and lldiv() relies on the same
>implementation, as does usec_to_tick() in lib/time.c. GCC 14 at -Os
>compiles this without any call to a division helper.
>
>However, the overflow described in the comment is in the 32-bit tick
>count itself, not in an intermediate calculation. Fixing it would
>therefore require usec2ticks() to return 64-bit tick counts and
>wait_ticks() to accept them as well.

hmm. any way overflow could be stopped?

>
>Josef
>

--- Thanks!

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-20 16:04             ` Bradley Morgan
@ 2026-11-20 16:16               ` Tom Rini
  2026-11-20 16:18                 ` Bradley Morgan
  0 siblings, 1 reply; 24+ messages in thread
From: Tom Rini @ 2026-11-20 16:16 UTC (permalink / raw)
  To: Bradley Morgan
  Cc: Josef Schlehofer, u-boot, Christophe Leroy (CS GROUP),
	Marek Behún, Marek Mojík, Peng Fan, Priyanka Jain,
	Qiang Zhao, Shengzhou Liu, Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

[-- Attachment #1: Type: text/plain, Size: 1241 bytes --]

On Fri, Nov 20, 2026 at 04:04:10PM +0000, Bradley Morgan wrote:
> On 20 November 2026 09:08:54 GMT, Josef Schlehofer
> <pepe.schlehofer@gmail.com> wrote:
> >Hi Bradley,
> >
> >On 19. 11. 26 19:55, Bradley Morgan wrote:
> >> Well, Christophe has the concern, he can assess, also mind answering my
> >> question about the user?
> >
> >Tom asked to update the common code, so v4 will convert the callers and
> >drop this patch.
> 
> Oof.. (also please don't keep doing new threads, it's a pain)
> 
> >
> >As for usec2ticks() in arch/powerpc/lib/time.c, a 64-bit implementation
> >would divide by the constant 1000000. With a constant divisor, do_div()
> >uses reciprocal multiplication, and lldiv() relies on the same
> >implementation, as does usec_to_tick() in lib/time.c. GCC 14 at -Os
> >compiles this without any call to a division helper.
> >
> >However, the overflow described in the comment is in the 32-bit tick
> >count itself, not in an intermediate calculation. Fixing it would
> >therefore require usec2ticks() to return 64-bit tick counts and
> >wait_ticks() to accept them as well.
> 
> hmm. any way overflow could be stopped?

The question is, is it an overflow we might ever encounter?

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 04/14] powerpc: lib: Add 64-bit division to the private libgcc
  2026-11-20 16:16               ` Tom Rini
@ 2026-11-20 16:18                 ` Bradley Morgan
  0 siblings, 0 replies; 24+ messages in thread
From: Bradley Morgan @ 2026-11-20 16:18 UTC (permalink / raw)
  To: Tom Rini
  Cc: Josef Schlehofer, u-boot, Christophe Leroy (CS GROUP),
	Marek Behún, Marek Mojík, Peng Fan, Priyanka Jain,
	Qiang Zhao, Shengzhou Liu, Mario Six, Dario Binacchi,
	Michael Trimarchi, Heiko Schocher, Holger Brunck, Simon Glass,
	Bradley Morgan

On 20 November 2026 16:16:03 GMT, Tom Rini <trini@konsulko.com> wrote:
>On Fri, Nov 20, 2026 at 04:04:10PM +0000, Bradley Morgan wrote:
>> On 20 November 2026 09:08:54 GMT, Josef Schlehofer
>> <pepe.schlehofer@gmail.com> wrote:
>> >Hi Bradley,
>> >
>> >On 19. 11. 26 19:55, Bradley Morgan wrote:
>> >> Well, Christophe has the concern, he can assess, also mind answering
>my
>> >> question about the user?
>> >
>> >Tom asked to update the common code, so v4 will convert the callers and
>> >drop this patch.
>> 
>> Oof.. (also please don't keep doing new threads, it's a pain)
>> 
>> >
>> >As for usec2ticks() in arch/powerpc/lib/time.c, a 64-bit implementation
>> >would divide by the constant 1000000. With a constant divisor, do_div()
>> >uses reciprocal multiplication, and lldiv() relies on the same
>> >implementation, as does usec_to_tick() in lib/time.c. GCC 14 at -Os
>> >compiles this without any call to a division helper.
>> >
>> >However, the overflow described in the comment is in the 32-bit tick
>> >count itself, not in an intermediate calculation. Fixing it would
>> >therefore require usec2ticks() to return 64-bit tick counts and
>> >wait_ticks() to accept them as well.
>> 
>> hmm. any way overflow could be stopped?
>
>The question is, is it an overflow we might ever encounter?

I had a quick peek, it's not something you'd just reach from booting and
praying.

But, my opinion is, it should be fixed in case. Just in case.

If it "can't" be fixed without a sacrifice, id just leave it.

>
>

--- Thanks!

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-11-20 16:18 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 13:32 [PATCH v3 00/14] powerpc: Enable LTO on mpc85xx Josef Schlehofer
2026-11-19 13:32 ` [PATCH v3 01/14] board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy Josef Schlehofer
2026-11-19 13:32 ` [PATCH v3 02/14] powerpc: Make the global data pointer LTO safe Josef Schlehofer
2026-11-19 13:32 ` [PATCH v3 03/14] powerpc: lib: Add GPR save and restore routines to the private libgcc Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 04/14] powerpc: lib: Add 64-bit division " Josef Schlehofer
2026-11-19 14:21   ` Christophe Leroy (CS GROUP)
2026-11-19 16:01     ` Bradley Morgan
2026-11-19 18:42       ` Josef Schlehofer
2026-11-19 18:55         ` Bradley Morgan
2026-11-20  9:08           ` Josef Schlehofer
2026-11-20 16:04             ` Bradley Morgan
2026-11-20 16:16               ` Tom Rini
2026-11-20 16:18                 ` Bradley Morgan
2026-11-19 20:09         ` Tom Rini
2026-11-19 13:33 ` [PATCH v3 05/14] powerpc: mpc85xx: Use the private libgcc with LTO Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 06/14] powerpc: mpc85xx: Discard LTO keep-syms sections Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 07/14] powerpc: Drop -ffunction-sections and -fdata-sections with LTO Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 08/14] powerpc: mpc85xx: Allow LTO Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 09/14] xpl: Pass the make jobserver to the xPL link Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 10/14] configs: turris_1x: Enable LTO Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 11/14] mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 12/14] board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 13/14] configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI Josef Schlehofer
2026-11-19 13:33 ` [PATCH v3 14/14] board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP Josef Schlehofer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.