Commit Graph

43 Commits

Author SHA1 Message Date
Andrzej Puzdrowski f48de7a523 boot/boot_serial: allow nonaligned last chunk
The last data packet might be non aligned to multiple of
the flash write-block-size. This cause that the `image upload`
mcumgr command mighty fail if the device flash driver doesn't
support one-byte write-block-size.

This patch complements the last write operation to aligned chunk
so it meet the requirements.

Added check for ensure than received data chunk doesn't
cross expected image size.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-10-23 17:01:00 +02:00
Kumar Gala 0813efeac6 zephyr: Convert from Zephyr to C99 types
Use C99 types in favor of the Zephyr defined types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-04 08:28:35 -06:00
Øyvind Rønningstad 16d7b73cd2 serial_recovery: Reduce minimum number of members in packet
Was 3, but mcumgr sometimes sends 2 ("off" + "data", "len" is not needed
when "off" != 0). Reduce to 1 to avoid the problem, since the code
has other checks to catch this.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2020-05-13 07:59:22 -06:00
David Brown 57f0df3e18 boot_serial: Initialize possibly initialized variable
The variable `dec_off` can possibly be uninitialized in this function.
As long as the serial protocol used is formed correctly, the
initialization will always happen.  Place an initialization upon
function entry to protect against a case where a malformed protocol is
able to provoke this variable being used before being initialized.

Signed-off-by: David Brown <david.brown@linaro.org>
2020-05-12 13:50:58 -06:00
Carles Cufi 7e7b4ad199 zephyr: boot_serial: Use K_MSEC() with k_sleep
k_sleep() requires explicit conversion of the unit since it takes an
opaque type starting with:
https://github.com/zephyrproject-rtos/zephyr/pull/23382

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-30 21:39:29 +02:00
Øyvind Rønningstad d071356a73 serial_recovery: Add copied and generated CBOR decoding code files
Generated serial_recovery_cbor.c and serial_recovery_cbor.h
Copied cbor_decode.c and cbor_decode.h

This commit is the result of running
./regenerate_serial_recovery_cbor.sh "2020 Nordic Semiconductor ASA"

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2020-03-24 13:10:17 -06:00
Øyvind Rønningstad f42a8205e8 serial_recovery: Replace CBOR decoding code with generated code
- Add the cddl_gen repository as a submodule.
 - Add a CDDL description file for the serial recovery packets to be
   decoded.
 - Add generated code files and cddl_gen's CBOR library to CMakeList.txt
   for Zephyr.
 - Convert boot_serial.c to use the new code.
 - Add a bash script to (re)generate code files using cddl_gen.py.

Serial recovery should work exactly as before, but the binary should be
about 1k smaller.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2020-03-24 13:10:17 -06:00
Dominik Ermel 470e2f3d5b zephyr: Enabling Zephyr/mynewt-core version of tinycbor
Changes needed due to overwrite of Zephyr fork of Tinycbor with
mynewt-core version.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-03-12 15:00:30 +01:00
Peter Bigot 54c1e3fb6b zephyr: fix driver include paths
Zephyr will soon no longer add the drivers subdirectory of the include
hierarchy to the search path, so references to driver headers must
include the drivers/ prefix.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-25 10:01:42 -03:00
Andrzej Puzdrowski f1d189c486 zephyr: switch to recent defines and include headers
In zephyr code-base some generic include patches
and defines had been deprecated since a while.
This condition was maintained until zephyr v2.1.0 inclusive.

Recently these deprecated items were removed completely from
the zephyr master branch. Zephyr current SHA of this patch is
e124c1cd34938f02bbe879533c6bd29b5ff53707

This patch switch mcuboot to using most recent items.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-12-12 11:54:44 +01:00
Andy Gross 441e997891 mynewt: Make cflags consistent for if or ifdef usage
This patch changes the cflag entry for MCUBOOT_MYNEWT to make it
consistent when using #if or #ifdef.

Signed-off-by: Andy Gross <andy.gross@juul.com>
2019-10-21 17:22:34 -03:00
Fabio Utzig ea34f9a77b Fix Mynewt boot_serial unittest
The boot_serial test was failing build because it hadn't been updated to
use new multi-image flash area nomenclature. This fixes the build.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-10-01 17:36:12 -03:00
Fabio Utzig 6f49c27a56 Add boot_serial support for multi-images
This updates `image list` and `image upload` objects to support
multi-images. The information about which image is being handled was
added to the CBOR as "image" field, which when not available, is
considered to have value 0.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig 10ee648145 Update bootutil to reduce amount of global state
The boot loader state currently exists as global variable (boot_data)
which is accessed by all routines; this updates all routines that
require access to the state to receive it by parameter.

Variables that are declared as "static" (globals) were #ifdef'ed to
only use static when building a native bootloader, to avoid stack
allocation. When bootutil is built to run in the simulator they are
stack allocated to avoid thread share.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-07 14:33:36 -03:00
Fabio Utzig b0f0473352 Remove current_image global and macro updates
Currently to determine which image is being operated on, there is a global
variable called current_image which is used by most macros and APIs to
correctly access the flash areas required by the bootloader. This moves
this variable to the already existing state struct and refactors all
macros and APIs to receive the current image by parameters. To maintain
compatibility some of the macros were not updated and use image 0 when
called.

The definitions of FLASH_AREA_IMAGE_PRIMARY and FLASH_AREA_IMAGE_SECONDARY
for Mynewt compatibility were moved out of bootutil sources to a Mynewt
specific include file.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-07 14:33:36 -03:00
Christopher Collins 30151a33be Mynewt: Fix boot_serial unit tests
These unit tests were failing with build errors such as this:

    boot/boot_serial/test/src/testcases/boot_serial_img_msg.c:64:26: error: use of undeclared identifier 'FLASH_AREA_IMAGE_PRIMARY'
        rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fap);
                             ^
The `FLASH_AREA_IMAGE_{PRIMARY,SECONDARY} definitions were not visible
because `MCUBOOT_MYNEWT` was not getting defined in the boot_serial
unit test package.

This commit defines `MCUBOOT_MYNEWT` in the boot_serial unit test
package, and adds the necessary include to pull in the PRIMARY /
SECONDARY definitions.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2019-03-21 09:05:22 -07:00
David Vincze 2d736ad4c5 Replace flash partitioning terminology
This change replaces the slot 0/1 terminology with primary/secondary
slot and replaces FLASH_AREA_IMAGE_0/1 with
FLASH_AREA_IMAGE_PRIMARY/SECONDARY. This naming convention may be more
understandable, fits better to MCUs with multiple images and it is an
architecture agnostic alternative as well.

Change-Id: I655a585f6ae023852c671ee6635399efe25209c9
Signed-off-by: David Vincze <david.vincze@arm.com>
Signed-off-by: David Brown <david.brown@linaro.org>
2019-03-13 15:40:21 -06:00
Andrzej Puzdrowski 0cd178d0e9 zephyr: fix build with zephyr
zephyr macro min() was hanged to MIN()
Kconfig key CDC_ACM_PORT_NAME was changed to CDC_ACM_PORT_NAME_0

zephyr sha of the fixing time is 406dc2cb0e2868392f444677ace416440695829f.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-02-22 10:36:41 +01:00
Christopher Collins fea163c6a4 Fix Mynewt builds; add log stub dependency
A recent change in the Mynewt repo
(b10cbea5ef882e7f91d1c34ffcf2506d3e183003) imposes the LOG API
requirement on the `sys/mfg` package.  To fix broken builds, make the
Mynewt app and test package depend on `sys/log/stub`.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2019-01-12 14:38:41 -07:00
Emanuele Di Santo 401d7b33d3 zephyr: boot_serial: fix CRC header warning
The crc16.h header has been deprecated in Zephyr.
Update include directive to use the new header.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
2019-01-11 13:39:22 +01:00
Emanuele Di Santo 9f1933d1a5 boot: zephyr: migrate to new log subystem
The old log subsystem has been deprecated in Zephyr.
Migrate to the new subsystem to avoid compilation warnings.

In-place log processing is selected as it is required as MCUBoot is
one thread application.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-01-10 19:11:15 +01:00
Marko Kiiskila e5aeee4ad1 boot_serial; check CRC for RX only if all data has arrived.
Signed-off-by: Marko Kiiskila <marko@apache.org>
2018-12-24 08:47:25 -02:00
Andrzej Puzdrowski c2e30cf2c3 serial recovery: always erase image status
It is possible that while flash was erased progressively
the flash image status page was not erased.
This patch check this case and performs additional eras
if it was required.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-08-04 09:13:23 -03:00
Emanuele Di Santo 205c8c6980 zephyr: erase flash pages progressively
This commit adds the option to erase flash pages while receiving
the firmware, opposed to bulk-erasing the whole image area at
the beginning of the DFU process. This is required on some
hardware that has long erase times, to prevent a long wait
and possibly a timeout during DFU.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-08-04 09:13:23 -03:00
Szymon Janc c48e7f917e boot_serial: Fix build on Zephyr with ECDSA enabled
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-07-03 17:46:33 +02:00
Andrzej Puzdrowski ec1e4d1bef boot_serial: preserve against buffer overflow for zephyr
For zephyr it was possible to make buffer overflow while decoding
incoming base64 sting. This patch correct the available
buffer size transferred to base64 decoding function, which mitigate the
issue.

Clean up boot_serial_start function from unwanted
execution constant pointers.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-20 16:08:58 +02:00
Marko Kiiskila 8b1ce3a6ce boot_serial; re-enable mynewt boot_serial unittests.
Signed-off-by: Marko Kiiskila <marko@runtime.io>
2018-06-18 13:13:41 -07:00
Marko Kiiskila c427af2e7e zephyr/serial_adapter; no need to inject \r on \n anymore.
boot_serial; syscfg tabs to spaces.

Signed-off-by: Marko Kiiskila <marko@runtime.io>
2018-06-14 23:19:06 +03:00
Marko Kiiskila 149b457a22 boot_serial; improve platform abstraction.
Pass function pointers to do reads/writes from uart.

Signed-off-by: Marko Kiiskila <marko@runtime.io>
2018-06-14 23:19:06 +03:00
Marko Kiiskila c0011585be boot_serial; fix mynewt unit test.
Signed-off-by: Marko Kiiskila <marko@runtime.io>
2018-06-14 23:19:06 +03:00
Marko Kiiskila ce50ab0648 boot_serial; text size reduction.
- Remove dependency to sprintf()
 - Remove dependency to cborattr
 - mynewt: replace console with more direct interface to uart
 - mynewt: settings to reduce included os code

Signed-off-by: Marko Kiiskila <marko@runtime.io>
2018-06-14 23:19:06 +03:00
Marko Kiiskila 316d361fb3 mynewt app; support additional options to enter serial dfu.
Signed-off-by: Marko Kiiskila <marko@runtime.io>
2018-06-14 23:19:06 +03:00
Fabio Utzig 48841f28ce Remove per file log level configs
This removes settings of log level on a per file basis. The log level
should be set by the global config, while per file log configuration can
still be set, don't enforce them.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-06-04 06:54:39 -03:00
Andrzej Puzdrowski b788c71c08 Replace mcuboot flash_map by zephyr flash_map
The patch introduce usage of zephyr flas_map module instead
of mcuboot zephyr-only implementation. Unused flash_area_to_sectors
API of former flash_map was removed as well.
Size of sector-status-update-map entry is now defined thanks to the
minimum write size supported by the flash driver.

For avoid ambiguity former zephyr-only files flash_map.c
were renamed to flash_map_extended.c (its code now implements
only addition to this what zephyr flash_map implements).

flash_map.h header include is now warped by flash_map_backedn.h headre
because implementations and include pathes are diferent in Zephyr and Mynewt.

Usage of hal_flash_align() were replaced by usage flash_area_align().
This provide consistency between MyNewt and Zephyr implementation as
this API is available in both RTOSes.

flash_map.h was moved to the simulator c-support files as now missing in
the boot/zephyr subdirectories.

f. boot_scratch_fa_device_id was removed as unused.
f. boot_img_fa_device_id was and expanded the only use of it
(on loader.c).

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-05-16 16:05:17 -03:00
Christopher Collins 2844faaccc Mynewt unit tests - Add repo prefix to dep lists.
The unit tests depend on a few Mynewt packages (`test/testutil` and
`sys/console/stub`).  If there is no repo prefix in the dependency
specifier, newt assumes the package is in the local repo (mcuboot)`.
This commit adds the `@apache-mynewt-core/` prefix to these
dependencies.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-05-01 15:05:57 -03:00
Andrzej Puzdrowski 268cdd0e09 fix warnings while building along with serial recovery
Following warnings were fixed within this patch:

 'isspace' macro should take an int value

 function 'bs_reset' should return void

 redefinition of 'MBEDTLS_CONFIG_FILE' macro while
 it is already defined by the zephyr build system.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-10 08:16:35 -03:00
