Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makefiles/boot/riotboot: clean bootloader when cleaning application #16197

Merged
merged 1 commit into from
Jun 15, 2021

Conversation

fjmolinas
Copy link
Contributor

@fjmolinas fjmolinas commented Mar 16, 2021

Contribution description

When using riotboot conveniently the extended binary is used. But if clean is also used then the bootloader binary is not cleaned, this can lead to unexpected behavior where a previous bootloader (eg: different start addresses) is used.

Testing procedure

  • make -C tests/riotboot flash
  • make -C tests/riotboot clean flash -j3 you should see that that the bootloader and application are compiled while in master only the application is:
# application
"make" -C /home/francisco/workspace/RIOT2/boards/stm32f429i-disc1
"make" -C /home/francisco/workspace/RIOT2/core
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32
"make" -C /home/francisco/workspace/RIOT2/cpu/cortexm_common
"make" -C /home/francisco/workspace/RIOT2/cpu/cortexm_common/periph
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32/periph
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32/stmclk
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32/vectors
"make" -C /home/francisco/workspace/RIOT2/drivers
"make" -C /home/francisco/workspace/RIOT2/drivers/periph_common
"make" -C /home/francisco/workspace/RIOT2/sys
"make" -C /home/francisco/workspace/RIOT2/sys/auto_init
"make" -C /home/francisco/workspace/RIOT2/sys/checksum
"make" -C /home/francisco/workspace/RIOT2/sys/isrpipe
"make" -C /home/francisco/workspace/RIOT2/sys/malloc_thread_safe
"make" -C /home/francisco/workspace/RIOT2/sys/newlib_syscalls_default
"make" -C /home/francisco/workspace/RIOT2/sys/pm_layered
"make" -C /home/francisco/workspace/RIOT2/sys/riotboot
"make" -C /home/francisco/workspace/RIOT2/sys/shell
"make" -C /home/francisco/workspace/RIOT2/sys/shell/commands
"make" -C /home/francisco/workspace/RIOT2/sys/stdio_uart
"make" -C /home/francisco/workspace/RIOT2/sys/test_utils/interactive_sync
"make" -C /home/francisco/workspace/RIOT2/sys/tsrb
# bootloader
"make" -C /home/francisco/workspace/RIOT2/boards/stm32f429i-disc1
"make" -C /home/francisco/workspace/RIOT2/core
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32
"make" -C /home/francisco/workspace/RIOT2/cpu/cortexm_common
"make" -C /home/francisco/workspace/RIOT2/cpu/cortexm_common/periph
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32/periph
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32/stmclk
"make" -C /home/francisco/workspace/RIOT2/cpu/stm32/vectors
"make" -C /home/francisco/workspace/RIOT2/drivers
"make" -C /home/francisco/workspace/RIOT2/drivers/periph_common
"make" -C /home/francisco/workspace/RIOT2/sys
"make" -C /home/francisco/workspace/RIOT2/sys/checksum
"make" -C /home/francisco/workspace/RIOT2/sys/malloc_thread_safe
"make" -C /home/francisco/workspace/RIOT2/sys/newlib_syscalls_default
"make" -C /home/francisco/workspace/RIOT2/sys/riotboot
"make" -C /home/francisco/workspace/RIOT2/sys/stdio_null

What is actually called can be seen with this patch easily:

