Skip to contentSkip to conversation

rockchip: Fix TPL link error

PATCH In review FUKAUMI Naoki 2 participants 4 messages Feb 11, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 rockchip: Fix TPL link error

Rockchip RK3399 targets build TPL. If CONFIG_SPL_USB_DWC3_GENERIC and CONFIG_SPL_USB_GADGET are enabled, linking u-boot-tpl will fail.

LD tpl/u-boot-tpl
ld.bfd: drivers/usb/dwc3/dwc3-generic.o: in function `dwc3_glue_bind_common':
/home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:527:(.text.dwc3_glue_bind_common+0x20): undefined reference to usb_get_dr_mode' /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:527:(.text.dwc3_glue_bind_common+0x20): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol usb_get_dr_mode' ld.bfd: /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:529:(.text.dwc3_glue_bind_common+0x2c): undefined reference to usb_get_dr_mode' /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:529:(.text.dwc3_glue_bind_common+0x2c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol usb_get_dr_mode' ld.bfd: drivers/usb/dwc3/dwc3-generic.o: in function `dwc3_glue_probe':
/home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:683:(.text.dwc3_glue_probe+0xb0): undefined reference to usb_get_dr_mode' /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:683:(.text.dwc3_glue_probe+0xb0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol usb_get_dr_mode'

Do not compile drivers/usb/ for TPL.

---
Changes in v2:
- Move drivers/usb/{dwc,cdns}3 from scripts/Makefeile.xpl to drivers/Makefile
- Suppress unused warnings

---
 drivers/Makefile                | 2 ++
 drivers/usb/dwc3/dwc3-generic.c | 2 ++
 scripts/Makefile.xpl            | 2 --
 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/Makefile +2 -0
index 0e1f58c515b..3ec05b942de 100644
@@ -62,6 +62,8 @@ obj-$(CONFIG_ARCH_IMX9) += ddr/imx/imx9/
 obj-$(CONFIG_DRAM_SUN20I_D1) += ram/
 obj-$(CONFIG_SPL_DM_RESET) += reset/
 obj-$(CONFIG_SPL_MUSB_NEW) += usb/musb-new/
+obj-$(CONFIG_SPL_USB_GADGET) += usb/dwc3/
+obj-$(CONFIG_SPL_USB_GADGET) += usb/cdns3/
 obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/
 obj-$(CONFIG_SPL_USB_GADGET) += usb/common/
 obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/udc/
drivers/usb/dwc3/dwc3-generic.c +2 -0
index 55e62b35c61..8c2545bc2ec 100644
@@ -50,6 +50,7 @@ struct dwc3_generic_host_priv {
 	struct udevice *vbus_supply;
 };
 
+#if !CONFIG_IS_ENABLED(SPL_BUILD) || CONFIG_IS_ENABLED(SPL_USB_DWC3_GENERIC)
 static int dwc3_generic_probe(struct udevice *dev,
 			      struct dwc3_generic_priv *priv,
 			      enum usb_dr_mode mode)
@@ -192,6 +193,7 @@ static int dwc3_generic_of_to_plat(struct udevice *dev)
 
 	return 0;
 }
+#endif
 
 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
 static int dwc3_generic_peripheral_probe(struct udevice *dev)
scripts/Makefile.xpl +0 -2
index abc49fbe6c9..a819af8a9b7 100644
@@ -125,8 +125,6 @@ endif
 
 libs-y += drivers/
 libs-$(CONFIG_SPL_MEMORY) += drivers/memory/
-libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
-libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
 libs-y += dts/
 libs-y += fs/
 libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/2 rockchip: Fix SPL link error for Radxa ROCK Pi 4

If CONFIG_EFI_CAPSULE_FIRMWARE_RAW, CONFIG_SPL_ENV_SUPPORT, and CONFIG_SPL_DFU are enabled, linking u-boot-spl will fail.

LD spl/u-boot-spl
ld.bfd: drivers/dfu/dfu.o: in function `dfu_init_env_entities':
/home/radxa/u-boot/drivers/dfu/dfu.c:173:(.text.dfu_init_env_entities+0x24): undefined reference to `set_dfu_alt_info'

Separate the EFI specific parts from board.c into efi.c.

---
Changes in v2:
- Separate the EFI specific parts from board.c into efi.c

---
 arch/arm/mach-rockchip/Makefile |   1 +
 arch/arm/mach-rockchip/board.c  | 165 --------------------------
 arch/arm/mach-rockchip/efi.c    | 201 ++++++++++++++++++++++++++++++++
 3 files changed, 202 insertions(+), 165 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/efi.c
