Skip to contentSkip to conversation

Avoid build failure on veyron board

PATCH In review Alvaro Fernando García 3 participants 6 messages Aug 4, 2023 – Aug 12, 2023 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

cover Avoid build failure on veyron board

I noticed that u-boot stopped building for Veyron boards since commit 533ad9dc, which may also affect other 32bit boards.

This series fixes compilation by using div_u64 operation.

I apologize for any inconvenient, this is my first patch.

Alvaro Fernando García (1):
video: avoid build failure on veyron board

 drivers/video/pwm_backlight.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/1 video: avoid build failure on veyron board

533ad9dc avoided an overflow but causes compilation failure on 32bit boards (eg. veyron speedy)

this commit uses div_u64 which has a fallback codepath for 32bit platforms

---

 drivers/video/pwm_backlight.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/video/pwm_backlight.c +5 -2
index 46c16a8f44..aa0e292866 100644
@@ -14,6 +14,7 @@
 #include <pwm.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <power/regulator.h>
 
 /**
@@ -59,12 +60,14 @@ struct pwm_backlight_priv {
 
 static int set_pwm(struct pwm_backlight_priv *priv)
 {
+	u64 width;
 	uint duty_cycle;
 	int ret;
 
 	if (priv->period_ns) {
-		duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) /
-			(priv->max_level - priv->min_level);
+		width = priv->period_ns * (priv->cur_level - priv->min_level);
+		duty_cycle = div_u64(width,
+				     (priv->max_level - priv->min_level));
 		ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
 				     duty_cycle);
 	} else {
Signature · 1 line
2.41.0
Tested-by on v1 1/1
#2 lore raw

Re: [PATCH 1/1] video: avoid build failure on veyron board

Hi,

Quoted 4 lines · Alvaro Fernando García

533ad9dc avoided an overflow but causes compilation failure on 32bit boards (eg. veyron speedy)

Quoted 8 lines

this commit uses div_u64 which has a fallback codepath for 32bit platforms

---

 drivers/video/pwm_backlight.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Can you please advise which toolchain you are using and what the warning actually says? I don't see this on my board.

Quoted 31 lines
drivers/video/pwm_backlight.c +5 -3
index 46c16a8f44..aa0e292866 100644
@@ -14,6 +14,7 @@
 #include <pwm.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <power/regulator.h>
 
 /**
@@ -59,12 +60,14 @@ struct pwm_backlight_priv {
 
 static int set_pwm(struct pwm_backlight_priv *priv)
 {
+       u64 width;
        uint duty_cycle;
        int ret;
 
        if (priv->period_ns) {
-               duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) /
-                       (priv->max_level - priv->min_level);
+               width = priv->period_ns * (priv->cur_level - priv->min_level);
+               duty_cycle = div_u64(width,
+                                    (priv->max_level - priv->min_level));
                ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
                                     duty_cycle);
        } else {
--
Quoted 2 lines

2.41.0

Regards,
Simon

#3 lore raw

Re: [PATCH 1/1] video: avoid build failure on veyron board

Hello Simon,

Quoted 55 lines · Simon Glass

Hi,

Quoted 4 lines · Alvaro Fernando García

533ad9dc avoided an overflow but causes compilation failure on 32bit boards (eg. veyron speedy)

Quoted 8 lines

this commit uses div_u64 which has a fallback codepath for 32bit platforms

---

 drivers/video/pwm_backlight.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Can you please advise which toolchain you are using and what the warning actually says? I don't see this on my board.

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/video/pwm_backlight.c

Quoted 12 lines

index 46c16a8f44..aa0e292866 100644

drivers/video/pwm_backlight.c +1 -0
@@ -14,6 +14,7 @@
 #include <pwm.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <power/regulator.h>
 
 /**

drivers/video/pwm_backlight.c struct pwm_backlight_priv { · line 66

Quoted 9 lines
drivers/video/pwm_backlight.c +1 -1
@@ -59,12 +60,14 @@ struct pwm_backlight_priv {
 
 static int set_pwm(struct pwm_backlight_priv *priv)
 {
+       u64 width;
        uint duty_cycle;
        int ret;
 
        if (priv->period_ns) {
-               duty_cycle = (u64)priv->period_ns * (priv->cur_level -

priv->min_level) /

drivers/video/pwm_backlight.c struct pwm_backlight_priv { · line 68

Quoted 2 lines
drivers/video/pwm_backlight.c +1 -1
-                       (priv->max_level - priv->min_level);
+               width = priv->period_ns * (priv->cur_level -

priv->min_level);

drivers/video/pwm_backlight.c struct pwm_backlight_priv { · line 70

Quoted 2 lines
drivers/video/pwm_backlight.c +2 -0
+               duty_cycle = div_u64(width,
+                                    (priv->max_level -

priv->min_level));

drivers/video/pwm_backlight.c struct pwm_backlight_priv { · line 71

Quoted 1 line
drivers/video/pwm_backlight.c +0 -0
                ret = pwm_set_config(priv->pwm, priv->channel,

priv->period_ns,

Quoted 9 lines
Quoted 5 lines
drivers/video/pwm_backlight.c +0 -1
                                     duty_cycle);
        } else {
--

2.41.0

Regards,
Simon

I built U-Boot on a Debian Bookworm container following these steps:

make distclean

Quoted 2 lines

make chromebook_speedy_defconfig
make -j8

Container is using these gcc and linker versions:

# gcc --version
Quoted 1 line

gcc (Debian 12.2.0-14) 12.2.0

# ld --version
Quoted 1 line

GNU ld (GNU Binutils for Debian) 2.40

The error I was getting before the patch is this one:

ld.bfd: error: /usr/lib/gcc/arm-linux-gnueabihf/12/libgcc.a(_udivmoddi4.o)

Quoted 8 lines

uses VFP register arguments, u-boot does not
ld.bfd: warning:
/usr/lib/gcc/arm-linux-gnueabihf/12/libgcc.a(_udivmoddi4.o) uses 4-byte wchar_t yet the output is to use 2-byte wchar_t; use of wchar_t values across objects may fail
ld.bfd: failed to merge target specific data of file /usr/lib/gcc/arm-linux-gnueabihf/12/libgcc.a(_udivmoddi4.o)
make: *** [Makefile:1764: u-boot] Error 1

Please do tell me if there is any other information I can provide.

Signature · 2 lines
Alvaro F. García
Functional-oriented Software Architect
#4 lore raw

Re: [PATCH 1/1] video: avoid build failure on veyron board

Hi Alvaro,

Quoted 84 lines · Alvaro Fernando García

Hello Simon,

Quoted 44 lines · Simon Glass

Hi,

Quoted 4 lines · Alvaro Fernando García

533ad9dc avoided an overflow but causes compilation failure on 32bit boards (eg. veyron speedy)

Quoted 8 lines

this commit uses div_u64 which has a fallback codepath for 32bit platforms

---

 drivers/video/pwm_backlight.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Can you please advise which toolchain you are using and what the warning actually says? I don't see this on my board.

Quoted 21 lines
drivers/video/pwm_backlight.c +2 -0
index 46c16a8f44..aa0e292866 100644
@@ -14,6 +14,7 @@
 #include <pwm.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <power/regulator.h>
 
 /**
@@ -59,12 +60,14 @@ struct pwm_backlight_priv {
 
 static int set_pwm(struct pwm_backlight_priv *priv)
 {
+       u64 width;
        uint duty_cycle;
        int ret;
 
Quoted 15 lines
Quoted 10 lines
drivers/video/pwm_backlight.c +3 -3
        if (priv->period_ns) {
-               duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) /
-                       (priv->max_level - priv->min_level);
+               width = priv->period_ns * (priv->cur_level - priv->min_level);
+               duty_cycle = div_u64(width,
+                                    (priv->max_level - priv->min_level));
                ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
                                     duty_cycle);
        } else {
--
Quoted 2 lines

2.41.0

Regards,
Simon

I built U-Boot on a Debian Bookworm container following these steps:

Quoted 3 lines

make distclean
make chromebook_speedy_defconfig
make -j8

Container is using these gcc and linker versions:

Quoted 6 lines
# gcc --version
gcc (Debian 12.2.0-14) 12.2.0
# ld --version
GNU ld (GNU Binutils for Debian) 2.40

The error I was getting before the patch is this one:

Quoted 7 lines
Quoted 4 lines

ld.bfd: error: /usr/lib/gcc/arm-linux-gnueabihf/12/libgcc.a(_udivmoddi4.o) uses VFP register arguments, u-boot does not
ld.bfd: warning: /usr/lib/gcc/arm-linux-gnueabihf/12/libgcc.a(_udivmoddi4.o) uses 4-byte wchar_t yet the output is to use 2-byte wchar_t; use of wchar_t values across objects may fail ld.bfd: failed to merge target specific data of file /usr/lib/gcc/arm-linux-gnueabihf/12/libgcc.a(_udivmoddi4.o)
make: *** [Makefile:1764: u-boot] Error 1

Please do tell me if there is any other information I can provide.

OK, thank you.

Regards,
Simon

Reviewed-by on v1 1/1
#5 lore raw

Re: [PATCH 1/1] video: avoid build failure on veyron board

In reply to Alvaro Fernando García
Quoted 7 lines · Alvaro Fernando García

533ad9dc avoided an overflow but causes compilation failure on 32bit boards (eg. veyron speedy)

this commit uses div_u64 which has a fallback codepath for 32bit platforms

Thanks,
- Kever

Quoted 34 lines

---

  drivers/video/pwm_backlight.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/video/pwm_backlight.c +5 -2
index 46c16a8f44..aa0e292866 100644
@@ -14,6 +14,7 @@
  #include <pwm.h>
  #include <asm/gpio.h>
  #include <linux/delay.h>
+#include <linux/math64.h>
  #include <power/regulator.h>
 
  /**
@@ -59,12 +60,14 @@ struct pwm_backlight_priv {
 
  static int set_pwm(struct pwm_backlight_priv *priv)
  {
+	u64 width;
  	uint duty_cycle;
  	int ret;
 
  	if (priv->period_ns) {
-		duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) /
-			(priv->max_level - priv->min_level);
+		width = priv->period_ns * (priv->cur_level - priv->min_level);
+		duty_cycle = div_u64(width,
+				     (priv->max_level - priv->min_level));
  		ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
  				     duty_cycle);
  	} else {