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

boards/frdm-kw41z-k64f: add riotboot #11562

Merged
merged 2 commits into from
Jun 7, 2019

Conversation

fjmolinas
Copy link
Contributor

@fjmolinas fjmolinas commented May 22, 2019

Contribution description

This PR adds riotboot support for kw41z. To do this the following changes had to be done:

  • modify tests/cortex_comon_ldscript to also work for kinetis
  • add script to prevent bricked kinetis when flashing binary files
  • handle rom_offset in kinetis.ld script

I know the linker script related changes should be in another PR but I wanted to get @cladmi feedback on them before splitting them up.

Testing procedure

Run ldscript test:

BOARD=frdm-kw41z APP_VER=$(date +%s) make -C tests/cortexm_common_ldscript/

Run riotboot tests:
BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C examples/hello-world/ riotboot/flash-extended-slot0

BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/xtimer_usleep riotboot/flash-extended-slot0

BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C examples/hello-world/ riotboot/flash-slot1

BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/xtimer_usleep riotboot/flash-slot1

Issues/PRs references

Depends on:

@fjmolinas fjmolinas added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Area: build system Area: Build system Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: OTA Area: Over-the-air updates labels May 22, 2019
@fjmolinas fjmolinas requested a review from cladmi May 22, 2019 07:43
@cladmi
Copy link
Contributor

cladmi commented May 22, 2019

Currently I have issue with the test output:

The board should be whitelisted here:

RIOT_CI_BUILD=1 BOARD=frdm-kw41z APP_VER=$(date +%s) make -C tests/cortexm_common_ldscript/
make: Entering directory '/home/harter/work/git/RIOT/tests/cortexm_common_ldscript'
The selected BOARD=frdm-kw41z is not whitelisted: iotlab-a8-m3 iotlab-m3 samr21-xpro arduino-mkr1000 arduino-mkrfox1200 arduino-mkrzero blackpill bluepill feather-m0 opencm904 spark-core


EXPECT ERRORS!


Building application "tests_cortexm_common_ldscript" for "frdm-kw41z" with MCU "kinetis".

   text    data     bss     dec     hex filename
   8928     116    2544   11588    2d44 /home/harter/work/git/RIOT/tests/cortexm_common_ldscript/bin/frdm-kw41z/tests_cortexm_common_ldscript.elf
Test rom offset 1 byte overflow detection: [OK]
Test rom offset substracted from rom length in elffile: [SKIP](Reason: board does not have a ROM_OFFSET configured)
Test compilation with offset 0x1000: [OK]
Test compilation with offset 0x2000: [OK]
Test compilation with half ROM length: [OK]
Test ROM overflow detection (too_big_for_rom): [OK]
Test ROM overflow detection (offset_and_romlen): [OK]
make: Leaving directory '/home/harter/work/git/RIOT/tests/cortexm_common_ldscript'

And the flash fails too with arithmetic expression: expeting primary: " + "

RIOT_CI_BUILD=1 BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C examples/hello-world/ riotboot/flash-extended-slot0
make: Entering directory '/home/harter/work/git/RIOT/examples/hello-world'
"make" -C /home/harter/work/git/RIOT/boards/frdm-kw41z
"make" -C /home/harter/work/git/RIOT/boards/common/kw41z
"make" -C /home/harter/work/git/RIOT/core
"make" -C /home/harter/work/git/RIOT/cpu/kinetis
"make" -C /home/harter/work/git/RIOT/cpu/cortexm_common
"make" -C /home/harter/work/git/RIOT/cpu/cortexm_common/periph
"make" -C /home/harter/work/git/RIOT/cpu/kinetis/periph
"make" -C /home/harter/work/git/RIOT/drivers
"make" -C /home/harter/work/git/RIOT/drivers/periph_common
"make" -C /home/harter/work/git/RIOT/sys
"make" -C /home/harter/work/git/RIOT/sys/checksum
"make" -C /home/harter/work/git/RIOT/sys/newlib_syscalls_default
"make" -C /home/harter/work/git/RIOT/sys/riotboot
"make" -C /home/harter/work/git/RIOT/sys/stdio_uart
compiling /home/harter/work/git/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
/bin/sh: 1: arithmetic expression: expecting primary: " + "
/home/harter/work/git/RIOT/makefiles/boot/riotboot.mk:25: recipe for target '/home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world-slot0.elf' failed
make: *** [/home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world-slot0.elf] Error 2
make: Leaving directory '/home/harter/work/git/RIOT/examples/hello-world'
RIOT_CI_BUILD=1 BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C examples/hello-world/ riotboot/flash-slot1 
make: Entering directory '/home/harter/work/git/RIOT/examples/hello-world'
compiling /home/harter/work/git/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
/bin/sh: 1: arithmetic expression: expecting primary: " + "
/home/harter/work/git/RIOT/makefiles/boot/riotboot.mk:25: recipe for target '/home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world-slot1.elf' failed
make: *** [/home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world-slot1.elf] Error 2
make: Leaving directory '/home/harter/work/git/RIOT/examples/hello-world'

And currently, tests/riotboot does not work:

RIOT_CI_BUILD=1 BOARD=frdm-kw41z make -C tests/riotboot  flash test
make: Entering directory '/home/harter/work/git/RIOT/tests/riotboot'
Building application "tests_riotboot" for "frdm-kw41z" with MCU "kinetis".

"make" -C /home/harter/work/git/RIOT/boards/frdm-kw41z
"make" -C /home/harter/work/git/RIOT/boards/common/kw41z
"make" -C /home/harter/work/git/RIOT/core
"make" -C /home/harter/work/git/RIOT/cpu/kinetis
"make" -C /home/harter/work/git/RIOT/cpu/cortexm_common
"make" -C /home/harter/work/git/RIOT/cpu/cortexm_common/periph
"make" -C /home/harter/work/git/RIOT/cpu/kinetis/periph
"make" -C /home/harter/work/git/RIOT/drivers
"make" -C /home/harter/work/git/RIOT/drivers/periph_common
"make" -C /home/harter/work/git/RIOT/sys
"make" -C /home/harter/work/git/RIOT/sys/checksum
"make" -C /home/harter/work/git/RIOT/sys/newlib_syscalls_default
"make" -C /home/harter/work/git/RIOT/sys/riotboot
"make" -C /home/harter/work/git/RIOT/sys/stdio_uart
compiling /home/harter/work/git/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0.riot.bin...
   text    data     bss     dec     hex filename
  12440     500    2608   15548    3cbc /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot.elf
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0-combined.bin
### Flashing Target ###
arm-none-eabi-objdump: /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0-combined.bin: File format not recognized
arm-none-eabi-objdump: section '.fcfield' mentioned in a -j option, but not found in any input file
Danger of bricking the device during flash!
Flash configuration field of /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0-combined.bin:
arm-none-eabi-objdump: /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0-combined.bin: File format not recognized
arm-none-eabi-objdump: section '.fcfield' mentioned in a -j option, but not found in any input file
Abort flash procedure!
pre-flash checks failed, status=1
/home/harter/work/git/RIOT/tests/riotboot/../../Makefile.include:538: recipe for target 'flash' failed
make: *** [flash] Error 1
make: Leaving directory '/home/harter/work/git/RIOT/tests/riotboot'

@fjmolinas
Copy link
Contributor Author

fjmolinas commented May 22, 2019

@cladmi

And the flash fails too with arithmetic expression: expeting primary: " + "

Oh... sorry I forgot that riotboot changed and know you need to USEMODULE += riotboot_slot in your application ... I'll open a PR to fix the dependency...

And currently, tests/riotboot does not work:
RIOT_CI_BUILD=1 BOARD=frdm-kw41z make -C tests/riotboot flash test

The command is RIOT_CI_BUILD=1 BOARD=frdm-kw41z make -C tests/riotboot riotboot/flash test

boards/common/frdm/Makefile.include Outdated Show resolved Hide resolved
cpu/kinetis/dist/check-fcfield-bin.sh Outdated Show resolved Hide resolved
cpu/kinetis/dist/check-fcfield-bin.sh Outdated Show resolved Hide resolved
tests/cortexm_common_ldscript/Makefile Outdated Show resolved Hide resolved
@cladmi
Copy link
Contributor

cladmi commented May 22, 2019

Somehow I think handling the .fcfield is not needed when flashing with an offset, as long as IMAGE_OFFSET > FCFIELD_END='0x410'.