arch/arm/mach-rockchip/Makefile +1 -0
index 5e7edc99cdc..cf66a507c8e 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
 endif
 
 ifeq ($(CONFIG_TPL_BUILD),)
+obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += efi.o
 obj-$(CONFIG_DISPLAY_CPUINFO) += cpu-info.o
 endif
 
arch/arm/mach-rockchip/board.c +0 -165

171 lines not on this page · raw message

arch/arm/mach-rockchip/efi.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 2/2] rockchip: Fix SPL link error for Radxa ROCK Pi 4

Hi Naoki,

Quoted 9 lines · FUKAUMI Naoki

If CONFIG_EFI_CAPSULE_FIRMWARE_RAW, CONFIG_SPL_ENV_SUPPORT, and CONFIG_SPL_DFU are enabled, linking u-boot-spl will fail.

LD spl/u-boot-spl
ld.bfd: drivers/dfu/dfu.o: in function `dfu_init_env_entities':
/home/radxa/u-boot/drivers/dfu/dfu.c:173:(.text.dfu_init_env_entities+0x24): undefined reference to `set_dfu_alt_info'

Separate the EFI specific parts from board.c into efi.c.

The issue here is not EFI, it's SPL_DFU. It's because set_dfu_alt_info is contained in board.o which is only ever compiled for U-Boot proper.

Quoted 16 lines

---
Changes in v2:
- Separate the EFI specific parts from board.c into efi.c

---
  arch/arm/mach-rockchip/Makefile |   1 +
  arch/arm/mach-rockchip/board.c  | 165 --------------------------
  arch/arm/mach-rockchip/efi.c    | 201 ++++++++++++++++++++++++++++++++
  3 files changed, 202 insertions(+), 165 deletions(-)

create mode 100644 arch/arm/mach-rockchip/efi.c

arch/arm/mach-rockchip/Makefile +0 -0
index 5e7edc99cdc..cf66a507c8e 100644

arch/arm/mach-rockchip/Makefile obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o · line 29

Quoted 4 lines
arch/arm/mach-rockchip/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
  endif
 
  ifeq ($(CONFIG_TPL_BUILD),)
+obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += efi.o

Please have a separate commit for moving the code into efi.c but keep compiling efi.o the same way it is done for board.o and then in the next commit move efi.o to SPL only.

If I'm not mistaken, you simply need to move get_mmc_desc and set_dfu_alt_info in a file that you'll compile only if $(CONFIG_$(XPL_)DFU) = y.

The "issue" here is that you need get_mmc_desc also for EFI, but nothing that cannot be fixed by adding some stuff to some header and removing the static keyword :)

Also I would assume we still want to compile EFI and DFU support in xPL phases, e.g. for using DFU in SPL to boot U-Boot proper?

[...]

Quoted 6 lines
arch/arm/mach-rockchip/Makefile +0 -6
-__weak int rk_board_late_init(void)
-{
-	return 0;
-}
-
-int board_late_init(void)

arch/arm/mach-rockchip/Makefile obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o

Quoted 10 lines
arch/arm/mach-rockchip/Makefile +0 -10
-{
-	setup_boot_mode();
-
-#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)
-	gpt_capsule_update_setup();
-#endif
-
-	return rk_board_late_init();
-}
-

I don't think you should be moving board_late_init and rk_board_late_init to a different file, especially since this new file will not be compiled under the same rules as the current one. Therefore, we may now be missing board_late_init for some boards for example if I'm not mistaken.

