Skip to contentSkip to conversation

powerpc: Enable LTO on mpc85xx

PATCH Superseded Josef Schlehofer 3 participants 28 messages Sep 28 – Oct 14

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover powerpc: Enable LTO on mpc85xx

This series allows LTO on mpc85xx and enables it for the CZ.NIC Turris 1.x, whose NOR image has a 768 KiB limit. LTO, together with dropping NVMe and SCSI from the NOR build, makes room for the ubi command and the BCH ECC code that the Turris NAND needs.

The series consists of:

1-3. Generic LTO link fixes:
- skip undefined symbols in the generated keep-syms file;
- keep a toolchain libgcc out of --whole-archive;
- avoid the implicit -pie added by default-PIE toolchains.

4-5. PowerPC global data:
- drop an unused SPL copy of gd;
- make the global data pointer usable with LTO. This also converts the remaining direct PowerPC gd assignments to set_gd().

6-8. mpc85xx LTO support:
- discard the LTO keep-syms section and its fixups from the image;
- allow CONFIG_LTO=y on mpc85xx;
- pass the make jobserver to the SPL/TPL link, as GCC 12's lto-wrapper requires.

9-13. Turris 1.x:
- enable LTO;
- select the BCH ECC code that the NAND needs;
- 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 when the environment was reset.

Patch 13 adds a weak hook to the P1/P2 RDB board code that Turris 1.x shares, since an EVT_FT_FIXUP spy is never called for the kernel device tree on this board.

Why next: patches 1-3 change the link of the existing LTO boards and are therefore meant for next, although they carry Fixes: tags. Patch 10 is a fix too: without it, U-Boot hits BUG() at the NAND probe. On main it helps only turris_1x_nor, as the turris_1x_sdcard u-boot.bin with the BCH code exceeds the 1 MiB its SPL loads from the card, which the build does not catch; with LTO (patch 9) both fit. Patch 13 is of no use without patch 10.

With Debian's GCC 14.2, turris_1x_nor u-boot-nodtb.bin goes from 757072 to 754920 bytes while gaining LTO, the BCH code and the ubi command and dropping NVMe and SCSI, and turris_1x_sdcard u-boot.bin from 1047795 to 996899 bytes. Both images fit their size limits.

All 83 PowerPC boards build with the series, and all 71 mpc85xx boards link with CONFIG_LTO=y. The 39 ARM defconfigs that set CONFIG_LTO=y and sandbox were also built before and after patches 1-3. No .discard* section and no zero fixup entry is left in the LTO images. test.py on qemu-ppce500 gives the same results before and after the series, also with CONFIG_LTO=y; the one failing timing test fails on next as well. With the kernel.org GCC 14.2 that CI uses, both Turris 1.x LTO builds fit. With Debian's GCC 12.2 and make 4.3, the Turris SD card SPL links at -j8 only with patch 8.

A Turris 1.x also needs two patches of the fixes series for main, the SPD read and the mpc85xx alignment padding:
https://lore.kernel.org/u-boot/[email protected]/

Boot tested on a Turris 1.1 together with the fixes series, from NOR and from the SD card. The NOR build also booted OpenWrt from the kernel UBI volume on the NAND. Linux got the OTP MAC addresses and serial number also after "env default -a", and with the SD card build, an ethaddr and a serial# set in the environment were kept. The other boards are build tested only.

Josef Schlehofer (13):
Makefile: Skip undefined symbols in keep-syms-lto.c
Makefile: Link a toolchain libgcc outside --whole-archive with LTO
Makefile: Pass -static to the LTO link
board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy
powerpc: Make the global data pointer LTO safe
powerpc: mpc85xx: Discard LTO keep-syms sections
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

 Makefile                                  | 12 +++++++--
 arch/powerpc/Kconfig                      |  1 +
 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                 |  1 +
 arch/powerpc/lib/gd.c                     | 14 +++++++++++
 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                      | 12 ++++++---
 31 files changed, 159 insertions(+), 63 deletions(-)
 create mode 100644 arch/powerpc/lib/gd.c

base-commit: 951132236b9adc592c2e49faadd103c6a355cac3
prerequisite-patch-id: c2cc988027a3f33da10e9d5e1f437c590fa32ad8
prerequisite-patch-id: a4fac862dc6152c7663a15e01be1307613627ca5
prerequisite-patch-id: 8208f6e784698a3a3e04a308f23ebdb7cc431156

Signature · 1 line
2.54.0 (Apple Git-157)
#1 lore raw

PATCH 1/13 Makefile: Skip undefined symbols in keep-syms-lto.c

The generated keep-syms-lto.c gets an __ADDRESSABLE() entry for every linker list symbol that nm prints, including symbols the input objects only reference and nothing defines. keep-syms-lto.c is compiled with the LTO flags filtered out, so such an entry turns into a hard reference that the link cannot resolve unless .discard.addressable is dropped.

The turris_1x SD card SPL, for example, links board/CZ.NIC/turris_atsha_otp.o, which references the ATSHA204 driver, while the driver itself is not part of the SPL. With LTO, which mpc85xx allows later in this series, and without the /DISCARD/ rule that "powerpc: mpc85xx: Discard LTO keep-syms sections" adds, its link fails:

keep-syms-lto.c:5:(.discard.addressable+0xc):
undefined reference to `_u_boot_list_2_driver_2_atsha204'

Pass --defined-only to nm, so that only symbols defined by the scanned objects reach the generator.

Fixes c1094987d1dc ("build: support building with Link Time Optimizations")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>
Cc Patrick Delaunay <[email protected]>

---
The option goes to the two callers rather than into the script, as the script runs the command it is given, which can start with a wrapper such as the ccache that buildman can put in front of the toolchain.

---
 Makefile             | 2 +-
 scripts/Makefile.xpl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
index c898f4b9df3..e8615c247bd 100644
@@ -2076,7 +2076,7 @@ u-boot-keep-syms-lto_c := $(patsubst %.o,%.c,$(u-boot-keep-syms-lto))
 
 quiet_cmd_keep_syms_lto = KSL     $@
       cmd_keep_syms_lto = \
-	$(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@
+	$(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) --defined-only $^ > $@
 
 quiet_cmd_keep_syms_lto_cc = KSLCC   $@
       cmd_keep_syms_lto_cc = \
scripts/Makefile.xpl +1 -1
index a3fd3e1375f..53522ced84b 100644
@@ -491,7 +491,7 @@ u-boot-spl-keep-syms-lto_c := \
 
 quiet_cmd_keep_syms_lto = KSL     $@
       cmd_keep_syms_lto = \
-	$(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@
+	$(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) --defined-only $^ > $@
 
 quiet_cmd_keep_syms_lto_cc = KSLCC   $@
       cmd_keep_syms_lto_cc = \
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 1/13
#2 lore raw

Re: [PATCH next 01/13] Makefile: Skip undefined symbols in keep-syms-lto.c

Quoted 20 lines · Josef Schlehofer

The generated keep-syms-lto.c gets an __ADDRESSABLE() entry for every linker list symbol that nm prints, including symbols the input objects only reference and nothing defines. keep-syms-lto.c is compiled with the LTO flags filtered out, so such an entry turns into a hard reference that the link cannot resolve unless .discard.addressable is dropped.

The turris_1x SD card SPL, for example, links board/CZ.NIC/turris_atsha_otp.o, which references the ATSHA204 driver, while the driver itself is not part of the SPL. With LTO, which mpc85xx allows later in this series, and without the /DISCARD/ rule that "powerpc: mpc85xx: Discard LTO keep-syms sections" adds, its link fails:

keep-syms-lto.c:5:(.discard.addressable+0xc):
undefined reference to `_u_boot_list_2_driver_2_atsha204'