https://cache.freescale.com/files/microcontrollers/doc/app_note/AN4507.pdf

For me it seems like this flash configuration field is at a fixed address and not relative to the jump address. If we can confirm this, it makes things way easier.

And we could just say "We do not want to try flashing a binary if it does not start at 0 or is over FCFIELD_END". It somebody really want to handle it in the future, he can verify that the right bits are correct.

Even if the .fcfield is not required with an offset, we can still use the same linkerscript anyway, its just "wasting" 40bytes or something.

@cladmi
Copy link
Contributor

cladmi commented May 22, 2019

And currently, tests/riotboot does not work:
RIOT_CI_BUILD=1 BOARD=frdm-kw41z make -C tests/riotboot flash test

The command is RIOT_CI_BUILD=1 BOARD=frdm-kw41z make -C tests/riotboot riotboot/flash test

It is supposed to work with flash test as the makefile is setting FLASHFILE:
Thats why check-field should know which one to call depending on the file format. I can help on this if you want to do it in make only. Doing it in the script could also work.

# tests/riotboot/Makefile

# Target 'all' will generate the combined file directly.
# It also makes 'flash' and 'flash-only' work without specific command.
FLASHFILE = $(RIOTBOOT_COMBINED_BIN)

To make it work in the current version, I also needed to export RIOTBOOT_HDR_LEN. But as mentioned inline, I think we do not need to care if fcfield is as 0 + fcfieldstart.

diff --git a/sys/riotboot/Makefile.include b/sys/riotboot/Makefile.include
index 4e2d9b6c6..607a1fe1d 100644
--- a/sys/riotboot/Makefile.include
+++ b/sys/riotboot/Makefile.include
@@ -1,7 +1,7 @@
 # Indicate the reserved space for a header, 256B by default
 # Notice that it must be 256B aligned. This is restricted by
 # the Cortex-M0+/3/4/7 architecture
-RIOTBOOT_HDR_LEN ?= 0x100
+export RIOTBOOT_HDR_LEN ?= 0x100

 # By default, slot 0 is found just after RIOTBOOT_LEN. Slot 1 after
 # slot 0. The values might be overridden to add more or less offset

And then the test succeed !!!! 👍

> 2019-05-22 17:31:11,218 - INFO #  main(): This is RIOT! (Version: buildtest)
2019-05-22 17:31:11,227 - INFO # Hello riotboot!
2019-05-22 17:31:11,229 - INFO # You are running RIOT on a(n) frdm-kw41z board.
2019-05-22 17:31:11,230 - INFO # This board features a(n) kinetis MCU.
2019-05-22 17:31:11,232 - INFO # riotboot_test: running from slot 0
2019-05-22 17:31:11,233 - INFO # Image magic_number: 0x544f4952
2019-05-22 17:31:11,237 - INFO # Image Version: 0x5ce56b3a
2019-05-22 17:31:11,239 - INFO # Image start address: 0x00001100
2019-05-22 17:31:11,242 - INFO # Header chksum: 0x431476c1
2019-05-22 17:31:11,243 - INFO #
> 2019-05-22 17:31:11,282 - INFO #  curslotnr
2019-05-22 17:31:11,287 - INFO # Current slot=0
> curslothdr
2019-05-22 17:31:11,348 - INFO #  curslothdr
2019-05-22 17:31:11,350 - INFO # Image magic_number: 0x544f4952
2019-05-22 17:31:11,353 - INFO # Image Version: 0x5ce56b3a
2019-05-22 17:31:11,354 - INFO # Image start address: 0x00001100
2019-05-22 17:31:11,358 - INFO # Header chksum: 0x431476c1
2019-05-22 17:31:11,358 - INFO #
> getslotaddr 0
2019-05-22 17:31:11,418 - INFO #  getslotaddr 0
2019-05-22 17:31:11,419 - INFO # Slot 0 address=0x00001100
> dumpaddrs
2019-05-22 17:31:11,478 - INFO #  dumpaddrs
2019-05-22 17:31:11,483 - INFO # slot 0: metadata: 0x1000 image: 0x00001100
2019-05-22 17:31:11,489 - INFO # slot 1: metadata: 0x40800 image: 0x00000000

otherwise I got

RIOT_CI_BUILD=1 BOARD=frdm-kw41z make -C tests/riotboot riotboot/flash test
make: Entering directory '/home/harter/work/git/RIOT/tests/riotboot'
compiling /home/harter/work/git/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0.riot.bin...
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0.riot.bin
### Flashing Target ###
/home/harter/work/git/RIOT/cpu/kinetis/dist/check-fcfield-bin.sh: 1: /home/harter/work/git/RIOT/cpu/kinetis/dist/check-fcfield-bin.sh: arithmetic expression: expecting primary: "0x400+"
Danger of bricking the device during flash!
Flash configuration field of /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0.riot.bin:
arm-none-eabi-objdump: /home/harter/work/git/RIOT/tests/riotboot/bin/frdm-kw41z/tests_riotboot-slot0.riot.bin: File format not recognized
Abort flash procedure!
pre-flash checks failed, status=1

@fjmolinas
Copy link
Contributor Author

To make it work in the current version, I also needed to export RIOTBOOT_HDR_LEN. But as mentioned inline, I think we do not need to care if fcfield is as 0 + fcfieldstart.

Yes sorry, I had rebased my branch to remove a couple of uneeded commits and removed that. I had realized that but was trying to address all your comments before pushing updates.

Somehow I think handling the .fcfield is not needed when flashing with an offset, as long as IMAGE_OFFSET > FCFIELD_END='0x410'.

Yes I think you are right, I'll try to implement!

Thanks for the comments!

cpu/kinetis/dist/check-fcfield-bin.sh Outdated Show resolved Hide resolved
boards/common/frdm/Makefile.include Outdated Show resolved Hide resolved
@cladmi
Copy link
Contributor

cladmi commented May 22, 2019

To make it work in the current version, I also needed to export RIOTBOOT_HDR_LEN. But as mentioned inline, I think we do not need to care if fcfield is as 0 + fcfieldstart.

Yes sorry, I had rebased my branch to remove a couple of uneeded commits and removed that. I had realized that but was trying to address all your comments before pushing updates.

No worry, I play stupid first, execute the command, post the error, and then try to understand :)
At the end, we may not even need to export anything after cleaning up.

It's working already, so it's good :)

@fjmolinas fjmolinas force-pushed the pr_kinetis_riotboot_frdm_kw41z branch from bcc4d23 to ea9b013 Compare May 26, 2019 17:02
@fjmolinas
Copy link
Contributor Author

fjmolinas commented May 26, 2019

Somehow I think handling the .fcfield is not needed when flashing with an offset, as long as IMAGE_OFFSET > FCFIELD_END='0x410'.

Even if the .fcfield is not required with an offset, we can still use the same linkerscript anyway, its just "wasting" 40bytes or something.

This is true although it would still mean having two linker scripts: one when at offset<0x410 and another when flashing after 0x410 (cortexm.ld). Where the first one would have the .fcfield definition but not the second one. Would you be okay with that?

@cladmi
Copy link
Contributor

cladmi commented May 27, 2019

Somehow I think handling the .fcfield is not needed when flashing with an offset, as long as IMAGE_OFFSET > FCFIELD_END='0x410'.

Even if the .fcfield is not required with an offset, we can still use the same linkerscript anyway, its just "wasting" 40bytes or something.

This is true although it would still mean having two linker scripts: one when at offset<0x410 and another when flashing after 0x410 (cortexm.ld). Where the first one would have the .fcfield definition but not the second one. Would you be okay with that?

No I would keep using the same linkerscript for simplicity.

I was referring more to checking the fcfield in the script.

@cladmi
Copy link
Contributor

cladmi commented May 27, 2019

Could you split moving to the common fcfield.sh only supporting elf and hex in a separate PR ?

@fjmolinas
Copy link
Contributor Author

Could you split moving to the common fcfield.sh only supporting elf and hex in a separate PR ?

Will do, do you mind if I push force to take into account all your comments and clean up the commit history?

@cladmi
Copy link
Contributor

cladmi commented May 27, 2019

@fjmolinas no problem, I followed the changes and will be able to review the rebased version.

cpu/kinetis/dist/check-fcfield.sh Outdated Show resolved Hide resolved
cpu/kinetis/dist/check-fcfield.sh Outdated Show resolved Hide resolved
cpu/kinetis/dist/check-fcfield.sh Outdated Show resolved Hide resolved
@cladmi
Copy link
Contributor

