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

Design doc fixups #104

Merged
merged 10 commits into from
Aug 10, 2017
Merged

Design doc fixups #104

merged 10 commits into from
Aug 10, 2017

Conversation

mbolivar
Copy link

@mbolivar mbolivar commented Aug 4, 2017

This continues the work in MCUB-67. The substantial change is deleting the 'pending' / 'confirmed' state space in favor of one defined in terms of 'swap types'.

Marti Bolivar added 9 commits August 4, 2017 14:45
Adjust alignment and add missing leading zero to
IMAGE_F_PKCS1_PSS_RSA2048_SHA256. This needed some comment changes to
keep things 80 column clean.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
The comment for BOOT_SWAP_TYPE_NONE says "Just boot whatever is in
slot 0". That's not correct: if configured to do so (and this the
strongly recommended configuration), mcuboot will first
cryptographically validate the contents of slot 0 before booting it.

Fix the comment to be more accurate.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Copy up to date image flags from image.h. Fixes for:

- Wrong comment for IMAGE_F_ECDSA224_SHA256
- Missing definition for IMAGE_F_PKCS1_PSS_RSA2048_SHA256

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Distinguish between flash areas and flash area IDs. Say what the
bootloader area is, since that's not discussed anywhere else.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
The discussion about image slots assumes that the bootloader swaps,
but that is not all it can do. Clear this up.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
The design document says that image trailers can be located in
scratch. That's not true: the contents in scratch are just a subset of
the complete image trailer.

Fix this up by making it clear that image trailers are at the end of
image areas, and sometimes some of their data is copied into and out
of scratch.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
The swap status field definition claims image data are swapped one
sector at a time, but that's not true: image data are actually swapped
around in increments equal to the size of the scratch area, which
can be multiple sectors in length.

Its contents are also misleading in claiming that it's a series of
single byte records, which ignores padding when min-write-size > 1.

It also assumes the reader knows how images are swapped, but that's
not explained until later on in the document.

Finally, the paragraph is in a list of "definitions" of the image
trailer's fields, but it doesn't actually define the contents; it's
just a high level description of what the field is for.

Fix all of these issues by re-working this paragraph.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
@mbolivar mbolivar requested review from d3zd3z and utzig August 4, 2017 21:47
The current "boot states" description doesn't make sense and shouldn't
be used.

For one thing, with three possible pending states, two possible
confirmed states, and two image slots each with a combined (pending,
confirmed) state, the total number of boot states is 36, but the
document says there are "four possible states".

For another, the actual bits on flash map to the "boot states" in a
way that is carefully designed to ensure that only those 4 are the
"outcome" of a boot.

The fact that this map does not cover the entire space of what is
being presented as the "logical" states of the device is a strong
indication that the pending/confirmed state space is a bad choice, not
connected with the actual operation of the bootloader.

A state space that is better for describing how the bootloader behaves
is given the by the enumeration of "swap types" which appear under
each of the tables in the "IMAGE TRAILERS" section, as well as the
bootloader code itself.

To help fix the description of the bootloader' operation, rewrite the
"boot states" portions of the design document, deleting the
pending/confirmed "states" and replacing them with swap types.

There is still more work to do here:

- There is still an "important caveat" to describing things in
  terms of swap types, which means it's not quite right.

- It's strange to say that "none" is a swap type.

- This doesn't provide a clean explanation for how mcuboot handles an
  interrupted swap.

But it's another step.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
@mbolivar
Copy link
Author

mbolivar commented Aug 4, 2017

I fixed some issues with the commit log in the last patch in v2. No changes to the patches themselves.

Copy link
Member

@d3zd3z d3zd3z left a comment

Choose a reason for hiding this comment

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

Just a few things that still feel a little awkward.

@@ -222,21 +218,31 @@ An image trailer has the following structure:
| MAGIC (16 octets) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

These records are at the end of each image slot. The offset immediately
following such a record represents the start of the next flash area.
The offset immediately following such a record represents the start of the next
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. This sentence is still somewhat awkward, and I think you've removed the part that is easier to understand. The current wording sounds like a good way to describe it for a standard document, but not really a design document. How about something like:

"The image trailer is placed such that it butts up against the end of the partition. For example, if the following slot begins at offset 'n', the MAGIC field will be at offset 'n-16'."

Copy link
Author

Choose a reason for hiding this comment

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

Good idea. The next thing might not be a 'slot', so I'll use 'flash area'.

trailers" what is meant is the aggregate information provided by both image
slot's trailers.
At startup, the boot loader determines the boot swap type by inspecting the
image trailers. When using the term "image trailers" what is meant is the
Copy link
Member

Choose a reason for hiding this comment

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

I think this sentence really just indicates that the following description was awkward. If we take it out, do things still make sense? If not, I think we should fix the descriptions below, rather than try to define what plural means.

Copy link
Author

Choose a reason for hiding this comment

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

I've tried to improve this paragraph.

@mbolivar
Copy link
Author

mbolivar commented Aug 5, 2017

v3 posted accounting for review comments from @d3zd3z. Diff from v2:

diff --git a/doc/design.txt b/doc/design.txt
index 8894304..27facc4 100644
--- a/doc/design.txt
+++ b/doc/design.txt
@@ -218,8 +218,9 @@ image trailer. An image trailer has the following structure:
     |                       MAGIC (16 octets)                       |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
-The offset immediately following such a record represents the start of the next
-flash area.
+Each image trailer is placed at the very end of its flash area. For example, if
+the following flash area begins at offset 'n', the MAGIC field of the image
+trailer starts at offset 'n-16', the 'Image OK' byte is at offset 'n-24', etc.
 
 Note: "min-write-size" is a property of the flash hardware.  If the hardware
 allows individual bytes to be written at arbitrary addresses, then
@@ -261,9 +262,10 @@ confirmed as good by the user (0x01=confirmed; 0xff=not confirmed).
 
 *** IMAGE TRAILERS
 
-At startup, the boot loader determines the boot swap type by inspecting the
-image trailers.  When using the term "image trailers" what is meant is the
-aggregate information provided by both image slot's trailers.
+At startup, mcuboot determines the boot swap type by inspecting the image
+trailers. If a previous boot was interrupted, some of the contents of the image
+trailers may be in the swap flash area as well, as described in more detail
+below in IMAGE SWAPPING and RESET RECOVERY.
 
 The image trailers records are structured around the limitations imposed by flash
 hardware.  As a consequence, they do not have a very intuitive design, and it

Copy link
Member

@utzig utzig left a comment

Choose a reason for hiding this comment

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

LGTM. Please squash this doc stuff.

confirmed | X | |
-----------------+--------+--------'
swap: test |
result: BOOT_SWAP_TYPE_TEST |
Copy link
Member

Choose a reason for hiding this comment

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

I changed the same thing on my last doc updates, but decided to rollback before finishing the commit! :-)

@mbolivar
Copy link
Author

mbolivar commented Aug 9, 2017

@utzig are you saying I should squash all of the design doc changes into one commit? I made the commits separate logical changes on purpose so they'd be easier to review.

@utzig utzig merged commit 9521a38 into mcu-tools:master Aug 10, 2017
@mbolivar mbolivar deleted the design-doc-fixups branch September 1, 2017 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants