Hi Kevin,

On Fri, Dec 02, 2016 at 09:51:25AM +0100, Kevin Townsend wrote:
> Is there a means with newtmgr today to delete an image in bank 1, for 
> example if you uploaded an image there incorrectly?

There is no way to delete the image in slot 0.  This is an instance of a
more general rule: mynewt won't let you overwrite an image that is
currently "in use" (more on this below).  Slot 0 is always in use,
because it is always the image that is currently running.

This email, while light on implementation details, may help to
explain what the various flags mean:
https://lists.apache.org/thread.html/2dd29b459958b54543b9a7b75ccf7e0879b4a11b39191ab420105b0e@%3Cdev.mynewt.apache.org%3E

> 
> Assuming the following situation:
> 
> Images:
>   slot=0
>    version: 0.3.0
>    bootable: true
>    flags: active
>    hash: 7494da56ead5fe83a0e26ad72fdf1bc8a4d1d6b01b1712e4e1bf4437218f4d8b
>   slot=1
>    version: 0.2.0
>    bootable: true
>    flags: confirmed
>    hash: bd2fb0d9b2c771b284b19d7c143754a8e26cfae837f1e50bb2467ee8dd57e9da
> 
> If you try to upload an image to bank 1 again you will get this error:
> 
> newtmgr -c serial image upload 
> /Users/antonio/Development/Adafruit/NewtManager/imgfiles/bleuart_0_3_0.img
> Error: Target error: 2
> 
> newtmgr -c serial image upload 
> /Users/antonio/Development/Adafruit/NewtManager/imgfiles/throughput_0_2_0.img 
> 
> Error: Target error: 2

In this case, both slots are in use, so you can't delete either.  Slot 0
is in use because it is running (active).  Slot 1 is also "in use"
because of the confirmed flag.  There are two ways to get out of this
state:

1. Confirm the current image state (newtmgr image confirm).  This tells
Mynewt to continue running the image in slot 0 after the next reboot,
and to stop using the slot 1 image.

2. Reboot the device.  This causes Mynewt to fall back to the confirmed
image.  After a reboot, the two slots will be swapped, slot 0 will
be confirmed and active, and slot 1 will have no flags set.

> Would it make sense to have an option to clear the second bank as an 
> option via a specific newtmgr command, or perhaps there are some 
> specific reasons to prevent the second image from being changed or 
> overwritten that I'm not aware of?

There are two reasons why the image management commands might seem
overly "fiddly".  One is to protect the user from themself.  The
situation above is one of those cases; the image in slot 0 is being
tested, and Mynewt tries to prevent the device from being bricked by
only booting into the image once unless manual confirmation is provided.

The other reason image management is tricky has to do with the boot
loader implementation.  Some of the image properties flags (e.g., "under
test") get written at the end of the image slot.  (As I'm sure you
know,) There is no way to clear this part of flash without erasing the
entire sector.  So, in some cases, you have to allow Mynewt to swap the
two images in order to clear the flags.

Today I plan on documenting the boot loader, which may also help explain
some of this behavior.

Please let me know if it is still unclear.

Thanks,
Chris

Reply via email to