Andrzej Puzdrowski 386b592109 use zephyr tincybor instead of mcuboot build-in tinycbor
Zephyr has build-in tinycbor code of version which doesn't
require newlib-c by default. Also the cborattr module is now
taken form the zephyr code.

This patch decrease flash consumption by 10 KB for serial recovery build.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-10 10:36:20 +02:00
Fabio Utzig 30f6b2a908 Fix boot_serial to follow flash write alignment
This fixes an issue found on stm32f3 where newtmgr after writing an odd
sized packet, would hardfault on the next write due to trying to write an
odd address which is not valid on stm32f3 flash.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-04-03 11:42:58 -03:00
Carles Cufi 0165be8ba8 boot_serial: zephyr: Use new base64 library
Instead of relying on mbedTLS' base64 codec, use the new Zephyr base64
library.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-27 10:12:11 -03:00
Fabio Utzig 1a2e41ae44 Fix serial boot functionality for Mynewt
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-02-22 15:51:39 -07:00
Andrzej Puzdrowski 8e96b8352f enable serial recovery functionality on the zephyr mcuboot
This patch introduced serial bootloader functionality ported
from mynewt targets tree.

For achieving this following changes were applied:
- Modified boot_serial module for using, zephyr-os modules
  (crc driver, mbedtls-base64 library) and the zephyr serial adapter module
  introduced recently.
- Added service of boot serial recovery mode to main.
- Adapted the input parser to using static buffers.

Default serial-boot-pin configuration was added for nrf52_pca10040
and nrf52840_pca10056 boards.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-12-06 16:11:10 -07:00
Fabio Utzig d0116731a9 Remove incubator references from mynewt dev email
Also use a single email for all packages.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-21 12:06:44 -06:00
Christopher Collins 39a5fa95c3 Move packages into "boot" top-level directory. 2016-12-12 17:51:23 -08:00