[PATCH 0/1] 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(-)

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
Signed-off-by: Alvaro Fernando García alvarofernandogarcia@gmail.com ---
drivers/video/pwm_backlight.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index 46c16a8f44..aa0e292866 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -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 {

Hi,
On Thu, 3 Aug 2023 at 18:37, Alvaro Fernando García alvarofernandogarcia@gmail.com wrote:
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
Signed-off-by: Alvaro Fernando García alvarofernandogarcia@gmail.com
drivers/video/pwm_backlight.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Tested-by: Simon Glass sjg@chromium.org # chromebook_jerry
Can you please advise which toolchain you are using and what the warning actually says? I don't see this on my board.
diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index 46c16a8f44..aa0e292866 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -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 {
-- 2.41.0
Regards, Simon

Hello Simon,
El vie, 4 ago 2023 a la(s) 00:02, Simon Glass (sjg@google.com) escribió:
Hi,
On Thu, 3 Aug 2023 at 18:37, Alvaro Fernando García alvarofernandogarcia@gmail.com wrote:
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
Signed-off-by: Alvaro Fernando García alvarofernandogarcia@gmail.com
drivers/video/pwm_backlight.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Tested-by: Simon Glass sjg@chromium.org # chromebook_jerry
Can you please advise which toolchain you are using and what the warning actually says? I don't see this on my board.
diff --git a/drivers/video/pwm_backlight.c
b/drivers/video/pwm_backlight.c
index 46c16a8f44..aa0e292866 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -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 {
-- 2.41.0
Regards, Simon
I built U-Boot on a Debian Bookworm container following these steps:
make distclean
make chromebook_speedy_defconfig make -j8
Container is using these gcc and linker versions:
# 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:
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.

Hi Alvaro,
On Fri, 4 Aug 2023 at 06:42, Alvaro Fernando García alvarofernandogarcia@gmail.com wrote:
Hello Simon,
El vie, 4 ago 2023 a la(s) 00:02, Simon Glass (sjg@google.com) escribió:
Hi,
On Thu, 3 Aug 2023 at 18:37, Alvaro Fernando García alvarofernandogarcia@gmail.com wrote:
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
Signed-off-by: Alvaro Fernando García alvarofernandogarcia@gmail.com
drivers/video/pwm_backlight.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Tested-by: Simon Glass sjg@chromium.org # chromebook_jerry
Can you please advise which toolchain you are using and what the warning actually says? I don't see this on my board.
diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index 46c16a8f44..aa0e292866 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -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 {
-- 2.41.0
Regards, Simon
I built U-Boot on a Debian Bookworm container following these steps:
make distclean make chromebook_speedy_defconfig make -j8
Container is using these gcc and linker versions:
# 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:
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

On 2023/8/4 08:35, Alvaro Fernando García wrote:
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
Signed-off-by: Alvaro Fernando García alvarofernandogarcia@gmail.com
Reviewed-by: Kever Yang kever.yang@rock-chips.com
Thanks, - Kever
drivers/video/pwm_backlight.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index 46c16a8f44..aa0e292866 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -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,
ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns, duty_cycle); } else {(priv->max_level - priv->min_level));
participants (3)
-
Alvaro Fernando García
-
Kever Yang
-
Simon Glass