Quoted 37 lines
  int board_init(void)
  {
  	return 0;
arch/arm/mach-rockchip/efi.c new file +28 -0
new file mode 100644
index 00000000000..5173a7c1b4e
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 Rockchip Electronics Co., Ltd.
+ *
+ * Copyright (C) 2019 Collabora Inc - https://www.collabora.com/
+ *      Rohan Garg <[email protected]>
+ *
+ * Based on puma-rk3399.c:
+ *      (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
+ */
+#include <config.h>
+#include <clk.h>
+#include <cpu_func.h>
+#include <env.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
+#include <efi_loader.h>
+#include <fastboot.h>
+#include <hash.h>
+#include <init.h>
+#include <log.h>
+#include <mmc.h>
+#include <dm/uclass-internal.h>
+#include <misc.h>
+#include <part.h>
+#include <ram.h>
+#include <syscon.h>
+#include <u-boot/uuid.h>

arch/arm/mach-rockchip/efi.c line 38

Quoted 10 lines
arch/arm/mach-rockchip/efi.c new file +10 -0
+#include <u-boot/crc.h>
+#include <u-boot/sha256.h>
+#include <asm/cache.h>
+#include <asm/io.h>
+#include <asm/arch-rockchip/boot_mode.h>
+#include <asm/arch-rockchip/clock.h>
+#include <asm/arch-rockchip/periph.h>
+#include <power/regulator.h>
+
+#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && IS_ENABLED(CONFIG_EFI_PARTITION)

Considering that almost the entirety of this file is guarded by this ifdef, maybe make the rule in the Makefile for building efi.c only added when this is the case, e.g.

ifeq ($(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)$(CONFIG_EFI_PARTITION),yy) obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += efi.o
endif

?

[...]
Cheers,
Quentin

#3 lore raw
In reply to FUKAUMI Naoki

Hi Naoki,

Quoted 13 lines · FUKAUMI Naoki

Rockchip RK3399 targets build TPL. If CONFIG_SPL_USB_DWC3_GENERIC and CONFIG_SPL_USB_GADGET are enabled, linking u-boot-tpl will fail.

LD tpl/u-boot-tpl
ld.bfd: drivers/usb/dwc3/dwc3-generic.o: in function `dwc3_glue_bind_common':
/home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:527:(.text.dwc3_glue_bind_common+0x20): undefined reference to usb_get_dr_mode' /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:527:(.text.dwc3_glue_bind_common+0x20): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol usb_get_dr_mode' ld.bfd: /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:529:(.text.dwc3_glue_bind_common+0x2c): undefined reference to usb_get_dr_mode' /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:529:(.text.dwc3_glue_bind_common+0x2c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol usb_get_dr_mode' ld.bfd: drivers/usb/dwc3/dwc3-generic.o: in function `dwc3_glue_probe':
/home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:683:(.text.dwc3_glue_probe+0xb0): undefined reference to usb_get_dr_mode' /home/radxa/u-boot/drivers/usb/dwc3/dwc3-generic.c:683:(.text.dwc3_glue_probe+0xb0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol usb_get_dr_mode'

Quoted 2 lines

Do not compile drivers/usb/ for TPL.

You should provide more info here because we do not get this information from the diff in this patch. Indeed it is compiled only for SPL, because the rules are added in a

ifndef CONFIG_TPL_BUILD
ifndef CONFIG_VPL_BUILD
ifdef CONFIG_XPL_BUILD

block which is essentially if stage == SPL.

Quoted 16 lines

---
Changes in v2:
- Move drivers/usb/{dwc,cdns}3 from scripts/Makefeile.xpl to drivers/Makefile
- Suppress unused warnings

---
  drivers/Makefile                | 2 ++
  drivers/usb/dwc3/dwc3-generic.c | 2 ++
  scripts/Makefile.xpl            | 2 --
  3 files changed, 4 insertions(+), 2 deletions(-)
drivers/Makefile +0 -0
index 0e1f58c515b..3ec05b942de 100644

drivers/Makefile obj-$(CONFIG_ARCH_IMX9) += ddr/imx/imx9/ · line 66

Quoted 5 lines
drivers/Makefile +2 -0
@@ -62,6 +62,8 @@ obj-$(CONFIG_ARCH_IMX9) += ddr/imx/imx9/
  obj-$(CONFIG_DRAM_SUN20I_D1) += ram/
  obj-$(CONFIG_SPL_DM_RESET) += reset/
  obj-$(CONFIG_SPL_MUSB_NEW) += usb/musb-new/
+obj-$(CONFIG_SPL_USB_GADGET) += usb/dwc3/
+obj-$(CONFIG_SPL_USB_GADGET) += usb/cdns3/

Please have a separate patch for moving the rule from scripts/Makefile.xpl to drivers/Makefile.

drivers/usb/dwc3/dwc3-generic.c struct dwc3_generic_host_priv { · line 53

Quoted 12 lines
drivers/Makefile +0 -0
  obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/
  obj-$(CONFIG_SPL_USB_GADGET) += usb/common/
  obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/udc/
drivers/usb/dwc3/dwc3-generic.c +1 -0
index 55e62b35c61..8c2545bc2ec 100644
@@ -50,6 +50,7 @@ struct dwc3_generic_host_priv {
  	struct udevice *vbus_supply;
  };
 
+#if !CONFIG_IS_ENABLED(SPL_BUILD) || CONFIG_IS_ENABLED(SPL_USB_DWC3_GENERIC)

It's not entirely clear what this should be fixing...

The users of that function are actually ifdef'ed by

CONFIG_IS_ENABLED(DM_USB_GADGET)

and

CONFIG_IS_ENABLED(USB_HOST)

so maybe just replace this with

#if CONFIG_IS_ENABLED(DM_USB_GADGET) || CONFIG_IS_ENABLED(USB_HOST)

instead? But please explain why this is needed?

Cheers,
Quentin