Commit Graph

2055 Commits

Author SHA1 Message Date
David Brown 4c036158d4 imgtool: Fix key argument
Changing the name of the command line argument changes the name of the
fields used to access it.  Change the keysigning code to reflect this,
avoiding a stack dump when trying to generate keys.
2017-06-07 09:19:21 -06:00
David Brown 07916c3155 imgtool.py: Support PKCS#1.5 v2.1 RSA-PSS
Add support for the RSA-PSS signature algorithm to imgtool.py.  This
algorithm has a strong security proof, and is recommended for all new
designs.  The new algorithm is enabled by default for RSA signatures to
match the default in the bootloader also being changed.
2017-06-07 09:19:21 -06:00
David Brown 23f91ad152 scripts: Initial version of Python imgtool
This is the start of a python implementation of imgtool.  This
implements all of the functionality that was missing in the zep2newt.py
tool, namely creation of keypairs, and converting the public version of
these keys into C code.
2017-06-07 09:19:21 -06:00
David Brown 38e6a1637d Merge pull request #52 from utzig/decouple-mynewt
Make mcuboot less mynewt style
2017-06-06 10:24:06 -06:00
Fabio Utzig 19356bf45f Make mcuboot less mynewt style
Remove most of mynewt specific stuff to a separate port package. This
should make mcuboot less "mynewt'y" and slightly easier to port to.

- Mynewt specific stuff moved to boot/mynewt.
- Sample app moved from apps/boot to boot/mynewt.
- Use MYNEWT_VAL macro only on mynewt port.
- BOOTUTIL_* and MYNEWT_VAL() usage moved to MCUBOOT_ defines.
2017-06-02 10:55:27 -07:00
David Brown df3c3da4e7 Merge pull request #41 from utzig/update-status-mgmt
Update to status management
2017-05-30 16:57:01 -06:00
Fabio Utzig 9678c97128 Add comment about trailer swap logic 2017-05-24 09:16:15 -04:00
Fabio Utzig de8a38abb3 Use better naming for flags 2017-05-24 09:16:15 -04:00
Fabio Utzig 34e393ee2d Remove newline from log message 2017-05-24 09:16:15 -04:00
Fabio Utzig acfba2e86e Fix for boot_read_swap_state_by_id to close flash area on errors 2017-05-24 09:16:15 -04:00
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