cladmi commented May 28, 2019

After the linkerscript change, I think you can add all the kinetis boards to BOARD_WHITELIST in tests/cortexm_common_ldscript.

When refactoring, kinetis.ld to be more similar to cortexm.ld, I think the following changes could be done too:

  • I think that somehow all the LINKFLAGS with defsym in cpu/kinetis/Makefile.include can be removed as already defined by cpu/cortexm_common/Makefile.include (_ram_base_addr is unused from a git grep search, did not check history yet)
  • It could be the right time to put the _rom_offset/_fw_rom_length calculation in its own file to not duplicate between both kinetis.ld and cortexm.ld.
  • The OUTPUT_FORMAT/OUTPUT_ARCH may not be needed as they are set in cortexm_base.ld.

To put the riotboot features, it may be a good idea to check that the same issue as #11274 is not present.

@fjmolinas fjmolinas force-pushed the pr_kinetis_riotboot_frdm_kw41z branch from 2341dcf to 96f67b3 Compare May 28, 2019 11:59
@fjmolinas
Copy link
Contributor Author

To put the riotboot features, it may be a good idea to check that the same issue as #11274 is not present.

It is needed for frdm-k64f since its sector/page size is 4k, but not for frdm-kw41z. There is another pr that implements flashpage for kinetis #11422. But it depends on including CPU_FAM before Makefile.features so its still delayed.

Anyway thats not the point. I can add support for frdm-k64f in the PR and that way included RIOTBOOT_LEN definition for that case.

I think that somehow all the LINKFLAGS with defsym in cpu/kinetis/Makefile.include can be removed as already defined by cpu/cortexm_common/Makefile.include (_ram_base_addr is unused from a git grep search, did not check history yet)
It could be the right time to put the _rom_offset/_fw_rom_length calculation in its own file to not duplicate between both kinetis.ld and cortexm.ld.

Ok will need to look into a it a bit!

@fjmolinas fjmolinas changed the title boards/frdm-kw41z: add riotboot boards/frdm-kw41z-k64f: add riotboot May 29, 2019
@fjmolinas fjmolinas removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label May 29, 2019
@fjmolinas
Copy link
Contributor Author

@cladmi I found the reason why it wasn't working for pba-d-01-kw2x:

"ARMv7-M Architecture Reference Manual" B1.5.3 The vector table

The Vector table must be naturally aligned to a power of two whose alignment value is greater than or equal to (Number of Exceptions supported x 4), with a minimum alignment of 128 bytes.

"Cortex-M4 Devices Generic User Guide" 4.3.4. Vector Table Offset Register

The minimum alignment is 32 words, enough for up to 16 interrupts. For more interrupts, adjust the alignment by rounding up to the next power of two. For example, if you require 21 interrupts, the alignment must be on a 64-word boundary because the required table size is 37 words, and the next power of two is 64.

For MKW22D5 the number of INT_VECTORS is (82 + 16), so it need to be po2(4x98) = 512 (0x200) aligned.

In this case by default it is located at RIOTBOOT_LEN + RIOTBOOT_HDR_LEN = 0x1100 which is not aligned to 0x200. If RIOTBOOT_LEN is increased to be 0x1100 it works. But here comes the tricky part... We still need the whole image to start at the beginning of a page. So what should actually be done is increase RIOTBOOT_HDRL_LEN to be 0x200 aligned.

This need to be done for all M4, I had struggled a while ago debugging why riotboot doesn't work on stm32l4 and its the exact same issue, I'm now able to make it work by changing RIOTBOOT_HDRL_LEN size to 0x200.

Anyway I will open separate PR's for this.

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

@fjmolinas Congratulation for finding it.

This details deserve its place too in https://github.com/RIOT-OS/RIOT/tree/master/bootloaders/riotboot on the RIOTBOOT_HDR_LEN section

Please note that RIOTBOOT_HDR_LEN depends on the architecture of the
MCU, since it needs to be aligned to 256B. This is fixed regardless of
sizeof(riotboot_hdr_t)

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

@fjmolinas can you rebase this one on master ? we could get this ones in already.