Pass --defined-only to nm, so that only symbols defined by the scanned objects reach the generator.

Quoted 6 lines
Fixes c1094987d1dc ("build: support building with Link Time Optimizations")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>
Cc Patrick Delaunay <[email protected]>
Signature · 1 line
Tom
#3 lore raw

PATCH 2/13 Makefile: Link a toolchain libgcc outside --whole-archive with LTO

In reply to Josef Schlehofer

Commit c1094987d1dc ("build: support building with Link Time Optimizations") put $(PLATFORM_LIBS) inside the --whole-archive group of the LTO link rules. That works for the in-tree libgcc that CONFIG_USE_PRIVATE_LIBGCC builds.

A toolchain libgcc, though, then gets every member force-linked, split-stack helpers included. With Debian's powerpc-linux-gnu GCC 14.2, turris_1x_nor with CONFIG_LTO=y, which mpc85xx allows later in this series, fails to link with undefined references such as __morestack_fail and __tls_get_addr.

Keep the in-tree libgcc inside --whole-archive, but link a toolchain libgcc after --no-whole-archive, as the non-LTO link rules do. ARM64 has no private libgcc, so its LTO boards now link libgcc this way too.

Fixes c1094987d1dc ("build: support building with Link Time Optimizations")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

---
--gc-sections, which commit 34ccadcd3334 ("ARM: don't use --gc-sections with LTO when using private libgcc") keeps on ARM for LTO with a toolchain libgcc, is set on powerpc and does not help here.

---
 Makefile             | 10 +++++++++-
 scripts/Makefile.xpl |  8 +++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
Makefile +9 -1
index e8615c247bd..ca18c3b32c9 100644
@@ -1158,6 +1158,13 @@ KBUILD_CFLAGS += --coverage
 PLATFORM_LIBGCC += -lgcov
 endif
 
+# The LTO link force-links the in-tree libgcc with --whole-archive. A
+# toolchain libgcc goes after --no-whole-archive: force-linking all of
+# its members pulls in split-stack and other hosted helpers that do not
+# resolve.
+LTO_LIBS_WHOLE := $(if $(CONFIG_USE_PRIVATE_LIBGCC),$(PLATFORM_LIBS))
+LTO_LIBS_AFTER := $(if $(CONFIG_USE_PRIVATE_LIBGCC),,$(PLATFORM_LIBS))
+
 export PLATFORM_LIBS
 export PLATFORM_LIBGCC
 
@@ -2103,8 +2110,9 @@ quiet_cmd_u-boot__ ?= LTO     $@
 		-Wl,--whole-archive						\
 			$(u-boot-main)						\
 			$(u-boot-keep-syms-lto)					\
-			$(PLATFORM_LIBS)					\
+			$(LTO_LIBS_WHOLE)					\
 		-Wl,--no-whole-archive						\
+		$(LTO_LIBS_AFTER)						\
 		-Wl,-Map,u-boot.map;						\
 		$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 else
scripts/Makefile.xpl +7 -1
index 53522ced84b..221ef7f29b3 100644
@@ -144,6 +144,11 @@ libs-y := $(patsubst %/, %/built-in.a, $(libs-y))
 ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
 PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
 PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC)
+LTO_LIBS_WHOLE := $(PLATFORM_LIBS)
+LTO_LIBS_AFTER :=
+else
+LTO_LIBS_WHOLE :=
+LTO_LIBS_AFTER := $(PLATFORM_LIBS)
 endif
 
 u-boot-spl-init := $(head-y)
@@ -520,8 +525,9 @@ quiet_cmd_u-boot-spl ?= LTO     $@
 			$(patsubst $(obj)/%,%,$(u-boot-spl-main))		\
 			$(patsubst $(obj)/%,%,$(u-boot-spl-platdata))		\
 			$(patsubst $(obj)/%,%,$(u-boot-spl-keep-syms-lto))	\
-			$(PLATFORM_LIBS)					\
+			$(LTO_LIBS_WHOLE)					\
 		-Wl,--no-whole-archive						\
+		$(LTO_LIBS_AFTER)						\
 		-Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN)				\
 	)
 else
Signature · 1 line
2.54.0 (Apple Git-157)
#4 lore raw

Re: [PATCH next 02/13] Makefile: Link a toolchain libgcc outside --whole-archive with LTO

Quoted 20 lines · Josef Schlehofer

Commit c1094987d1dc ("build: support building with Link Time Optimizations") put $(PLATFORM_LIBS) inside the --whole-archive group of the LTO link rules. That works for the in-tree libgcc that CONFIG_USE_PRIVATE_LIBGCC builds.

A toolchain libgcc, though, then gets every member force-linked, split-stack helpers included. With Debian's powerpc-linux-gnu GCC 14.2, turris_1x_nor with CONFIG_LTO=y, which mpc85xx allows later in this series, fails to link with undefined references such as __morestack_fail and __tls_get_addr.

Keep the in-tree libgcc inside --whole-archive, but link a toolchain libgcc after --no-whole-archive, as the non-LTO link rules do. ARM64 has no private libgcc, so its LTO boards now link libgcc this way too.

Fixes c1094987d1dc ("build: support building with Link Time Optimizations")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>
Quoted 4 lines

---
--gc-sections, which commit 34ccadcd3334 ("ARM: don't use --gc-sections with LTO when using private libgcc") keeps on ARM for LTO with a toolchain libgcc, is set on powerpc and does not help here.

Since we have ARM boards that do, and others that don't, set USE_PRIVATE_LIBGCC why isn't the solution to just replicate that logic under arch/powerpc/config.mk ? I also don't see a later patch that guards and drops out -ffunction-sections -fdata-sections when LTO is enabled.

Also, in your next iteration please drop Pali Rohár from the emails as he does not wish to be involved with U-Boot. Thanks.

Signature · 1 line
Tom
#5 lore raw

Re: [PATCH next 02/13] Makefile: Link a toolchain libgcc outside --whole-archive with LTO

Hi

po 28. 9. 2026 v 21:46 odesílatel Tom Rini <[email protected]> napsal:

Quoted 2 lines

why isn't the solution to just replicate that logic under arch/powerpc/config.mk ?

PowerPC's private libgcc only has the three shift helpers, so with it the LTO builds I tried don't link (no _restgpr_*_x, and on the Turris no __udivdi3/__umoddi3). PowerPC needs the toolchain libgcc, and the --whole-archive in the generic LTO rule is what breaks it.

Quoted 3 lines

I also don't see a later patch that
guards and drops out -ffunction-sections -fdata-sections when LTO is enabled.

The ARM conditions for that have had no effect on U-Boot proper since
a55014d09b2: LTO_ENABLE is only set after arch/$(ARCH)/config.mk is included. Should I send a fix for that, and add the same condition for PowerPC in v2?

Quoted 5 lines

Also, in your next iteration please drop Pali Rohár from the emails as he does not wish to be involved with U-Boot. Thanks.

Yes, I take that into account, and I'm loosely aware of what took place

here. However, I wanted to inform Pali that I'd be glad to finish up his work regarding Turris 1.x, seeing how much time and effort he dedicated to it.

Thanks,
Josef

#6 lore raw

Re: [PATCH next 02/13] Makefile: Link a toolchain libgcc outside --whole-archive with LTO

Quoted 4 lines · Josef Schlehofer

Hi

po 28. 9. 2026 v 21:46 odesílatel Tom Rini <[email protected]> napsal:

Quoted 8 lines
Quoted 2 lines

why isn't the solution to just replicate that logic under arch/powerpc/config.mk ?

PowerPC's private libgcc only has the three shift helpers, so with it the LTO builds I tried don't link (no _restgpr_*_x, and on the Turris no __udivdi3/__umoddi3). PowerPC needs the toolchain libgcc, and the --whole-archive in the generic LTO rule is what breaks it.

Can those just be imported from elsewhere? That's essentially what the private libgcc is.

Quoted 8 lines
Quoted 3 lines

I also don't see a later patch that
guards and drops out -ffunction-sections -fdata-sections when LTO is enabled.

The ARM conditions for that have had no effect on U-Boot proper since
a55014d09b2: LTO_ENABLE is only set after arch/$(ARCH)/config.mk is included. Should I send a fix for that, and add the same condition for PowerPC in v2?

Please fix the ARM issue in its own patch outside this series, and handle PowerPC with that in mind for v2, yes, thanks.

Signature · 1 line
Tom
#7 lore raw

PATCH 3/13 Makefile: Pass -static to the LTO link

In reply to Josef Schlehofer

The LTO link runs through the compiler driver. On a toolchain configured with --enable-default-pie, such as Debian's GCC, the driver adds -pie, and links that are not PIE without LTO, such as the SPLs, then get dynamic sections that the non-LTO link does not create. With Debian's GCC 14.2 they make some ARM LTO boards exceed their SPL or image size limits, and turris_1x_nor with CONFIG_LTO=y, which mpc85xx allows later in this series, fails to link:

ld: section .bootpg LMA [effff000,effff4c7] overlaps section

      .rela.dyn LMA [effe8048,efffff03]

Pass -static, which keeps the driver from adding -pie. ARM still links U-Boot proper with -pie, which the LTO link passes to the linker as -Wl,-pie, and u-boot.bin of the ARM LTO boards does not change.

Fixes c1094987d1dc ("build: support building with Link Time Optimizations")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

---
With Debian's GCC 14.2, imx6dl_mamoj and phycore-rk3288 exceed their SPL size limits and turris_omnia its u-boot-with-spl.kwb limit without this patch; the cover letter has the build results.

---
 Makefile             | 2 +-
 scripts/Makefile.xpl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
index ca18c3b32c9..d9f53e20b9a 100644
@@ -2112,7 +2112,7 @@ quiet_cmd_u-boot__ ?= LTO     $@
 			$(u-boot-keep-syms-lto)					\
 			$(LTO_LIBS_WHOLE)					\
 		-Wl,--no-whole-archive						\
-		$(LTO_LIBS_AFTER)						\
+		$(LTO_LIBS_AFTER) -static					\
 		-Wl,-Map,u-boot.map;						\
 		$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 else
scripts/Makefile.xpl +1 -1
index 221ef7f29b3..69b35d6ffb6 100644
@@ -527,7 +527,7 @@ quiet_cmd_u-boot-spl ?= LTO     $@
 			$(patsubst $(obj)/%,%,$(u-boot-spl-keep-syms-lto))	\
 			$(LTO_LIBS_WHOLE)					\
 		-Wl,--no-whole-archive						\
-		$(LTO_LIBS_AFTER)						\
+		$(LTO_LIBS_AFTER) -static					\
 		-Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN)				\
 	)
 else
Signature · 1 line
2.54.0 (Apple Git-157)
#8 lore raw

Re: [PATCH next 03/13] Makefile: Pass -static to the LTO link

Quoted 47 lines · Josef Schlehofer

The LTO link runs through the compiler driver. On a toolchain configured with --enable-default-pie, such as Debian's GCC, the driver adds -pie, and links that are not PIE without LTO, such as the SPLs, then get dynamic sections that the non-LTO link does not create. With Debian's GCC 14.2 they make some ARM LTO boards exceed their SPL or image size limits, and turris_1x_nor with CONFIG_LTO=y, which mpc85xx allows later in this series, fails to link:

ld: section .bootpg LMA [effff000,effff4c7] overlaps section

      .rela.dyn LMA [effe8048,efffff03]

Pass -static, which keeps the driver from adding -pie. ARM still links U-Boot proper with -pie, which the LTO link passes to the linker as -Wl,-pie, and u-boot.bin of the ARM LTO boards does not change.

Fixes c1094987d1dc ("build: support building with Link Time Optimizations")
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

---
With Debian's GCC 14.2, imx6dl_mamoj and phycore-rk3288 exceed their SPL size limits and turris_omnia its u-boot-with-spl.kwb limit without this patch; the cover letter has the build results.

---
 Makefile             | 2 +-
 scripts/Makefile.xpl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
index ca18c3b32c9..d9f53e20b9a 100644
@@ -2112,7 +2112,7 @@ quiet_cmd_u-boot__ ?= LTO     $@
 			$(u-boot-keep-syms-lto)					\
 			$(LTO_LIBS_WHOLE)					\
 		-Wl,--no-whole-archive						\
-		$(LTO_LIBS_AFTER)						\
+		$(LTO_LIBS_AFTER) -static					\
 		-Wl,-Map,u-boot.map;						\
 		$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 else
scripts/Makefile.xpl +0 -0
index 221ef7f29b3..69b35d6ffb6 100644

scripts/Makefile.xpl quiet_cmd_u-boot-spl ?= LTO $@ · line 533

Quoted 8 lines
scripts/Makefile.xpl +1 -1
@@ -527,7 +527,7 @@ quiet_cmd_u-boot-spl ?= LTO     $@
 			$(patsubst $(obj)/%,%,$(u-boot-spl-keep-syms-lto))	\
 			$(LTO_LIBS_WHOLE)					\
 		-Wl,--no-whole-archive						\
-		$(LTO_LIBS_AFTER)						\
+		$(LTO_LIBS_AFTER) -static					\
 		-Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN)				\
 	)
 else

This is another generic change that should be done on its own, outside the series, thanks.

Signature · 1 line
Tom
#9 lore raw

PATCH 4/13 board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy

In reply to Josef Schlehofer

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

Cc Priyanka Jain <[email protected]>
Cc Qiang Zhao <[email protected]>
Cc Peng Fan <[email protected]>
Cc Marek Behún <[email protected]>
Cc Marek Mojík <[email protected]>
---
 board/nxp/p1010rdb/spl.c     | 9 +--------
 board/nxp/p1_p2_rdb_pc/spl.c | 9 +--------
 2 files changed, 2 insertions(+), 16 deletions(-)
board/nxp/p1010rdb/spl.c +1 -8
index fc26cef2cc8..7c36026a55a 100644
@@ -60,22 +60,17 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_VAL(RELOC_STACK), 0, CONFIG_SPL_RELOC_TEXT_BASE);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *)CONFIG_VAL(GD_ADDR);
 	struct bd_info *bd;
 
-	memset(gd, 0, sizeof(gd_t));
 	bd = (struct bd_info *)(CONFIG_VAL(GD_ADDR) + sizeof(gd_t));
 	memset(bd, 0, sizeof(struct bd_info));
-	gd->bd = bd;
 
 	arch_cpu_init();
 	get_clocks();
 	mem_malloc_init(CONFIG_VAL(RELOC_MALLOC_ADDR),
 			CONFIG_VAL(RELOC_MALLOC_SIZE));
-	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 
 #ifndef CONFIG_SPL_NAND_BOOT
 	env_init();
@@ -88,8 +83,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #ifdef CONFIG_SPL_NAND_BOOT
 	nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
 			    (uchar *)SPL_ENV_ADDR);
-			    gd->env_addr  = (ulong)(SPL_ENV_ADDR);
-	gd->env_valid = ENV_VALID;
 #else
 	env_relocate();
 #endif
board/nxp/p1_p2_rdb_pc/spl.c +1 -8
index b07f481fbf9..6db77682e3c 100644
@@ -72,22 +72,17 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_VAL(RELOC_STACK), 0, CONFIG_SPL_RELOC_TEXT_BASE);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *)CONFIG_VAL(GD_ADDR);
 	struct bd_info *bd;
 
-	memset(gd, 0, sizeof(gd_t));
 	bd = (struct bd_info *)(CONFIG_VAL(GD_ADDR) + sizeof(gd_t));
 	memset(bd, 0, sizeof(struct bd_info));
-	gd->bd = bd;
 
 	arch_cpu_init();
 	get_clocks();
 	mem_malloc_init(CONFIG_VAL(RELOC_MALLOC_ADDR),
 			CONFIG_VAL(RELOC_MALLOC_SIZE));
-	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 #ifndef CONFIG_SPL_NAND_BOOT
@@ -102,8 +97,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #ifdef CONFIG_SPL_NAND_BOOT
 	nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
 			    (uchar *)SPL_ENV_ADDR);
-	gd->env_addr  = (ulong)(SPL_ENV_ADDR);
-	gd->env_valid = ENV_VALID;
 #else
 	env_relocate();
 #endif
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 4/13
#10 lore raw

Re: [PATCH next 04/13] board: nxp: p1_p2_rdb_pc, p1010rdb: Drop unused SPL gd copy

Quoted 19 lines · Josef Schlehofer

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

Quoted 6 lines
Cc Priyanka Jain <[email protected]>
Cc Qiang Zhao <[email protected]>
Cc Peng Fan <[email protected]>
Cc Marek Behún <[email protected]>
Cc Marek Mojík <[email protected]>
#11 lore raw

PATCH 5/13 powerpc: Make the global data pointer LTO safe

In reply to Josef Schlehofer

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.

Cc Marek Behún <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Mario Six <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Qiang Zhao <[email protected]>
Cc Peng Fan <[email protected]>
Cc Shengzhou Liu <[email protected]>
Cc Marek Mojík <[email protected]>

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

checkpatch asks for IS_ENABLED() on the #if lines in common/board_r.c, common/init/board_init.c and common/spl/spl.c. They choose how gd is set per architecture: set_gd() exists only on ARM, RISC-V and PowerPC, so IS_ENABLED() cannot replace them. The new arch/powerpc/lib/gd.c is covered by the POWERPC entry in MAINTAINERS.

---
 arch/powerpc/cpu/mpc83xx/cpu_init.c       |  3 +--
 arch/powerpc/cpu/mpc83xx/spl_minimal.c    |  3 +--
 arch/powerpc/cpu/mpc85xx/cpu_init_early.c |  3 +--
 arch/powerpc/include/asm/global_data.h    | 30 +++++++++++++++++++++++
 arch/powerpc/lib/Makefile                 |  1 +
 arch/powerpc/lib/gd.c                     | 14 +++++++++++
 board/nxp/p1010rdb/spl_minimal.c          |  2 +-
 board/nxp/p1_p2_rdb_pc/spl_minimal.c      |  2 +-
 board/nxp/t102xrdb/spl.c                  |  4 +--
 board/nxp/t104xrdb/spl.c                  |  4 +--
 board/nxp/t208xqds/spl.c                  |  4 +--
 board/nxp/t208xrdb/spl.c                  |  4 +--
 board/nxp/t4rdb/spl.c                     |  4 +--
 common/board_r.c                          |  2 +-
 common/init/board_init.c                  |  9 ++++---
 common/spl/spl.c                          |  4 ++-
 16 files changed, 69 insertions(+), 24 deletions(-)
 create mode 100644 arch/powerpc/lib/gd.c
arch/powerpc/cpu/mpc83xx/cpu_init.c +1 -2
index 340f9a0da56..5618b79a78b 100644
@@ -139,8 +139,7 @@ void cpu_init_f (volatile immap_t * im)
 #endif
 		0;
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *)SYS_INIT_SP_ADDR;
+	set_gd((gd_t *)SYS_INIT_SP_ADDR);
 
 	/* global data region was cleared in start.S */
 
arch/powerpc/cpu/mpc83xx/spl_minimal.c +1 -2
index 7036e3fae0c..1d48428573d 100644
@@ -25,8 +25,7 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 void cpu_init_f (volatile immap_t * im)
 {
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *)SYS_INIT_SP_ADDR;
+	set_gd((gd_t *)SYS_INIT_SP_ADDR);
 
 	/* global data region was cleared in start.S */
 
