Skip to content

nrf52: use cortexm.ld script when applicable#11127

Merged
kYc0o merged 3 commits intoRIOT-OS:masterfrom
bergzand:pr/nrf52/ref_ldscripts
Mar 13, 2019
Merged

nrf52: use cortexm.ld script when applicable#11127
kYc0o merged 3 commits intoRIOT-OS:masterfrom
bergzand:pr/nrf52/ref_ldscripts

Conversation

@bergzand
Copy link
Copy Markdown
Member

@bergzand bergzand commented Mar 7, 2019

Contribution description

Split off from #11126, this reworks the nrf52840 and nrf52832 makefiles to use the cortexm.ld script when the nordic_softdevice_ble is not included in the build. The common linker script is not used when the nordic_softdevice_ble is
included

the nrf52832xxaa.ld included a boot_offset in the calculation, not sure if it was used or not.

Testing procedure

Builds with the nrf52840 and nrf52832 should still work.

Issues/PRs references

Required for #11126

@bergzand bergzand added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Area: cpu Area: CPU/MCU ports labels Mar 7, 2019
@bergzand bergzand mentioned this pull request Mar 7, 2019
4 tasks
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

It looks like the boot_offset was for introduced for multislot.ld introduced by #7209

So need to adapt makefiles/mcuboot.mk I guess. I will verify and if needed to make the file working with this PR or both maybe.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

Indeed tests/mcuboot is currently broken with this. I will look for it.

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Mar 7, 2019

Indeed tests/mcuboot is currently broken with this. I will look for it.

Thanks!

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

Testing command: have make term open for nrf52dk and run BOARD=nrf52dk make -C tests/mcuboot/ clean mcuboot-flash it will print

2019-03-07 16:41:08,983 - INFO # Hello MCUBoot!
2019-03-07 16:41:08,987 - INFO # You are running RIOT on a(n) nrf52dk board.
2019-03-07 16:41:08,990 - INFO # This board features a(n) nrf52 MCU.
2019-03-07 16:41:08,992 - INFO # The startup address is: 0x8200

You would need to add this before changing the linker to have both supported:

diff --git a/makefiles/mcuboot.mk b/makefiles/mcuboot.mk
index 09987798c..a20cc686b 100644
--- a/makefiles/mcuboot.mk
+++ b/makefiles/mcuboot.mk
@@ -22,6 +22,7 @@ $(MCUBOOT_KEYFILE):
        $(Q)$(IMGTOOL) keygen -k $@ -t rsa-2048
 endif

+mcuboot: ROM_OFFSET=$$(($(MCUBOOT_SLOT0_SIZE) + $(IMAGE_HDR_SIZE)))
 mcuboot: mcuboot-create-key link
        @$(COLOR_ECHO)
        @$(COLOR_ECHO) '$(COLOR_PURPLE)Re-linking for MCUBoot at $(MCUBOOT_SLOT0_SIZE)...$(COLOR_RESET)'

And then after changing the linker script you can remove these lines:

diff --git a/makefiles/mcuboot.mk b/makefiles/mcuboot.mk
index 09987798c..86bf9b092 100644
--- a/makefiles/mcuboot.mk
+++ b/makefiles/mcuboot.mk
@@ -26,9 +26,7 @@ mcuboot: mcuboot-create-key link
        @$(COLOR_ECHO)
        @$(COLOR_ECHO) '$(COLOR_PURPLE)Re-linking for MCUBoot at $(MCUBOOT_SLOT0_SIZE)...$(COLOR_RESET)'
        @$(COLOR_ECHO)
