Commit Graph

295 Commits

Author SHA1 Message Date
Fabio Utzig 856f783d7d Fix some error return codes 2017-05-24 09:16:14 -04:00
Fabio Utzig 94d998c61b Remove special cases, non needed tests 2017-05-24 09:16:14 -04:00
Fabio Utzig 4cee4f758f Move trailer status size calculation to its own function 2017-05-24 09:16:14 -04:00
Fabio Utzig ba49f84f03 Add macros for image ok values 2017-05-24 09:16:14 -04:00
Fabio Utzig 2473ac0e5b Add support for swapping only fw sectors in use
Before this patch, the swapping would process all sectors in a slot
not matter what the size of the binary firmware was. This changes the
swap process to swap only sectors that are in use by firmware.

Also, if the last slot sector, which stores the trailer, is actually not
in use by the binary firmware, now trailer is never written to scratch.
`use_scratch` temp variable was added to boot_status struct to control
this (this var is never written to disk).

Random other small refactorings were applied.
2017-05-24 08:58:59 -04:00
Fabio Utzig 7ebb7c23d9 Update how trailer is handled during a swap
Before this change, trailer was handled as part of the binary image,
which during a swap was just copied around together with the image.
This had issues if some fault happened while the trailer copy was
underway.

This patch changes how trailer is handled by making by non-copying.
The trailer is now updated step-by-step based on the current status.
Magic, copy_done and image_ok are also handled by writing them
individually, not by copying.

The trailer on scratch area was reduced to include at most swap state for
one sector, since it is only used temporarily while erasing the last
sector of the slot that stores the final trailer.

Many other small fixes were applied.
2017-05-24 08:45:53 -04:00
David Brown 1d9f185b62 Revert "Merge pull request #49 from mbolivar/flash-map-updates"
This reverts commit a52d7a21f0, reversing
changes made to d21abaaa35.

Premature merge.  Will bring this back in after #41 merges.
2017-05-23 10:32:22 -06:00
David Brown a52d7a21f0 Merge pull request #49 from mbolivar/flash-map-updates
MCUB-54: Flash map API improvements

The series adds new flash_device_base() and flash_area_get_sectors() routines to flash_map.h. If accepted, it needs to be propagated to mynewt as well, as it also ports the core bootutil library to use flash_area_get_sectors().
2017-05-23 10:24:59 -06:00
David Brown d21abaaa35 Merge pull request #55 from utzig/move-signing-doc
Move signed image doc to docs dir
2017-05-19 10:11:24 -06:00
Fabio Utzig afc517e4b8 Move signed image doc to docs dir 2017-05-17 19:37:41 -04:00
David Brown dc76c9690c Merge pull request #48 from d3zd3z/pr/overwrite
Add overwrite-only upgrade
2017-05-11 15:52:06 -06:00
David Brown b706777993 log: fix message for "info" logs in sim
Messages logged at "info" level were printing as "WRN" which was
misleading.
2017-05-11 09:20:02 -06:00
David Brown 51b6b81b47 sim: Set compiled log level to INFO
In order to allow messages to be printed, set the compiled level to
INFO.  This allows messages at this level to be printed without having
to recompile.
2017-05-11 09:17:03 -06:00
David Brown 2d1d7cfd47 sim: Allow Rust logging level to control C logging
Change the C logging code, when in the simulator, to query what the rust
logging level is set to.  This allows the level of logging from the C
code to be set through the environment.  For example

    RUST_LOG=bootsim=info cargo run --release runall

will enable logging at the "info" level for all of the C code as well as
the simulator code.  The C code's logging can be selected specifically
by using bootsim::api instead of just bootsim in the above.
2017-05-11 09:17:03 -06:00
David Brown 186323e47e Merge pull request #50 from utzig/fix-var-shadowing
Fix shadowing of variable in print
2017-05-10 08:58:20 -06:00
David Brown 17609d8a7e Add "upgrade only" support
Add a configuration option "BOOTUTIL_OVERWRITE_ONLY" that avoids using
the image swap code.  Instead, when an upgrade is detected in slot 1, it
is copied directly onto slot 0.  As long as the image in slot 1 is
valid, this should work robustly (it will redo it if power is lost
during the upgrade).