@fjmolinas fjmolinas force-pushed the pr_kinetis_riotboot_frdm_kw41z branch from 723b2c4 to 937276a Compare June 6, 2019 09:11
@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Jun 6, 2019
@fjmolinas
Copy link
Contributor Author

@cladmi Rebased and all is green!

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

Thanks, I will re-run the tests once more this afternoon.

# If RIOTBOOT_LEN uses an uneven number of flashpages, the remainder of the
# flash cannot be divided by two slots while staying FLASHPAGE_SIZE aligned.
ifeq (K, $(KINETIS_SERIES))
RIOTBOOT_LEN ?= 0x2000
Copy link
Contributor

@cladmi cladmi Jun 6, 2019

Choose a reason for hiding this comment

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

Would need two spaces here for indentation

Suggested change
RIOTBOOT_LEN ?= 0x2000
RIOTBOOT_LEN ?= 0x2000

Could you also add that the flashpage size is 4k (0x1000) in the comment ?

You can squash them directly.

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

I could successfully test the frdm-kw41z

BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/xtimer_usleep riotboot/flash-extended-slot0 term
# Runs the firmware without crash (test currently does not wait for the uart input in master)

BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/riotboot riotboot/flash-slot1 test
# Runs the test successfully

# make slot 1 with a lower version
BOARD=frdm-kw41z FEATURES_REQUIRED+=riotboot APP_VER=1 make -C tests/riotboot riotboot/flash-slot1 term
# Show again the xtimer_usleep output

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

However for the frdm-k64f, the xtimer_usleep currently does not work with the same test

BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/xtimer_usleep riotboot/flash-extended-slot0 term
# Errors with crash
2019-06-06 14:13:10,140 - INFO # Running test 5 times with 7 distinct sleep times
2019-06-06 14:13:10,144 - INFO # Please hit any key and then ENTER to continue
2019-06-06 14:13:10,154 - INFO #
2019-06-06 14:13:10,165 - INFO # Context before hamain(): This is RIOT! (Version: 2019.07-devel-604-g937276-pr/riot/11562/add_riotboot)
2019-06-06 14:13:10,169 - INFO # Running test 5 times with 7 distinct sleep times
2019-06-06 14:13:10,173 - INFO # Please hit any key and then ENTER to continue
2019-06-06 14:13:10,183 - INFO #
2019-06-06 14:13:10,194 - INFO # Context before hamain(): This is RIOT! (Version: 2019.07-devel-604-g937276-pr/riot/11562/add_riotboot)


BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/riotboot riotboot/flash-slot1 test
# Runs the test successfully

# make slot 1 with a lower version
BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=1 make -C tests/riotboot riotboot/flash-slot1 term
# Show again the xtimer_usleep output with the crashes

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

For the frdm-k64f when setting RIOTBOOT_HDR_LEN=0x400 I get a few lines of output

Type '/exit' to exit.
2019-06-06 14:18:38,196 - INFO # Please hit any key and then ENTER to continue
2019-06-06 14:18:38,198 - INFO # Slept for 10014 us (expected: 10000 us) Offset: 14 us
2019-06-06 14:18:38,200 - INFO # Slept for 50014 us (expected: 50000 us) Offset: 14 us
2019-06-06 14:18:38,204 - INFO # �main(): This is RIOT! (Version: 2019.07-devel-604-g937276-pr/riot/11562/add_riotboot)
2019-06-06 14:18:38,206 - INFO # Running test 5 times with 7 distinct sleep times
2019-06-06 14:18:38,207 - INFO # Please hit any key and then ENTER to continue
2019-06-06 14:18:38,210 - INFO # Slept for 10014 us (expected: 10000 us) Offsepected: 10000 us) Offset: 14 us

# It gets stuck there

# In the output buffer there was still `Slept for 50014 us (expected: 50` but was only shown after resetting the board

And if I then reset, I get a normal full output of the xtimer_usleep test.

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

We could go for only the frdm-kw41z as you originally planned, I Approve that part already.

I did not know there would be more issues with the k64f and it does not need to delay more the frdm-kw41z.

@fjmolinas fjmolinas force-pushed the pr_kinetis_riotboot_frdm_kw41z branch from 937276a to 6f978a5 Compare June 6, 2019 13:19
@fjmolinas fjmolinas removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 6, 2019
@fjmolinas fjmolinas force-pushed the pr_kinetis_riotboot_frdm_kw41z branch from 6f978a5 to 42b1118 Compare June 6, 2019 13:21
@fjmolinas
Copy link
Contributor Author

@cladmi You are right about frdm-k64f, it's has the same vector table alignment problem. But for me running tests/xtimer_usleep is working fine (I pushed a change to redefine RIOTBOOT_HDR_LEN). The exact command I'm running is:

BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make clean -C tests/xtimer_usleep/ riotboot/flash

And then:

BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make -C tests/xtimer_usleep/ test

2019-06-06 15:24:39,136 - INFO # main(): This is RIOT! (Version: 2019.07-devel-616-g6f978-pr_kinetis_riotboot_frdm_kw41z)
2019-06-06 15:24:39,140 - INFO # Running test 5 times with 7 distinct sleep times
2019-06-06 15:24:39,144 - INFO # Please hit any key and then ENTER to continue
2019-06-06 15:24:39,158 - INFO # Slept for 10015 us (expected: 10000 us) Offset: 15 us
a
2019-06-06 15:24:39,212 - INFO # Slept for 50015 us (expected: 50000 us) Offset: 15 us
2019-06-06 15:24:39,226 - INFO # Slept for 10249 us (expected: 10234 us) Offset: 15 us
2019-06-06 15:24:39,287 - INFO # Slept for 56795 us (expected: 56780 us) Offset: 15 us
2019-06-06 15:24:39,303 - INFO # Slept for 12137 us (expected: 12122 us) Offset: 15 us
2019-06-06 15:24:39,406 - INFO # Slept for 98779 us (expected: 98765 us) Offset: 14 us
2019-06-06 15:24:39,485 - INFO # Slept for 75015 us (expected: 75000 us) Offset: 15 us
2019-06-06 15:24:39,499 - INFO # Slept for 10015 us (expected: 10000 us) Offset: 15 us
2019-06-06 15:24:39,553 - INFO # Slept for 50015 us (expected: 50000 us) Offset: 15 us
2019-06-06 15:24:39,567 - INFO # Slept for 10249 us (expected: 10234 us) Offset: 15 us
2019-06-06 15:24:39,628 - INFO # Slept for 56795 us (expected: 56780 us) Offset: 15 us
2019-06-06 15:24:39,645 - INFO # Slept for 12136 us (expected: 12122 us) Offset: 14 us
2019-06-06 15:24:39,747 - INFO # Slept for 98780 us (expected: 98765 us) Offset: 15 us
2019-06-06 15:24:39,826 - INFO # Slept for 75015 us (expected: 75000 us) Offset: 15 us
2019-06-06 15:24:39,840 - INFO # Slept for 10015 us (expected: 10000 us) Offset: 15 us
2019-06-06 15:24:39,894 - INFO # Slept for 50015 us (expected: 50000 us) Offset: 15 us
2019-06-06 15:24:39,908 - INFO # Slept for 10249 us (expected: 10234 us) Offset: 15 us
2019-06-06 15:24:39,969 - INFO # Slept for 56795 us (expected: 56780 us) Offset: 15 us
2019-06-06 15:24:39,985 - INFO # Slept for 12137 us (expected: 12122 us) Offset: 15 us
2019-06-06 15:24:40,088 - INFO # Slept for 98780 us (expected: 98765 us) Offset: 15 us
2019-06-06 15:24:40,167 - INFO # Slept for 75015 us (expected: 75000 us) Offset: 15 us
2019-06-06 15:24:40,181 - INFO # Slept for 10015 us (expected: 10000 us) Offset: 15 us
2019-06-06 15:24:40,235 - INFO # Slept for 50014 us (expected: 50000 us) Offset: 14 us
2019-06-06 15:24:40,249 - INFO # Slept for 10249 us (expected: 10234 us) Offset: 15 us
2019-06-06 15:24:40,310 - INFO # Slept for 56795 us (expected: 56780 us) Offset: 15 us
2019-06-06 15:24:40,326 - INFO # Slept for 12137 us (expected: 12122 us) Offset: 15 us
2019-06-06 15:24:40,429 - INFO # Slept for 98780 us (expected: 98765 us) Offset: 15 us
2019-06-06 15:24:40,508 - INFO # Slept for 75015 us (expected: 75000 us) Offset: 15 us
2019-06-06 15:24:40,522 - INFO # Slept for 10014 us (expected: 10000 us) Offset: 14 us
2019-06-06 15:24:40,576 - INFO # Slept for 50015 us (expected: 50000 us) Offset: 15 us
2019-06-06 15:24:40,590 - INFO # Slept for 10249 us (expected: 10234 us) Offset: 15 us
2019-06-06 15:24:40,651 - INFO # Slept for 56795 us (expected: 56780 us) Offset: 15 us
2019-06-06 15:24:40,667 - INFO # Slept for 12137 us (expected: 12122 us) Offset: 15 us
2019-06-06 15:24:40,770 - INFO # Slept for 98780 us (expected: 98765 us) Offset: 15 us
2019-06-06 15:24:40,849 - INFO # Slept for 75015 us (expected: 75000 us) Offset: 15 us
2019-06-06 15:24:40,851 - INFO # Test ran for 1704919 us