-       $(Q)$(_LINK) $(LINKFLAGPREFIX)--defsym=offset="$$(($(MCUBOOT_SLOT0_SIZE) + $(IMAGE_HDR_SIZE)))" \
-       $(LINKFLAGPREFIX)--defsym=length="$$(($(MCUBOOT_SLOT1_SIZE) - $(IMAGE_HDR_SIZE)))" \
-       $(LINKFLAGPREFIX)--defsym=image_header="$(IMAGE_HDR_SIZE)" -o $(ELFFILE) && \
+       $(Q)$(_LINK) -o $(ELFFILE) && \
        $(OBJCOPY) $(OFLAGS) -Obinary $(ELFFILE) $(BINFILE) && \
        $(IMGTOOL) sign --key $(MCUBOOT_KEYFILE) --version $(IMAGE_VERSION) --align \
        $(MCUBOOT_IMAGE_ALIGN) -H $(IMAGE_HDR_SIZE) $(BINFILE) $(SIGN_BINFILE)

You can also remove cpu/cortexm_common/ldscripts/multislot.ld when you remove cpu/nrf52/ldscripts/nrf52832xxaa.ld.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

I can push them to your branch if you want.

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Mar 7, 2019

I can push them to your branch if you want.

Please do so, I think you should know by now how skilled I am with makefiles :-)

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Mar 7, 2019

Although I should be able to manage this much, anyway feel free to push :-)

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

I checked just in case, it cannot currently be used for the softdevice case as it would require to configure _ram_offset in the same way as _rom_offset with also the _ram_length handling. So would be for another pull request :)

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

I will run the whole test suite with this configuration on nrf52dk.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 7, 2019

The test suit have the same failure as master:

Failures during test:
- [tests/gnrc_ipv6_ext](tests/gnrc_ipv6_ext/test.failed)
- [tests/gnrc_rpl_srh](tests/gnrc_rpl_srh/test.failed)
- [tests/pkg_fatfs_vfs](tests/pkg_fatfs_vfs/test.failed)

examples/default and such do not work but it is also the case in master #11091

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 11, 2019

I tested for the nrf52dk and the resulting binary is the same by comparing to the master (origin) commit:

cd examples/hello-world
RIOT_CI_BUILD=1 BOARD=nrf52dk make all clean-intermediates; mv bin bin_master
sha1sum bin_master/nrf52dk/* bin_pr/nrf52dk/* | sort
403673ef4e0e21f307387297f38afce4b8a94207  bin_pr/nrf52dk/hello-world.elf
4f3119f27fe3b694a3618effe55d48f1967b71dc  bin_master/nrf52dk/hello-world.elf
73f21fd1f29af794a440c0cc4656215cd606ca6f  bin_master/nrf52dk/hello-world.bin
73f21fd1f29af794a440c0cc4656215cd606ca6f  bin_pr/nrf52dk/hello-world.bin
792c2c40097879103ec2cdcf6f382fa777d1c5a2  bin_master/nrf52dk/hello-world.map
adcf866733ccbe766209576636dca491508183a5  bin_pr/nrf52dk/hello-world.map

diff -r bin_master/ bin_pr/                                                                                                                                                                                                                                                           
Binary files bin_master/nrf52dk/hello-world.elf and bin_pr/nrf52dk/hello-world.elf differ                                                                                                                                                                                                 
diff -r bin_master/nrf52dk/hello-world.map bin_pr/nrf52dk/hello-world.map
2605a2606,2609
>                 0x0000000000000000                _rom_start_addr = 0x0
>                 0x0000000020000000                _ram_start_addr = 0x20000000
>                 0x0000000000080000                _rom_length = 0x80000
>                 0x0000000000010000                _ram_length = 0x10000
2616,2618c2620,2622
<                 0x0000000000080000                rom_length = 0x80000
<                 0x0000000000000000                boot_offset = DEFINED (offset)?offset:0x0
<                 [0x0000000000080000]                rom_length = DEFINED (length)?length:rom_length
---
>                 0x0000000000000000                _rom_offset = DEFINED (_rom_offset)?_rom_offset:0x0
>                 0x0000000000080000                _fw_rom_length = DEFINED (_fw_rom_length)?_fw_rom_length:(_rom_length - _rom_offset)
>                 0x0000000000000001                ASSERT ((_fw_rom_length <= (_rom_length - _rom_offset)), Specified firmware size does not fit in ROM)

Are there other things that need to be checked ?

@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 Mar 11, 2019
cladmi
cladmi previously requested changes Mar 11, 2019
@cladmi cladmi added CI: run tests If set, CI server will run tests on hardware for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines labels Mar 11, 2019
@cladmi cladmi dismissed their stale review March 11, 2019 17:21

Comments addressed

@cladmi cladmi added CI: ready for build If set, CI server will compile all applications for all available boards 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 11, 2019
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 11, 2019

For me the changes look ok and good on my local tests with the nrf52dk.
Are there other tests to run for this ?

@cladmi cladmi added this to the Release 2019.04 milestone Mar 11, 2019
@bergzand
Copy link
Copy Markdown
Member Author

I don't have anything specific for this. I would assume that if the binaries still work it should be okay. @kYc0o Do you have any suggestions for testing this?

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 12, 2019

I will check all examples with nrf52 based boards.

@kaspar030
Copy link
Copy Markdown
Contributor

I will check all examples with nrf52 based boards.

CI should do most if the flag is enabled, for nrf52dk.

@kaspar030
Copy link
Copy Markdown
Contributor

CI should do most if the flag is enabled, for nrf52dk.

sorry, no, not the examples...

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 12, 2019

I don't have anything specific for this. I would assume that if the binaries still work it should be okay. @kYc0o Do you have any suggestions for testing this?

It looks ok for me and if the test tests/cortexm_common_ldscript/ succeeds everything should be ok to merge it.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 12, 2019

I meant checking the .bin sha1 for examples.
I just want to add other tests than just saying "CI is ok", test/mcuboot would have been broken by trusting the CI only.

And no worry examples/default is correctly still not working with this PR as it is in the base commit.

@cladmi cladmi added Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Mar 12, 2019
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 12, 2019

I compared the BINFILE sha1sum in all supported examples for all the nrf52 boards acd52832 nrf52840-mdk nrf52840dk nrf52dk ruuvitag thingy52 and it is the same as the reference commit.

The BINFILE is also the same in tests/mcuboot for the nrf52dk, the signed file is different but it is because of the randomness of the signature.

Copy link
Copy Markdown
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.

I agree with the changes and tested. Please squash.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 12, 2019

As I also contributed to this PR maybe somebody else should also hack ACK.

@bergzand
Copy link
Copy Markdown
Member Author

hack

Hack and ACK? 😆

Copy link
Copy Markdown
Contributor

@kYc0o kYc0o left a comment

Choose a reason for hiding this comment

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

Double (H)ACK.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 12, 2019

Please squash for the final check.

cladmi and others added 3 commits March 13, 2019 11:57
Prepare mcuboot for changing `nrf52` to use `cortexm.ld`. It sets the
offset for linking the image.
The common linker script is not used when the nordic_softdevice_ble is
included
Linkerscript for `nrf52dk` has been updated to use `cortexm.ld` so does
not need the configuration anymore for the removed
`cpu/nrf52/ldscripts/nrf52832xxaa.ld`.
@bergzand bergzand force-pushed the pr/nrf52/ref_ldscripts branch from 5daeede to a3df00c Compare March 13, 2019 10:58
@bergzand
Copy link
Copy Markdown
Member Author

@cladmi Squashed, please verify if I put the commits in the right order :)

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 13, 2019

The order is good for me.

I re-tested mcuboot-flash and it works BOARD=nrf52dk make -C tests/mcuboot/ mcuboot-flash
Otherwise the rebased version is the same as the other one so just waiting for murdock.

Small non related issue:

For some reason, my board was in a state where I needed to erase the rom to have it working. But after that, it worked properly

# Erase the rom with an interactive application
JLINK_PRE_FLASH=erase BOARD=nrf52dk make -C tests/shell  flash

@bergzand
Copy link
Copy Markdown
Member Author

Seems to be an issue with the nrf52dk board hooked up to the CI here.

@bergzand bergzand 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 CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Mar 13, 2019
@bergzand
Copy link
Copy Markdown
Member Author

All green, who would like to press the big green button‽

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Mar 13, 2019

Everything good here -> go!

@kYc0o kYc0o merged commit de72073 into RIOT-OS:master Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports 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 Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants