You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by marko kiiskila <ma...@runtime.io> on 2016/06/17 23:44:32 UTC

Re: [2/2] incubator-mynewt-core git commit: boot; conditionally check whether to expect image download commands over serial. Whether code gets built in depends on target features.

Hi,

I checked in a package that can be included in bootloader, and
it will accept image upgrades over serial port.

It expects that the image upgrade is done using the newtmgr
protocol. Command set that it supports is limited; it can list images,
accept an image upload command (stores it to slot 0), and also reset.

For testing, I added a snippet of code to apps/boot which can
be conditionally compiled in by defining target features for boot loader
to include BOOT_SERIAL.
The code monitors a GPIO pin, and if it’s set to specific state during
bootup, it’ll enter the serial downloader, awaiting these commands.
Again for testing, I added the pin config to use for Arduino MKR1000
BSP.

Here’s my target definition for using this, in case you want to try this
out:
[marko@IsMyLaptop:~/src/incubator-mynewt-blinky]$ newt target show boot_mkr1000 
targets/boot_mkr1000
    app=@apache-mynewt-core/apps/boot
    bsp=@mynewt-arduino-zero/hw/bsp/arduino_mkr1000
    build_profile=optimized
    features=BOOT_SERIAL 

Feedback appreciated,
M

> On Jun 17, 2016, at 4:26 PM, marko@apache.org wrote:
> 
> boot; conditionally check whether to expect image download commands
> over serial. Whether code gets built in depends on target features.
> 
> 


Re: boot_serial support

Posted by Christopher Collins <cc...@apache.org>.
On Sat, Jun 18, 2016 at 11:38:02AM +0200, Kevin Townsend wrote:
> Hi Marko,
> 
> Thanks for getting this into the development branch! ... I was just 
> setting things up to test it out, and I had a look at the code directly 
> on github in the 'develop' branch, but despite my project being on 
> '0-dev' it doesn't pull the changes locally when I run 'newt upgrade'. 

Unfortunately, pulling from git manually (as you did) is currently the
only way to get the latest changes.  This is a known shortcoming, and
there is a fix planned (https://issues.apache.org/jira/browse/MYNEWT-307).

Thanks,
Chris

boot_serial support

Posted by Kevin Townsend <ke...@adafruit.com>.
Hi Marko,

Thanks for getting this into the development branch! ... I was just 
setting things up to test it out, and I had a look at the code directly 
on github in the 'develop' branch, but despite my project being on 
'0-dev' it doesn't pull the changes locally when I run 'newt upgrade'. 
My project.yml is shown below:

    # Use github's distribution mechanism for core ASF libraries.
    # This provides mirroring automatically for us.
    #
    repository.apache-mynewt-core:
         type: github
         vers: 0-dev
         user: apache
         repo: incubator-mynewt-core

Is that still the correct 'vers' field, or should it be changed to 
something else? I thought this particular name mapped to 'develop' in 
the repo.

I can pull the remote changes via git easily enough, but I'd like to 
stick to using 'upgrade' if possible simply to avoid issues moving forward?

I assume these should be defined at the BSP level as well? 
https://github.com/apache/incubator-mynewt-core/blob/develop/apps/boot/src/boot.c#L184

K.


On 18/06/16 01:44, marko kiiskila wrote:
> Hi,
>
> I checked in a package that can be included in bootloader, and
> it will accept image upgrades over serial port.
>
> It expects that the image upgrade is done using the newtmgr
> protocol. Command set that it supports is limited; it can list images,
> accept an image upload command (stores it to slot 0), and also reset.
>
> For testing, I added a snippet of code to apps/boot which can
> be conditionally compiled in by defining target features for boot loader
> to include BOOT_SERIAL.
> The code monitors a GPIO pin, and if it\u2019s set to specific state during
> bootup, it\u2019ll enter the serial downloader, awaiting these commands.
> Again for testing, I added the pin config to use for Arduino MKR1000
> BSP.
>
> Here\u2019s my target definition for using this, in case you want to try this
> out:
> [marko@IsMyLaptop:~/src/incubator-mynewt-blinky]$ newt target show boot_mkr1000
> targets/boot_mkr1000
>      app=@apache-mynewt-core/apps/boot
>      bsp=@mynewt-arduino-zero/hw/bsp/arduino_mkr1000
>      build_profile=optimized
>      features=BOOT_SERIAL
>
> Feedback appreciated,
> M
>
>> On Jun 17, 2016, at 4:26 PM, marko@apache.org wrote:
>>
>> boot; conditionally check whether to expect image download commands
>> over serial. Whether code gets built in depends on target features.
>>
>>


Re: [2/2] incubator-mynewt-core git commit: boot; conditionally check whether to expect image download commands over serial. Whether code gets built in depends on target features.

Posted by marko kiiskila <ma...@runtime.io>.
Hi,

indeed, bootloader does get bigger. I didn’t try this out on Nordic to see
if something gets out of whack. I’ll check it to see if there are pieces
that came in with unintentionally. ‘newt size <target>’  will show what
components get bigger.

To make the bootloader fit, there’s 2 options:
- make bootloader flash area larger, or
- don’t use NFFS, instead switch over to using FCB

To increase area for bootloader, you need to adjust the linker scripts for
bootloader and the image, as well as the BSP’s flash map. And that should
be it. Nordic has 1k sectors, so the adjustments can be pretty fine-grained.
This are in the files Wayne pointed out.

Or don’t use NFFS, instead use FCB for config. This will drop the size
of the bootloader quite a bit, close to 8k. We’ll want to make the bootloader
vs app comm to take place via some other method than NFFS. NFFS
support brings in a lot of text.

I briefly talked about this with Peter Snyder, and thought we should see
if we can steal some bytes from the end of the 2nd image slot for this.

However, in the short term, I suggest increasing the bootloader area.

> On Jun 18, 2016, at 3:29 AM, Kevin Townsend <ke...@adafruit.com> wrote:
> 
> I was able to build manually pulling via git, and adding the following macros in my custom BSP:
> 
>   /* BOOT_SERIAL pins */
>   /* DFU pin is set to 0.07 on the BLEFRIEND32 */
>   #define BOOT_SERIAL_DETECT_PIN      (7)
>   /* 0 = No pullup, 1 = Pull Up, 2 = Pull Down */
>   #define BOOT_SERIAL_DETECT_PIN_CFG  (0)
>   /* Board has external pullup and the tact switch sets the pin to GND */
>   #define BOOT_SERIAL_DETECT_PIN_VAL  (0)
> 
> This corresponds to the HW bootloader pin on this board: https://cdn-learn.adafruit.com/assets/assets/000/024/297/original/adafruit_products_schem.png?1428267509
> 
> Even with the new nrf51_bootser target set to optimized, though, it's running over the .text region limit for the nRF51:
> 
>   Error:
>   /Users/ktown/prog/gcc-arm-none-eabi-4_9-2015q1/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
>   /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/apps/boot/boot.elf
>   section `.text' will not fit in region `FLASH'
>   /Users/ktown/prog/gcc-arm-none-eabi-4_9-2015q1/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
>   region `FLASH' overflowed by 1288 bytes
>   /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/libs/os/os.a(os_arch_arm.o):
>   In function `os_arch_os_init':
>   /Users/ktown/Dropbox/microBuilder/Code/nRF52/Mynewt/bletest/repos/apache-mynewt-core/libs/os/src/arch/cortex_m0/os_arch_arm.c:218:
>   undefined reference to `bsp_init'
> 
> There do tend to be meaningful gains in optimisation between releases, so I switched to 2016q1 (5.3.1) and it's closer, but still not quite small enough:
> 
>   Linking boot.elf
>   Error:
>   /Users/ktown/prog/gcc-arm-none-eabi-5_3-2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld:
>   /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/apps/boot/boot.elf
>   section `.text' will not fit in region `FLASH'
>   /Users/ktown/prog/gcc-arm-none-eabi-5_3-2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld:
>   region `FLASH' overflowed by 700 bytes
>   /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/libs/os/os.a(os_arch_arm.o):
>   In function `os_arch_os_init':
>   /Users/ktown/Dropbox/microBuilder/Code/nRF52/Mynewt/bletest/repos/apache-mynewt-core/libs/os/src/arch/cortex_m0/os_arch_arm.c:218:
>   undefined reference to `bsp_init'
>   collect2: error: ld returned 1 exit status
> 
> Looking at what 'optimized' gets converted to, it seems like it's '-Os' which is the best we'll get for size (compiler.yml states: "compiler.flags.optimized: [compiler.flags.default, -Os -ggdb]")
> 
> Which version of GCC were you using yourself?
> 
> Best regards,
> Kevin
> 
> On 18/06/16 01:44, marko kiiskila wrote:
>> Hi,
>> 
>> I checked in a package that can be included in bootloader, and
>> it will accept image upgrades over serial port.
>> 
>> It expects that the image upgrade is done using the newtmgr
>> protocol. Command set that it supports is limited; it can list images,
>> accept an image upload command (stores it to slot 0), and also reset.
>> 
>> For testing, I added a snippet of code to apps/boot which can
>> be conditionally compiled in by defining target features for boot loader
>> to include BOOT_SERIAL.
>> The code monitors a GPIO pin, and if it’s set to specific state during
>> bootup, it’ll enter the serial downloader, awaiting these commands.
>> Again for testing, I added the pin config to use for Arduino MKR1000
>> BSP.
>> 
>> Here’s my target definition for using this, in case you want to try this
>> out:
>> [marko@IsMyLaptop:~/src/incubator-mynewt-blinky]$ newt target show boot_mkr1000
>> targets/boot_mkr1000
>>     app=@apache-mynewt-core/apps/boot
>>     bsp=@mynewt-arduino-zero/hw/bsp/arduino_mkr1000
>>     build_profile=optimized
>>     features=BOOT_SERIAL
>> 
>> Feedback appreciated,
>> M
>> 
>>> On Jun 17, 2016, at 4:26 PM, marko@apache.org wrote:
>>> 
>>> boot; conditionally check whether to expect image download commands
>>> over serial. Whether code gets built in depends on target features.
>>> 
>>> 
> 


Re: [2/2] incubator-mynewt-core git commit: boot; conditionally check whether to expect image download commands over serial. Whether code gets built in depends on target features.

Posted by Wayne Keenan <wa...@gmail.com>.
Hi Kevin,

Coming at it from another angle...

When my app took up too much space that optimising was not going to fix  I
simply changed the application FLASH ORIGIN in Newt's nrf51 linker script
hw/bsp/nrf51dk/*nrf51dk.ld*

That was fine for my testing as I didn't really have to worry about the
knock on effect of it's (Newt logically defined) neighbouring regions
higher up in FLASH.

However, the boot loader obviously can't go over 0x8000 without moving the
app...

I've found that in apps/boot/pkg.yml is:

pkg.features: bootloader


This must be being used to choose the linker script because in this file:

apache-mynewt-core/hw/bsp/nrf51dk/pkg.ym

there are these 2 lines:

pkg.linkerscript: "*nrf51dk.ld*"
pkg.linkerscript.bootloader.OVERWRITE: "*boot-nrf51dk.ld*"

In order for the boot loader to know the start address of the app (default
of 0x8000) I  found a Newt configuration structure for the 'logical' flash
areas in:

repos/apache-mynewt-core/hw/bsp/nrf51dk/src/os_bsp.c

It would appear you would need to alter:
1. FLASH LENGTH in the boot-nrf51dk.ld and
2. FLASH ORIGIN in the nrf51dk.ld linker scripts and also
3. change the 'fa_off' for each flash area in the bsp_flash_areas
structure.

That's my (untested) working out for increasing the flash space for the
boot loader. Hope it works.


Dear Newt Devs,

It would be nice to be able to specify the flash areas in the pkg.yml (or
project.yml) and for the Newt OS 'flash areas structure' and (perhaps
templated)  linker scripts to pick the values up from that single
configuration place.


All the best
Wayne

On 18 June 2016 at 11:29, Kevin Townsend <ke...@adafruit.com> wrote:

> I was able to build manually pulling via git, and adding the following
> macros in my custom BSP:
>
>    /* BOOT_SERIAL pins */
>    /* DFU pin is set to 0.07 on the BLEFRIEND32 */
>    #define BOOT_SERIAL_DETECT_PIN      (7)
>    /* 0 = No pullup, 1 = Pull Up, 2 = Pull Down */
>    #define BOOT_SERIAL_DETECT_PIN_CFG  (0)
>    /* Board has external pullup and the tact switch sets the pin to GND */
>    #define BOOT_SERIAL_DETECT_PIN_VAL  (0)
>
> This corresponds to the HW bootloader pin on this board:
> https://cdn-learn.adafruit.com/assets/assets/000/024/297/original/adafruit_products_schem.png?1428267509
>
> Even with the new nrf51_bootser target set to optimized, though, it's
> running over the .text region limit for the nRF51:
>
>    Error:
>
>  /Users/ktown/prog/gcc-arm-none-eabi-4_9-2015q1/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
>
>  /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/apps/boot/boot.elf
>    section `.text' will not fit in region `FLASH'
>
>  /Users/ktown/prog/gcc-arm-none-eabi-4_9-2015q1/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
>    region `FLASH' overflowed by 1288 bytes
>
>  /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/libs/os/os.a(os_arch_arm.o):
>    In function `os_arch_os_init':
>
>  /Users/ktown/Dropbox/microBuilder/Code/nRF52/Mynewt/bletest/repos/apache-mynewt-core/libs/os/src/arch/cortex_m0/os_arch_arm.c:218:
>    undefined reference to `bsp_init'
>
> There do tend to be meaningful gains in optimisation between releases, so
> I switched to 2016q1 (5.3.1) and it's closer, but still not quite small
> enough:
>
>    Linking boot.elf
>    Error:
>
>  /Users/ktown/prog/gcc-arm-none-eabi-5_3-2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld:
>
>  /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/apps/boot/boot.elf
>    section `.text' will not fit in region `FLASH'
>
>  /Users/ktown/prog/gcc-arm-none-eabi-5_3-2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld:
>    region `FLASH' overflowed by 700 bytes
>
>  /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/libs/os/os.a(os_arch_arm.o):
>    In function `os_arch_os_init':
>
>  /Users/ktown/Dropbox/microBuilder/Code/nRF52/Mynewt/bletest/repos/apache-mynewt-core/libs/os/src/arch/cortex_m0/os_arch_arm.c:218:
>    undefined reference to `bsp_init'
>    collect2: error: ld returned 1 exit status
>
> Looking at what 'optimized' gets converted to, it seems like it's '-Os'
> which is the best we'll get for size (compiler.yml states:
> "compiler.flags.optimized: [compiler.flags.default, -Os -ggdb]")
>
> Which version of GCC were you using yourself?
>
> Best regards,
> Kevin
>
>
> On 18/06/16 01:44, marko kiiskila wrote:
>
>> Hi,
>>
>> I checked in a package that can be included in bootloader, and
>> it will accept image upgrades over serial port.
>>
>> It expects that the image upgrade is done using the newtmgr
>> protocol. Command set that it supports is limited; it can list images,
>> accept an image upload command (stores it to slot 0), and also reset.
>>
>> For testing, I added a snippet of code to apps/boot which can
>> be conditionally compiled in by defining target features for boot loader
>> to include BOOT_SERIAL.
>> The code monitors a GPIO pin, and if it’s set to specific state during
>> bootup, it’ll enter the serial downloader, awaiting these commands.
>> Again for testing, I added the pin config to use for Arduino MKR1000
>> BSP.
>>
>> Here’s my target definition for using this, in case you want to try this
>> out:
>> [marko@IsMyLaptop:~/src/incubator-mynewt-blinky]$ newt target show
>> boot_mkr1000
>> targets/boot_mkr1000
>>      app=@apache-mynewt-core/apps/boot
>>      bsp=@mynewt-arduino-zero/hw/bsp/arduino_mkr1000
>>      build_profile=optimized
>>      features=BOOT_SERIAL
>>
>> Feedback appreciated,
>> M
>>
>> On Jun 17, 2016, at 4:26 PM, marko@apache.org wrote:
>>>
>>> boot; conditionally check whether to expect image download commands
>>> over serial. Whether code gets built in depends on target features.
>>>
>>>
>>>
>

Re: [2/2] incubator-mynewt-core git commit: boot; conditionally check whether to expect image download commands over serial. Whether code gets built in depends on target features.

Posted by Kevin Townsend <ke...@adafruit.com>.
I was able to build manually pulling via git, and adding the following 
macros in my custom BSP:

    /* BOOT_SERIAL pins */
    /* DFU pin is set to 0.07 on the BLEFRIEND32 */
    #define BOOT_SERIAL_DETECT_PIN      (7)
    /* 0 = No pullup, 1 = Pull Up, 2 = Pull Down */
    #define BOOT_SERIAL_DETECT_PIN_CFG  (0)
    /* Board has external pullup and the tact switch sets the pin to GND */
    #define BOOT_SERIAL_DETECT_PIN_VAL  (0)

This corresponds to the HW bootloader pin on this board: 
https://cdn-learn.adafruit.com/assets/assets/000/024/297/original/adafruit_products_schem.png?1428267509

Even with the new nrf51_bootser target set to optimized, though, it's 
running over the .text region limit for the nRF51:

    Error:
    /Users/ktown/prog/gcc-arm-none-eabi-4_9-2015q1/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
    /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/apps/boot/boot.elf
    section `.text' will not fit in region `FLASH'
    /Users/ktown/prog/gcc-arm-none-eabi-4_9-2015q1/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
    region `FLASH' overflowed by 1288 bytes
    /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/libs/os/os.a(os_arch_arm.o):
    In function `os_arch_os_init':
    /Users/ktown/Dropbox/microBuilder/Code/nRF52/Mynewt/bletest/repos/apache-mynewt-core/libs/os/src/arch/cortex_m0/os_arch_arm.c:218:
    undefined reference to `bsp_init'

There do tend to be meaningful gains in optimisation between releases, 
so I switched to 2016q1 (5.3.1) and it's closer, but still not quite 
small enough:

    Linking boot.elf
    Error:
    /Users/ktown/prog/gcc-arm-none-eabi-5_3-2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld:
    /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/apps/boot/boot.elf
    section `.text' will not fit in region `FLASH'
    /Users/ktown/prog/gcc-arm-none-eabi-5_3-2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld:
    region `FLASH' overflowed by 700 bytes
    /Users/ktown/Dropbox/microBuilder/code/nRF52/Mynewt/bletest/bin/nrf51_bootser/libs/os/os.a(os_arch_arm.o):
    In function `os_arch_os_init':
    /Users/ktown/Dropbox/microBuilder/Code/nRF52/Mynewt/bletest/repos/apache-mynewt-core/libs/os/src/arch/cortex_m0/os_arch_arm.c:218:
    undefined reference to `bsp_init'
    collect2: error: ld returned 1 exit status

Looking at what 'optimized' gets converted to, it seems like it's '-Os' 
which is the best we'll get for size (compiler.yml states: 
"compiler.flags.optimized: [compiler.flags.default, -Os -ggdb]")

Which version of GCC were you using yourself?

Best regards,
Kevin

On 18/06/16 01:44, marko kiiskila wrote:
> Hi,
>
> I checked in a package that can be included in bootloader, and
> it will accept image upgrades over serial port.
>
> It expects that the image upgrade is done using the newtmgr
> protocol. Command set that it supports is limited; it can list images,
> accept an image upload command (stores it to slot 0), and also reset.
>
> For testing, I added a snippet of code to apps/boot which can
> be conditionally compiled in by defining target features for boot loader
> to include BOOT_SERIAL.
> The code monitors a GPIO pin, and if it\u2019s set to specific state during
> bootup, it\u2019ll enter the serial downloader, awaiting these commands.
> Again for testing, I added the pin config to use for Arduino MKR1000
> BSP.
>
> Here\u2019s my target definition for using this, in case you want to try this
> out:
> [marko@IsMyLaptop:~/src/incubator-mynewt-blinky]$ newt target show boot_mkr1000
> targets/boot_mkr1000
>      app=@apache-mynewt-core/apps/boot
>      bsp=@mynewt-arduino-zero/hw/bsp/arduino_mkr1000
>      build_profile=optimized
>      features=BOOT_SERIAL
>
> Feedback appreciated,
> M
>
>> On Jun 17, 2016, at 4:26 PM, marko@apache.org wrote:
>>
>> boot; conditionally check whether to expect image download commands
>> over serial. Whether code gets built in depends on target features.
>>
>>