diff --git a/makefiles/boot/riotboot.mk b/makefiles/boot/riotboot.mk
index 164b6f7062..440f669b79 100644
--- a/makefiles/boot/riotboot.mk
+++ b/makefiles/boot/riotboot.mk
@@ -79,7 +79,7 @@ RIOTBOOT_CLEAN = $(if $(filter clean, $(MAKECMDGOALS)),riotboot/bootloader/clean
 # riotboot bootloader compile target
 riotboot/flash-bootloader: riotboot/bootloader/flash
 riotboot/bootloader/%: $(BUILDDEPS) | $$(filter-out $$@,$$(RIOTBOOT_CLEAN))
-       $(Q)/usr/bin/env -i \
+       /usr/bin/env -i \
                QUIET=$(QUIET) PATH="$(PATH)"\
                EXTERNAL_BOARD_DIRS="$(EXTERNAL_BOARD_DIRS)" BOARD=$(BOARD)\
                DEBUG_ADAPTER_ID=$(DEBUG_ADAPTER_ID) \

@fjmolinas fjmolinas added Area: build system Area: Build system Area: OTA Area: Over-the-air updates labels Mar 16, 2021
@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 16, 2021
# riotboot bootloader compile target
riotboot/flash-bootloader: riotboot/bootloader/flash
riotboot/bootloader/%: $(BUILDDEPS)
riotboot/bootloader/%: $(BUILDDEPS) | $$(filter-out $$@,$$(RIOTBOOT_CLEAN))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just add | $(CLEAN) here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, no, it must be riotboot/bootloader/clean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe riotboot/bootloader/clean can be added to "clean" as prerequisite?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does the trick as well.

@fjmolinas
Copy link
Contributor Author

Split out the secondexpansion part as it is now unrelated.

@fjmolinas
Copy link
Contributor Author

Split out the secondexpansion part as it is now unrelated.

Hmm this also introduces a circular dependency:

make: Circular /home/francisco/workspace/RIOT2/cpu/stm32/vectors/STM32F429xx.c <- clean dependency dropped.
make: Circular /home/francisco/workspace/RIOT2/cpu/stm32/include/irqs/f4/irqs.h <- clean dependency dropped.

@fjmolinas
Copy link
Contributor Author

Split out the secondexpansion part as it is now unrelated.

Hmm this also introduces a circular dependency:

make: Circular /home/francisco/workspace/RIOT2/cpu/stm32/vectors/STM32F429xx.c <- clean dependency dropped.
make: Circular /home/francisco/workspace/RIOT2/cpu/stm32/include/irqs/f4/irqs.h <- clean dependency dropped.

Only related to stm32 and the fact the build the vectors.

@fjmolinas
Copy link
Contributor Author

Split out the secondexpansion part as it is now unrelated.

Hmm this also introduces a circular dependency:

make: Circular /home/francisco/workspace/RIOT2/cpu/stm32/vectors/STM32F429xx.c <- clean dependency dropped.
make: Circular /home/francisco/workspace/RIOT2/cpu/stm32/include/irqs/f4/irqs.h <- clean dependency dropped.

Only related to stm32 and the fact the build the vectors.

I think I like the other version better, by adding it ti clean I'll get circular dependencies every time something extra is added to BUILDDEPS, make removes this on its own but it leads to these ugly messages. Do you have another suggestion otherwise @kaspar030? Maybe the latest change is not what you had in mind?

@fjmolinas
Copy link
Contributor Author

ping @kaspar030!

@github-actions github-actions bot removed the Area: OTA Area: Over-the-air updates label Jun 7, 2021
@fjmolinas
Copy link
Contributor Author

ping @kaspar030!

Figured out a solution with secondexpansion.

@fjmolinas fjmolinas added CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 7, 2021
@kaspar030
Copy link
Contributor

kaspar030 commented Jun 8, 2021

I think there is an issue:

riot/tests/riotboot on  pr/16197                                                                                                         [16/5152]
❯ BOARD=nrf52840dk make clean all -j                                      
Building application "tests_riotboot" for "nrf52840dk" with MCU "nrf52".
                                                                         
compiling /home/kaspar/src/riot/dist/tools/riotboot_gen_hdr/bin/genhdr... 
make: Nothing to be done for 'all'.                                      
"make" -C /home/kaspar/src/riot/boards/nrf52840dk
"make" -C /home/kaspar/src/riot/core                   
"make" -C /home/kaspar/src/riot/cpu/nrf52
"make" -C /home/kaspar/src/riot/drivers              
"make" -C /home/kaspar/src/riot/sys
"make" -C /home/kaspar/src/riot/boards/common/nrf52xxxdk
"make" -C /home/kaspar/src/riot/cpu/cortexm_common    
"make" -C /home/kaspar/src/riot/sys/auto_init              
"make" -C /home/kaspar/src/riot/drivers/periph_common
"make" -C /home/kaspar/src/riot/cpu/nrf52/periph
"make" -C /home/kaspar/src/riot/sys/checksum
"make" -C /home/kaspar/src/riot/cpu/nrf52/vectors
"make" -C /home/kaspar/src/riot/sys/isrpipe
"make" -C /home/kaspar/src/riot/sys/malloc_thread_safe
"make" -C /home/kaspar/src/riot/sys/newlib_syscalls_default
"make" -C /home/kaspar/src/riot/cpu/nrf5x_common
"make" -C /home/kaspar/src/riot/sys/riotboot
"make" -C /home/kaspar/src/riot/sys/shell
"make" -C /home/kaspar/src/riot/sys/shell/commands
"make" -C /home/kaspar/src/riot/sys/stdio_uart
"make" -C /home/kaspar/src/riot/sys/test_utils/interactive_sync
"make" -C /home/kaspar/src/riot/cpu/cortexm_common/periph
"make" -C /home/kaspar/src/riot/sys/tsrb
"make" -C /home/kaspar/src/riot/cpu/nrf5x_common/periph
"make" -C /home/kaspar/src/riot/boards/nrf52840dk
"make" -C /home/kaspar/src/riot/boards/common/nrf52xxxdk
creating /home/kaspar/src/riot/tests/riotboot/bin/nrf52840dk/tests_riotboot-slot0.1623144927.riot.bin...
   text    data     bss     dec     hex filename
  12772     128    2396   15296    3bc0 `
"make" -C /home/kaspar/src/riot/core 
"make" -C /home/kaspar/src/riot/cpu/nrf52
"make" -C /home/kaspar/src/riot/cpu/cortexm_common
"make" -C /home/kaspar/src/riot/cpu/cortexm_common/periph
"make" -C /home/kaspar/src/riot/cpu/nrf52/periph
"make" -C /home/kaspar/src/riot/cpu/nrf52/vectors
"make" -C /home/kaspar/src/riot/cpu/nrf5x_common
"make" -C /home/kaspar/src/riot/cpu/nrf5x_common/periph
"make" -C /home/kaspar/src/riot/drivers
"make" -C /home/kaspar/src/riot/drivers/periph_common
"make" -C /home/kaspar/src/riot/sys
"make" -C /home/kaspar/src/riot/sys/checksum
"make" -C /home/kaspar/src/riot/sys/malloc_thread_safe
"make" -C /home/kaspar/src/riot/sys/newlib_syscalls_default
"make" -C /home/kaspar/src/riot/sys/riotboot
"make" -C /home/kaspar/src/riot/sys/stdio_null
riot/tests/riotboot on  pr/16197 took 5s 
❯ 

see compilation going on (I think it is riotboot) after /home/kaspar/src/riot/tests/riotboot/bin/nrf52840dk/tests_riotboot.elf has been linked.

@kaspar030 kaspar030 self-assigned this Jun 8, 2021
@kaspar030
Copy link
Contributor

see compilation going on (I think it is riotboot) after /home/kaspar/src/riot/tests/riotboot/bin/nrf52840dk/tests_riotboot.elf has been linked.

This is actually alright, thanks @fjmolinas. The elf gets built, then the bootloader, then they get combined into the final .bin.

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

@fjmolinas fjmolinas merged commit 6756563 into RIOT-OS:master Jun 15, 2021
@fjmolinas fjmolinas deleted the pr_riotboot_submake_clean branch June 15, 2021 09:14
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants