zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.12k stars 6.21k forks source link

Adafruit Feather M0 does not flash correctly - incorrect flash code offset and bossa version incompatibility #22062

Closed KubaFYI closed 4 years ago

KubaFYI commented 4 years ago

Describe the bug Adafruit Feather M0 does not flash correctly.

To Reproduce Steps to reproduce the behavior:

  1. west build -b adafruit_feather_m0_basic_proto samples/basic/blinky --pristine
  2. west flash

Expected behavior The board flashes and runs the blinky code.

Impact Showstopper - can't develop with west with default config.

Environment (please complete the following information):

Additional context

I've managed to partially resolve the two parts of the problem with those tweaks:

  1. Added CONFIG_USE_DT_CODE_PARTITION=y to adafruit_deather_m0_masic_proto_defconfig.

The adafruit boards ship with a protected bootloader expecting the code to start at 0x2000. Setting FLASH_LOAD_OFFSET to 0x2000 also seems to do the job but after perusing threads of various issues it seems like this is the cleaner way of forcing the device tree-defined code partition to actually be linked where it belongs.

  1. Using bossa version 1.9.1 instead.

It seems like previous version of bossa don't implement the necessary --offset parameter. The SDK actually used to use 1.9.1 but that was reverted to 1.7 by zephyrproject-rtos/sdk-ng#68 because an upgrade to 1.9.1 stopped Arduino Due from flashing correctly. My understanding is that there was a change in how bossa approached offsets in that starting with 1.9 it needs them explicitly specified while earlier versions assumed certain values. I feel like an appropriate way to go would be to bump it up to 1.9.1 once again and fix up the Arduino Due config instead so that it handles code offsetting correctly?

  1. Bossa runner needs to actually be passed the correct offset value

It seems like currently even with the two above west flash still doesn't flash correctly. This is because the correct offset is at no point passed down to the bossa runner and so it uses it's default argparse value of 0. I'm not sure where would be an appropriate place to get that value from for west flash. Ideas?

henrikbrixandersen commented 4 years ago

Thank you for reporting this. It is not specific to the Adafruit Feather M0 Basic Proto board.

The issue indeed arises since the version of bossac shipped in the Zephyr SDK no longer supports -o for specifying an offset, which is required by the Zephyr bossac west runner in scripts/west_commands/runners/bossac.py.

The version of bossac was reverted by @galak in zephyrproject-rtos/sdk-ng/pull/68 but the west runner was not updated. I believe we need to get back to a more recent version of bossa and fix any incompatibilities in the command line.

KubaFYI commented 4 years ago

I know it's not specific to Adafruit Feather but that's how I came across those several problems so I thought I'd bundle them together. I'm aware that the version of bossac is a part of the problem (as mentioned in the original issue text) but just clearing out the mismatch between bossac and bossac west runner won't fix the issue. USE_DT_CODE_PARTITION has to be added to Feather's defconfig. Should I go ahead and do it?

henrikbrixandersen commented 4 years ago

@KubaFYI I take it this can be closed now?

henrikbrixandersen commented 4 years ago

Assuming this is fixed. Please reopen if not so.