arch/powerpc/cpu/mpc85xx/cpu_init_early.c +1 -2
index 75bfc07fe97..fb3d662c9d3 100644
@@ -95,8 +95,7 @@ void cpu_init_early_f(void *fdt)
 	int i;
 #endif
 
-	/* Pointer is writable since we allocated a register for it */
-	gd = (gd_t *)SYS_INIT_SP_ADDR;
+	set_gd((gd_t *)SYS_INIT_SP_ADDR);
 
 	/* gd area was zeroed during startup */
 
arch/powerpc/include/asm/global_data.h +30 -0
index 26cbc7854d9..d8aefd2ca0a 100644
@@ -93,8 +93,38 @@ struct arch_global_data {
 
 #include <asm-generic/global_data.h>
 
+#ifdef LTO_ENABLE
+
+#define DECLARE_GLOBAL_DATA_PTR
+#define gd	get_gd()
+
+static inline gd_t *get_gd(void)
+{
+	gd_t *gd_ptr;
+
+	__asm__ volatile("mr %0, 2\n" : "=r" (gd_ptr));
+
+	return gd_ptr;
+}
+
+static inline void set_gd(gd_t *gd_ptr)
+{
+	__asm__ volatile("mr 2, %0\n" : : "r" (gd_ptr));
+}
+
+#else
+
 #define DECLARE_GLOBAL_DATA_PTR     register gd_t *gd asm ("r2")
 
+/*
+ * GCC does not see an asm statement write r2 and assumes that the
+ * register variable is unchanged, so it may move gd accesses across the
+ * write. Assign the variable itself.
+ */
+#define set_gd(gd_ptr)	(gd = (gd_ptr))
+
+#endif
+
 #include <asm/u-boot.h>
 
 #endif /* __ASM_GBL_DATA_H */
arch/powerpc/lib/Makefile +1 -0
index c0caa703caa..a3048975ae7 100644
@@ -18,6 +18,7 @@ endif
 endif
 
 obj-y	+= bdinfo.o
+obj-y	+= gd.o
 
 ifdef MINIMAL
 obj-y += cache.o time.o
arch/powerpc/lib/gd.c new file +14 -0
new file mode 100644
index 00000000000..d36f784fbf7
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Josef Schlehofer <[email protected]>
+ */
+
+#include <init.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void arch_setup_gd(gd_t *new_gd)
+{
+	set_gd(new_gd);
+}
board/nxp/p1010rdb/spl_minimal.c +1 -1
index 8cd79c6fb5f..33930fef8d9 100644
@@ -45,7 +45,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	puts("\nSecond program loader running in sram...");
 	nand_boot();
board/nxp/p1_p2_rdb_pc/spl_minimal.c +1 -1
index 511bcf5506b..960b2c41457 100644
@@ -43,7 +43,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	puts("\nSecond program loader running in sram...");
 	nand_boot();
board/nxp/t102xrdb/spl.c +2 -2
index de6cdda194e..f527f62a5dd 100644
@@ -58,7 +58,7 @@ void board_init_f(ulong bootflag)
 	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
 
 	/* Update GD pointer */
-	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	set_gd((gd_t *)(CONFIG_SPL_GD_ADDR));
 
 	console_init_f();
 
@@ -87,7 +87,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	struct bd_info *bd;
 
board/nxp/t104xrdb/spl.c +2 -2
index e02a1f95d4c..0310baa381c 100644
@@ -55,7 +55,7 @@ void board_init_f(ulong bootflag)
 	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
 
 	/* Update GD pointer */
-	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	set_gd((gd_t *)(CONFIG_SPL_GD_ADDR));
 
 #ifdef CONFIG_DEEP_SLEEP
 	/* disable the console if boot from deep sleep */
@@ -78,7 +78,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	struct bd_info *bd;
 
board/nxp/t208xqds/spl.c +2 -2
index 44ad4e68d9f..f8c641a9c64 100644
@@ -73,7 +73,7 @@ void board_init_f(ulong bootflag)
 	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
 
 	/* Update GD pointer */
-	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	set_gd((gd_t *)(CONFIG_SPL_GD_ADDR));
 
 	console_init_f();
 
@@ -96,7 +96,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	struct bd_info *bd;
 
board/nxp/t208xrdb/spl.c +2 -2
index df3b9c6fe40..4b1ab3618c3 100644
@@ -33,7 +33,7 @@ void board_init_f(ulong bootflag)
 	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
 
 	/* Update GD pointer */
-	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	set_gd((gd_t *)(CONFIG_SPL_GD_ADDR));
 
 	console_init_f();
 
@@ -56,7 +56,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	struct bd_info *bd;
 
board/nxp/t4rdb/spl.c +2 -2
index 9d2472dec25..441015bf5a4 100644
@@ -39,7 +39,7 @@ void board_init_f(ulong bootflag)
 	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
 
 	/* Update GD pointer */
-	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	set_gd((gd_t *)(CONFIG_SPL_GD_ADDR));
 
 	/* compiler optimization barrier needed for GCC >= 3.4 */
 	__asm__ __volatile__("" : : : "memory");
@@ -59,7 +59,7 @@ void board_init_f(ulong bootflag)
 	relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
 	struct bd_info *bd;
 
common/board_r.c +1 -1
index a397e20959d..7a9de6ba5f3 100644
@@ -796,7 +796,7 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
 	if (CONFIG_IS_ENABLED(X86_64) && !IS_ENABLED(CONFIG_EFI_APP))
 		arch_setup_gd(new_gd);
 
-#if defined(CONFIG_RISCV)
+#if defined(CONFIG_RISCV) || defined(CONFIG_PPC)
 	set_gd(new_gd);
 #elif !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
 	gd = new_gd;
common/init/board_init.c +5 -4
index 2a6f39f51ad..2faea5432c0 100644
@@ -14,15 +14,16 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 /*
- * Unfortunately x86, ARM and RISC-V can't compile this code as gd is defined
- * as macro and cannot be assigned.
+ * x86, RISC-V and PowerPC provide their own arch_setup_gd(), and ARM does
+ * not call it.
  */
-#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
+#if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_RISCV) && \
+	!defined(CONFIG_PPC)
 __weak void arch_setup_gd(struct global_data *gd_ptr)
 {
 	gd = gd_ptr;
 }
-#endif /* !CONFIG_X86 && !CONFIG_ARM */
+#endif /* !CONFIG_X86 && !CONFIG_ARM && !CONFIG_RISCV && !CONFIG_PPC */
 
 /**
  * This function is called from board_init_f_init_reserve to set up
common/spl/spl.c +3 -1
index 6c9a1a1cbcc..81aec2b1108 100644
@@ -956,7 +956,9 @@ ulong spl_relocate_stack_gd(void)
 #if CONFIG_IS_ENABLED(LOG)
 	log_fixup_for_gd_move(new_gd);
 #endif
-#if !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
+#if defined(CONFIG_PPC)
+	set_gd(new_gd);
+#elif !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
 	gd = new_gd;
 #endif
 	return ptr;
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 5/13
#12 lore raw

Re: [PATCH next 05/13] powerpc: Make the global data pointer LTO safe

Quoted 13 lines · Josef Schlehofer

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.

Quoted 9 lines
Cc Marek Behún <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Mario Six <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Qiang Zhao <[email protected]>
Cc Peng Fan <[email protected]>
Cc Shengzhou Liu <[email protected]>
Cc Marek Mojík <[email protected]>
#13 lore raw

PATCH 6/13 powerpc: mpc85xx: Discard LTO keep-syms sections

In reply to Josef Schlehofer

With LTO, keep-syms-lto.o puts a pointer to every linker list entry into .discard.addressable, only so that LTO does not drop the entries. On mpc85xx the section still ends up in the image: -mrelocatable gives each pointer a .fixup entry, and the linker scripts keep all .fixup input, which keeps the section alive.

Discard .discard* sections, as their name says. The .fixup entries of keep-syms-lto.o point into the discarded section, so leave them out of the fixup table and discard them as well. ld would otherwise keep them as zero words, which the relocation loop in start.S treats as addresses to fix up; with them, turris_1x_nor with LTO hung after the DRAM line.

---
 arch/powerpc/cpu/mpc85xx/u-boot-spl.lds | 11 ++++++++++-
 arch/powerpc/cpu/mpc85xx/u-boot.lds     | 11 ++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
arch/powerpc/cpu/mpc85xx/u-boot-spl.lds +10 -1
index d918b4395bf..dd4d18bc24b 100644
@@ -35,7 +35,7 @@ SECTIONS
 		KEEP(*(.got2))
 		KEEP(*(.got))
 		_FIXUP_TABLE_ = .;
-		KEEP(*(.fixup))
+		KEEP(*(EXCLUDE_FILE(*keep-syms-lto.o) .fixup))
 	}
 	__got2_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT2_TABLE_) >> 2) - 1;
 	__fixup_entries = (. - _FIXUP_TABLE_) >> 2;
@@ -63,6 +63,15 @@ SECTIONS
 	__init_end = .;
 	_end = .;
 
+	/*
+	 * .discard.addressable of keep-syms-lto.o only keeps the linker lists
+	 * alive during an LTO link. Drop it, and its fixups with it.
+	 */
+	/DISCARD/ : {
+		*(.discard*)
+		*keep-syms-lto.o(.fixup)
+	}
+
 #if CONFIG_IS_ENABLED(SYS_MPC85XX_NO_RESETVEC)
 #if defined(CONFIG_SDCARD) && !defined(CFG_SYS_MMC_U_BOOT_OFFS)
 	mmc_u_boot_offs = .;
arch/powerpc/cpu/mpc85xx/u-boot.lds +10 -1
index bedd2d47472..4bb9b4ecfb2 100644
@@ -49,7 +49,7 @@ SECTIONS
     KEEP(*(.got2))
     KEEP(*(.got))
     _FIXUP_TABLE_ = .;
-    KEEP(*(.fixup))
+    KEEP(*(EXCLUDE_FILE(*keep-syms-lto.o) .fixup))
   }
   __got2_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT2_TABLE_) >> 2) - 1;
   __fixup_entries = (. - _FIXUP_TABLE_) >> 2;
@@ -107,6 +107,15 @@ SECTIONS
 #endif
 #endif
 
+  /*
+   * .discard.addressable of keep-syms-lto.o only keeps the linker lists
+   * alive during an LTO link. Drop it, and its fixups with it.
+   */
+  /DISCARD/ : {
+    *(.discard*)
+    *keep-syms-lto.o(.fixup)
+  }
+
   __bss_start = .;
   .bss (NOLOAD)       :
   {
Signature · 1 line
2.54.0 (Apple Git-157)
#14 lore raw

PATCH 7/13 powerpc: mpc85xx: Allow LTO

In reply to Josef Schlehofer

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.

Cc Marek Behún <[email protected]>
Cc Priyanka Jain <[email protected]>
---
 arch/powerpc/Kconfig | 1 +
 doc/build/gcc.rst    | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -0
index f20d58b4de6..70ba76e530d 100644
@@ -17,6 +17,7 @@ config MPC83xx
 
 config MPC85xx
 	bool "MPC85xx"
+	select ARCH_SUPPORTS_LTO
 	select CREATE_ARCH_SYMLINK
 	select SYS_FSL_DDR
 	select SYS_FSL_DDR_BE
doc/build/gcc.rst +3 -3
index 1fef718ceec..48d22a3c8d4 100644
@@ -193,9 +193,9 @@ Link-time optimisation (LTO)
 U-Boot supports link-time optimisation which can reduce the size of the final
 U-Boot binaries, particularly with SPL.
 
-At present this can be enabled by ARM boards by adding `CONFIG_LTO=y` into the
-defconfig file. Other architectures are not supported. LTO is enabled by default
-for sandbox.
+At present this can be enabled by ARM boards and by PowerPC mpc85xx boards by
+adding `CONFIG_LTO=y` into the defconfig file. Other architectures are not
+supported. LTO is enabled by default for sandbox.
 
 This does incur a link-time penalty of several seconds. For faster incremental
 builds during development, you can disable it by setting `NO_LTO` to `1`.
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 7/13
#15 lore raw

Re: [PATCH next 07/13] powerpc: mpc85xx: Allow LTO

Quoted 11 lines · Josef Schlehofer

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.

Cc Marek Behún <[email protected]>
Cc Priyanka Jain <[email protected]>
Signature · 1 line
Tom
#16 lore raw

PATCH 8/13 xpl: Pass the make jobserver to the xPL link

In reply to Josef Schlehofer

With LTO, the SPL, TPL and VPL are linked through the compiler driver, and GCC's lto-wrapper runs the LTO code generation through make. The link rule is not marked as recursive, so make does not pass its jobserver to that command. With Debian's GCC 12.2 and make 4.3, the SPL link of turris_1x_sdcard, which the next patch switches to LTO, then 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 U-Boot link rule in the top Makefile already is.

Tested with Debian's GCC 12.2, where that link now passes, and GCC 14.2, where the '+' does not change the images of three mpc85xx LTO builds.

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

---
GCC 14.2 (Debian 14.2.0-19) links without the '+' as well, at -j8; the LTO images of turris_1x_sdcard, P2020RDB-PC_NAND and T2080RDB_NAND are byte for byte the same with and without it.

---
 scripts/Makefile.xpl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.xpl +1 -1
index 69b35d6ffb6..601de94f5c9 100644
@@ -549,7 +549,7 @@ endif
 $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
 		$(u-boot-spl-main) $(u-boot-spl-keep-syms-lto) \
 		$(obj)/u-boot-spl.lds FORCE
-	$(call if_changed,u-boot-spl)
+	+$(call if_changed,u-boot-spl)
 
 $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
 
Signature · 1 line
2.54.0 (Apple Git-157)
#17 lore raw

PATCH 9/13 configs: turris_1x: Enable LTO

In reply to Josef Schlehofer

Enable LTO in both Turris 1.x builds. The NOR build needs the space for the ubi command next to the BCH code, and the SD card build needs it for the BCH code: its u-boot.bin is otherwise within 1 KiB of the 1 MiB its SPL loads from the card.

---
 configs/turris_1x_nor_defconfig    | 1 +
 configs/turris_1x_sdcard_defconfig | 1 +
 2 files changed, 2 insertions(+)
configs/turris_1x_nor_defconfig +1 -0
index 070428ae25e..d8ce4aed4a7 100644
@@ -19,6 +19,7 @@ CONFIG_PCIE1=y
 CONFIG_PCIE2=y
 CONFIG_PCIE3=y
 CONFIG_OPTIMIZE_INLINING=y
+CONFIG_LTO=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=786432
configs/turris_1x_sdcard_defconfig +1 -0
index dbeb34dacfb..982a6cb0703 100644
@@ -29,6 +29,7 @@ CONFIG_OF_BOARD_FIXUP=y
 CONFIG_PCIE1=y
 CONFIG_PCIE2=y
 CONFIG_PCIE3=y
+CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=1048576
 CONFIG_MP=y
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 9/13
#18 lore raw

Re: [PATCH next 09/13] configs: turris_1x: Enable LTO

Quoted 7 lines · Josef Schlehofer

Enable LTO in both Turris 1.x builds. The NOR build needs the space for the ubi command next to the BCH code, and the SD card build needs it for the BCH code: its u-boot.bin is otherwise within 1 KiB of the 1 MiB its SPL loads from the card.

#19 lore raw

PATCH 10/13 mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH

In reply to Josef Schlehofer

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 LTO, the turris_1x_sdcard u-boot.bin with the BCH code would exceed the 1 MiB its SPL loads from the card.

Tested on CZ.NIC Turris 1.1.

Fixes b182816c1fb4 ("turris_1x: Normalize Kconfig usage")
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Michael Trimarchi <[email protected]>
Cc Dario Binacchi <[email protected]>
Cc Holger Brunck <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Marek Mojík <[email protected]>

---
Only the two Turris 1.x defconfigs enable NAND_FSL_ELBC_DT, so the ECC of no other board changes. 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 a fixed 1 MiB of u-boot.bin, device tree included. That is left for a follow-up.

---
 configs/kmcoge5ne_defconfig        | 1 -
 configs/turris_1x_nor_defconfig    | 1 -
 configs/turris_1x_sdcard_defconfig | 1 -
 drivers/mtd/nand/raw/Kconfig       | 2 ++
 4 files changed, 2 insertions(+), 3 deletions(-)
configs/kmcoge5ne_defconfig +0 -1
index 69ef6cf3b9b..ef03f02d1e5 100644
@@ -200,5 +200,4 @@ CONFIG_QE_UEC=y
 # CONFIG_PINCTRL_FULL is not set
 CONFIG_QE=y
 CONFIG_SYS_NS16550=y
-CONFIG_BCH=y
 CONFIG_POST=y
configs/turris_1x_nor_defconfig +0 -1
index d8ce4aed4a7..35df37fbc70 100644
@@ -119,5 +119,4 @@ CONFIG_USB_EHCI_FSL=y
 CONFIG_USB_STORAGE=y
 CONFIG_WDT=y
 CONFIG_WDT_MAX6370=y
-CONFIG_BCH=y
 # CONFIG_BINMAN_FDT is not set
configs/turris_1x_sdcard_defconfig +0 -1
index 982a6cb0703..5e99d895b2f 100644
@@ -151,4 +151,3 @@ CONFIG_USB_EHCI_FSL=y
 CONFIG_WDT=y
 CONFIG_WDT_MAX6370=y
 CONFIG_FAT_WRITE=y
-CONFIG_BCH=y
drivers/mtd/nand/raw/Kconfig +2 -0
index b5dfad7380f..52c6520bb2f 100644
@@ -241,6 +241,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"
@@ -260,6 +261,7 @@ config NAND_KIRKWOOD
 
 config NAND_ECC_BCH
 	bool
+	select BCH
 
 config NAND_KMETER1
 	bool "Support KMETER1 NAND controller"
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 10/13
#20 lore raw

Re: [PATCH next 10/13] mtd: rawnand: fsl_elbc: Select NAND_ECC_BCH

Quoted 18 lines · Josef Schlehofer

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 LTO, the turris_1x_sdcard u-boot.bin with the BCH code would exceed the 1 MiB its SPL loads from the card.

Tested on CZ.NIC Turris 1.1.

Quoted 9 lines
Fixes b182816c1fb4 ("turris_1x: Normalize Kconfig usage")
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Michael Trimarchi <[email protected]>
Cc Dario Binacchi <[email protected]>
Cc Holger Brunck <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Marek Mojík <[email protected]>
#21 lore raw

PATCH 11/13 board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional

In reply to Josef Schlehofer

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.

---
u-boot.bin of turris_1x_nor and turris_1x_sdcard has the same size and md5 before and after this patch (Debian GCC 14.2).

---
 include/configs/turris_1x.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
include/configs/turris_1x.h +16 -4
index c05614950c7..3a2818d1904 100644
@@ -71,6 +71,18 @@
  *         define CONFIG_SPL_MAX_SIZE = CONFIG_SYS_L2_SIZE
  */
 
+#ifdef CONFIG_NVME
+#define BOOT_TARGET_NVME(func) func(NVME, nvme, 0)
+#else
+#define BOOT_TARGET_NVME(func)
+#endif
+
+#ifdef CONFIG_SCSI
+#define BOOT_TARGET_SCSI(func) func(SCSI, scsi, 0)
+#else
+#define BOOT_TARGET_SCSI(func)
+#endif
+
 #ifdef CONFIG_SDCARD
 #define CFG_SYS_MMC_U_BOOT_SIZE	CONFIG_BOARD_SIZE_LIMIT
 #define CFG_SYS_MMC_U_BOOT_DST	CONFIG_TEXT_BASE
@@ -266,8 +278,8 @@
 #ifdef CONFIG_SDCARD
 #define BOOT_TARGET_DEVICES(func) \
 	func(MMC, mmc, 0) \
-	func(NVME, nvme, 0) \
-	func(SCSI, scsi, 0) \
+	BOOT_TARGET_NVME(func) \
+	BOOT_TARGET_SCSI(func) \
 	func(USB, usb, 0) \
 	func(USB, usb, 1) \
 	func(USB, usb, 2) \
@@ -279,8 +291,8 @@
 #else
 #define BOOT_TARGET_DEVICES(func) \
 	func(MMC, mmc, 0) \
-	func(NVME, nvme, 0) \
-	func(SCSI, scsi, 0) \
+	BOOT_TARGET_NVME(func) \
+	BOOT_TARGET_SCSI(func) \
 	func(USB, usb, 0) \
 	func(USB, usb, 1) \
 	func(USB, usb, 2) \
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 11/13
#22 lore raw

Re: [PATCH next 11/13] board: CZ.NIC: turris_1x: Make NVMe and SCSI boot targets conditional

Quoted 8 lines · Josef Schlehofer

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'

Quoted 7 lines

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.

#23 lore raw

PATCH 12/13 configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI

In reply to Josef Schlehofer

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.

---
The default environment does not call ubi. The boot above used:

setenv bootargs ubi.mtd=nand_ubi,2048 rootwait console=ttyS0,115200 wdt dev watchdog@2; wdt stop
ubi part rootfs 2048; ubi read $kernel_addr_r kernel bootm $kernel_addr_r

---
 configs/turris_1x_nor_defconfig | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
configs/turris_1x_nor_defconfig +2 -6
index 35df37fbc70..c5aaf55a75c 100644
@@ -55,6 +55,8 @@ CONFIG_CMD_EXT4=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_CMD_FS_UUID=y
+CONFIG_CMD_UBI=y
+# CONFIG_CMD_UBIFS is not set
 CONFIG_OF_CONTROL=y
 CONFIG_OF_INITIAL_DTB_READONLY=y
 CONFIG_ENV_OVERWRITE=y
@@ -63,9 +65,6 @@ CONFIG_ENV_RELOC_GD_ENV_ADDR=y
 CONFIG_USE_ETHPRIME=y
 CONFIG_ETHPRIME="eth2"
 # CONFIG_DM_DEVICE_REMOVE is not set
-CONFIG_AHCI=y
-CONFIG_SCSI_AHCI=y
-CONFIG_AHCI_PCI=y
 CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
 CONFIG_DDR_CLK_FREQ=66666666
@@ -101,14 +100,11 @@ CONFIG_SYS_MAX_FLASH_SECT=128
 CONFIG_MTD_RAW_NAND=y
 CONFIG_NAND_FSL_ELBC=y
 CONFIG_NAND_FSL_ELBC_DT=y
-CONFIG_MTD_UBI=y
 CONFIG_DM_MDIO=y
 CONFIG_MII=y
 CONFIG_TSEC_ENET=y
 CONFIG_PHY_FIXED=y
-CONFIG_NVME_PCI=y
 CONFIG_PCIE_FSL=y
-CONFIG_SCSI=y
 CONFIG_SPECIFY_CONSOLE_INDEX=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 12/13
#24 lore raw

Re: [PATCH next 12/13] configs: turris_1x_nor: Enable CMD_UBI, drop NVMe and SCSI

Quoted 8 lines · Josef Schlehofer

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.

Quoted 6 lines

Tested on CZ.NIC Turris 1.1: with the MAX6370 watchdog stopped first, the NOR build read the OpenWrt kernel from its UBI volume on the NAND and booted OpenWrt.

#25 lore raw

PATCH 13/13 board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP

In reply to Josef Schlehofer

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")
Cc Marek Mojík <[email protected]>
Cc Marek Behún <[email protected]>
Cc Priyanka Jain <[email protected]>
---
 board/CZ.NIC/turris_1x/turris_1x.c    | 20 ++++++++++++++++++++
 board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c |  3 +++
 2 files changed, 23 insertions(+)
board/CZ.NIC/turris_1x/turris_1x.c +20 -0
index 32535ed6ee0..8173e021f11 100644
@@ -315,6 +315,26 @@ int misc_init_r(void)
 	return 0;
 }
 
+/*
+ * The generic fixups copy the MAC addresses and the serial number from the
+ * environment into the kernel device tree. misc_init_r() puts them there, but
+ * if the environment is reset before booting, e.g. by "env default -a", they
+ * are gone. Read them from the OTP again and repeat these fixups. Valid MAC
+ * addresses and a 16-character serial# set in the environment are kept.
+ */
+void p1_p2_rdb_pc_fix_fdt_env(void *blob)
+{
+	int ret;
+
+	ret = turris_atsha_otp_init_mac_addresses(0);
+	if (ret)
+		printf("Cannot read MAC addresses from OTP: %d\n", ret);
+	turris_atsha_otp_init_serial_number();
+
+	fdt_fixup_ethernet(blob);
+	fdt_root(blob);
+}
+
 /* This comes from ../../nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c */
 extern int checkboard_p1_p2(void);
 
board/nxp/p1_p2_rdb_pc/p1_p2_rdb_pc.c +3 -0
index a19a98dd0d1..07c18117cbe 100644
@@ -373,6 +373,8 @@ int board_early_init_r(void)
 
 __weak void p1_p2_rdb_pc_fix_fdt_model(void *blob) {}
 
+__weak void p1_p2_rdb_pc_fix_fdt_env(void *blob) {}
+
 #if defined(CONFIG_OF_BOARD_SETUP) || defined(CONFIG_OF_BOARD_FIXUP)
 static void fix_max6370_watchdog(void *blob)
 {
@@ -418,6 +420,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
 	p1_p2_rdb_pc_fix_fdt_model(blob);
 	fix_max6370_watchdog(blob);
+	p1_p2_rdb_pc_fix_fdt_env(blob);
 
 #if defined(CONFIG_HAS_FSL_DR_USB)
 	fsl_fdt_fixup_dr_usb(blob, bd);
Signature · 1 line
2.54.0 (Apple Git-157)
Reviewed-by on v1 13/13
#26 lore raw

Re: [PATCH next 13/13] board: CZ.NIC: turris_1x: Fix up MACs and serial number from OTP

Quoted 15 lines · Josef Schlehofer

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.

Quoted 8 lines

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")
Cc Marek Mojík <[email protected]>
Cc Marek Behún <[email protected]>
Cc Priyanka Jain <[email protected]>
Tested-by on the v1 series
#27 lore raw
In reply to Josef Schlehofer
Quoted 4 lines · Josef Schlehofer

This series allows LTO on mpc85xx and enables it for the CZ.NIC Turris 1.x, whose NOR image has a 768 KiB limit. LTO, together with dropping NVMe and SCSI from the NOR build, makes room for the ubi command and the BCH ECC code that the Turris NAND needs.

Tested on a Turris 1.1, built with kernel.org GCC 14.2:

- turris_1x_sdcard: the SPL loads the LTO u-boot from sdcard, NAND probes without BUG() and UBI attaches and boots.
- turris_1x_nor: the LTO u-boot boots from NOR, NAND probes without BUG() and UBI attaches.
- After an environment reset the OTP MAC and serial number are inserted into device tree in both builds.

I will test the v2 again once it's in.