4ms / mp1-boot

STM32MP15x Minimal Performant Bootloader
MIT License
7 stars 3 forks source link

missing abs during compile? #6

Closed mstaack closed 10 months ago

mstaack commented 11 months ago

gcc:

arm-none-eabi-gcc (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1 20231009
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

host:

Linux buildroot 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:29:11 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

error:

max@buildroot:~/stm32mp1-baremetal/bootloaders/mp1-boot$ nano mak^C
max@buildroot:~/stm32mp1-baremetal/bootloaders/mp1-boot$ ls
Makefile   boot_detect.hh     boot_loader.hh        boot_nor.hh  clocks.hh  delay.h         gpt            main.cc   pmic.hh            startup.s              systeminit.c  uboot-port
README.md  boot_image_def.hh  boot_media_loader.hh  boot_sd.hh   ddr        fsbl_header.py  linkscript.ld  norflash  print_messages.hh  stm32mp1xx_hal_conf.h  systeminit.h
max@buildroot:~/stm32mp1-baremetal/bootloaders/mp1-boot$ nano main.cc
max@buildroot:~/stm32mp1-baremetal/bootloaders/mp1-boot$ make
Building startup.s at -O3
Building main.cc at -O3
Building systeminit.c at -O3
Building ../../shared/system/syscalls.c at -O3
Building ../../shared/system/libc_stub.c at -O3
Building ../../shared/system/libcpp_stub.cc at -O3
Building ../../shared/print.cc at -O3
Building ../../third-party/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_ll_usart.c at -O3
Building ../../third-party/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_ll_rcc.c at -O3
Building ../../third-party/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal.c at -O3
Building ../../third-party/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_ll_sdmmc.c at -O3
Building ../../third-party/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_sd.c at -O3
Building ddr/stm32mp1_ddr.cc at -O3
Building ddr/stm32mp1_ram.cc at -O3
ddr/stm32mp1_ram.cc: In function 'int stm32mp1_ddr_clk_enable(ddr_info*, u32)':
ddr/stm32mp1_ram.cc:39:19: error: 'abs' was not declared in this scope
   39 |         ddr_clk = abs((int)ddrphy_clk - (int)mem_speed * 1000);
      |                   ^~~
make: *** [../../shared/makefile-common.mk:112: build/obj/obj/ddr/stm32mp1_ram.o] Error 1
danngreen commented 11 months ago

Thanks for the report.

I believe this is related to gcc 13's change in what is included with the -ffreestandingflag.

Since abs is the only function in the project that's no longer part of a freestanding environment with gcc 13, probably the most simple way to work around this is just define it ourselves. Another approach would be to remove the flag and change the return type of main, but I'm not certain this would not entail other unforeseen issues.

I'll push a fix for it.

mstaack commented 11 months ago

Great! Thanks for this repo/information about stm32mp1 booting and baremetal.

would it be possible to use this bootloader to then boot a real linux kernel? thinking about ditching u-boot

danngreen commented 10 months ago

I haven't tried that, but I think it would depend a lot on the kernel configuration. For instance, mp1-boot doesn't support FIT images or compressed kernel images, nor does it handle secure booting. It also doesn't configure a display, USB, or ethernet, nor does it pass any parameters to the kernel. There's probably a lot more to this list... You could configure a minimal kernel to not need any of those things, or you could implement the ones you need in mp1-boot. I'd be curious to see how it works out if you decide to tackle that.