make: Leaving directory '/home/francisco/workspace/RIOT/tests/xtimer_usleep'

Everything is as expected. Maybe you need to run make clean after changing RIOTBOOT_HDR_LEN? I also ran the test with RIOTBOOT_HDR_LEN ?= 0x400 and it was working the same.

@cladmi
Copy link
Contributor

cladmi commented Jun 6, 2019

@fjmolinas after make reset that is done by make test it works. The issue I had was without reset. Maybe because of the long

Error: timed out while waiting for target halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0000319e psp: 0x1fff0420
Error: error executing cortex_m crc algorithm
verified 528896 bytes in 48.328571s (10.687 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked

I will see if I can get a clean failure output.

@fjmolinas
Copy link
Contributor Author

fjmolinas commented Jun 6, 2019

after make reset that is done by make test it works. The issue I had was without reset.

That is weird, I opened a terminal before flashing and from another terminal executed:

BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make clean -C tests/xtimer_usleep/ riotboot/flash

The application restes 4 times during flashing, I don't now why but when flashing k64f I always detect an eternal reset after which the flash hangs for a while.

Info : Kinetis MK64FN1M0xxx12 detected: 2 flash blocks
Info : 2 PFlash banks: 1024k total
wrote 16384 bytes from file /home/francisco/workspace/RIOT/tests/xtimer_usleep/bin/frdm-k64f/tests_xtimer_usleep-slot0.riot.bin in 0.804033s (19.900 KiB/s)
Info : kx.cpu: external reset detected
Error: timed out while waiting for target halted
target halted due to debug-request, current mode: Thread 

But everything succeeds eventually, without any manual make reset

@cladmi cladmi added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 7, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 7, 2019

I re-tried many times on my side and I could not reproduce the issue.
I am thinking it was a situation with the flasher ending up in a weird mode, or me not cleaning everything properly even it should not matter there.

@cladmi
Copy link
Contributor

cladmi commented Jun 7, 2019

I managed to reproduce it again, but not consistently with flashing it two times. with:

BOARD=frdm-k64f FEATURES_REQUIRED+=riotboot APP_VER=$(date +%s) make clean -C tests/xtimer_usleep/ riotboot/flash-extended-slot0 term

It may be an openocd issue too.

GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)

As it works after reset anyway, I would handle it as a tools issue and not of the support.

Copy link
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

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

ACK tested with tests/riotboot and tests/xtimer_usleep for both boards.

I did not double check the number of interrupt set in the Makefile.include, but it was not working without RIOTBOOT_HDR_LEN = 0x200 for the frdm-k64f

I had some nondeterministic issues when flashing the combined/extended slot0 with xtimer_usleep but it looked more like a flasher issue and it was working after reset.

The slot alignment is consistent with the 4k (0x1000) FLASHPAGE_SIZE.

@cladmi cladmi merged commit 632da8a into RIOT-OS:master Jun 7, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 7, 2019

Congratulation for taking care of adding the support from start to end. It has been a long and tough process.

@fjmolinas
Copy link
Contributor Author

@cladmi Thanks a lot for the review and very helpfull advice!

@fjmolinas fjmolinas deleted the pr_kinetis_riotboot_frdm_kw41z branch August 7, 2019 15:42
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 Area: OTA Area: Over-the-air updates CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants