Skip to contentSkip to conversation

fpga: add inline stub for fpga_load

PATCH RESEND In review Eugen Hristev 3 participants 6 messages Aug 8, 2023 – Aug 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v3 1/1 fpga: add inline stub for fpga_load

In case CC_OPTIMIZE_FOR_DEBUG is set, unused code will not be optimized out, hence the reference to fpga_load will be compiled.
if DM_FPGA and SPL_FPGA are not set, the build will fail with :

aarch64-none-linux-gnu-ld.bfd: common/spl/spl_fit.o: in function `spl_fit_upload_fpga':
u-boot/common/spl/spl_fit.c:595: undefined reference to `fpga_load'

To solve this, added an inline empty stub in the header if CC_OPTIMIZE_FOR_DEBUG is set such that the build will succeed.

---
Changes in v3:
- return -ENOSYS
Changes in v2:
- this is a rework as suggested by Simon of this previous patch :
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

 include/fpga.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/fpga.h +9 -0
index ed688cc0fa3b..33d0dbbe2ba4 100644
@@ -60,8 +60,17 @@ int fpga_add(fpga_type devtype, void *desc);
 int fpga_count(void);
 const fpga_desc *const fpga_get_desc(int devnum);
 int fpga_is_partial_data(int devnum, size_t img_len);
+#if defined(CONFIG_CC_OPTIMIZE_FOR_DEBUG)
+static inline int fpga_load(int devnum, const void *buf, size_t bsize,
+			    bitstream_type bstype, int flags)
+{
+	return -ENOSYS;
+}
+#else
 int fpga_load(int devnum, const void *buf, size_t bsize,
 	      bitstream_type bstype, int flags);
+#endif
+
 int fpga_fsload(int devnum, const void *buf, size_t size,
 		fpga_fs_info *fpga_fsinfo);
 int fpga_loads(int devnum, const void *buf, size_t size,
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 33 lines · Eugen Hristev

In case CC_OPTIMIZE_FOR_DEBUG is set, unused code will not be optimized out, hence the reference to fpga_load will be compiled.
if DM_FPGA and SPL_FPGA are not set, the build will fail with :

aarch64-none-linux-gnu-ld.bfd: common/spl/spl_fit.o: in function `spl_fit_upload_fpga':
u-boot/common/spl/spl_fit.c:595: undefined reference to `fpga_load'

To solve this, added an inline empty stub in the header if CC_OPTIMIZE_FOR_DEBUG is set such that the build will succeed.

---
Changes in v3:
- return -ENOSYS
Changes in v2:
- this is a rework as suggested by Simon of this previous patch :
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

  include/fpga.h | 9 +++++++++
  1 file changed, 9 insertions(+)
include/fpga.h +4 -0
index ed688cc0fa3b..33d0dbbe2ba4 100644
@@ -60,8 +60,17 @@ int fpga_add(fpga_type devtype, void *desc);
  int fpga_count(void);
  const fpga_desc *const fpga_get_desc(int devnum);
  int fpga_is_partial_data(int devnum, size_t img_len);
+#if defined(CONFIG_CC_OPTIMIZE_FOR_DEBUG)
+static inline int fpga_load(int devnum, const void *buf, size_t bsize,
+			    bitstream_type bstype, int flags)
+{

include/fpga.h int fpga_add(fpga_type devtype, void *desc); · line 76

Quoted 10 lines
include/fpga.h +5 -0
+	return -ENOSYS;
+}
+#else
  int fpga_load(int devnum, const void *buf, size_t bsize,
  	      bitstream_type bstype, int flags);
+#endif
+
  int fpga_fsload(int devnum, const void *buf, size_t size,
  		fpga_fs_info *fpga_fsinfo);
  int fpga_loads(int devnum, const void *buf, size_t size,

Actually there is another patch targeting the same code. Please take a look at
https://lore.kernel.org/r/[email protected]
and get Chanho on board and create a patch to cover both cases.

Thanks,
Michal

#2 lore raw
Quoted 52 lines · Michal Simek

Hi,

Quoted 33 lines · Eugen Hristev

In case CC_OPTIMIZE_FOR_DEBUG is set, unused code will not be optimized out, hence the reference to fpga_load will be compiled.
if DM_FPGA and SPL_FPGA are not set, the build will fail with :

aarch64-none-linux-gnu-ld.bfd: common/spl/spl_fit.o: in function `spl_fit_upload_fpga':
u-boot/common/spl/spl_fit.c:595: undefined reference to `fpga_load'

To solve this, added an inline empty stub in the header if CC_OPTIMIZE_FOR_DEBUG is set such that the build will succeed.

---
Changes in v3:
- return -ENOSYS
Changes in v2:
- this is a rework as suggested by Simon of this previous patch :
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

  include/fpga.h | 9 +++++++++

  1 file changed, 9 insertions(+)
include/fpga.h +4 -0
index ed688cc0fa3b..33d0dbbe2ba4 100644
@@ -60,8 +60,17 @@ int fpga_add(fpga_type devtype, void *desc);
   int fpga_count(void);
   const fpga_desc *const fpga_get_desc(int devnum);
   int fpga_is_partial_data(int devnum, size_t img_len);
+#if defined(CONFIG_CC_OPTIMIZE_FOR_DEBUG)
+static inline int fpga_load(int devnum, const void *buf, size_t bsize,
+                bitstream_type bstype, int flags)
+{

include/fpga.h int fpga_add(fpga_type devtype, void *desc); · line 76

Quoted 10 lines
include/fpga.h +5 -0
+    return -ENOSYS;
+}
+#else
   int fpga_load(int devnum, const void *buf, size_t bsize,
             bitstream_type bstype, int flags);
+#endif
+
   int fpga_fsload(int devnum, const void *buf, size_t size,
           fpga_fs_info *fpga_fsinfo);
   int fpga_loads(int devnum, const void *buf, size_t size,

Actually there is another patch targeting the same code. Please take a look at
https://lore.kernel.org/r/[email protected]
and get Chanho on board and create a patch to cover both cases.

Quoted 2 lines

Thanks,
Michal

Hello Michal,

Looking at Chanho's patch, it appears that he is solving the same issue. These are not two separate cases.
He fixed it the other way around : if CONFIG_FPGA define the right prototype, else define the stub, while I did if CONFIG_DEBUG define stub, else define the right prototype.

I think you should select the patch that you deem more appropriate to fix this, I don't mind which one.

Thanks,
Eugen

#3 lore raw
In reply to Eugen Hristev

Hi Eugen, + Chanho,

Quoted 3 lines · Eugen Hristev

In case CC_OPTIMIZE_FOR_DEBUG is set, unused code will not be optimized out, hence the reference to fpga_load will be compiled.
if DM_FPGA and SPL_FPGA are not set, the build will fail with :

this is not correct. It is not DM_FPGA but only FPGA.

Quoted 23 lines

aarch64-none-linux-gnu-ld.bfd: common/spl/spl_fit.o: in function `spl_fit_upload_fpga':
u-boot/common/spl/spl_fit.c:595: undefined reference to `fpga_load'

To solve this, added an inline empty stub in the header if CC_OPTIMIZE_FOR_DEBUG is set such that the build will succeed.

---
Changes in v3:
- return -ENOSYS
Changes in v2:
- this is a rework as suggested by Simon of this previous patch :
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

  include/fpga.h | 9 +++++++++
  1 file changed, 9 insertions(+)
include/fpga.h +0 -0
index ed688cc0fa3b..33d0dbbe2ba4 100644

include/fpga.h int fpga_add(fpga_type devtype, void *desc); · line 63

Quoted 4 lines
include/fpga.h +1 -0
@@ -60,8 +60,17 @@ int fpga_add(fpga_type devtype, void *desc);
  int fpga_count(void);
  const fpga_desc *const fpga_get_desc(int devnum);
  int fpga_is_partial_data(int devnum, size_t img_len);
+#if defined(CONFIG_CC_OPTIMIZE_FOR_DEBUG)

And when you enable CONFIG_CC_OPTIMIZE_FOR_DEBUG and FPGA you get compilation warnings.

drivers/fpga/fpga.c:265:5: error: redefinition of 'fpga_load'
265 | int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type
bstype,

      |     ^~~~~~~~~

In file included from include/xilinx.h:7,
from drivers/fpga/fpga.c:11:
include/fpga.h:64:19: note: previous definition of 'fpga_load' with type 'int(int, const void *, size_t, bitstream_type, int)' {aka 'int(int, const void *, long unsigned int, bitstream_type, int)'}
64 | static inline int fpga_load(int devnum, const void *buf, size_t bsize,

      |                   ^~~~~~~~~

make[2]: *** [scripts/Makefile.build:257: drivers/fpga/fpga.o] Error 1

I means please tune that condition properly not to create additional compilation warnings for other combinations.

Thanks,
Michal

Quoted 13 lines
include/fpga.h +8 -0
+static inline int fpga_load(int devnum, const void *buf, size_t bsize,
+			    bitstream_type bstype, int flags)
+{
+	return -ENOSYS;
+}
+#else
  int fpga_load(int devnum, const void *buf, size_t bsize,
  	      bitstream_type bstype, int flags);
+#endif
+
  int fpga_fsload(int devnum, const void *buf, size_t size,
  		fpga_fs_info *fpga_fsinfo);
  int fpga_loads(int devnum, const void *buf, size_t size,
#4 lore raw
Quoted 52 lines · Michal Simek

Hi Eugen, + Chanho,

Quoted 3 lines · Eugen Hristev

In case CC_OPTIMIZE_FOR_DEBUG is set, unused code will not be optimized out, hence the reference to fpga_load will be compiled.
if DM_FPGA and SPL_FPGA are not set, the build will fail with :

this is not correct. It is not DM_FPGA but only FPGA.

Quoted 23 lines

aarch64-none-linux-gnu-ld.bfd: common/spl/spl_fit.o: in function `spl_fit_upload_fpga':
u-boot/common/spl/spl_fit.c:595: undefined reference to `fpga_load'

To solve this, added an inline empty stub in the header if CC_OPTIMIZE_FOR_DEBUG is set such that the build will succeed.

---
Changes in v3:
- return -ENOSYS
Changes in v2:
- this is a rework as suggested by Simon of this previous patch :
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

  include/fpga.h | 9 +++++++++

  1 file changed, 9 insertions(+)
include/fpga.h +0 -0
index ed688cc0fa3b..33d0dbbe2ba4 100644

include/fpga.h int fpga_add(fpga_type devtype, void *desc); · line 63

Quoted 4 lines
include/fpga.h +1 -0
@@ -60,8 +60,17 @@ int fpga_add(fpga_type devtype, void *desc);
   int fpga_count(void);
   const fpga_desc *const fpga_get_desc(int devnum);
   int fpga_is_partial_data(int devnum, size_t img_len);
+#if defined(CONFIG_CC_OPTIMIZE_FOR_DEBUG)

And when you enable CONFIG_CC_OPTIMIZE_FOR_DEBUG and FPGA you get compilation warnings.

drivers/fpga/fpga.c:265:5: error: redefinition of 'fpga_load'
  265 | int fpga_load(int devnum, const void *buf, size_t bsize,
bitstream_type bstype,
      |     ^~~~~~~~~
In file included from include/xilinx.h:7,
                 from drivers/fpga/fpga.c:11:
include/fpga.h:64:19: note: previous definition of 'fpga_load' with type 'int(int,  const void *, size_t,  bitstream_type,  int)' {aka 'int(int, const void *, long unsigned int,  bitstream_type,  int)'}
   64 | static inline int fpga_load(int devnum, const void *buf, size_t
bsize,
      |                   ^~~~~~~~~
make[2]: *** [scripts/Makefile.build:257: drivers/fpga/fpga.o] Error 1

Quoted 5 lines

I means please tune that condition properly not to create additional compilation warnings for other combinations.

Thanks,
Michal

Hello Michal,

Thanks for reviewing .

Chanho, I cannot try this at the moment, if you are in a hurry you can send a v4 or v2 to your patch addressing this (or maybe your patch does not have this problem)

Thanks,
Eugen

Quoted 14 lines
Quoted 14 lines
include/fpga.h +8 -0
+static inline int fpga_load(int devnum, const void *buf, size_t bsize,
+                bitstream_type bstype, int flags)
+{
+    return -ENOSYS;
+}
+#else
   int fpga_load(int devnum, const void *buf, size_t bsize,
             bitstream_type bstype, int flags);
+#endif
+
   int fpga_fsload(int devnum, const void *buf, size_t size,
           fpga_fs_info *fpga_fsinfo);
   int fpga_loads(int devnum, const void *buf, size_t size,
#5 lore raw

Hi Eugen,

Quoted 74 lines

-----Original Message-----
From: Eugen Hristev <[email protected]>
Sent: Monday, August 28, 2023 8:47 PM
To: Michal Simek <[email protected]>; [email protected]; [email protected]; Chanho Park <[email protected]>
Subject: Re: [PATCH RESEND v3] fpga: add inline stub for fpga_load

Quoted 56 lines · Michal Simek

Hi Eugen, + Chanho,

Quoted 3 lines · Eugen Hristev

In case CC_OPTIMIZE_FOR_DEBUG is set, unused code will not be optimized out, hence the reference to fpga_load will be compiled. if DM_FPGA and SPL_FPGA are not set, the build will fail with :

this is not correct. It is not DM_FPGA but only FPGA.

Quoted 27 lines

aarch64-none-linux-gnu-ld.bfd: common/spl/spl_fit.o: in function `spl_fit_upload_fpga':
u-boot/common/spl/spl_fit.c:595: undefined reference to `fpga_load'

To solve this, added an inline empty stub in the header if CC_OPTIMIZE_FOR_DEBUG is set such that the build will succeed.

---
Changes in v3:
- return -ENOSYS
Changes in v2:
- this is a rework as suggested by Simon of this previous patch :
https://protect2.fireeye.com/v1/url?k=eed360f4-8f5875c2-eed2ebbb-74fe
485cbff1-6ddceb7720c8265c&q=1&e=f4039d69-e052-4de7-b3b0-f25e8f4581a3& u=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F2023 0619102839.277902-1-eugen.hristev%40collabora.com%2F

  include/fpga.h | 9 +++++++++
  1 file changed, 9 insertions(+)
include/fpga.h index renamed from include/fpga.h +0 -0

ed688cc0fa3b..33d0dbbe2ba4 100644

include/fpga.h int fpga_add(fpga_type devtype, void *desc); · line 63

Quoted 4 lines
include/fpga.h +1 -0
@@ -60,8 +60,17 @@ int fpga_add(fpga_type devtype, void *desc);
  int fpga_count(void);
  const fpga_desc *const fpga_get_desc(int devnum);
  int fpga_is_partial_data(int devnum, size_t img_len);
+#if defined(CONFIG_CC_OPTIMIZE_FOR_DEBUG)

And when you enable CONFIG_CC_OPTIMIZE_FOR_DEBUG and FPGA you get compilation warnings.

drivers/fpga/fpga.c:265:5: error: redefinition of 'fpga_load'
265 | int fpga_load(int devnum, const void *buf, size_t bsize,
bitstream_type bstype,

       |     ^~~~~~~~~

In file included from include/xilinx.h:7,
from drivers/fpga/fpga.c:11:
include/fpga.h:64:19: note: previous definition of 'fpga_load' with type 'int(int, const void *, size_t, bitstream_type, int)' {aka 'int(int, const void *, long unsigned int, bitstream_type, int)'}
64 | static inline int fpga_load(int devnum, const void *buf,
size_t bsize,

Quoted 9 lines
       |                   ^~~~~~~~~

make[2]: *** [scripts/Makefile.build:257: drivers/fpga/fpga.o] Error 1

I means please tune that condition properly not to create additional compilation warnings for other combinations.

Thanks,
Michal

Quoted 7 lines

Hello Michal,

Thanks for reviewing .

Chanho, I cannot try this at the moment, if you are in a hurry you can send a v4 or v2 to your patch addressing this (or maybe your patch does not have this problem)

Sure. Actually, my patch does not have the problem. Michal, could review my patch?

Best Regards,
Chanho Park