This doesn't protect against the case of deploying an image that fails
to boot on some devices.  But, the behavior is similar to the swap
upgrade approach when the slot 1 image is marked initially as "image
ok", but without the complexity (or need of a swap partition) of the
swap code.
2017-05-10 08:33:19 -06:00
David Brown 902d617687 Add capabilities query
Add a simple function to query the bootloader for capabilities.
Ultimately, this API should be available to the running app, but the
simulator can use this to determine what to test.
2017-05-10 08:32:42 -06:00
David Brown 276633cee7 Merge pull request #47 from d3zd3z/pr/logging
Add logging to the simulator
2017-05-10 08:20:43 -06:00
David Brown 9e300d6f3f Merge pull request #46 from d3zd3z/imgtool
imgtool: Pad file with 0xff
2017-05-10 08:19:19 -06:00
Fabio Utzig 5ac0a1ae29 Fix shadowing of variable in print 2017-05-10 08:49:39 -03:00
Marti Bolivar dfa18ce677 zephyr: warn on boot if flash areas are still open
Add reference counting to the flash areas, and a zephyr-only routine
which warns when areas are still open when none should be. Call the
warn routine right before chain-loading.

This prints warnings due to code in loader.c. Future work will be
needed to clean this up.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-09 13:22:36 -04:00
Marti Bolivar 736e446f08 Take flash base address into account when booting.
Use flash_device_base() in the boot code to compute a real address,
given the offset returned by boot_go().

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-09 13:17:45 -04:00
Marti Bolivar a05cba2c7a Rename br_flash_id to br_flash_dev_id.
Similarly, it's confusing whether br_flash_id is a flash device ID or
a flash area ID. Make this unambiguous.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-09 13:17:17 -04:00
Marti Bolivar 2f66e51e1a Rename br_image_addr to br_image_off.
The boot response returns a flash offset, not a flash address. This is
causing confusion and leading to crashes on some platforms which don't
have flash at address 0.

Rename the field to make it more clear what its purpose is; future
patches can start fixing up usages.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-09 13:17:15 -04:00
Marti Bolivar 6fe8fa1f7c bootutil: use flash_area_get_sectors()
The flash map API has added a new routine, flash_area_get_sectors().
Use that instead of flash_area_to_sectors(), which is now deprecated.

This exposed a bug in boot_swap_sectors() (a large sz would still lead
to copying past the end of the area, including the trailer); fix it.

This also exposed a bug in split_go(). Calling boot_read_sectors()
there makes a potentially invalid assumption, namely:

      (loader_slot == FLASH_AREA_IMAGE_0 &&
       split_slot == FLASH_AREA_IMAGE_1)

We make this slightly better by making sure that loader_slot and
split_slot in split_go() get placed into boot_data at indices
mynewt-core currently sets LOADER_SLOT and SPLIT_SLOT to, but a real
fix is left to future work.

This patch also frees up about 650B of RAM, since struct flash_sector
is smaller than struct flash_area.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-09 13:16:25 -04:00
Marti Bolivar fa264cbeb7 flash_map: distinguish between areas and sectors
The current flash_map.h API treats flash areas and flash sectors
synonymously.  This isn't totally accurate; a flash area comprises one
or more sectors.

To distinguish them, add a new struct flash_sector, and a new
flash_area_get_sectors() which initializes an array of struct
flash_sector instead of struct flash area.

That done, deprecate flash_area_to_sectors().

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-08 10:24:31 -04:00
Marti Bolivar f6603066c0 flash_map: add flash_device_base()
This accessor returns the physical base address of a flash device,
given its ID.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-08 10:24:31 -04:00
Marti Bolivar 2bcf7c1cb4 flash_map.h: add docstrings
Add Doxygen docstrings to struct flash_area fields.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-08 10:24:31 -04:00
Marti Bolivar 8ae1147f42 bootutil: whitespace fixes
Delete some trailing whitespace.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-08 10:24:31 -04:00
David Brown 5b35d1f467 sim: Enable warnings in sim builds
Enable -Wall so that warnings will be generated.  Remove an unneeded
declaration that this reveals.
2017-05-05 11:07:42 -06:00
David Brown 585fa14456 logging: Simplify sim logging
Instead of a separate invocation of printf to print the trailing
newline, use some modern cpp trickery to expand the format string
explicitly.  The ## will remove the preceding comma of the argument list
if empty.
2017-05-05 11:07:42 -06:00
David Brown 54b7779803 sim: Clean up logging
Make error the default log level in the sim shims, and add a function
name to two of the calls.
2017-05-05 11:07:42 -06:00
David Brown 75fd5dc05e sim: Generate logging within the sim
Add logging support for when running in the simulator.  Log messages are
still based on compile-time determinations, and log using printf.

Based on a patch from Marti Bolivar <marti.bolivar@linaro.org>.
2017-05-05 11:07:42 -06:00
David Brown 27e382ac68 imgtool: Pad file with 0xff
The bootloader assumes that parts of the flash that aren't written
still have 0xff in them.  Fix the padding code so that the padding is
done this way.
2017-05-03 10:14:48 -06:00
David Brown a5c12c6ad7 Merge pull request #44 from utzig/create-doc
Move design doc to doc dir
2017-05-01 09:38:38 -06:00
David Brown 079793ca46 Merge pull request #43 from d3zd3z/frdm
Better frdm_k64f partitions
2017-05-01 09:38:28 -06:00
David Brown 8b445b5737 Merge pull request #42 from d3zd3z/tinycrypt
Tinycrypt updates
2017-05-01 09:38:17 -06:00
David Brown 45979592a7 Merge pull request #40 from utzig/switch-to-mynewt-master
Switch mynewt repo to master
2017-05-01 09:34:27 -06:00
David Brown 946b2bea4d Merge pull request #39 from utzig/fix-random-resets
Fix random reset behavior
2017-05-01 09:34:12 -06:00
Fabio Utzig 9d6ee9de31 Move design doc to doc dir 2017-05-01 07:41:59 -03:00
David Brown b8e9dde77c frdm_k64f: Use entire flash.
Expand the data slots to 384K each, leaving the boot and scratch areas
as 128K.  This allows more room for code, but will wear the scratch
partition about 3x faster because of the more extensive use of the
partition.
2017-04-27 16:35:27 -06:00
David Brown e629bf3745 Generalize SHA256 code to allow tinycrypt support
When building with ECDSA P-256 as the signature algorithm, we are still
bringing in SHA256 and some ASN.1 code from mbed TLS.  Fix part of this
by wrapping the hash functions with general routines (inline functions)
allowing to select between mbed TLS and Tinycrypt for the
implementation.

Update the Zephyr config files so that the Tinycrypt version is used
when building the ECDSA P-256 signing variant.
2017-04-27 16:31:12 -06:00
David Brown d7e350df7d zephyr: Fix up mbed TLS configuration
There are some problems with how mbed TLS is configured in Zephyr.
First, include the makefile stub in the Makefile that uses these
defines.  This makes sure the right definitions get made so that our
custom config gets used for all compiled files, rather than a mixed set.

Also, fix up the wrappers on the custom configs so that each is
different, making it easier to detect if multiple configs are being
included.

Lastly, only include the right header in the image validation.  The mbed
TLS includes don't seem to want to allow both RSA and ECDSA to be used
(due to the key size), and including the wrong header results in a
compilation error.
2017-04-27 16:31:04 -06:00
Fabio Utzig e3aa2e00b1 Switch mynewt repo to master 2017-04-26 10:49:44 -03:00
Fabio Utzig 57652319ae Fix random reset behaviour 2017-04-25 19:54:26 -03:00
David Brown 3e1c38c624 Merge pull request #38 from utzig/magic-sz-const
Use constant for magic size
2017-04-25 15:01:24 -06:00
David Brown 91c2fd6703 Merge pull request #37 from utzig/max-align-as-param
Make max align size a #define
2017-04-25 15:00:39 -06:00
David Brown 2ad2f96720 Merge pull request #36 from utzig/add-generated-to-ignore
Add more state files to ignore list
2017-04-25 15:00:08 -06:00
David Brown bef227c3a0 Merge pull request #35 from utzig/increase-sim-debug-info
Add extra information on errors
2017-04-25 14:59:42 -06:00
Fabio Utzig 19b2c1a927 Add extra information on errors
* Print bail out error information
* Print specific location of non-ff writes
2017-04-20 08:25:30 -03:00