[mynewt-mcumgr] branch master updated: zephyr: Allow to select slot for DFU as image

2021-07-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 4fa8691  zephyr: Allow to select slot for DFU as image
4fa8691 is described below

commit 4fa869142f16e00d42415bc6dbcb7f1f92ba4abd
Author: Dominik Ermel 
AuthorDate: Thu Jun 10 09:00:09 2021 +

zephyr: Allow to select slot for DFU as image

The change alters Zephyr port of mcumgr to use "image" parameter,
from update packet, to identify slot the update should be written to.
The number of available images/slots have also been extended with
image_2 and image_3.
WARNING: Due to mcumgr always sending "erase" command, which is
hardcoded to erase slot number 1, to upload to slot > 2, the -e
switch to mcumgr, which means no erase, image upload is required;
otherwise innocent slot 1 will be erased while other slot is uploaded.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index be139c4..afa3e6e 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -91,7 +91,10 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool 
*out_empty)
 }
 
 /**
- * Get flash_area ID for a image slot number.
+ * Get flash_area ID for a image number; actually the slots are images
+ * for Zephyr, as slot 0 of image 0 is image_0, slot 0 of image 1 is
+ * image_2 and so on. The function treats slot numbers as absolute
+ * slot number starting at 0.
  */
 static int
 zephyr_img_mgmt_flash_area_id(int slot)
@@ -107,6 +110,18 @@ zephyr_img_mgmt_flash_area_id(int slot)
 fa_id = FLASH_AREA_ID(image_1);
 break;
 
+#if FLASH_AREA_LABEL_EXISTS(image_2)
+case 2:
+fa_id = FLASH_AREA_ID(image_2);
+break;
+#endif
+
+#if FLASH_AREA_LABEL_EXISTS(image_3)
+case 3:
+fa_id = FLASH_AREA_ID(image_3);
+break;
+#endif
+
 default:
 fa_id = -1;
 break;
@@ -490,7 +505,7 @@ img_mgmt_impl_upload_inspect(const struct 
img_mgmt_upload_req *req,
 }
 }
 
-action->area_id = img_mgmt_get_unused_slot_area_id(-1);
+action->area_id = img_mgmt_get_unused_slot_area_id(req->image - 1);
 if (action->area_id < 0) {
 /* No slot where to upload! */
 *errstr = img_mgmt_err_str_no_slot;


[mynewt-core] branch master updated: baselibc: Fix build with -Werror=array-parameter enabled

2021-07-14 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new d3ded77  baselibc: Fix build with -Werror=array-parameter enabled
d3ded77 is described below

commit d3ded778aec32af75ddfe716ab2a38e26bc9fc24
Author: Szymon Janc 
AuthorDate: Mon Jul 12 15:32:27 2021 +0200

baselibc: Fix build with -Werror=array-parameter enabled

repos/apache-mynewt-core/libc/baselibc/src/jrand48.c:8:29: error: argument 
1 of type
‘short unsigned int[3]’ with mismatched bound [-Werror=array-parameter=]
8 | long jrand48(unsigned short xsubi[3])
  |  ~~~^~~~
In file included from 
repos/apache-mynewt-core/libc/baselibc/src/jrand48.c:5:
repos/apache-mynewt-core/libc/baselibc/include/stdlib.h:66:23: note: 
previously declared
as ‘short unsigned int *’
   66 | __extern long jrand48(unsigned short *);
  |   ^~~~
cc1: all warnings being treated as errors
---
 libc/baselibc/include/stdlib.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/baselibc/include/stdlib.h b/libc/baselibc/include/stdlib.h
index 0abc783..d80a0f8 100644
--- a/libc/baselibc/include/stdlib.h
+++ b/libc/baselibc/include/stdlib.h
@@ -63,9 +63,9 @@ __extern void *bsearch(const void *, const void *, size_t, 
size_t,
   __comparefunc_t);
 __extern void qsort(void *, size_t, size_t, __comparefunc_t);
 
-__extern long jrand48(unsigned short *);
+__extern long jrand48(unsigned short xsubi[3]);
 __extern long mrand48(void);
-__extern long nrand48(unsigned short *);
+__extern long nrand48(unsigned short xsubi[3]);
 __extern long lrand48(void);
 __extern unsigned short *seed48(const unsigned short *);
 __extern void srand48(long);


[mynewt-mcumgr] branch master updated: samples/smp_svr/zephyr: Update stack size

2021-07-13 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new d8802de  samples/smp_svr/zephyr: Update stack size
d8802de is described below

commit d8802deabde876b8faca2389cca7090d40dd530b
Author: Dominik Ermel 
AuthorDate: Fri Jun 11 07:55:03 2021 +

samples/smp_svr/zephyr: Update stack size

The addition of image interpretation requires increase in stack
size.

Signed-off-by: Dominik Ermel 
---
 samples/smp_svr/zephyr/prj.conf  | 2 +-
 samples/smp_svr/zephyr/prj_tiny.conf | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/samples/smp_svr/zephyr/prj.conf b/samples/smp_svr/zephyr/prj.conf
index ce0551b..61b775e 100644
--- a/samples/smp_svr/zephyr/prj.conf
+++ b/samples/smp_svr/zephyr/prj.conf
@@ -2,7 +2,7 @@
 CONFIG_MCUMGR=y
 
 # Some command handlers require a large stack.
-CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
+CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
 
 # Ensure an MCUboot-compatible binary is generated.
 CONFIG_BOOTLOADER_MCUBOOT=y
diff --git a/samples/smp_svr/zephyr/prj_tiny.conf 
b/samples/smp_svr/zephyr/prj_tiny.conf
index c53800d..3faa416 100644
--- a/samples/smp_svr/zephyr/prj_tiny.conf
+++ b/samples/smp_svr/zephyr/prj_tiny.conf
@@ -6,7 +6,7 @@
 CONFIG_MCUMGR=y
 
 # Some command handlers require a large stack.
-CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
+CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
 
 # Ensure an MCUboot-compatible binary is generated.
 CONFIG_BOOTLOADER_MCUBOOT=y


[mynewt-documentation] branch master updated: native_install: Update link to toolchain for Windows

2021-07-07 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-documentation.git


The following commit(s) were added to refs/heads/master by this push:
 new 9d44d22  native_install: Update link to toolchain for Windows
9d44d22 is described below

commit 9d44d22b14bcb14380f59c810df24b28ad68c446
Author: Magdalena Kasenberg 
AuthorDate: Wed Jul 7 12:01:04 2021 +0200

native_install: Update link to toolchain for Windows

This fixes error that occurred on Windows at newt create-image command:
Error: arm-none-eabi-objcopy
[..]pache-mynewt-nimble/apps/bttester/bttester.hex 64-bit address
0x4b4fa3c000 out of range for Intel Hex file
---
 docs/get_started/native_install/cross_tools.rst | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/docs/get_started/native_install/cross_tools.rst 
b/docs/get_started/native_install/cross_tools.rst
index 0cf1686..c0adc4d 100644
--- a/docs/get_started/native_install/cross_tools.rst
+++ b/docs/get_started/native_install/cross_tools.rst
@@ -64,9 +64,9 @@ 
https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa.
 Installing the ARM Toolchain for Windows
 ~
 
-#.  Download and run the `installer 
<https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-win32.exe>`__
+#.  Download and run the `installer 
<https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-win32.exec>`__
 to install arm-none-eabi-gcc and arm-none-eabi-gdb. Select the default
-destination folder: **C:\\Program Files (x86)\\GNU Tools ARM Embedded\\8 
2018-q4-major**.
+destination folder: **C:\\Program Files (x86)\\GNU Arm Embedded 
Toolchain\\10 2020-q4-major**.
 
 **Notes:**
 
@@ -84,9 +84,9 @@ Installing the ARM Toolchain for Windows
 .. code-block:: console
 
 $ which arm-none-eabi-gcc
-/c/Program Files (x86)/GNU Tools ARM Embedded/8 
2018-q4-major/bin/arm-none-eabi-gcc
-$which arm-none-eabi-gdb
-/c/Program Files (x86)/GNU Tools ARM Embedded/8 
2018-q4-major/bin/arm-none-eabi-gdb
+/c/Program Files (x86)/GNU Arm Embedded Toolchain/10 
2020-q4-major/bin/arm-none-eabi-gcc
+$ which arm-none-eabi-gdb
+/c/Program Files (x86)/GNU Arm Embedded Toolchain/10 
2020-q4-major/bin/arm-none-eabi-gdb
 
 Installing the Debuggers
 


[mynewt-mcumgr] 03/03: zephyr: Improve and rename img_mgmt_find_best_area_id

2021-06-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit e71063a3c01d6ea8b73a06f14c1d3006f2de9e7a
Author: Dominik Ermel 
AuthorDate: Wed Jun 9 13:15:52 2021 +

zephyr: Improve and rename img_mgmt_find_best_area_id

The img_mgmt_find_best_area_id has been renamed to
img_mgmt_get_unused_slot_area_id and now takes one integer parameter,
that is a slot number to check.
The parameter may be -1, in which case the function will check the
first two slots for availability to perform DFU.  In case when
positive integer is provided the function will address directly
selected slot, and will perform the same tests, as in auto-select,
for first two slots, but in case of slot numbers above 1, it will
just check if the slot has been defined.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 66 +-
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 9eb9450..be139c4 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -93,7 +93,7 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool 
*out_empty)
 /**
  * Get flash_area ID for a image slot number.
  */
-static uint8_t
+static int
 zephyr_img_mgmt_flash_area_id(int slot)
 {
 uint8_t fa_id;
@@ -108,48 +108,46 @@ zephyr_img_mgmt_flash_area_id(int slot)
 break;
 
 default:
-assert(0);
-fa_id = FLASH_AREA_ID(image_1);
+fa_id = -1;
 break;
 }
 
 return fa_id;
 }
 
+/**
+ * The function will check if given slot is available, and allowed, for DFU;
+ * providing -1 as a parameter means find any unused and non-active available;
+ * if checks area positive, then area ID is returned, -1 is returned otherwise.
+ * Note that auto-selection is performed only between two first slots.
+ */
 static int
-img_mgmt_find_best_area_id(void)
+img_mgmt_get_unused_slot_area_id(int slot)
 {
-struct image_version ver;
-int best = -1;
-int i;
-int rc;
-
-for (i = 0; i < 2; i++) {
-rc = img_mgmt_read_info(i, , NULL, NULL);
-if (rc < 0) {
-continue;
-}
-if (rc == 0) {
-/* Image in slot is ok. */
-if (img_mgmt_slot_in_use(i)) {
-/* Slot is in use; can't use this. */
-continue;
-} else {
-/*
- * Not active slot, but image is ok. Use it if there are
- * no better candidates.
- */
-best = i;
+/* Auto select slot; note that this is performed only between two first
+ * slots, at this pointi, which will require fix when Direct-XIP, which may
+ * support more slots, gets support within Zephyr. */
+if (slot < -1) {
+return -1;
+} else if (slot == -1) {
+for (slot = 0; slot < 2; slot++) {
+if (img_mgmt_slot_in_use(slot) == 0) {
+int area_id = zephyr_img_mgmt_flash_area_id(slot);
+if (area_id != -1) {
+return area_id;
+}
 }
-continue;
 }
-best = i;
-break;
+return -1;
 }
-if (best >= 0) {
-best = zephyr_img_mgmt_flash_area_id(best);
+/* Direct selection; the first two slots are checked for being available
+ * and unused; the all other slots are just checked for availability. */
+if (slot < 2) {
+slot = img_mgmt_slot_in_use(slot) == 0 ? slot : -1;
 }
-return best;
+
+/* Return area ID for the slot or -1 */
+return slot != -1  ? zephyr_img_mgmt_flash_area_id(slot) : -1;
 }
 
 /**
@@ -194,8 +192,8 @@ img_mgmt_impl_erase_slot(void)
 bool empty;
 int rc, best_id;
 
-/* Select non-active slot */
-best_id = img_mgmt_find_best_area_id();
+/* Select any non-active, unused slot */
+best_id = img_mgmt_get_unused_slot_area_id(-1);
 if (best_id < 0) {
 return MGMT_ERR_EUNKNOWN;
 }
@@ -492,7 +490,7 @@ img_mgmt_impl_upload_inspect(const struct 
img_mgmt_upload_req *req,
 }
 }
 
-action->area_id = img_mgmt_find_best_area_id();
+action->area_id = img_mgmt_get_unused_slot_area_id(-1);
 if (action->area_id < 0) {
 /* No slot where to upload! */
 *errstr = img_mgmt_err_str_no_slot;


[mynewt-mcumgr] branch master updated (a5d3441 -> e71063a)

2021-06-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git.


from a5d3441  Merge pull request #125 from vrahane/img_mgmt_erase_stop_dfu
 new 71c76f5  zephyr: Upload should use g_img_mgmt_state
 new e215d26  zephyr: Check area id in erase slot processing
 new e71063a  zephyr: Improve and rename img_mgmt_find_best_area_id

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 76 +-
 1 file changed, 38 insertions(+), 38 deletions(-)


[mynewt-mcumgr] 02/03: zephyr: Check area id in erase slot processing

2021-06-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit e215d26bb7c7ea1352bc954b2b59a6fc0a234a46
Author: Dominik Ermel 
AuthorDate: Wed Jun 9 13:51:18 2021 +

zephyr: Check area id in erase slot processing

The img_mgmt_impl_erase_slot was not checking the return value
of the img_mgmt_find_best_area_id.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 25b9318..9eb9450 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -192,11 +192,13 @@ int
 img_mgmt_impl_erase_slot(void)
 {
 bool empty;
-int rc;
+int rc, best_id;
 
 /* Select non-active slot */
-const int best_id = img_mgmt_find_best_area_id();
-
+best_id = img_mgmt_find_best_area_id();
+if (best_id < 0) {
+return MGMT_ERR_EUNKNOWN;
+}
 rc = zephyr_img_mgmt_flash_check_empty(best_id, );
 if (rc != 0) {
 return MGMT_ERR_EUNKNOWN;


[mynewt-mcumgr] 01/03: zephyr: Upload should use g_img_mgmt_state

2021-06-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 71c76f5642af0f5567c50b0d7430eb2cda47220f
Author: Dominik Ermel 
AuthorDate: Wed Jun 9 13:09:16 2021 +

zephyr: Upload should use g_img_mgmt_state

The upload was calling img_mgmt_find_best_area_id each time it needed
to provide area_id, while it should have been using the already selected
area from the g_img_mgmt_state.area_id.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 777aad5..25b9318 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -292,7 +292,7 @@ img_mgmt_impl_write_image_data(unsigned int offset, const 
void *data,
}
}
 #endif
-   rc = flash_img_init_id(ctx, img_mgmt_find_best_area_id());
+   rc = flash_img_init_id(ctx, g_img_mgmt_state.area_id);
 
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
@@ -330,7 +330,7 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned 
int num_bytes)
 goto end;
 }
 
-rc = flash_area_open(img_mgmt_find_best_area_id(), );
+rc = flash_area_open(g_img_mgmt_state.area_id, );
 if (rc != 0) {
 LOG_ERR("Can't bind to the flash area (err %d)", rc);
 rc = MGMT_ERR_EUNKNOWN;


[mynewt-mcumgr] branch master updated: img_mgmt: Add interpretation of "image" parameter

2021-06-10 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 6a10fa6  img_mgmt: Add interpretation of "image" parameter
6a10fa6 is described below

commit 6a10fa6c4b36a754fbf57688ad9adc32c1bef4ee
Author: Dominik Ermel 
AuthorDate: Wed Jun 9 13:56:07 2021 +

img_mgmt: Add interpretation of "image" parameter

The commit extends img_mgmt_upload_req with image member that will
be used to hold image number; it also adds code that picks the
image number from update frame.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/include/img_mgmt/img_mgmt.h |  1 +
 cmd/img_mgmt/src/img_mgmt.c  | 17 -
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt.h 
b/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
index 69f6f1b..0e4230b 100644
--- a/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
@@ -74,6 +74,7 @@ extern struct img_mgmt_state g_img_mgmt_state;
 
 /** Represents an individual upload request. */
 struct img_mgmt_upload_req {
+unsigned long long int image;   /* 0 by default */
 unsigned long long int off; /* -1 if unspecified */
 unsigned long long int size;/* -1 if unspecified */
 size_t data_len;
diff --git a/cmd/img_mgmt/src/img_mgmt.c b/cmd/img_mgmt/src/img_mgmt.c
index 9cb7b7d..f87f74b 100644
--- a/cmd/img_mgmt/src/img_mgmt.c
+++ b/cmd/img_mgmt/src/img_mgmt.c
@@ -394,42 +394,49 @@ img_mgmt_upload(struct mgmt_ctxt *ctxt)
 .data_len = 0,
 .data_sha_len = 0,
 .upgrade = false,
+.image = 0,
 };
 
 const struct cbor_attr_t off_attr[] = {
 [0] = {
+.attribute = "image",
+.type = CborAttrUnsignedIntegerType,
+.addr.uinteger = ,
+.nodefault = true
+},
+[1] = {
 .attribute = "data",
 .type = CborAttrByteStringType,
 .addr.bytestring.data = req.img_data,
 .addr.bytestring.len = _len,
 .len = sizeof(req.img_data)
 },
-[1] = {
+[2] = {
 .attribute = "len",
 .type = CborAttrUnsignedIntegerType,
 .addr.uinteger = ,
 .nodefault = true
 },
-[2] = {
+[3] = {
 .attribute = "off",
 .type = CborAttrUnsignedIntegerType,
 .addr.uinteger = ,
 .nodefault = true
 },
-[3] = {
+[4] = {
 .attribute = "sha",
 .type = CborAttrByteStringType,
 .addr.bytestring.data = req.data_sha,
 .addr.bytestring.len = _sha_len,
 .len = sizeof(req.data_sha)
 },
-[4] = {
+[5] = {
 .attribute = "upgrade",
 .type = CborAttrBooleanType,
 .addr.boolean = ,
 .dflt.boolean = false,
 },
-[5] = { 0 },
+[6] = { 0 },
 };
 int rc;
 const char *errstr = NULL;


[mynewt-core] branch master updated: nxp: kinetis: decrease LPUART RAM usage

2021-06-01 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 63e14b7  nxp: kinetis: decrease LPUART RAM usage
63e14b7 is described below

commit 63e14b70af0e4309402e86a7fcdd8e5bfc81a879
Author: Fabio Utzig 
AuthorDate: Mon May 31 12:05:06 2021 -0300

nxp: kinetis: decrease LPUART RAM usage

Refactor LPUART driver to only allocated RAM proportional to the number
of enabled Uarts; each UART uses about 230 bytes for its state, so
having a single UART enabled should provide a significant reduction in
RAM usage.

The driver's flash usage was also reduced, by about 20% when a single
UART is being used.

Signed-off-by: Fabio Utzig 
---
 hw/mcu/nxp/kinetis/include/hal_lpuart_nxp.h |  18 ---
 hw/mcu/nxp/kinetis/src/hal_lpuart.c | 193 
 2 files changed, 137 insertions(+), 74 deletions(-)

diff --git a/hw/mcu/nxp/kinetis/include/hal_lpuart_nxp.h 
b/hw/mcu/nxp/kinetis/include/hal_lpuart_nxp.h
index 9b9174a..10783b0 100644
--- a/hw/mcu/nxp/kinetis/include/hal_lpuart_nxp.h
+++ b/hw/mcu/nxp/kinetis/include/hal_lpuart_nxp.h
@@ -24,24 +24,6 @@
 extern "C" {
 #endif
 
-#define NXP_UART_EXISTS  { 1, \
-   1, \
-   (FSL_FEATURE_SOC_LPUART_COUNT > 2U), \
-   (FSL_FEATURE_SOC_LPUART_COUNT > 3U), \
-   (FSL_FEATURE_SOC_LPUART_COUNT > 4U) }
-
-#define NXP_UART_ENABLED { MYNEWT_VAL(UART_0), \
-   MYNEWT_VAL(UART_1), \
-   MYNEWT_VAL(UART_2), \
-   MYNEWT_VAL(UART_3), \
-   MYNEWT_VAL(UART_4) }
-
-#define NXP_UART_CLOCKS  { kCLOCK_Osc0ErClk, \
-   kCLOCK_Osc0ErClk, \
-   kCLOCK_Osc0ErClk, \
-   kCLOCK_Osc0ErClk, \
-   kCLOCK_Osc0ErClk }
-
 #define NXP_UART_PORTS   { MYNEWT_VAL(UART_0_PORT), \
MYNEWT_VAL(UART_1_PORT), \
MYNEWT_VAL(UART_2_PORT), \
diff --git a/hw/mcu/nxp/kinetis/src/hal_lpuart.c 
b/hw/mcu/nxp/kinetis/src/hal_lpuart.c
index 3b83a37..2742fe7 100644
--- a/hw/mcu/nxp/kinetis/src/hal_lpuart.c
+++ b/hw/mcu/nxp/kinetis/src/hal_lpuart.c
@@ -70,25 +70,112 @@ struct hal_uart {
 };
 
 /* UART configurations */
-static struct hal_uart uarts[FSL_FEATURE_SOC_LPUART_COUNT];
+#define UART_CNT (((uint8_t)(MYNEWT_VAL(UART_0) != 0)) + \
+  ((uint8_t)(MYNEWT_VAL(UART_1) != 0)) + \
+  ((uint8_t)(MYNEWT_VAL(UART_2) != 0)) + \
+  ((uint8_t)(MYNEWT_VAL(UART_3) != 0)) + \
+  ((uint8_t)(MYNEWT_VAL(UART_4) != 0)))
+
+static struct hal_uart uarts[UART_CNT];
+static struct hal_uart *
+uart_by_port(int port)
+{
+int index;
+
+(void)index;
+(void)uarts;
+
+index = 0;
+#if MYNEWT_VAL(UART_0)
+if (port == 0) {
+return [index];
+}
+index++;
+#endif
+#if MYNEWT_VAL(UART_1)
+if (port == 1) {
+return [index];
+}
+index++;
+#endif
+#if MYNEWT_VAL(UART_2)
+#   if FSL_FEATURE_SOC_LPUART_COUNT < 3
+#   error "UART_2 is not supported on this MCU"
+#   endif
+if (port == 2) {
+return [index];
+}
+index++;
+#endif
+#if MYNEWT_VAL(UART_3)
+#   if FSL_FEATURE_SOC_LPUART_COUNT < 4
+#   error "UART_3 is not supported on this MCU"
+#   endif
+if (port == 3) {
+return [index];
+}
+index++;
+#endif
+#if MYNEWT_VAL(UART_4)
+#   if FSL_FEATURE_SOC_LPUART_COUNT < 5
+#   error "UART_4 is not supported on this MCU"
+#   endif
+if (port == 4) {
+return [index];
+}
+#endif
+return NULL;
+};
 
-static uint8_t const s_uartExists[] = NXP_UART_EXISTS;
-static uint8_t const s_uartEnabled[] = NXP_UART_ENABLED;
 static LPUART_Type *const s_uartBases[] = LPUART_BASE_PTRS;
-static clock_name_t s_uartClocks[] = NXP_UART_CLOCKS;
 static uint8_t const s_uartIRQ[] = LPUART_RX_TX_IRQS;
 static PORT_Type *const s_uartPort[] = NXP_UART_PORTS;
 static clock_ip_name_t const s_uartPortClocks[] = NXP_UART_PORT_CLOCKS;
 static uint8_t const s_uartPIN_RX[] = NXP_UART_PIN_RX;
 static uint8_t const s_uartPIN_TX[] = NXP_UART_PIN_TX;
 
+#if MYNEWT_VAL(UART_0)
 static void uart_irq0(void);
+#endif
+#if MYNEWT_VAL(UART_1)
 static void uart_irq1(void);
+#endif
+#if MYNEWT_VAL(UART_2)
 static void uart_irq2(void);
+#endif
+#if MYNEWT_VAL(UART_3)
 static void uart_irq3(void);
+#endif
+#if MYNEWT_VAL(UART_4)
 static void uart_irq4(void);
-static void (*s_uartirqs[])(void) = {
-uart_irq0, uart_irq1, uart_irq2, uart_irq3, uart_irq4
+#endif
+
+static void (*const s_uartirqs[]

[mynewt-core] branch master updated: fs: littlefs: add migrate/readonly build options

2021-05-05 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 406e623  fs: littlefs: add migrate/readonly build options
 new 1d72ee5  Merge pull request #2587 from utzig/littlefs-options
406e623 is described below

commit 406e623689bf51d79a56138327f7782f35c068a7
Author: Fabio Utzig 
AuthorDate: Wed May 5 12:20:21 2021 -0300

fs: littlefs: add migrate/readonly build options

Add syscfg options that enable building the v1 metadata format migration
to v2, and read-only support (for smaller build sizes).

Signed-off-by: Fabio Utzig 
---
 fs/littlefs/pkg.yml|  6 ++
 fs/littlefs/syscfg.yml | 10 ++
 2 files changed, 16 insertions(+)

diff --git a/fs/littlefs/pkg.yml b/fs/littlefs/pkg.yml
index 2c14a32..8c3471b 100644
--- a/fs/littlefs/pkg.yml
+++ b/fs/littlefs/pkg.yml
@@ -33,5 +33,11 @@ pkg.deps:
 - "@apache-mynewt-core/kernel/os"
 - "@apache-mynewt-core/sys/flash_map"
 
+pkg.cflags.LITTLEFS_MIGRATE_V1:
+- -DLFS_MIGRATE
+
+pkg.cflags.LITTLEFS_READONLY:
+- -DLFS_READONLY
+
 pkg.init:
 littlefs_pkg_init: 'MYNEWT_VAL(LITTLEFS_SYSINIT_STAGE)'
diff --git a/fs/littlefs/syscfg.yml b/fs/littlefs/syscfg.yml
index a45fd39..4dbbad0 100644
--- a/fs/littlefs/syscfg.yml
+++ b/fs/littlefs/syscfg.yml
@@ -36,6 +36,16 @@ syscfg.defs:
 must have the same size.
 value: -1
 
+LITTLEFS_MIGRATE_V1:
+description: >
+Enable support for migrating LFSv1 filesystems to v2.
+value: 0
+
+LITTLEFS_READONLY:
+description: >
+Build LittleFS without write support.
+value: 0
+
 LITTLEFS_BLOCK_COUNT:
 description: >
 Number of blocks/sectors use by this partition.


[mynewt-core] branch master updated: Fix trailing spaces in yaml files

2021-05-05 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 61aa3ae  Fix trailing spaces in yaml files
 new 810bf0d  Merge pull request #2586 from 
utzig/yaml-trailing-space-cleanup
61aa3ae is described below

commit 61aa3ae7f355e5d81341d1e06f2b66db3d178294
Author: Fabio Utzig 
AuthorDate: Sun May 2 22:06:49 2021 -0300

Fix trailing spaces in yaml files

Clean up trailing spaces, to avoid copypasta of pkg.yml and syscfg.yml
with trailing spaces in the license headers to keep propagating.

Signed-off-by: Fabio Utzig 
---
 apps/bleprph_oic/pkg.yml|  4 ++--
 apps/bleprph_oic/syscfg.yml |  2 +-
 apps/blesplit/pkg.yml   |  2 +-
 apps/bus_test/lis2dh_node/pkg.yml   |  2 +-
 apps/bus_test/pkg.yml   |  2 +-
 apps/coremark/pkg.yml   |  2 +-
 apps/ffs2native/pkg.yml |  2 +-
 apps/lora_app_shell/pkg.yml |  2 +-
 apps/loraping/pkg.yml   |  2 +-
 apps/lorashell/pkg.yml  |  2 +-
 apps/metrics/pkg.yml|  8 
 apps/metrics/syscfg.yml |  2 +-
 apps/ocf_sample/pkg.yml |  2 +-
 apps/sensors_test/pkg.yml   |  2 +-
 apps/slinky/pkg.yml |  2 +-
 apps/splitty/pkg.yml|  2 +-
 apps/testbench/pkg.yml  |  2 +-
 apps/trng_test/pkg.yml  |  4 ++--
 apps/trng_test/syscfg.yml   |  2 +-
 boot/split/pkg.yml  |  2 +-
 boot/split/syscfg.yml   |  2 +-
 boot/split_app/pkg.yml  |  2 +-
 boot/stub/pkg.yml   |  2 +-
 compiler/arc/pkg.yml|  2 +-
 compiler/arm-none-eabi-m0/compiler.yml  |  2 +-
 compiler/arm-none-eabi-m0/pkg.yml   |  2 +-
 compiler/arm-none-eabi-m3/compiler.yml  |  2 +-
 compiler/arm-none-eabi-m3/pkg.yml   |  2 +-
 compiler/arm-none-eabi-m33/compiler.yml |  2 +-
 compiler/arm-none-eabi-m33/pkg.yml  |  2 +-
 compiler/arm-none-eabi-m4/compiler.yml  |  2 +-
 compiler/arm-none-eabi-m4/pkg.yml   |  2 +-
 compiler/arm-none-eabi-m7/compiler.yml  |  2 +-
 compiler/arm-none-eabi-m7/pkg.yml   |  2 +-
 compiler/sim/pkg.yml|  2 +-
 crypto/mbedtls/pkg.yml  |  2 +-
 crypto/mbedtls/selftest/pkg.yml |  4 ++--
 crypto/tinycrypt/pkg.yml|  2 +-
 encoding/base62/pkg.yml |  2 +-
 encoding/base62/selftest/pkg.yml|  4 ++--
 encoding/base64/pkg.yml |  2 +-
 encoding/base64/selftest/pkg.yml|  4 ++--
 encoding/cborattr/pkg.yml   |  2 +-
 encoding/json/hosttest/pkg.yml  |  4 ++--
 encoding/json/pkg.yml   |  4 ++--
 encoding/json/selftest/pkg.yml  |  4 ++--
 encoding/tinycbor/pkg.yml   |  6 +++---
 fs/disk/pkg.yml |  2 +-
 fs/fatfs/pkg.yml|  2 +-
 fs/fatfs/syscfg.yml |  2 +-
 fs/fcb/pkg.yml  |  2 +-
 fs/fcb/selftest/pkg.yml |  4 ++--
 fs/fcb2/pkg.yml |  2 +-
 fs/fcb2/selftest/pkg.yml|  4 ++--
 fs/fs/pkg.yml   |  2 +-
 fs/nffs/pkg.yml |  2 +-
 fs/nffs/selftest/pkg.yml|  4 ++--
 hw/bsp/ada_feather_stm32f405/pkg.yml|  2 +-
 hw/bsp/apollo2_evb/bsp.yml  |  2 +-
 hw/bsp/b-l072z-lrwan1/pkg.yml   |  2 +-
 hw/bsp/b-l475e-iot01a/pkg.yml   |  2 +-
 hw/bsp/black_vet6/pkg.yml   |  2 +-
 hw/bsp/bluepill/bsp.yml |  2 +-
 hw/bsp/calliope_mini/syscfg.yml |  4 ++--
 hw/bsp/native-armv7/pkg.yml |  2 +-
 hw/bsp/native-mips/pkg.yml  |  2 +-
 hw/bsp/native/pkg.yml   |  2 +-
 hw/bsp/nucleo-f072rb/pkg.yml|  2 +-
 hw/bsp/nucleo-f103rb/pkg.yml|  2 +-
 hw/bsp/nucleo-f103rb/syscfg.yml |  2 +-
 hw/bsp/nucleo-f303k8/pkg.yml|  2 +-
 hw/bsp/nucleo-f303re/pkg.yml|  2 +-
 hw/bsp/nucleo-f401re/pkg.yml|  2 +-
 hw/bsp/nucleo-f411re/pkg.yml|  2

[mynewt-newt] branch master updated: Allow working on repos that lack a "master" branch

2021-05-04 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
 new fd9df1e  Allow working on repos that lack a "master" branch
fd9df1e is described below

commit fd9df1ed93ac1692d0b2bbc96b43f5bef81d14c8
Author: Fabio Utzig 
AuthorDate: Tue May 4 07:40:59 2021 -0300

Allow working on repos that lack a "master" branch

Add a new key option `branch:` that can be configured for git/github
downloaders, so a user can override the default of "master", and
`newt` is gonna look for the yaml files on the given branch, eg:

```
repository.my_development_repo:
type: git
url: g...@github.com:my_org/my_development_repo.git
branch: dev
vers: 0-dev
```

This will clone the repo using "dev" as the default branch.

Signed-off-by: Fabio Utzig 
---
 newt/downloader/downloader.go | 38 --
 newt/repo/repo.go |  5 +++--
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 2230db1..9dd6d05 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -93,6 +93,10 @@ type Downloader interface {
//
// If such a commit exists, it is returned.  Otherwise, "" is returned.
LatestRc(path string, base string) (string, error)
+
+   // Returns the branch that contains the YAML control files; this option
+   // allows implementers to override "master" as the main branch.
+   MainBranch() string
 }
 
 type Commit struct {
@@ -117,6 +121,7 @@ type GithubDownloader struct {
Server string
User   string
Repo   string
+   Branch string
 
// Login for private repos.
Login string
@@ -131,7 +136,8 @@ type GithubDownloader struct {
 
 type GitDownloader struct {
GenericDownloader
-   Url string
+   Urlstring
+   Branch string
 }
 
 type LocalDownloader struct {
@@ -851,8 +857,7 @@ func (gd *GithubDownloader) setRemoteAuth(path string) 
error {
 }
 
 func (gd *GithubDownloader) Clone(commit string, dstPath string) error {
-   // Currently only the master branch is supported.
-   branch := "master"
+   branch := gd.MainBranch()
 
url, publicUrl := gd.remoteUrls()
 
@@ -908,6 +913,14 @@ func (gd *GithubDownloader) FixupOrigin(path string) error 
{
return gd.setOriginUrl(path, publicUrl)
 }
 
+func (gd *GithubDownloader) MainBranch() string {
+   if gd.Branch != "" {
+   return gd.Branch
+   } else {
+   return "master"
+   }
+}
+
 func NewGithubDownloader() *GithubDownloader {
return {}
 }
@@ -934,8 +947,7 @@ func (gd *GitDownloader) FetchFile(
 }
 
 func (gd *GitDownloader) Clone(commit string, dstPath string) error {
-   // Currently only the master branch is supported.
-   branch := "master"
+   branch := gd.MainBranch()
 
util.StatusMessage(util.VERBOSITY_DEFAULT,
"Downloading repository %s (commit: %s)\n", gd.Url, commit)
@@ -985,6 +997,14 @@ func (gd *GitDownloader) FixupOrigin(path string) error {
return setRemoteUrl(path, "origin", gd.Url, true)
 }
 
+func (gd *GitDownloader) MainBranch() string {
+   if gd.Branch != "" {
+   return gd.Branch
+   } else {
+   return "master"
+   }
+}
+
 func NewGitDownloader() *GitDownloader {
return {}
 }
@@ -1005,7 +1025,7 @@ func (ld *LocalDownloader) FetchFile(
 
 func (ld *LocalDownloader) Fetch(path string) error {
os.RemoveAll(path)
-   return ld.Clone("master", path)
+   return ld.Clone(ld.MainBranch(), path)
 }
 
 func (ld *LocalDownloader) Checkout(path string, commit string) error {
@@ -1032,6 +1052,10 @@ func (ld *LocalDownloader) FixupOrigin(path string) 
error {
return nil
 }
 
+func (gd *LocalDownloader) MainBranch() string {
+   return "master"
+}
+
 func NewLocalDownloader() *LocalDownloader {
return {}
 }
@@ -1051,6 +1075,7 @@ func LoadDownloader(repoName string, repoVars 
map[string]string) (
gd.Server = repoVars["server"]
gd.User = repoVars["user"]
gd.Repo = repoVars["repo"]
+   gd.Branch = repoVars["branch"]
 
// The project.yml file can contain github access tokens and
// authentication credentials, but this file is probably 
world-readable
@@ -1080,6 +1105,7 @@ func LoadDownloader(repoName string, repoVars 
map[string]string) (
case "git":
gd := NewGitDownloa

[mynewt-mcumgr] branch master updated: samples: smp_svr: zephyr: Update MTU Kconfig values

2021-04-28 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 757965c  samples: smp_svr: zephyr: Update MTU Kconfig values
 new 798f7fe  Merge pull request #121 from 
XavierChapron/xch/update-zephyr-sample
757965c is described below

commit 757965cba413796805400aa076a01289155b543c
Author: Xavier Chapron 
AuthorDate: Wed Apr 28 13:47:54 2021 +0200

samples: smp_svr: zephyr: Update MTU Kconfig values

The usage of theses kconfig have changed in
zephyrproject-rtos/zephyr#26447

Hence their values should be updated.

Signed-off-by: Xavier Chapron 
---
 samples/smp_svr/zephyr/prj.conf  | 3 ++-
 samples/smp_svr/zephyr/prj_tiny.conf | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/samples/smp_svr/zephyr/prj.conf b/samples/smp_svr/zephyr/prj.conf
index fe7fdcd..ce0551b 100644
--- a/samples/smp_svr/zephyr/prj.conf
+++ b/samples/smp_svr/zephyr/prj.conf
@@ -8,7 +8,8 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
 CONFIG_BOOTLOADER_MCUBOOT=y
 
 # Allow for large Bluetooth data packets.
-CONFIG_BT_L2CAP_TX_MTU=260
+CONFIG_BT_L2CAP_TX_MTU=252
+CONFIG_BT_L2CAP_RX_MTU=252
 CONFIG_BT_RX_BUF_LEN=260
 
 # Enable the Bluetooth (unauthenticated) and shell mcumgr transports.
diff --git a/samples/smp_svr/zephyr/prj_tiny.conf 
b/samples/smp_svr/zephyr/prj_tiny.conf
index 9f526ba..c53800d 100644
--- a/samples/smp_svr/zephyr/prj_tiny.conf
+++ b/samples/smp_svr/zephyr/prj_tiny.conf
@@ -12,7 +12,8 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
 CONFIG_BOOTLOADER_MCUBOOT=y
 
 # Allow for large Bluetooth data packets.
-CONFIG_BT_L2CAP_TX_MTU=260
+CONFIG_BT_L2CAP_TX_MTU=252
+CONFIG_BT_L2CAP_RX_MTU=252
 CONFIG_BT_RX_BUF_LEN=260
 
 # Enable the Bluetooth (unauthenticated) and UART mcumgr transports.


[mynewt-core] branch master updated: flash_map: make mfg support optional

2021-04-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 437f2b1  flash_map: make mfg support optional
 new cd3f797  Merge pull request #2566 from utzig/optional-flashmap-mfg
437f2b1 is described below

commit 437f2b158115f9aba5c50c6b7bef262d916ece25
Author: Fabio Utzig 
AuthorDate: Wed Apr 14 08:18:35 2021 -0300

flash_map: make mfg support optional

A flash map configuration may be stored in the manufacturing meta
region, and be used instead of the one build time generated from
bsp.yml. This is currently hard-coded in the flash map code. For
users who don't use a mmr, this adds somewhere between 500 and
1000 bytes of code who serves no purpose. This PR adds a syscfg to
allow enabling/disabling the use of the MMR in the flash map thus
making the mfg dependency optional.

Signed-off-by: Fabio Utzig 
---
 sys/flash_map/pkg.yml |  4 +++-
 sys/flash_map/src/flash_map.c | 10 +-
 sys/flash_map/syscfg.yml  |  4 
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/sys/flash_map/pkg.yml b/sys/flash_map/pkg.yml
index 2482833..623fd7f 100644
--- a/sys/flash_map/pkg.yml
+++ b/sys/flash_map/pkg.yml
@@ -27,8 +27,10 @@ pkg.keywords:
 
 pkg.deps:
 - "@apache-mynewt-core/sys/defs"
-- "@apache-mynewt-core/sys/mfg"
 - "@apache-mynewt-core/sys/log/modlog"
 
+pkg.deps.FLASH_MAP_SUPPORT_MFG:
+- "@apache-mynewt-core/sys/mfg"
+
 pkg.init:
 flash_map_init: 'MYNEWT_VAL(FLASH_MAP_SYSINIT_STAGE)'
diff --git a/sys/flash_map/src/flash_map.c b/sys/flash_map/src/flash_map.c
index 6d3dcca..f5b7b13 100644
--- a/sys/flash_map/src/flash_map.c
+++ b/sys/flash_map/src/flash_map.c
@@ -25,7 +25,9 @@
 #include "hal/hal_bsp.h"
 #include "hal/hal_flash.h"
 #include "hal/hal_flash_int.h"
+#if MYNEWT_VAL(FLASH_MAP_SUPPORT_MFG)
 #include "mfg/mfg.h"
+#endif
 #include "flash_map/flash_map.h"
 
 const struct flash_area *flash_map;
@@ -360,6 +362,7 @@ flash_area_id_to_image_slot(int area_id)
  *
  * @return  0 on success; nonzero on failure.
  */
+#if MYNEWT_VAL(FLASH_MAP_SUPPORT_MFG)
 static int
 flash_map_read_mfg(int max_areas,
struct flash_area *out_areas, int *out_num_areas)
@@ -405,6 +408,7 @@ flash_map_read_mfg(int max_areas,
 (*out_num_areas)++;
 }
 }
+#endif
 
 /**
  * Determines if the specified flash area overlaps any areas in the flash map.
@@ -487,9 +491,11 @@ flash_map_add_new_dflt_areas(void)
 void
 flash_map_init(void)
 {
+#if MYNEWT_VAL(FLASH_MAP_SUPPORT_MFG)
 static struct flash_area mfg_areas[MYNEWT_VAL(FLASH_MAP_MAX_AREAS)];
-
 int num_areas;
+#endif
+
 int rc;
 
 /* Ensure this function only gets called by sysinit. */
@@ -509,6 +515,7 @@ flash_map_init(void)
 flash_map = sysflash_map_dflt;
 flash_map_entries = sizeof sysflash_map_dflt / sizeof sysflash_map_dflt[0];
 
+#if MYNEWT_VAL(FLASH_MAP_SUPPORT_MFG)
 /* Attempt to read the flash map from the manufacturing meta regions.  On
  * success, use the new flash map instead of the default hardcoded one.
  */
@@ -519,6 +526,7 @@ flash_map_init(void)
 }
 flash_map = mfg_areas;
 flash_map_entries = num_areas;
+#endif
 
 /* The hardcoded flash map may contain new areas that aren't present in the
  * manufacturing flash map.  Try including them if they don't overlap with
diff --git a/sys/flash_map/syscfg.yml b/sys/flash_map/syscfg.yml
index 342efb4..7f72509 100644
--- a/sys/flash_map/syscfg.yml
+++ b/sys/flash_map/syscfg.yml
@@ -20,6 +20,10 @@ syscfg.defs:
 description: 'Maximum number of expected flash areas'
 value: 10
 
+FLASH_MAP_SUPPORT_MFG:
+description: 'Enable use of flash map stored in manufacturing meta 
region'
+value: 0
+
 FLASH_MAP_SYSINIT_STAGE:
 description: >
 Sysinit stage for flash map functionality.


[mynewt-core] branch aditihilbert-patch-1 created (now 34755c4)

2021-04-15 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch aditihilbert-patch-1
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


  at 34755c4  Update newtmgr.h

No new revisions were added by this update.


[mynewt-site] branch master updated: Update python requirements with upto date versions

2021-04-15 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-site.git


The following commit(s) were added to refs/heads/master by this push:
 new 0fab732  Update python requirements with upto date versions
0fab732 is described below

commit 0fab732bdcc5bf77a947a8546139bee728d68472
Author: Fabio Utzig 
AuthorDate: Wed Apr 14 20:12:08 2021 -0300

Update python requirements with upto date versions

Signed-off-by: Fabio Utzig 
---
 requirements.txt | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index 309285a..226d3a3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
-mkdocs==1.0.4
-sh==1.12.14
-Sphinx==1.8.4
-recommonmark==0.5.0
-breathe==4.11.1
+mkdocs==1.1.2
+sh==1.14.1
+Sphinx==3.5.4
+recommonmark==0.6.0
+breathe==4.28.0


[mynewt-core] branch master updated: crypto: mbedtls: optional montgomery curve support

2021-04-14 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 352e598  crypto: mbedtls: optional montgomery curve support
 new 4f394bd  Merge pull request #2567 from utzig/optional-montgomery-curves
352e598 is described below

commit 352e598191331fcdd5efbd4871b205c62d864a3c
Author: Fabio Utzig 
AuthorDate: Wed Apr 14 10:30:46 2021 -0300

crypto: mbedtls: optional montgomery curve support

Add a new syscfg to enable/disable Curve448 support. Both Curve25519 and
Curve448 are montgomery form elliptic curves, and bring in a lot of
supporting code. Curve25519 was already disabled by default, but there
was no option to disable Curve448, so the montgomery support code was
built whenever MbedTLS based EC code was being used. Leaving this option
disabled reduces MbedTLS' size by about 2KB (for EC users).

Signed-off-by: Fabio Utzig 
---
 crypto/mbedtls/include/mbedtls/config_mynewt.h | 3 +++
 crypto/mbedtls/selftest/syscfg.yml | 1 +
 crypto/mbedtls/syscfg.yml  | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/crypto/mbedtls/include/mbedtls/config_mynewt.h 
b/crypto/mbedtls/include/mbedtls/config_mynewt.h
index b61c314..82858d2 100644
--- a/crypto/mbedtls/include/mbedtls/config_mynewt.h
+++ b/crypto/mbedtls/include/mbedtls/config_mynewt.h
@@ -214,6 +214,9 @@ extern "C" {
 #if MYNEWT_VAL(MBEDTLS_ECP_DP_CURVE25519) == 0
 #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED
 #endif
+#if MYNEWT_VAL(MBEDTLS_ECP_DP_CURVE448) == 0
+#undef MBEDTLS_ECP_DP_CURVE448_ENABLED
+#endif
 
 #if MYNEWT_VAL(MBEDTLS_ECJPAKE_C) == 0
 #undef MBEDTLS_ECJPAKE_C
diff --git a/crypto/mbedtls/selftest/syscfg.yml 
b/crypto/mbedtls/selftest/syscfg.yml
index bf78d87..748e17e 100644
--- a/crypto/mbedtls/selftest/syscfg.yml
+++ b/crypto/mbedtls/selftest/syscfg.yml
@@ -29,6 +29,7 @@ syscfg.vals:
   MBEDTLS_ECP_DP_BP384R1: 1
   MBEDTLS_ECP_DP_BP512R1: 1
   MBEDTLS_ECP_DP_CURVE25519: 1
+  MBEDTLS_ECP_DP_CURVE448: 1
   MBEDTLS_ECJPAKE_C: 1
 
   # Ciphers
diff --git a/crypto/mbedtls/syscfg.yml b/crypto/mbedtls/syscfg.yml
index 31d5917..485144f 100644
--- a/crypto/mbedtls/syscfg.yml
+++ b/crypto/mbedtls/syscfg.yml
@@ -48,6 +48,8 @@ syscfg.defs:
 value: 0
   MBEDTLS_ECP_DP_CURVE25519:
 value: 0
+  MBEDTLS_ECP_DP_CURVE448:
+value: 0
   MBEDTLS_ECJPAKE_C:
 value: 0
 


[mynewt-newt] branch master updated: docs: update Linux install instructions for 1.9.0

2021-04-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
 new b9d54f0  docs: update Linux install instructions for 1.9.0
b9d54f0 is described below

commit b9d54f0e5da10a8311937b3c6aef683340238411
Author: Fabio Utzig 
AuthorDate: Sun Apr 11 20:30:52 2021 -0300

docs: update Linux install instructions for 1.9.0

Signed-off-by: Fabio Utzig 
---
 docs/install/newt_linux.rst | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/docs/install/newt_linux.rst b/docs/install/newt_linux.rst
index 917b428..cfb11de 100644
--- a/docs/install/newt_linux.rst
+++ b/docs/install/newt_linux.rst
@@ -1,7 +1,7 @@
 Installing Newt on Linux
 
 
-You can install the latest release (1.7.0) of the newt tool from a Debian 
binary package (amd64). You can also download
+You can install the latest release (1.9.0) of the newt tool from a Debian 
binary package (amd64). You can also download
 and build the latest release version of newt from source.
 
 This page shows you how to:
@@ -101,8 +101,8 @@ Download and install the package manually.
 
 .. code-block:: console
 
-$ wget 
https://raw.githubusercontent.com/JuulLabs-OSS/binary-releases/master/mynewt-newt-tools_1.7.0/newt_1.7.0-1_amd64.deb
-$ sudo dpkg -i newt_1.7.0-1_amd64.deb
+$ wget 
https://raw.githubusercontent.com/JuulLabs-OSS/binary-releases/master/mynewt-newt-tools_1.9.0/newt_1.9.0-1_amd64.deb
+$ sudo dpkg -i newt_1.9.0-1_amd64.deb
 
 See `Checking the Installed Version of Newt`_ to verify that you are using the 
installed version of newt.
 
@@ -119,16 +119,16 @@ installed on your system. Please visit the Golang website 
for more information o
 
.. code-block:: console
 
-$ wget -P /tmp 
https://github.com/apache/mynewt-newt/archive/mynewt_1_8_0_tag.tar.gz
-$ tar -xzf /tmp/mynewt_1_8_0_tag.tar.gz
+$ wget -P /tmp 
https://github.com/apache/mynewt-newt/archive/mynewt_1_9_0_tag.tar.gz
+$ tar -xzf /tmp/mynewt_1_9_0_tag.tar.gz
 
 #. Run the build.sh to build the newt tool.
 
.. code-block:: console
 
-$ cd mynewt-newt-mynewt_1_8_0_tag
+$ cd mynewt-newt-mynewt_1_9_0_tag
 $ ./build.sh
-$ rm /tmp/mynewt_1_8_0_tag.tar.gz
+$ rm /tmp/mynewt_1_9_0_tag.tar.gz
 
 #. You should see the ``newt/newt`` executable. Move the executable to a bin 
directory in your PATH:
 
@@ -155,7 +155,7 @@ Checking the Installed Version of Newt
 $ which newt
 /usr/bin/newt
 $ newt version
-Apache Newt version: 1.8.0
+Apache Newt version: 1.9.0
 
 2. Get information about newt:
 


[mynewt-core] branch master updated: kinetis/hal_gpio.c: Fix hal_gpio_init_out, to make it set the pin to given initial value.

2021-04-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 361d21a  kinetis/hal_gpio.c: Fix hal_gpio_init_out, to make it set the 
pin to given initial value.
 new 207b3bd  Merge pull request #2542 from mlaz/kinetis_fixes
361d21a is described below

commit 361d21a9ed4abf29f3db6ab4c7bc8551d5a8a162
Author: Miguel Azevedo 
AuthorDate: Mon Mar 22 15:22:47 2021 +

kinetis/hal_gpio.c: Fix hal_gpio_init_out, to make it set the pin to given 
initial value.
---
 hw/mcu/nxp/kinetis/src/hal_gpio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/mcu/nxp/kinetis/src/hal_gpio.c 
b/hw/mcu/nxp/kinetis/src/hal_gpio.c
index e1d69e5..e328745 100644
--- a/hw/mcu/nxp/kinetis/src/hal_gpio.c
+++ b/hw/mcu/nxp/kinetis/src/hal_gpio.c
@@ -84,14 +84,13 @@ int
 hal_gpio_init_out(int pin, int val)
 {
 gpio_pin_config_t gconfig;
-port_pin_config_t pconfig;
 
 gconfig.pinDirection = kGPIO_DigitalOutput;
-pconfig.mux = kPORT_MuxAsGpio;
+gconfig.outputLogic = (uint8_t) val;
 
 CLOCK_EnableClock(s_portClocks[GPIO_PORT(pin)]);
-PORT_SetPinConfig(s_portBases[GPIO_PORT(pin)], GPIO_INDEX(pin), );
 GPIO_PinInit(s_gpioBases[GPIO_PORT(pin)], GPIO_INDEX(pin), );
+PORT_SetPinMux(s_portBases[GPIO_PORT(pin)], GPIO_INDEX(pin), 
kPORT_MuxAsGpio);
 
 return 0;
 }


[mynewt-core] branch master updated: hw: mcu: kinetis: Fix dual flash QSPI support

2021-03-29 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new f784382  hw: mcu: kinetis: Fix dual flash QSPI support
 new ffabfdd  Merge pull request #2548 from utzig/fix-k8x-dual-qspi
f784382 is described below

commit f7843827640954cdc7760698a5097143e6b1f2cb
Author: Fabio Utzig 
AuthorDate: Tue Mar 23 12:13:42 2021 -0300

hw: mcu: kinetis: Fix dual flash QSPI support

Update the QSPI flash driver so it can work correctly with two flashes
connected to the two QSPI channels. This is currenctly limited to using
two QSPI flashes of the same type.

Signed-off-by: Fabio Utzig 
---
 hw/mcu/nxp/kinetis/src/hal_qspi.c | 102 --
 1 file changed, 75 insertions(+), 27 deletions(-)

diff --git a/hw/mcu/nxp/kinetis/src/hal_qspi.c 
b/hw/mcu/nxp/kinetis/src/hal_qspi.c
index cea45a3..a9eff8a 100644
--- a/hw/mcu/nxp/kinetis/src/hal_qspi.c
+++ b/hw/mcu/nxp/kinetis/src/hal_qspi.c
@@ -93,13 +93,31 @@ uint32_t MX25U3235F_LUT[FSL_FEATURE_QSPI_LUT_DEPTH] = {
 
 };
 
+#if MYNEWT_VAL(QSPIB_ENABLE) && !(FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE)
+#error "This device has no parallel mode support (please disable QSPIB)"
+#endif
+
+/*
+ * XXX: This driver currently has the following limitations:
+ *  * QSPIA and QSPIB must use a QSPI flash of the same size (and model).
+ *  * Flashes with dual-die package are not supported.
+ */
+
 static qspi_flash_config_t g_qspi_flash_cfg = {
+#if MYNEWT_VAL(QSPIA_ENABLE)
 .flashA1Size = MYNEWT_VAL(QSPI_FLASH_SECTOR_COUNT) * 
MYNEWT_VAL(QSPI_FLASH_SECTOR_SIZE),
+#else
+.flashA1Size = 0,
+#endif
 .flashA2Size = 0,
 #if (FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE)
-.flashA1Size = MYNEWT_VAL(QSPI_FLASH_SECTOR_COUNT) * 
MYNEWT_VAL(QSPI_FLASH_SECTOR_SIZE),
-.flashA2Size = 0,
+#if MYNEWT_VAL(QSPIB_ENABLE)
+.flashB1Size = MYNEWT_VAL(QSPI_FLASH_SECTOR_COUNT) * 
MYNEWT_VAL(QSPI_FLASH_SECTOR_SIZE),
+#else
+.flashB1Size = 0,
 #endif
+.flashB2Size = 0,
+#endif /* (FSL_FEATURE_QSPI_SUPPORT_PARALLEL_MODE) */
 #if (!FSL_FEATURE_QSPI_HAS_NO_TDH)
 .dataHoldTime = 0,
 #endif
@@ -281,22 +299,33 @@ nxp_qspi_erase_sector(const struct hal_flash *dev, 
uint32_t sector_address)
 void
 nxp_qspi_erase_chip(void)
 {
+int chips = (MYNEWT_VAL(QSPIA_ENABLE) ? 1 : 0) +
+(MYNEWT_VAL(QSPIB_ENABLE) ? 1 : 0);
+uint32_t address;
+
 while (qspi_in_use(QuadSPI0));
 
 os_mutex_pend(_mtx, OS_TIMEOUT_NEVER);
 
-QSPI_ClearFifo(QuadSPI0, kQSPI_TxFifo);
-QSPI_SetIPCommandAddress(QuadSPI0, FSL_FEATURE_QSPI_AMBA_BASE);
-cmd_write_enable();
-QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_ERASE_CHIP);
-wait_until_finished();
-while (qspi_in_use(QuadSPI0));
+address = FSL_FEATURE_QSPI_AMBA_BASE;
+while (chips > 0) {
+QSPI_ClearFifo(QuadSPI0, kQSPI_TxFifo);
+QSPI_SetIPCommandAddress(QuadSPI0, address);
+cmd_write_enable();
+QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_ERASE_CHIP);
+wait_until_finished();
+while (qspi_in_use(QuadSPI0));
 
 #if QSPI_HAS_CLR
-QSPI_ClearCache(QuadSPI0);
+QSPI_ClearCache(QuadSPI0);
 #endif
 
-QSPI_SoftwareReset(QuadSPI0);
+QSPI_SoftwareReset(QuadSPI0);
+
+address += MYNEWT_VAL(QSPI_FLASH_SECTOR_SIZE) *
+   MYNEWT_VAL(QSPI_FLASH_SECTOR_COUNT);
+chips--;
+}
 
 os_mutex_release(_mtx);
 }
@@ -362,26 +391,37 @@ nxp_qspi_sector_info(const struct hal_flash *dev,
 static void
 enable_quad_mode(void)
 {
-QSPI_SetIPCommandAddress(QuadSPI0, FSL_FEATURE_QSPI_AMBA_BASE);
+int chips = (MYNEWT_VAL(QSPIA_ENABLE) ? 1 : 0) +
+(MYNEWT_VAL(QSPIB_ENABLE) ? 1 : 0);
+uint32_t address;
 
-QSPI_ClearFifo(QuadSPI0, kQSPI_TxFifo);
+address = FSL_FEATURE_QSPI_AMBA_BASE;
+while (chips > 0) {
+QSPI_SetIPCommandAddress(QuadSPI0, address);
 
-cmd_write_enable();
+QSPI_ClearFifo(QuadSPI0, kQSPI_TxFifo);
 
-/*
- * Set QE bit to enable quad mode.
- *
- * XXX need extra writes to fill the FIFO
- */
-QSPI_WriteData(QuadSPI0, 0xff40);
-QSPI_WriteData(QuadSPI0, 0x);
-QSPI_WriteData(QuadSPI0, 0x);
-QSPI_WriteData(QuadSPI0, 0x);
+cmd_write_enable();
+
+/*
+ * Set QE bit to enable quad mode.
+ *
+ * XXX need extra writes to fill the FIFO
+ */
+QSPI_WriteData(QuadSPI0, 0xff40);
+QSPI_WriteData(QuadSPI0, 0x);
+QSPI_WriteData(QuadSPI0, 0x);
+QSPI_WriteData(QuadSPI0, 0x);
 
-QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_WRITE_STATUS);
+QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_WRITE_STATUS);
 
-wait_until_finished();
-whi

[mynewt-core] branch master updated: doc: Fix post_link_cmds newt extcmd documentation

2021-03-18 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 7cbaf03  doc: Fix post_link_cmds newt extcmd documentation
 new e245901  Merge pull request #2534 from utzig/fix-post-link-doc
7cbaf03 is described below

commit 7cbaf0371b4a7d39aa4fa652c111521f7a902bf6
Author: Fabio Utzig 
AuthorDate: Tue Mar 16 13:14:58 2021 -0300

doc: Fix post_link_cmds newt extcmd documentation

The `post_build_cmds` step was renamed to `post_link_cmds` with


https://github.com/apache/mynewt-newt/commit/39005b80a6a034244061898c1b610dd7e4e34a36

Fix extcmd documentation appropriately.

Signed-off-by: Fabio Utzig 
---
 docs/os/modules/extcmd/extcmd.rst | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/os/modules/extcmd/extcmd.rst 
b/docs/os/modules/extcmd/extcmd.rst
index 3ee98bf..0e752c5 100644
--- a/docs/os/modules/extcmd/extcmd.rst
+++ b/docs/os/modules/extcmd/extcmd.rst
@@ -6,7 +6,7 @@ three types of commands:
 
 1. pre_build_cmds (run before the build)
 2. pre_link_cmds (run after compilation, before linking)
-3. post_build_cmds (run after the build)
+3. post_link_cmds (run after linking)
 
 Example
 ~~~
@@ -22,8 +22,8 @@ Example (apps/blinky/pkg.yml):
 pkg.pre_link_cmds:
 scripts/pre_link.sh: 500
 
-pkg.post_build_cmds:
-scripts/post_build.sh: 100
+pkg.post_link_cmds:
+scripts/post_link.sh: 100
 
 
 For each command, the string on the left specifies the command to run.
@@ -37,7 +37,7 @@ When newt builds this example, it performs the following 
sequence:
 - [compile]
 - scripts/pre_link.sh
 - [link]
-- scripts/post_build.sh
+- scripts/post_link.sh
 
 If other packages specify custom commands, those commands would also be
 executed during the above sequence.  For example, if another package



[mynewt-newt] branch master updated: Update to mynewt-artifact v0.0.22

2021-03-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
 new 53da553  Update to mynewt-artifact v0.0.22
53da553 is described below

commit 53da5538cf601fa4fbc93544e73c05eb65ad636b
Author: Fabio Utzig 
AuthorDate: Tue Mar 16 18:23:33 2021 -0300

Update to mynewt-artifact v0.0.22

Also run `go mod tidy` to clean up dependencies.

Signed-off-by: Fabio Utzig 
---
 go.mod |  7 ++-
 go.sum | 25 ++---
 2 files changed, 4 insertions(+), 28 deletions(-)

diff --git a/go.mod b/go.mod
index 71553a2..e44a3bb 100644
--- a/go.mod
+++ b/go.mod
@@ -3,9 +3,8 @@ module mynewt.apache.org/newt
 go 1.13
 
 require (
-   github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // 
indirect
-   github.com/apache/mynewt-artifact v0.0.21
+   github.com/apache/mynewt-artifact v0.0.22
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
@@ -14,7 +13,5 @@ require (
github.com/spf13/cast v1.3.0
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
-   github.com/ugorji/go v1.1.7
-   github.com/ugorji/go/codec v1.1.7
-   golang.org/x/crypto v0.0.0-2019062107-cc06ce4a13d4
+   golang.org/x/crypto v0.0.0-2019062107-cc06ce4a13d4 // indirect
 )
diff --git a/go.sum b/go.sum
index 198ce8a..1a46736 100644
--- a/go.sum
+++ b/go.sum
@@ -3,26 +3,8 @@ github.com/NickBall/go-aes-key-wrap 
v0.0.0-20170929221519-1c3aa3e4dfc5 h1:5BIUS5
 github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5/go.mod 
h1:w5D10RxC0NmPYxmQ438CC1S07zaC1zpvuNW7s5sUk2Q=
 github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 
h1:5sXbqlSomvdjlRbWyNqkPsJ3Fg+tQZCbgeX1VGljbQY=
 github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46/go.mod 
h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
-github.com/apache/mynewt-artifact v0.0.2 
h1:2tBlf84kyAifrEilcw1kQFQ8kpq4wBSudXpO8BEOXhw=
-github.com/apache/mynewt-artifact v0.0.2/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.3 
h1:760wpGruGSOPjslEo0fgs9PYJ58IAvyjuJqno1t4iOc=
-github.com/apache/mynewt-artifact v0.0.3/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.5 
h1:MfKbb7wILRUr/Q4UA4AxTkKVDNikyGwzcy2ZXmoS5XI=
-github.com/apache/mynewt-artifact v0.0.5/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.6 
h1:VvIdyo61Im7bvE5EGxByM6NzTaKkoqGQL3t17vyzjfQ=
-github.com/apache/mynewt-artifact v0.0.6/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.8 
h1:as5qSDTT5httEM1IclQM4XgoF9Wn/lTqeoJxV/PvZFw=
-github.com/apache/mynewt-artifact v0.0.8/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.9 
h1:Pv/nAD50Zvom6YJ5gzQG7M4jsItPA3txSV/5eelt3Cc=
-github.com/apache/mynewt-artifact v0.0.9/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.15 
h1:NOAdYAMjVBGVm/4iOs70+oQnb4StlD2tavkvwJiTbhI=
-github.com/apache/mynewt-artifact v0.0.15/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.16 
h1:MUy07kNuCgZHXqEpJRp3JbZcdT3FkWUW4oiOxf1NW/4=
-github.com/apache/mynewt-artifact v0.0.16/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.20 
h1:zf3RACAEGNH0s11QyqB8QeAuMr/e/DmRfHaP5pLjzpw=
-github.com/apache/mynewt-artifact v0.0.20/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
-github.com/apache/mynewt-artifact v0.0.21 
h1:1Gf5c+HRQvGmXdcAXZkBp/Bfe9tIKkRF6WeM09cOM8s=
-github.com/apache/mynewt-artifact v0.0.21/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
+github.com/apache/mynewt-artifact v0.0.22 
h1:pVst1vSAakgjM0iadcrNs5O/HexaC37P7VA6oowkrh4=
+github.com/apache/mynewt-artifact v0.0.22/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
 github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod 
h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
 github.com/coreos/etcd v3.3.10+incompatible/go.mod 
h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/go-etcd v2.0.0+incompatible/go.mod 
h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
@@ -70,9 +52,7 @@ github.com/stretchr/objx v0.1.1/go.mod 
h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/testify v1.2.2/go.mod 
h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0 
h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
 github.com/stretchr/testify v1.3.0/go.mod 
h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI

[mynewt-artifact] tag v0.0.22 created (now 21a0320)

2021-03-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to tag v0.0.22
in repository https://gitbox.apache.org/repos/asf/mynewt-artifact.git.


  at 21a0320  (commit)
No new revisions were added by this update.



[mynewt-core] branch master updated: crypto: mbedtls: Update to version 2.6.10

2021-03-14 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 86af505  crypto: mbedtls: Update to version 2.6.10
 new 4ccbf71  Merge pull request #2528 from utzig/mbedtls-2.6.10
86af505 is described below

commit 86af505a41cfdbee1b05aba8efbbc0f2ca3cb580
Author: Fabio Utzig 
AuthorDate: Sat Mar 13 17:53:49 2021 -0300

crypto: mbedtls: Update to version 2.6.10

Bring in last release of 2.6.x series. Release notes:

https://github.com/ARMmbed/mbedtls/releases/tag/v2.16.10

Signed-off-by: Fabio Utzig 
---
 crypto/mbedtls/include/mbedtls/config.h  |  17 
 crypto/mbedtls/include/mbedtls/ctr_drbg.h|  45 -
 crypto/mbedtls/include/mbedtls/entropy.h |   6 +-
 crypto/mbedtls/include/mbedtls/hmac_drbg.h   |  58 +++-
 crypto/mbedtls/include/mbedtls/net_sockets.h |  18 +++-
 crypto/mbedtls/include/mbedtls/rsa.h |   6 +-
 crypto/mbedtls/include/mbedtls/threading.h   |   3 +
 crypto/mbedtls/include/mbedtls/version.h |   8 +-
 crypto/mbedtls/src/base64.c  | 131 ---
 crypto/mbedtls/src/bignum.c  |   6 ++
 crypto/mbedtls/src/ctr_drbg.c|  16 ++--
 crypto/mbedtls/src/ecdsa.c   |   8 ++
 crypto/mbedtls/src/ecjpake.c |  11 +++
 crypto/mbedtls/src/entropy.c |   7 +-
 crypto/mbedtls/src/hmac_drbg.c   |  20 ++--
 crypto/mbedtls/src/net_sockets.c |  14 +++
 crypto/mbedtls/src/pkwrite.c |  22 ++---
 crypto/mbedtls/src/rsa.c |  28 --
 crypto/mbedtls/src/threading.c   |   6 ++
 crypto/mbedtls/src/version_features.c|   3 +
 20 files changed, 371 insertions(+), 62 deletions(-)

diff --git a/crypto/mbedtls/include/mbedtls/config.h 
b/crypto/mbedtls/include/mbedtls/config.h
index 9d5dbfa..15a59fb 100644
--- a/crypto/mbedtls/include/mbedtls/config.h
+++ b/crypto/mbedtls/include/mbedtls/config.h
@@ -1747,6 +1747,23 @@
 //#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
 
 /**
+ * \def MBEDTLS_TEST_HOOKS
+ *
+ * Enable features for invasive testing such as introspection functions and
+ * hooks for fault injection. This enables additional unit tests.
+ *
+ * Merely enabling this feature should not change the behavior of the product.
+ * It only adds new code, and new branching points where the default behavior
+ * is the same as when this feature is disabled.
+ * However, this feature increases the attack surface: there is an added
+ * risk of vulnerabilities, and more gadgets that can make exploits easier.
+ * Therefore this feature must never be enabled in production.
+ *
+ * Uncomment to enable invasive tests.
+ */
+//#define MBEDTLS_TEST_HOOKS
+
+/**
  * \def MBEDTLS_THREADING_ALT
  *
  * Provide your own alternate threading implementation.
diff --git a/crypto/mbedtls/include/mbedtls/ctr_drbg.h 
b/crypto/mbedtls/include/mbedtls/ctr_drbg.h
index 052f283..82a2322 100644
--- a/crypto/mbedtls/include/mbedtls/ctr_drbg.h
+++ b/crypto/mbedtls/include/mbedtls/ctr_drbg.h
@@ -214,6 +214,13 @@ typedef struct mbedtls_ctr_drbg_context
 void *p_entropy;/*!< The context for the entropy function. */
 
 #if defined(MBEDTLS_THREADING_C)
+/* Invariant: the mutex is initialized if and only if f_entropy != NULL.
+ * This means that the mutex is initialized during the initial seeding
+ * in mbedtls_ctr_drbg_seed() and freed in mbedtls_ctr_drbg_free().
+ *
+ * Note that this invariant may change without notice. Do not rely on it
+ * and do not access the mutex directly in application code.
+ */
 mbedtls_threading_mutex_t mutex;
 #endif
 }
@@ -277,6 +284,15 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx 
);
  *  device.
  */
 #endif
+#if defined(MBEDTLS_THREADING_C)
+/**
+ * \noteWhen Mbed TLS is built with threading support,
+ *  after this function returns successfully,
+ *  it is safe to call mbedtls_ctr_drbg_random()
+ *  from multiple threads. Other operations, including
+ *  reseeding, are not thread-safe.
+ */
+#endif /* MBEDTLS_THREADING_C */
 /**
  * \param ctx   The CTR_DRBG context to seed.
  *  It must have been initialized with
@@ -286,6 +302,8 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
  *  the same context unless you call
  *  mbedtls_ctr_drbg_free() and mbedtls_ctr_drbg_init()
  *  again first.
+ *  After a failed call to mbedtls_ctr_drbg_seed(),
+ *  you must call mbedtls_ctr_drbg_free().
  * \param f_entropy The entropy callback, taking as argume

[mynewt-core] branch master updated: apps: fs_test: Add filesystem testing application

2021-03-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 3ff50ac  apps: fs_test: Add filesystem testing application
 new 617b9c3  Merge pull request #2527 from utzig/apps-fs-test
3ff50ac is described below

commit 3ff50ac1b58121d4598354c135c8562dad2131b6
Author: Fabio Utzig 
AuthorDate: Fri Mar 12 07:18:46 2021 -0300

apps: fs_test: Add filesystem testing application

The fs_test app exercises all defined `fs/fs` interfaces, and is useful
when adding new filesystems' support or debugging filesystem issues.

Signed-off-by: Fabio Utzig 
---
 apps/fs_test/pkg.yml|  38 
 apps/fs_test/src/littlefs.c |  51 +
 apps/fs_test/src/main.c | 452 
 apps/fs_test/src/nffs.c |  39 
 apps/fs_test/syscfg.yml |  41 
 5 files changed, 621 insertions(+)

diff --git a/apps/fs_test/pkg.yml b/apps/fs_test/pkg.yml
new file mode 100644
index 000..af1d493
--- /dev/null
+++ b/apps/fs_test/pkg.yml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: apps/fs_test
+pkg.type: app
+pkg.description: "Exercise an FS using the standard FS interface."
+pkg.author: "Apache Mynewt "
+pkg.homepage: "http://mynewt.apache.org/;
+pkg.keywords:
+
+pkg.deps:
+- "@apache-mynewt-core/kernel/os"
+- "@apache-mynewt-core/sys/console/full"
+- "@apache-mynewt-core/sys/log/full"
+- "@apache-mynewt-core/sys/log/modlog"
+
+pkg.deps.FS_TEST_NFFS:
+- "@apache-mynewt-core/sys/stats/full"
+- "@apache-mynewt-core/fs/nffs"
+
+pkg.deps.FS_TEST_LITTLEFS:
+- "@apache-mynewt-core/fs/littlefs"
diff --git a/apps/fs_test/src/littlefs.c b/apps/fs_test/src/littlefs.c
new file mode 100644
index 000..74604d1
--- /dev/null
+++ b/apps/fs_test/src/littlefs.c
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/mynewt.h"
+
+#if MYNEWT_VAL(FS_TEST_LITTLEFS)
+
+#if !MYNEWT_VAL(LITTLEFS_FLASH_AREA)
+#error "No LITTLEFS_FLASH_AREA defined"
+#endif
+
+#include "littlefs/lfs.h"
+
+int littlefs_reformat(void);
+int littlefs_init(void);
+
+int
+fs_lowlevel_init(void)
+{
+int rc;
+
+(void)rc;
+
+/* always force format before starting */
+#if MYNEWT_VAL(FS_TEST_FORCE_REFORMAT)
+rc = littlefs_reformat();
+if (rc) {
+return rc;
+}
+#endif
+
+return littlefs_init();
+}
+
+#endif
diff --git a/apps/fs_test/src/main.c b/apps/fs_test/src/main.c
new file mode 100644
index 000..7246a94
--- /dev/null
+++ b/apps/fs_test/src/main.c
@@ -0,0 +1,452 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+

[mynewt-core] branch master updated (6ba5b5a -> b833c59)

2021-03-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 6ba5b5a  Merge pull request #2524 from utzig/flash-erase-error-check
 new 68bb14d  fs: littlefs: Add LittleFS v2.4 from upstream
 new 63177eb  Add LittleFS sources to ignored style check
 new 957aef2  Update LICENSE and RAT excludes for LittleFS
 new 4a8d519  fs: littlefs: Add Mynewt glue and metadata
 new 313e33e  sys: config: Allow LittleFS backend
 new 7331658  apps: slinky: Enable config using LittleFS
 new ce65bae  hw: bsp: frdm-k82f: add LittleFS configuration
 new b833c59  Merge pull request #2522 from utzig/littlefs

The 10010 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .rat-excludes   |8 +
 .style_ignored_dirs |8 +-
 LICENSE |   13 +-
 apps/slinky/pkg.yml |3 +
 fs/littlefs/DESIGN.md   | 2173 +
 fs/littlefs/README.md   |  258 ++
 fs/littlefs/SPEC.md |  787 +
 fs/littlefs/include/littlefs/lfs.h  |  695 
 fs/littlefs/include/littlefs/lfs_util.h |  244 ++
 fs/{fatfs => littlefs}/pkg.yml  |   15 +-
 fs/littlefs/src/lfs.c   | 5430 +++
 fs/littlefs/src/lfs_util.c  |   33 +
 fs/littlefs/src/mynewt_glue.c   |  839 +
 fs/{nffs => littlefs}/syscfg.yml|   47 +-
 hw/bsp/frdm-k82f/syscfg.yml |3 +
 sys/config/syscfg.yml   |   11 +
 16 files changed, 10532 insertions(+), 35 deletions(-)
 create mode 100644 fs/littlefs/DESIGN.md
 create mode 100644 fs/littlefs/README.md
 create mode 100644 fs/littlefs/SPEC.md
 create mode 100644 fs/littlefs/include/littlefs/lfs.h
 create mode 100644 fs/littlefs/include/littlefs/lfs_util.h
 copy fs/{fatfs => littlefs}/pkg.yml (82%)
 create mode 100644 fs/littlefs/src/lfs.c
 create mode 100644 fs/littlefs/src/lfs_util.c
 create mode 100644 fs/littlefs/src/mynewt_glue.c
 copy fs/{nffs => littlefs}/syscfg.yml (55%)



[mynewt-core] branch master updated: hw: hal: flash: Add proper check for erase

2021-03-11 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 2a02c4b  hw: hal: flash: Add proper check for erase
 new 6ba5b5a  Merge pull request #2524 from utzig/flash-erase-error-check
2a02c4b is described below

commit 2a02c4b5df8185b37569a85789a1f125f00e23cb
Author: Fabio Utzig 
AuthorDate: Thu Mar 11 09:48:16 2021 -0300

hw: hal: flash: Add proper check for erase

When a flash erase failed the error was ignored. This doesn't usually
happen in the internal flash but can happen on external flash due to bus
related issues, etc. Add a proper check and return an error that can be
used for verification.

Signed-off-by: Fabio Utzig 
---
 hw/hal/src/hal_flash.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index 943423e..32aea9e 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -269,7 +269,9 @@ hal_flash_erase(uint8_t id, uint32_t address, uint32_t 
num_bytes)
 }
 
 if (hf->hf_itf->hff_erase) {
-hf->hf_itf->hff_erase(hf, address, num_bytes);
+if (hf->hf_itf->hff_erase(hf, address, num_bytes)) {
+return SYS_EIO;
+}
 #if MYNEWT_VAL(HAL_FLASH_VERIFY_ERASES)
 assert(hal_flash_isempty_no_buf(id, address, num_bytes) == 1);
 #endif



[mynewt-core] branch master updated: hw: kinetis: Only allow aligned block erases

2021-03-11 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 5384299  hw: kinetis: Only allow aligned block erases
 new 4c5b1fa  Merge pull request #2523 from utzig/fix-qspi-block-erase
5384299 is described below

commit 5384299facac74b6213270cfc740d3db954a2f1c
Author: Fabio Utzig 
AuthorDate: Thu Mar 11 09:38:48 2021 -0300

hw: kinetis: Only allow aligned block erases

This fixes an issue where an erase command with sizes larger or equal
than a block erase (32K or 64K) could delete the whole block even when
it was not aligned. A block erase command is accepted for any address
inside the block, but if a flash area is not aligned to this block size,
it will result in erasing data which are not part of the expected
requested range. With this change the alignment must be valid when doing
block erases.

Signed-off-by: Fabio Utzig 
---
 hw/mcu/nxp/kinetis/src/hal_qspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/mcu/nxp/kinetis/src/hal_qspi.c 
b/hw/mcu/nxp/kinetis/src/hal_qspi.c
index d688283..cea45a3 100644
--- a/hw/mcu/nxp/kinetis/src/hal_qspi.c
+++ b/hw/mcu/nxp/kinetis/src/hal_qspi.c
@@ -320,10 +320,10 @@ nxp_qspi_erase(const struct hal_flash *dev,
 QSPI_ClearFifo(QuadSPI0, kQSPI_TxFifo);
 QSPI_SetIPCommandAddress(QuadSPI0, FSL_FEATURE_QSPI_AMBA_BASE + 
address);
 cmd_write_enable();
-if (size >= SZ64K) {
+if (size >= SZ64K && (address % SZ64K) == 0) {
 QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_ERASE_BLOCK64K);
 erased_size = SZ64K;
-} else if (size >= SZ32K) {
+} else if (size >= SZ32K && (address % SZ32K) == 0) {
 QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_ERASE_BLOCK32K);
 erased_size = SZ32K;
 } else {



[mynewt-core] branch master updated: travis: try running on Bionic

2021-03-11 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 86a1afa  travis: try running on Bionic
 new 0058a77  Merge pull request #2526 from utzig/travis-bionic-update
86a1afa is described below

commit 86a1afa2d200c7194e1ccebec891861e42c6b304
Author: Fabio Utzig 
AuthorDate: Thu Mar 11 14:36:58 2021 -0300

travis: try running on Bionic

Update the Travis environment to use Bionic (18.04) instead of Xenial
(16.04) due to issues installing gcc-multilib.

Signed-off-by: Fabio Utzig 
---
 .travis.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 4407e92..364de3a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,6 +17,8 @@
 
 language: go
 
+dist: bionic
+
 _addons: _conf
   apt:
 sources:



[mynewt-core] branch master updated (7ba5906 -> 89b7014)

2021-03-09 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 7ba5906  sys/log: Shell log dump enhancements
 new 5144a74  hw: mcu: kinetis: update QSPI flash driver
 new 5bce0b0  hw: kinetis: MK8xF: Use 8 for flash alignment
 new 0ffe1b3  hw: bsp: frdm-k82f: Fix flash areas and syscfgs
 new dce6a6f  hw: bsp: frdm-k82f: Fix QSPI flash definition
 new 89b7014  Merge pull request #2520 from utzig/kinetis-qspi-update

The 9996 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/frdm-k82f/MK82FN256xxx15_flash.ld |   4 +-
 hw/bsp/frdm-k82f/bsp.yml |  36 +--
 hw/bsp/frdm-k82f/src/hal_bsp.c   |   5 +-
 hw/bsp/frdm-k82f/syscfg.yml  |  38 ++-
 hw/mcu/nxp/kinetis/MK8xF/syscfg.yml  |   2 +-
 hw/mcu/nxp/kinetis/src/hal_qspi.c| 451 ++-
 hw/mcu/nxp/kinetis/syscfg.yml|  46 ++--
 7 files changed, 347 insertions(+), 235 deletions(-)



[mynewt-core] branch master updated (719760c -> b4dae17)

2021-03-01 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 719760c  sensors/lis2dh12: Fix constant expression result
 new 9b7fa0b  hw: mcu: kinetis: remove custom systick
 new 95e0acc  hw: mcu: kinetis: k8x: fix flash write alignment
 new a807de3  hw: mcu: kinetis: fix interrupted flash programming
 new 32311e0  hw: mcu: kinetis: clean commented out flash code
 new b4dae17  Merge pull request #2512 from utzig/kinetis-updates

The 9974 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .rat-excludes|  1 +
 .../drivers => kinetis/MK8xF/src}/fsl_ftfx_controller.c  |  3 +++
 hw/mcu/nxp/kinetis/MK8xF/syscfg.yml  |  2 +-
 hw/mcu/nxp/kinetis/src/hal_flash.c   |  2 --
 hw/mcu/nxp/kinetis/src/hal_os_tick.c | 12 
 hw/mcu/nxp/pkg.yml   |  2 ++
 6 files changed, 7 insertions(+), 15 deletions(-)
 copy hw/mcu/nxp/{src/ext/nxp-kinetis-sdk/drivers => 
kinetis/MK8xF/src}/fsl_ftfx_controller.c (97%)



[mynewt-core] branch master updated (9ea6df6 -> c061b58)

2021-02-25 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 9ea6df6  sensor_shell: return error in sensor_cmd_notify if no sensor 
found
 new 05a15a2  crypto: mbedtls: allow EC customizations
 new 656a73f  crypto: mbedtls: allow MPI size customization
 new a56a52b  crypto: mbedtls: allow alt bignum implementation
 new f978147  crypto: mbedtls: default secp256r1 to enabled
 new c061b58  Merge pull request #2478 from utzig/mbedtls-ecp-accel

The 9947 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 crypto/mbedtls/include/mbedtls/config_mynewt.h | 52 +++---
 crypto/mbedtls/src/bignum.c|  4 ++
 crypto/mbedtls/syscfg.yml  | 37 --
 3 files changed, 85 insertions(+), 8 deletions(-)



[mynewt-mcumgr] branch master updated: img_mgmt: Use IMG_MGMT_BOOT_CURR_SLOT as current running slot ID

2021-02-24 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 99f9fd6  img_mgmt: Use IMG_MGMT_BOOT_CURR_SLOT as current running slot 
ID
 new e289ead  Merge pull request #114 from de-nordic/img-mgmt-curr-slot
99f9fd6 is described below

commit 99f9fd685149cfb6f9be8442fed1d39c37a5990e
Author: Dominik Ermel 
AuthorDate: Thu Feb 18 11:56:19 2021 +

img_mgmt: Use IMG_MGMT_BOOT_CURR_SLOT as current running slot ID

The commit changes function img_mgmt_state_flasg functions to use
IMG_MGMT_BOOT_CURR_SLOT in comparisons as a currently running slot
number instead of previously hard-coded 0.
The change allows to correctly identify active partition when
application is running from different slot than 0.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/src/img_mgmt_state.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/cmd/img_mgmt/src/img_mgmt_state.c 
b/cmd/img_mgmt/src/img_mgmt_state.c
index ffbdd8e..79d147b 100644
--- a/cmd/img_mgmt/src/img_mgmt_state.c
+++ b/cmd/img_mgmt/src/img_mgmt_state.c
@@ -46,32 +46,32 @@ img_mgmt_state_flags(int query_slot)
 swap_type = img_mgmt_impl_swap_type();
 switch (swap_type) {
 case IMG_MGMT_SWAP_TYPE_NONE:
-if (query_slot == 0) {
+if (query_slot == IMG_MGMT_BOOT_CURR_SLOT) {
 flags |= IMG_MGMT_STATE_F_CONFIRMED;
 flags |= IMG_MGMT_STATE_F_ACTIVE;
 }
 break;
 
 case IMG_MGMT_SWAP_TYPE_TEST:
-if (query_slot == 0) {
+if (query_slot == IMG_MGMT_BOOT_CURR_SLOT) {
 flags |= IMG_MGMT_STATE_F_CONFIRMED;
-} else if (query_slot == 1) {
+} else {
 flags |= IMG_MGMT_STATE_F_PENDING;
 }
 break;
 
 case IMG_MGMT_SWAP_TYPE_PERM:
-if (query_slot == 0) {
+if (query_slot == IMG_MGMT_BOOT_CURR_SLOT) {
 flags |= IMG_MGMT_STATE_F_CONFIRMED;
-} else if (query_slot == 1) {
+} else {
 flags |= IMG_MGMT_STATE_F_PENDING | IMG_MGMT_STATE_F_PERMANENT;
 }
 break;
 
 case IMG_MGMT_SWAP_TYPE_REVERT:
-if (query_slot == 0) {
+if (query_slot == IMG_MGMT_BOOT_CURR_SLOT) {
 flags |= IMG_MGMT_STATE_F_ACTIVE;
-} else if (query_slot == 1) {
+} else {
 flags |= IMG_MGMT_STATE_F_CONFIRMED;
 }
 break;
@@ -79,7 +79,7 @@ img_mgmt_state_flags(int query_slot)
 
 /* Slot 0 is always active. */
 /* XXX: The slot 0 assumption only holds when running from flash. */
-if (query_slot == 0) {
+if (query_slot == IMG_MGMT_BOOT_CURR_SLOT) {
 flags |= IMG_MGMT_STATE_F_ACTIVE;
 }
 
@@ -300,7 +300,7 @@ img_mgmt_state_write(struct mgmt_ctxt *ctxt)
 /* Determine which slot is being operated on. */
 if (hash_len == 0) {
 if (confirm) {
-slot = 0;
+slot = IMG_MGMT_BOOT_CURR_SLOT;
 } else {
 /* A 'test' without a hash is invalid. */
 return MGMT_ERR_EINVAL;
@@ -312,7 +312,7 @@ img_mgmt_state_write(struct mgmt_ctxt *ctxt)
 }
 }
 
-if (slot == 0 && confirm) {
+if (slot == IMG_MGMT_BOOT_CURR_SLOT && confirm) {
 /* Confirm current setup. */
 rc = img_mgmt_state_confirm();
 } else {



[mynewt-mcumgr] branch master updated: zephyr: fix initialization of file struct

2021-02-23 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 6f52fd9  zephyr: fix initialization of file struct
6f52fd9 is described below

commit 6f52fd94cd31e57a40e21e8d96f1022166f827ab
Author: Nico Lastzka 
AuthorDate: Mon Feb 22 12:40:17 2021 +0100

zephyr: fix initialization of file struct

With release of Zephyr 2.5 the fs_file_t structure requires initialization 
prior to first usage.

Signed-off-by: Nico Lastzka 
---
 cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c 
b/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
index f3eb2e4..f63ae2b 100644
--- a/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
+++ b/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
@@ -49,6 +49,7 @@ fs_mgmt_impl_read(const char *path, size_t offset, size_t len,
 ssize_t bytes_read;
 int rc;
 
+fs_file_t_init();
 rc = fs_open(, path, FS_O_READ);
 if (rc != 0) {
 return MGMT_ERR_ENOENT;
@@ -123,6 +124,7 @@ fs_mgmt_impl_write(const char *path, size_t offset, const 
void *data,
 }
 }
 
+fs_file_t_init();
 rc = fs_open(, path, FS_O_CREATE | FS_O_WRITE);
 if (rc != 0) {
 return MGMT_ERR_EUNKNOWN;



[mynewt-core] branch master updated: hw: bsp: frdm-k82f: enable HW based CBC/CTR

2021-02-22 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 16e3830  hw: bsp: frdm-k82f: enable HW based CBC/CTR
 new f8ef3e8  Merge pull request #2495 from utzig/k82f-add-aes-hw-modes
16e3830 is described below

commit 16e383060ca16b202e4172cec555dba341b741f5
Author: Fabio Utzig 
AuthorDate: Mon Feb 22 16:21:31 2021 -0300

hw: bsp: frdm-k82f: enable HW based CBC/CTR

Avoid linking in CBC/CTR in SW, because this device can do it in HW.

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k82f/syscfg.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/bsp/frdm-k82f/syscfg.yml b/hw/bsp/frdm-k82f/syscfg.yml
index 58130d6..702ff91 100644
--- a/hw/bsp/frdm-k82f/syscfg.yml
+++ b/hw/bsp/frdm-k82f/syscfg.yml
@@ -80,3 +80,5 @@ syscfg.vals:
 KINETIS_TRNG_USE_TRNG: 1
 KINETIS_CRYPTO_USE_CAU: 0
 KINETIS_CRYPTO_USE_LTC: 1
+CRYPTO_HW_AES_CBC: 1
+CRYPTO_HW_AES_CTR: 1



[mynewt-core] branch master updated (5651eab -> c6ef274)

2021-02-22 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 5651eab  Merge pull request #2493 from 
stuffmatic/rust-blinky-build-profile-fix
 new ba4dc70  apps: hash_test: add single byte multi-write test
 new 62a9598  hw: drivers: hash_stm32: fix stream support
 new c6ef274  Merge pull request #2494 from utzig/fix-stm32-hash-stream

The 9927 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/hash_test/src/main.c | 190 +-
 hw/drivers/hash/hash_stm32/include/hash_context.h |  19 ++-
 hw/drivers/hash/hash_stm32/src/hash_stm32.c   |  50 --
 3 files changed, 208 insertions(+), 51 deletions(-)



[mynewt-core] branch master updated: apps/rust_blinky: use cargo release profile when mynewt build profile is not debug

2021-02-20 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new a2161f0  apps/rust_blinky: use cargo release profile when mynewt build 
profile is not debug
 new 5651eab  Merge pull request #2493 from 
stuffmatic/rust-blinky-build-profile-fix
a2161f0 is described below

commit a2161f059d7cd72d2d538914cac21368b9c7ffa2
Author: Per 
AuthorDate: Sat Feb 20 13:49:26 2021 +0100

apps/rust_blinky: use cargo release profile when mynewt build profile is 
not debug
---
 apps/rust_blinky/cargo_build.sh | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/apps/rust_blinky/cargo_build.sh b/apps/rust_blinky/cargo_build.sh
index 2ae27a8..230d59a 100755
--- a/apps/rust_blinky/cargo_build.sh
+++ b/apps/rust_blinky/cargo_build.sh
@@ -17,6 +17,7 @@ set -eu
 # limitations under the License.
 #
 
+# Map mynewt architecture to cargo target
 if [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m0"' ]]; then
   TARGET="thumbv6m-none-eabi"
 elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m3"' ]]; then
@@ -32,5 +33,16 @@ else
   exit 1
 fi
 
-cargo build --target="${TARGET}" --target-dir="${MYNEWT_PKG_BIN_DIR}"
-cp "${MYNEWT_PKG_BIN_DIR}"/${TARGET}/debug/*.a "${MYNEWT_PKG_BIN_ARCHIVE}"
+# Map mynewt build profile to cargo build profile
+if [[ ${MYNEWT_BUILD_PROFILE} == 'debug' ]]; then
+  # mynewt debug profile -> cargo debug profile
+  CARGO_PROFILE="debug"
+  CARGO_ARGS=""
+else
+  # all other mynewt profiles -> cargo release profile
+  CARGO_PROFILE="release"
+  CARGO_ARGS="--release"
+fi
+
+cargo build --target="${TARGET}" --target-dir="${MYNEWT_PKG_BIN_DIR}" 
${CARGO_ARGS}
+cp "${MYNEWT_PKG_BIN_DIR}"/${TARGET}/${CARGO_PROFILE}/*.a 
"${MYNEWT_PKG_BIN_ARCHIVE}"



[mynewt-core] branch master updated: hw: drivers: hash: fix Mbed TLS md interface usage

2021-02-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 804035c  hw: drivers: hash: fix Mbed TLS md interface usage
804035c is described below

commit 804035c8f6a1856d5f99c051058c353cb45afdba
Author: Fabio Utzig 
AuthorDate: Fri Feb 19 06:49:55 2021 -0300

hw: drivers: hash: fix Mbed TLS md interface usage

Using the md interface in Mynewt when a HW hash driver is enabled fails
because SHA-224 is calling `mbedtls_internal_sha256_process` directly.
Since SHA-224 is not commonly used, add a placeholder to allow building.

Signed-off-by: Fabio Utzig 
---
 hw/drivers/hash/include/hash/sha256_alt.h |  8 +---
 hw/drivers/hash/src/mbedtls_sha256_alt.c  | 33 ++-
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/hw/drivers/hash/include/hash/sha256_alt.h 
b/hw/drivers/hash/include/hash/sha256_alt.h
index b594eba..1529c1f 100644
--- a/hw/drivers/hash/include/hash/sha256_alt.h
+++ b/hw/drivers/hash/include/hash/sha256_alt.h
@@ -38,12 +38,14 @@ typedef struct mbedtls_sha256_context {
 void mbedtls_sha256_init(mbedtls_sha256_context *ctx);
 void mbedtls_sha256_free(mbedtls_sha256_context *ctx);
 void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
-const mbedtls_sha256_context *src);
+  const mbedtls_sha256_context *src);
 int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224);
 int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx,
-const unsigned char *input, size_t ilen);
+  const unsigned char *input, size_t ilen);
 int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx,
-unsigned char output[32]);
+  unsigned char output[32]);
+int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx,
+const unsigned char data[64]);
 
 /*
  * XXX deprecated functions
diff --git a/hw/drivers/hash/src/mbedtls_sha256_alt.c 
b/hw/drivers/hash/src/mbedtls_sha256_alt.c
index 82b2af6..ac8a02c 100644
--- a/hw/drivers/hash/src/mbedtls_sha256_alt.c
+++ b/hw/drivers/hash/src/mbedtls_sha256_alt.c
@@ -42,7 +42,7 @@ mbedtls_sha256_free(mbedtls_sha256_context *ctx)
 
 void
 mbedtls_sha256_clone(mbedtls_sha256_context *dst,
-const mbedtls_sha256_context *src)
+ const mbedtls_sha256_context *src)
 {
 memcpy(dst, src, sizeof(*dst));
 }
@@ -57,14 +57,16 @@ mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int 
is224)
 return hash_sha256_start(>sha256ctx, ctx->hash);
 }
 
-int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx,
-const unsigned char *input, size_t ilen)
+int
+mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx,
+  const unsigned char *input, size_t ilen)
 {
 return hash_sha256_update(>sha256ctx, input, ilen);
 }
 
-int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx,
-unsigned char output[32])
+int
+mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx,
+  unsigned char output[32])
 {
 return hash_sha256_finish(>sha256ctx, output);
 }
@@ -83,16 +85,29 @@ mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int 
is224)
 (void)hash_sha256_start(>sha256ctx, ctx->hash);
 }
 
-void mbedtls_sha256_update(mbedtls_sha256_context *ctx,
-const unsigned char *input, size_t ilen)
+void
+mbedtls_sha256_update(mbedtls_sha256_context *ctx,
+  const unsigned char *input, size_t ilen)
 {
 (void)hash_sha256_update(>sha256ctx, input, ilen);
 }
 
-void mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
-unsigned char output[32])
+void
+mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
+  unsigned char output[32])
 {
 (void)hash_sha256_finish(>sha256ctx, output);
 }
 
+int
+mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx,
+const unsigned char data[64])
+{
+/*
+ * Note: This function is only called by SHA-224 functions, only
+ * needed for building, shouldn't ever be called in practice.
+ */
+assert(0);
+}
+
 #endif /* MYNEWT_VAL(MBEDTLS_SHA256_ALT) */



[mynewt-core] branch master updated (fb33f18 -> 791b0cf)

2021-02-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from fb33f18  hw: driver: crypto: Mbed TLS alt improvements
 new d806377  apps: hash_test: add small varlen inputs test
 new 791b0cf  hw: drivers: hash_kinetis: fix small buffer hashing

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/hash_test/src/main.c   | 68 +
 hw/drivers/hash/hash_kinetis/src/hash_kinetis.c | 22 ++--
 2 files changed, 87 insertions(+), 3 deletions(-)



[mynewt-core] 02/02: hw: drivers: hash_kinetis: fix small buffer hashing

2021-02-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 791b0cf547ca9cb234cf39f0fdc4144970389db4
Author: Fabio Utzig 
AuthorDate: Thu Feb 18 20:32:01 2021 -0300

hw: drivers: hash_kinetis: fix small buffer hashing

Hashing a message with multiple blocks of length<=64 (SHA-256 block
length) was broken due to proper usage of the mmCAU padding. This commit
fixes the handling of the pad data.

Signed-off-by: Fabio Utzig 
---
 hw/drivers/hash/hash_kinetis/src/hash_kinetis.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/hash/hash_kinetis/src/hash_kinetis.c 
b/hw/drivers/hash/hash_kinetis/src/hash_kinetis.c
index 170e253..a9fbb13 100644
--- a/hw/drivers/hash/hash_kinetis/src/hash_kinetis.c
+++ b/hw/drivers/hash/hash_kinetis/src/hash_kinetis.c
@@ -68,29 +68,45 @@ kinetis_hash_start(struct hash_dev *hash, void *ctx, 
uint16_t algo)
 return 0;
 }
 
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
 static int
 kinetis_hash_update(struct hash_dev *hash, void *ctx, uint16_t algo,
-const void *inbuf, uint32_t inlen)
+const void *inbuf, uint32_t inlen)
 {
 uint32_t i;
 uint32_t remain;
 struct hash_sha256_context *sha256ctx;
 uint8_t *u8p;
+uint32_t len;
 
 sha256ctx = (struct hash_sha256_context *)ctx;
 i = 0;
 remain = inlen;
 u8p = (uint8_t *)inbuf;
 
+if (sha256ctx->remain > 0) {
+len = MIN(SHA256_BLOCK_LEN - sha256ctx->remain, inlen);
+memcpy(>pad[sha256ctx->remain], [0], len);
+sha256ctx->remain += len;
+remain -= len;
+
+if (sha256ctx->remain == SHA256_BLOCK_LEN) {
+cau_sha256_hash_n(sha256ctx->pad, 1, sha256ctx->output);
+sha256ctx->remain = 0;
+sha256ctx->len += SHA256_BLOCK_LEN;
+i = len;
+}
+}
+
 while (remain >= SHA256_BLOCK_LEN) {
 cau_sha256_hash_n((const unsigned char *)[i], 1,
 sha256ctx->output);
 remain -= SHA256_BLOCK_LEN;
 i += SHA256_BLOCK_LEN;
+sha256ctx->len += SHA256_BLOCK_LEN;
 }
 
-sha256ctx->len += i;
-
 if (remain > 0) {
 memcpy(sha256ctx->pad, [i], remain);
 sha256ctx->remain = remain;



[mynewt-core] 01/02: apps: hash_test: add small varlen inputs test

2021-02-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit d806377ca6eca58f71d86c9e6407899316ea76aa
Author: Fabio Utzig 
AuthorDate: Thu Feb 18 20:30:40 2021 -0300

apps: hash_test: add small varlen inputs test

Add a new test that hashes multiple small variable length strings into a
digest, where each string is smaller than SHA-256 block length.

Signed-off-by: Fabio Utzig 
---
 apps/hash_test/src/main.c | 68 +++
 1 file changed, 68 insertions(+)

diff --git a/apps/hash_test/src/main.c b/apps/hash_test/src/main.c
index 88c3a2b..9366c40 100755
--- a/apps/hash_test/src/main.c
+++ b/apps/hash_test/src/main.c
@@ -254,6 +254,71 @@ run_stream_test(struct hash_dev *hash)
 }
 }
 
+void
+run_varlength_sha256_test(struct hash_dev *hash)
+{
+struct hash_generic_context ctx;
+int i;
+int rc;
+uint16_t algo;
+char *string;
+uint8_t outbuf[SHA256_DIGEST_LEN];
+
+char *strings[] = {
+"All that is gold does not glitter,",
+"Not all those who wander are lost;",
+"The old that is strong does not wither,",
+"Deep roots are not reached by the frost.",
+"From the ashes a fire shall be woken,",
+"A light from the shadows shall spring;",
+"Renewed shall be blade that was broken,",
+"The crownless again shall be king.",
+};
+
+uint8_t digest[SHA256_DIGEST_LEN] = "\x83\x6c\x57\x9d\x0c\x13\xec\x71"
+"\x9f\x1d\x38\xf7\x34\xeb\x09\x4f"
+"\x83\x6e\xe9\x06\xc7\xda\x78\x71"
+"\x04\x87\x2b\xcf\x2d\x09\x84\x3d";
+
+algo = HASH_ALGO_SHA256;
+
+if (!hash_has_support(hash, algo)) {
+printf("unsupported\n");
+return;
+}
+
+rc = hash_custom_start(hash, , algo);
+if (rc) {
+printf("failure\n");
+return;
+}
+
+for (i = 0; i < sizeof strings / sizeof strings[0]; i++) {
+string = strings[i];
+printf("  %s: ", string);
+
+rc = hash_custom_update(hash, , algo, string, strlen(string));
+if (rc) {
+printf("failure\n");
+return;
+} else {
+printf("ok\n");
+}
+}
+
+rc = hash_custom_finish(hash, , algo, outbuf);
+if (rc) {
+printf("failure\n");
+return;
+}
+
+if (memcmp(outbuf, digest, SHA256_DIGEST_LEN) == 0) {
+printf("digest: ok\n");
+} else {
+printf("digest: invalid\n");
+}
+}
+
 typedef void (* hash_start_func_t)(void *, void *);
 typedef void (* hash_update_func_t)(void *, const uint8_t *, uint32_t);
 typedef void (* hash_finish_func_t)(void *, uint8_t *);
@@ -429,6 +494,9 @@ main(void)
 printf("\n=== SHA-256 of 100 'a' letters ===\n");
 run_stream_test(hash);
 
+printf("\n=== SHA-256 of variable length strings ===\n");
+run_varlength_sha256_test(hash);
+
 mbedtls_sha256_init(_sha256);
 tc_sha256_init(_sha256);
 



[mynewt-core] branch master updated: hw: driver: crypto: Mbed TLS alt improvements

2021-02-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new fb33f18  hw: driver: crypto: Mbed TLS alt improvements
fb33f18 is described below

commit fb33f18b0305acec2db83bb71ef3d30e717ecbdc
Author: Fabio Utzig 
AuthorDate: Thu Feb 18 18:26:03 2021 -0300

hw: driver: crypto: Mbed TLS alt improvements

* Export `mbedtls_aes_setkey_dec`
* Correctly handle encryption/decryption in ECB mode
* Add CBC alt implementation

Signed-off-by: Fabio Utzig 
---
 hw/drivers/crypto/include/crypto/aes_alt.h |  9 ++--
 hw/drivers/crypto/src/mbedtls_aes_alt.c| 37 +-
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/crypto/include/crypto/aes_alt.h 
b/hw/drivers/crypto/include/crypto/aes_alt.h
index abbc4b5..fffd0dc 100644
--- a/hw/drivers/crypto/include/crypto/aes_alt.h
+++ b/hw/drivers/crypto/include/crypto/aes_alt.h
@@ -39,9 +39,14 @@ typedef struct mbedtls_aes_context {
 void mbedtls_aes_init(mbedtls_aes_context *ctx);
 void mbedtls_aes_free(mbedtls_aes_context *ctx);
 int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
-unsigned int keybits);
+   unsigned int keybits);
+int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
+   unsigned int keybits);
 int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode,
-const unsigned char input[16], unsigned char output[16]);
+  const unsigned char input[16], unsigned char 
output[16]);
+int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, int mode,
+  size_t length, unsigned char iv[16], const unsigned 
char *input,
+  unsigned char *output);
 
 #ifdef __cplusplus
 }
diff --git a/hw/drivers/crypto/src/mbedtls_aes_alt.c 
b/hw/drivers/crypto/src/mbedtls_aes_alt.c
index cf46d82..1108fcb 100644
--- a/hw/drivers/crypto/src/mbedtls_aes_alt.c
+++ b/hw/drivers/crypto/src/mbedtls_aes_alt.c
@@ -94,9 +94,44 @@ int
 mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode,
   const unsigned char input[16], unsigned char output[16])
 {
-int ret = crypto_encrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
+int ret;
+
+switch (mode) {
+case MBEDTLS_AES_ENCRYPT:
+ret = crypto_encrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
+ (const uint8_t *)input, (uint8_t 
*)output, AES_BLOCK_LEN);
+break;
+case MBEDTLS_AES_DECRYPT:
+ret = crypto_decrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
  (const uint8_t *)input, (uint8_t 
*)output, AES_BLOCK_LEN);
+break;
+default:
+return -1;
+}
+
 return (ret == AES_BLOCK_LEN) ? 0 : -1;
 }
 
+int
+mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, int mode, size_t length, 
unsigned char iv[16],
+  const unsigned char *input, unsigned char *output)
+{
+int ret;
+
+switch (mode) {
+case MBEDTLS_AES_ENCRYPT:
+ret = crypto_encrypt_aes_cbc(ctx->crypto, ctx->key, ctx->keylen, 
(uint8_t *)iv,
+ (uint8_t *)input, (uint8_t *)output, 
length);
+break;
+case MBEDTLS_AES_DECRYPT:
+ret = crypto_decrypt_aes_cbc(ctx->crypto, ctx->key, ctx->keylen, 
(uint8_t *)iv,
+ (uint8_t *)input, (uint8_t *)output, 
length);
+break;
+default:
+return -1;
+}
+
+return (ret == length) ? 0 : -1;
+}
+
 #endif /* MYNEWT_VAL(MBEDTLS_AES_ALT) */



[mynewt-core] branch master updated: hw/mcu/da1469x: fix passing of uart name in da1469x_uart_create

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 5ae92c6  hw/mcu/da1469x: fix passing of uart name in 
da1469x_uart_create
5ae92c6 is described below

commit 5ae92c6521406ea75448fd875f022d04b68f57e2
Author: Ben McCrea 
AuthorDate: Wed Feb 17 12:39:50 2021 -0800

hw/mcu/da1469x: fix passing of uart name in da1469x_uart_create
---
 hw/mcu/dialog/da1469x/src/da1469x_periph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/mcu/dialog/da1469x/src/da1469x_periph.c 
b/hw/mcu/dialog/da1469x/src/da1469x_periph.c
index af9bda6..0ec0628 100644
--- a/hw/mcu/dialog/da1469x/src/da1469x_periph.c
+++ b/hw/mcu/dialog/da1469x/src/da1469x_periph.c
@@ -356,7 +356,7 @@ static int
 da1469x_uart_create(struct uart_dev *dev, const char *name, uint8_t priority,
 const struct da1469x_uart_cfg *cfg)
 {
-return os_dev_create(>ud_dev, "uart0",
+return os_dev_create(>ud_dev, name,
  OS_DEV_INIT_PRIMARY, priority, uart_hal_init,
  (void *)cfg);
 }



[mynewt-core] 01/02: apps: crypto_test: add AES-256 vectors

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 4530d8fc4ff04de4b67e51e0090ceea2bb49d118
Author: Fabio Utzig 
AuthorDate: Wed Feb 17 11:28:06 2021 -0300

apps: crypto_test: add AES-256 vectors

Add AES-256 vectors from NIST and expand inplace and iovect to test
AES-256.

Signed-off-by: Fabio Utzig 
---
 apps/crypto_test/src/main.c | 245 ++--
 1 file changed, 234 insertions(+), 11 deletions(-)

diff --git a/apps/crypto_test/src/main.c b/apps/crypto_test/src/main.c
index 99a2d41..09cc811 100755
--- a/apps/crypto_test/src/main.c
+++ b/apps/crypto_test/src/main.c
@@ -78,6 +78,35 @@ static struct test_vectors aes_128_ecb_vectors = {
 },
 },
 };
+
+static struct test_vectors aes_256_ecb_vectors = {
+.name = "AES-256-ECB",
+.algo = CRYPTO_ALGO_AES,
+.mode = CRYPTO_MODE_ECB,
+.key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
+   "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
+.keylen = 256,
+.iv = NULL,
+.len = 4,
+.vectors = {
+{
+.plain = 
"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
+.cipher = 
"\xf3\xee\xd1\xbd\xb5\xd2\xa0\x3c\x06\x4b\x5a\x7e\x3d\xb1\x81\xf8",
+},
+{
+.plain = 
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
+.cipher = 
"\x59\x1c\xcb\x10\xd4\x10\xed\x26\xdc\x5b\xa7\x4a\x31\x36\x28\x70",
+},
+{
+.plain = 
"\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
+.cipher = 
"\xb6\xed\x21\xb9\x9c\xa6\xf4\xf9\xf1\x53\xe7\xb1\xbe\xaf\xed\x1d",
+},
+{
+.plain = 
"\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
+.cipher = 
"\x23\x30\x4b\x7a\x39\xf9\xf3\xff\x06\x7d\x8d\x8f\x9e\x24\xec\xc7",
+},
+},
+};
 #endif /* MYNEWT_VAL(CRYPTOTEST_VECTORS_ECB) */
 
 #if MYNEWT_VAL(CRYPTOTEST_VECTORS_CBC)
@@ -108,6 +137,36 @@ static struct test_vectors aes_128_cbc_vectors = {
 },
 },
 };
+
+static struct test_vectors aes_256_cbc_vectors = {
+.name = "AES-256-CBC",
+.algo = CRYPTO_ALGO_AES,
+.mode = CRYPTO_MODE_CBC,
+.key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
+   "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
+.keylen = 256,
+.iv = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
+.len = 4,
+.vectors = {
+{
+.plain = 
"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
+.cipher = 
"\xf5\x8c\x4c\x04\xd6\xe5\xf1\xba\x77\x9e\xab\xfb\x5f\x7b\xfb\xd6",
+},
+{
+.plain = 
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
+.cipher = 
"\x9c\xfc\x4e\x96\x7e\xdb\x80\x8d\x67\x9f\x77\x7b\xc6\x70\x2c\x7d",
+},
+{
+.plain = 
"\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
+.cipher = 
"\x39\xf2\x33\x69\xa9\xd9\xba\xcf\xa5\x30\xe2\x63\x04\x23\x14\x61",
+},
+{
+.plain = 
"\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
+.cipher = 
"\xb2\xeb\x05\xe2\xc3\x9b\xe9\xfc\xda\x6c\x19\x07\x8c\x6a\x9d\x1b",
+},
+},
+};
+
 #endif /* MYNEWT_VAL(CRYPTOTEST_VECTORS_CBC) */
 
 #if MYNEWT_VAL(CRYPTOTEST_VECTORS_CTR)
@@ -142,17 +201,53 @@ static struct test_vectors aes_128_ctr_vectors = {
 },
 },
 };
+
+static struct test_vectors aes_256_ctr_vectors = {
+.name = "AES-256-CTR",
+.algo = CRYPTO_ALGO_AES,
+.mode = CRYPTO_MODE_CTR,
+.key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
+   "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
+.keylen = 256,
+.iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
+.len = 4,
+.vectors = {
+{
+.plain = 
"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
+.cipher = 
"\x60\x1e\xc3\x13\x77\x57\x89\xa5\xb7\xa7\xf5\x04\xbb\xf3\xd2\x28",
+.sz = AES_BLOCK_LEN,
+},
+{
+.plain = 
"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
+.cipher = 
"\xf4\x43\xe3\xca\x4d\x62\xb5\x9a\xca\x84\xe9\x90\xca\xca\xf5\xc5",
+.sz = AES_BLOCK_LEN,
+},
+{
+.plain = "\x30\xc8\x1c\x46\xa3\x5

[mynewt-core] branch master updated (164ecd5 -> 0f43d24)

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 164ecd5  bsp: frdm-k82f: enable CRYPTO acceleration
 new 4530d8f  apps: crypto_test: add AES-256 vectors
 new 0f43d24  apps: crypto_test: fix warnings from syscfg

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/crypto_test/src/main.c | 264 +---
 1 file changed, 251 insertions(+), 13 deletions(-)



[mynewt-core] 02/02: apps: crypto_test: fix warnings from syscfg

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 0f43d24dece396379bb96affa51bfdf3301c3061
Author: Fabio Utzig 
AuthorDate: Wed Feb 17 11:29:34 2021 -0300

apps: crypto_test: fix warnings from syscfg

Enabling/disabling some of the crypto_test syscfgs resulted in warnings
from non-used variables, etc. This commit fixes the issues so each
individual syscfg can be isolatedly used.

Signed-off-by: Fabio Utzig 
---
 apps/crypto_test/src/main.c | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/apps/crypto_test/src/main.c b/apps/crypto_test/src/main.c
index 09cc811..8e28879 100755
--- a/apps/crypto_test/src/main.c
+++ b/apps/crypto_test/src/main.c
@@ -46,6 +46,12 @@ struct test_vectors {
 
 static struct os_mutex mtx;
 
+#if (MYNEWT_VAL(CRYPTOTEST_VECTORS_ECB) || \
+ MYNEWT_VAL(CRYPTOTEST_VECTORS_CBC) || \
+ MYNEWT_VAL(CRYPTOTEST_VECTORS_CTR))
+#define RUN_VECTOR_TESTS 1
+#endif
+
 /*
  * Test vectors from "NIST Special Publication 800-38A"
  */
@@ -236,6 +242,7 @@ static struct test_vectors aes_256_ctr_vectors = {
 };
 #endif /* MYNEWT_VAL(CRYPTOTEST_VECTORS_CTR) */
 
+#if RUN_VECTOR_TESTS
 static struct test_vectors *all_tests[] = {
 #if MYNEWT_VAL(CRYPTOTEST_VECTORS_ECB)
 _128_ecb_vectors,
@@ -251,6 +258,7 @@ static struct test_vectors *all_tests[] = {
 #endif
 NULL,
 };
+#endif
 
 void
 run_test_vectors(struct crypto_dev *crypto, struct test_vectors *test_mode)
@@ -326,10 +334,13 @@ run_test_vectors(struct crypto_dev *crypto, struct 
test_vectors *test_mode)
 }
 }
 
-#if MYNEWT_VAL(CRYPTOTEST_BENCHMARK)
+#if MYNEWT_VAL(CRYPTOTEST_BENCHMARK) || MYNEWT_VAL(CRYPTOTEST_CONCURRENCY)
 extern uint8_t aes_128_key[];
 extern uint8_t aes_128_input[];
 extern uint8_t aes_128_ecb_expected[];
+#endif
+
+#if MYNEWT_VAL(CRYPTOTEST_BENCHMARK)
 extern uint8_t aes_128_cbc_expected[];
 extern uint8_t aes_128_cbc_iv[];
 extern uint8_t aes_128_ctr_expected[];
@@ -460,6 +471,7 @@ run_ctr_bench(struct crypto_dev *crypto, uint8_t iter)
 }
 #endif /* MYNEWT_VAL(CRYPTOTEST_BENCHMARK) */
 
+#if MYNEWT_VAL(CRYPTOTEST_CONCURRENCY)
 static void
 lock(void)
 {
@@ -478,7 +490,6 @@ unlock(void)
 assert(rc == 0);
 }
 
-#if MYNEWT_VAL(CRYPTOTEST_CONCURRENCY)
 static void
 concurrency_test_handler(void *arg)
 {
@@ -930,7 +941,9 @@ main(void)
 struct tc_aes_key_sched_struct tc_aes;
 int iterations;
 #endif
+#if RUN_VECTOR_TESTS || MYNEWT_VAL(CRYPTOTEST_BENCHMARK)
 int i;
+#endif
 int rc;
 
 sysinit();
@@ -941,10 +954,12 @@ main(void)
 rc = os_mutex_init();
 assert(rc == 0);
 
+#if RUN_VECTOR_TESTS
 printf("=== Test vectors ===\n");
 for (i = 0; all_tests[i] != NULL; i++) {
 run_test_vectors(crypto, all_tests[i]);
 }
+#endif
 
 #if MYNEWT_VAL(CRYPTOTEST_INPLACE)
 printf("\n=== In-place encrypt/decrypt ===\n");



[mynewt-core] 01/03: crypto: k64f: rename to kinetis

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit a28ab7ea5d0ab64e2164c2f38ca25d2d1a2fa35e
Author: Fabio Utzig 
AuthorDate: Tue Feb 9 10:11:19 2021 -0300

crypto: k64f: rename to kinetis

Make it clear this driver should work on other Kinetis family members as
well; the k64f uses a mmCAU which is one of the possible, and oldest, of
the acceleration units in those parts.

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k64f/pkg.yml   |  2 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c |  4 +--
 .../include/crypto_kinetis/crypto_kinetis.h}   |  8 +++---
 .../crypto/{crypto_k64f => crypto_kinetis}/pkg.yml |  4 +--
 .../src/crypto_kinetis.c}  | 32 +++---
 .../src/crypto_kinetis_cau.c}  |  2 +-
 .../{crypto_k64f => crypto_kinetis}/syscfg.yml |  0
 7 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/hw/bsp/frdm-k64f/pkg.yml b/hw/bsp/frdm-k64f/pkg.yml
index c1d234d..a6df39e 100644
--- a/hw/bsp/frdm-k64f/pkg.yml
+++ b/hw/bsp/frdm-k64f/pkg.yml
@@ -67,7 +67,7 @@ pkg.deps.TRNG:
 - "@apache-mynewt-core/hw/drivers/trng/trng_kinetis"
 
 pkg.deps.CRYPTO:
-- "@apache-mynewt-core/hw/drivers/crypto/crypto_k64f"
+- "@apache-mynewt-core/hw/drivers/crypto/crypto_kinetis"
 
 pkg.deps.ENC_FLASH_DEV:
 - "@apache-mynewt-core/hw/drivers/flash/enc_flash/ef_crypto"
diff --git a/hw/bsp/frdm-k64f/src/hal_bsp.c b/hw/bsp/frdm-k64f/src/hal_bsp.c
index 84c5a97..a55a8e2 100644
--- a/hw/bsp/frdm-k64f/src/hal_bsp.c
+++ b/hw/bsp/frdm-k64f/src/hal_bsp.c
@@ -34,7 +34,7 @@
 #endif
 #if MYNEWT_VAL(CRYPTO)
 #include "crypto/crypto.h"
-#include "crypto_k64f/crypto_k64f.h"
+#include "crypto_kinetis/crypto_kinetis.h"
 #endif
 #if MYNEWT_VAL(ENC_FLASH_DEV)
 #include 
@@ -217,7 +217,7 @@ hal_bsp_init(void)
 #if MYNEWT_VAL(CRYPTO)
 rc = os_dev_create(_bsp_crypto.dev, "crypto",
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
-   k64f_crypto_dev_init, NULL);
+   kinetis_crypto_dev_init, NULL);
 assert(rc == 0);
 #endif
 
diff --git a/hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h 
b/hw/drivers/crypto/crypto_kinetis/include/crypto_kinetis/crypto_kinetis.h
similarity index 85%
rename from hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h
rename to 
hw/drivers/crypto/crypto_kinetis/include/crypto_kinetis/crypto_kinetis.h
index 7442c8d..fde36cf 100644
--- a/hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h
+++ b/hw/drivers/crypto/crypto_kinetis/include/crypto_kinetis/crypto_kinetis.h
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#ifndef __CRYPTO_K64F_H__
-#define __CRYPTO_K64F_H__
+#ifndef __CRYPTO_KINETIS_H__
+#define __CRYPTO_KINETIS_H__
 
 #include "crypto/crypto.h"
 
@@ -26,10 +26,10 @@
 extern "C" {
 #endif
 
-int k64f_crypto_dev_init(struct os_dev *dev, void *arg);
+int kinetis_crypto_dev_init(struct os_dev *dev, void *arg);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* __CRYPTO_K64F_H__ */
+#endif /* __CRYPTO_KINETIS_H__ */
diff --git a/hw/drivers/crypto/crypto_k64f/pkg.yml 
b/hw/drivers/crypto/crypto_kinetis/pkg.yml
similarity index 91%
rename from hw/drivers/crypto/crypto_k64f/pkg.yml
rename to hw/drivers/crypto/crypto_kinetis/pkg.yml
index cbfd2f5..0180382 100644
--- a/hw/drivers/crypto/crypto_k64f/pkg.yml
+++ b/hw/drivers/crypto/crypto_kinetis/pkg.yml
@@ -17,8 +17,8 @@
 # under the License.
 #
 
-pkg.name: hw/drivers/crypto/crypto_k64f
-pkg.description: Crypto driver for NXP K64F
+pkg.name: hw/drivers/crypto/crypto_kinetis
+pkg.description: Crypto driver for NXP Kinetis Family
 pkg.author: "Apache Mynewt "
 pkg.homepage: "http://mynewt.apache.org/;
 pkg.keywords:
diff --git a/hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c 
b/hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c
similarity index 78%
rename from hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c
rename to hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c
index ec1799f..8261f5f 100644
--- a/hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c
+++ b/hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c
@@ -22,7 +22,7 @@
 #include 
 
 #include "crypto/crypto.h"
-#include "crypto_k64f/crypto_k64f.h"
+#include "crypto_kinetis/crypto_kinetis.h"
 
 static struct os_mutex gmtx;
 
@@ -71,7 +71,7 @@ typedef void (* cau_aes_func_t)(const unsigned char *in,
 unsigned char *out);
 
 static uint32_t
-k64f_crypto_cau_aes_nr(cau_aes_func_t aes_func, const uint8_t *key,
+kinetis_crypto_cau_aes_nr(cau_aes_func_t aes_func, const uint8_t *key,
 int keylen, const uint8_t *inbuf, uint8_t *outbuf, size_t len)
 {
 uint32_t i;
@@ -108,8 +108,8 @

[mynewt-core] 03/03: bsp: frdm-k82f: enable CRYPTO acceleration

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 164ecd5a1aee5a3581c80656c03cfa3d3945f4b5
Author: Fabio Utzig 
AuthorDate: Wed Feb 10 08:35:42 2021 -0300

bsp: frdm-k82f: enable CRYPTO acceleration

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k82f/pkg.yml   |  3 +++
 hw/bsp/frdm-k82f/src/hal_bsp.c | 15 +++
 hw/bsp/frdm-k82f/syscfg.yml|  2 ++
 3 files changed, 20 insertions(+)

diff --git a/hw/bsp/frdm-k82f/pkg.yml b/hw/bsp/frdm-k82f/pkg.yml
index e8caa1e..56101c6 100644
--- a/hw/bsp/frdm-k82f/pkg.yml
+++ b/hw/bsp/frdm-k82f/pkg.yml
@@ -60,6 +60,9 @@ pkg.deps.UART_3:
 pkg.deps.UART_4:
 - "@apache-mynewt-core/hw/drivers/uart/uart_hal"
 
+pkg.deps.CRYPTO:
+- "@apache-mynewt-core/hw/drivers/crypto/crypto_kinetis"
+
 pkg.deps.ENC_FLASH_DEV:
 - "@apache-mynewt-core/hw/drivers/flash/enc_flash/ef_crypto"
 
diff --git a/hw/bsp/frdm-k82f/src/hal_bsp.c b/hw/bsp/frdm-k82f/src/hal_bsp.c
index 4460a15..2837598 100644
--- a/hw/bsp/frdm-k82f/src/hal_bsp.c
+++ b/hw/bsp/frdm-k82f/src/hal_bsp.c
@@ -39,6 +39,10 @@
 #include "trng/trng.h"
 #include "trng_kinetis/trng_kinetis.h"
 #endif
+#if MYNEWT_VAL(CRYPTO)
+#include "crypto/crypto.h"
+#include "crypto_kinetis/crypto_kinetis.h"
+#endif
 #if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
 MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4)
 #include "uart/uart.h"
@@ -114,6 +118,10 @@ static struct hash_dev os_bsp_hash;
 static struct trng_dev os_bsp_trng;
 #endif
 
+#if MYNEWT_VAL(CRYPTO)
+static struct crypto_dev os_bsp_crypto;
+#endif
+
 /*
  * What memory to include in coredump.
  */
@@ -251,6 +259,13 @@ hal_bsp_init(void)
 assert(rc == 0);
 #endif
 
+#if MYNEWT_VAL(CRYPTO)
+rc = os_dev_create(_bsp_crypto.dev, "crypto",
+   OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+   kinetis_crypto_dev_init, NULL);
+assert(rc == 0);
+#endif
+
 #if MYNEWT_VAL(UART_0)
 rc = os_dev_create((struct os_dev *) _bsp_uart0, "uart0",
OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL);
diff --git a/hw/bsp/frdm-k82f/syscfg.yml b/hw/bsp/frdm-k82f/syscfg.yml
index a1f4b43..58130d6 100644
--- a/hw/bsp/frdm-k82f/syscfg.yml
+++ b/hw/bsp/frdm-k82f/syscfg.yml
@@ -78,3 +78,5 @@ syscfg.vals:
 
 KINETIS_TRNG_USE_RNGA: 0
 KINETIS_TRNG_USE_TRNG: 1
+KINETIS_CRYPTO_USE_CAU: 0
+KINETIS_CRYPTO_USE_LTC: 1



[mynewt-core] 02/03: kinetis: crypto: add initial LTC support

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit dfd1cbc27c0cc6d354d8feaa46bb5d7093d7ad53
Author: Fabio Utzig 
AuthorDate: Wed Feb 10 08:34:01 2021 -0300

kinetis: crypto: add initial LTC support

Signed-off-by: Fabio Utzig 
---
 .../crypto/crypto_kinetis/src/crypto_kinetis.c | 109 -
 hw/drivers/crypto/crypto_kinetis/syscfg.yml|  10 ++
 2 files changed, 117 insertions(+), 2 deletions(-)

diff --git a/hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c 
b/hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c
index 8261f5f..a4fba3e 100644
--- a/hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c
+++ b/hw/drivers/crypto/crypto_kinetis/src/crypto_kinetis.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+#include 
 #include 
 #include "mcu/cmsis_nvic.h"
 #include 
@@ -24,6 +25,15 @@
 #include "crypto/crypto.h"
 #include "crypto_kinetis/crypto_kinetis.h"
 
+#if MYNEWT_VAL(KINETIS_CRYPTO_USE_CAU)
+#define USE_CAU 1
+#elif MYNEWT_VAL(KINETIS_CRYPTO_USE_LTC)
+#define USE_LTC 1
+#include "fsl_ltc.h"
+#else
+#error "Unsupported CRYPTO HW"
+#endif
+
 static struct os_mutex gmtx;
 
 static inline uint8_t
@@ -39,6 +49,7 @@ ROUNDS_PER_KEYLEN(uint16_t keylen)
 }
 }
 
+#if USE_CAU
 /*
  * These routines are exported by NXP's provided CAU and mmCAU software
  * library.
@@ -107,6 +118,78 @@ kinetis_crypto_cau_aes_nr(cau_aes_func_t aes_func, const 
uint8_t *key,
 return i;
 }
 
+#else /* USE_LTC */
+
+static uint32_t
+kinetis_crypto_ltc_aes_encrypt(uint16_t mode, const uint8_t *key,
+int keylen, uint8_t *iv, const uint8_t *inbuf, uint8_t *outbuf,
+size_t len)
+{
+status_t ret = 0;
+uint32_t keysize = keylen / 8;
+
+switch (mode) {
+case CRYPTO_MODE_ECB:
+ret = LTC_AES_EncryptEcb(LTC0, inbuf, outbuf, len, key, keysize);
+if (ret == 0) {
+return len;
+}
+break;
+case CRYPTO_MODE_CTR:
+ret = LTC_AES_CryptCtr(LTC0, inbuf, outbuf, len, iv, key, keysize, 
NULL, NULL);
+if (ret == 0) {
+return len;
+}
+break;
+case CRYPTO_MODE_CBC:
+ret = LTC_AES_EncryptCbc(LTC0, inbuf, outbuf, len, iv, key, keysize);
+if (ret == 0) {
+memcpy(iv, [len-AES_BLOCK_LEN], AES_BLOCK_LEN);
+return len;
+}
+break;
+}
+
+return 0;
+}
+
+static uint32_t
+kinetis_crypto_ltc_aes_decrypt(uint16_t mode, const uint8_t *key,
+int keylen, uint8_t *iv, const uint8_t *inbuf, uint8_t *outbuf,
+size_t len)
+{
+status_t ret = 0;
+uint16_t keysize = keylen / 8;
+uint8_t iv_save[AES_BLOCK_LEN];
+
+switch (mode) {
+case CRYPTO_MODE_ECB:
+ret = LTC_AES_DecryptEcb(LTC0, inbuf, outbuf, len, key, keysize, 
kLTC_EncryptKey);
+if (ret == 0) {
+return len;
+}
+break;
+case CRYPTO_MODE_CTR:
+ret = LTC_AES_CryptCtr(LTC0, inbuf, outbuf, len, iv, key, keysize, 
NULL, NULL);
+if (ret == 0) {
+return len;
+}
+break;
+case CRYPTO_MODE_CBC:
+memcpy(iv_save, [len-AES_BLOCK_LEN], AES_BLOCK_LEN);
+ret = LTC_AES_DecryptCbc(LTC0, inbuf, outbuf, len, iv, key, keysize, 
kLTC_EncryptKey);
+if (ret == 0) {
+memcpy(iv, iv_save, AES_BLOCK_LEN);
+return len;
+}
+break;
+}
+
+return 0;
+}
+
+#endif
+
 static bool
 kinetis_crypto_has_support(struct crypto_dev *crypto, uint8_t op,
 uint16_t algo, uint16_t mode, uint16_t keylen)
@@ -117,11 +200,19 @@ kinetis_crypto_has_support(struct crypto_dev *crypto, 
uint8_t op,
 return false;
 }
 
-if (mode != CRYPTO_MODE_ECB) {
+#if USE_CAU
+if ((mode & CRYPTO_MODE_ECB) == 0) {
+#else
+if ((mode & (CRYPTO_MODE_ECB | CRYPTO_MODE_CBC | CRYPTO_MODE_CTR)) == 0) {
+#endif
 return false;
 }
 
+#if USE_CAU
 if (!CRYPTO_VALID_AES_KEYLEN(keylen)) {
+#else
+if (!ltc_check_key_size(keylen / 8)) {
+#endif
 return false;
 }
 
@@ -139,8 +230,13 @@ kinetis_crypto_encrypt(struct crypto_dev *crypto, uint16_t 
algo, uint16_t mode,
 return 0;
 }
 
+#if USE_CAU
 return kinetis_crypto_cau_aes_nr(cau_aes_encrypt, key, keylen, inbuf,
 outbuf, len);
+#else
+return kinetis_crypto_ltc_aes_encrypt(mode, key, keylen, iv, inbuf,
+outbuf, len);
+#endif
 }
 
 static uint32_t
@@ -154,8 +250,13 @@ kinetis_crypto_decrypt(struct crypto_dev *crypto, uint16_t 
algo, uint16_t mode,
 return 0;
 }
 
+#if USE_CAU
 return kinetis_crypto_cau_aes_nr(cau_aes_decrypt, key, keylen, inbuf,
 outbuf, len);
+#else
+return kinetis_crypto_ltc_aes_decrypt(mode, key, keylen, iv, inbuf,
+outbuf, len);
+#endif
 }
 
 static int
@@ -1

[mynewt-core] branch master updated (e53ca22 -> 164ecd5)

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from e53ca22  trng: kinetis: seed RNGA with SIM->UIDL
 new a28ab7e  crypto: k64f: rename to kinetis
 new dfd1cbc  kinetis: crypto: add initial LTC support
 new 164ecd5  bsp: frdm-k82f: enable CRYPTO acceleration

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/frdm-k64f/pkg.yml   |   2 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c |   4 +-
 hw/bsp/frdm-k82f/pkg.yml   |   3 +
 hw/bsp/frdm-k82f/src/hal_bsp.c |  15 +++
 hw/bsp/frdm-k82f/syscfg.yml|   2 +
 .../include/crypto_kinetis/crypto_kinetis.h}   |   8 +-
 .../crypto/{crypto_k64f => crypto_kinetis}/pkg.yml |   4 +-
 .../src/crypto_kinetis.c}  | 141 ++---
 .../src/crypto_kinetis_cau.c}  |   2 +-
 .../{crypto_k64f => crypto_kinetis}/syscfg.yml |  10 ++
 10 files changed, 163 insertions(+), 28 deletions(-)
 rename hw/drivers/crypto/{crypto_k64f/include/crypto_k64f/crypto_k64f.h => 
crypto_kinetis/include/crypto_kinetis/crypto_kinetis.h} (85%)
 rename hw/drivers/crypto/{crypto_k64f => crypto_kinetis}/pkg.yml (91%)
 rename hw/drivers/crypto/{crypto_k64f/src/crypto_k64f.c => 
crypto_kinetis/src/crypto_kinetis.c} (50%)
 rename hw/drivers/crypto/{crypto_k64f/src/crypto_k64f_cau.c => 
crypto_kinetis/src/crypto_kinetis_cau.c} (98%)
 rename hw/drivers/crypto/{crypto_k64f => crypto_kinetis}/syscfg.yml (76%)



[mynewt-core] 03/05: hw: bsp: frdm-k82f: enable TRNG usage

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit de7816922c95f2bd67f21af5c2e8a98853a9bec7
Author: Fabio Utzig 
AuthorDate: Tue Feb 9 07:11:12 2021 -0300

hw: bsp: frdm-k82f: enable TRNG usage

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k82f/pkg.yml   |  3 +++
 hw/bsp/frdm-k82f/src/hal_bsp.c | 18 +-
 hw/bsp/frdm-k82f/syscfg.yml|  3 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/hw/bsp/frdm-k82f/pkg.yml b/hw/bsp/frdm-k82f/pkg.yml
index 0389789..e8caa1e 100644
--- a/hw/bsp/frdm-k82f/pkg.yml
+++ b/hw/bsp/frdm-k82f/pkg.yml
@@ -65,3 +65,6 @@ pkg.deps.ENC_FLASH_DEV:
 
 pkg.deps.HASH:
 - "@apache-mynewt-core/hw/drivers/hash/hash_kinetis"
+
+pkg.deps.TRNG:
+- "@apache-mynewt-core/hw/drivers/trng/trng_kinetis"
diff --git a/hw/bsp/frdm-k82f/src/hal_bsp.c b/hw/bsp/frdm-k82f/src/hal_bsp.c
index 71162d2..4460a15 100644
--- a/hw/bsp/frdm-k82f/src/hal_bsp.c
+++ b/hw/bsp/frdm-k82f/src/hal_bsp.c
@@ -35,6 +35,10 @@
 #include "hash/hash.h"
 #include "hash_kinetis/hash_kinetis.h"
 #endif
+#if MYNEWT_VAL(TRNG)
+#include "trng/trng.h"
+#include "trng_kinetis/trng_kinetis.h"
+#endif
 #if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
 MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4)
 #include "uart/uart.h"
@@ -106,6 +110,10 @@ static const struct nxp_hal_i2c_cfg hal_i2c3_cfg = {
 static struct hash_dev os_bsp_hash;
 #endif
 
+#if MYNEWT_VAL(TRNG)
+static struct trng_dev os_bsp_trng;
+#endif
+
 /*
  * What memory to include in coredump.
  */
@@ -116,7 +124,8 @@ static const struct hal_bsp_mem_dump dump_cfg[] = {
 }
 };
 
-static void init_hardware(void)
+static void
+init_hardware(void)
 {
 /* Disable the MPU otherwise USB cannot access the bus */
 SYSMPU->CESR = 0;
@@ -235,6 +244,13 @@ hal_bsp_init(void)
 assert(rc == 0);
 #endif
 
+#if MYNEWT_VAL(TRNG)
+rc = os_dev_create(_bsp_trng.dev, "trng",
+   OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+   kinetis_trng_dev_init, NULL);
+assert(rc == 0);
+#endif
+
 #if MYNEWT_VAL(UART_0)
 rc = os_dev_create((struct os_dev *) _bsp_uart0, "uart0",
OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL);
diff --git a/hw/bsp/frdm-k82f/syscfg.yml b/hw/bsp/frdm-k82f/syscfg.yml
index 34d8130..a1f4b43 100644
--- a/hw/bsp/frdm-k82f/syscfg.yml
+++ b/hw/bsp/frdm-k82f/syscfg.yml
@@ -75,3 +75,6 @@ syscfg.vals:
 REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG
 NFFS_FLASH_AREA: FLASH_AREA_NFFS
 COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
+
+KINETIS_TRNG_USE_RNGA: 0
+KINETIS_TRNG_USE_TRNG: 1



[mynewt-core] 04/05: trng: kinetis: remove delay in poller

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 2ad881e32f03ac1c9c26be0f786d03518366809b
Author: Fabio Utzig 
AuthorDate: Tue Feb 16 19:14:13 2021 -0300

trng: kinetis: remove delay in poller

This delay was causing a race condition on trng_test during
console_printf, and can be safely removed.

Signed-off-by: Fabio Utzig 
---
 hw/drivers/trng/trng_kinetis/src/trng_kinetis.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c 
b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
index 4b79d55..4f3821c 100644
--- a/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
+++ b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
@@ -168,7 +168,6 @@ trng_poller_handler(void *arg)
 }
 os_mutex_release(_cache_mu);
 }
-os_time_delay(1);
 } else {
 (void)os_eventq_get(_evtq);
 }



[mynewt-core] 02/05: trng: kinetis: update driver for newer families

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit eea15f7f96ccec8238aae30228f4737c493b9ea3
Author: Fabio Utzig 
AuthorDate: Tue Feb 9 09:41:18 2021 -0300

trng: kinetis: update driver for newer families

Older Kinetis families used the RNGA HW module for random number
generation, newer models have a slightly different HW module called
TRNG; this commit adds TRNG API usage compatibility, and adds syscfg
to allow BSPs to choose from one of the HW modules.

Signed-off-by: Fabio Utzig 
---
 hw/drivers/trng/trng_kinetis/src/trng_kinetis.c | 67 -
 hw/drivers/trng/trng_kinetis/syscfg.yml | 10 
 2 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c 
b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
index 45d914c..4b79d55 100644
--- a/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
+++ b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
@@ -18,7 +18,27 @@
  */
 
 #include 
+#include "os/mynewt.h"
+
+#if MYNEWT_VAL(KINETIS_TRNG_USE_RNGA)
+#define USE_RNGA 1
 #include "fsl_rnga.h"
+#elif MYNEWT_VAL(KINETIS_TRNG_USE_TRNG)
+#define USE_TRNG 1
+#include "fsl_trng.h"
+#define TRNG_START(base)  \
+do {  \
+(base)->MCTL &= ~TRNG_MCTL_PRGM_MASK; \
+(base)->MCTL |= TRNG_MCTL_ERR_MASK;   \
+} while (0)
+#define TRNG_STOP(base)   \
+do {  \
+(base)->MCTL |= (TRNG_MCTL_PRGM_MASK | TRNG_MCTL_ERR_MASK);   \
+} while (0)
+#else
+#error "Unsupported TRNG interface"
+#endif
+
 #include "trng/trng.h"
 #include "trng_kinetis/trng_kinetis.h"
 
@@ -30,16 +50,20 @@ static os_stack_t *pstack;
 static bool running;
 static struct os_eventq rng_evtq;
 
-#define RNGA_POLLER_PRIO (8)
-#define RNGA_POLLER_STACK_SIZE OS_STACK_ALIGN(64)
+#define TRNG_POLLER_PRIO (8)
+#define TRNG_POLLER_STACK_SIZE OS_STACK_ALIGN(64)
 static struct os_task poller_task;
 
 static inline void
-kinetis_rnga_start(void)
+kinetis_trng_start(void)
 {
 struct os_event evt;
 
+#if USE_RNGA
 RNGA_SetMode(RNG, kRNGA_ModeNormal);
+#elif USE_TRNG
+TRNG_START(TRNG0);
+#endif
 running = true;
 
 evt.ev_queued = 0;
@@ -48,9 +72,14 @@ kinetis_rnga_start(void)
 }
 
 static inline void
-kinetis_rnga_stop(void)
+kinetis_trng_stop(void)
 {
-   RNGA_SetMode(RNG, kRNGA_ModeSleep);
+#if USE_RNGA
+RNGA_SetMode(RNG, kRNGA_ModeSleep);
+#elif USE_TRNG
+TRNG_STOP(TRNG0);
+#endif
+
running = false;
 }
 
@@ -83,7 +112,7 @@ kinetis_trng_read(struct trng_dev *trng, void *ptr, size_t 
size)
 rng_cache_out = (rng_cache_out + num_read) % sizeof(rng_cache);
 
 if (num_read > 0) {
-kinetis_rnga_start();
+kinetis_trng_start();
 }
 
 os_mutex_release(_cache_mu);
@@ -110,7 +139,7 @@ kinetis_trng_get_u32(struct trng_dev *trng)
 }
 
 static void
-rnga_poller_handler(void *arg)
+trng_poller_handler(void *arg)
 {
 int8_t i;
 uint8_t data[4];
@@ -118,8 +147,12 @@ rnga_poller_handler(void *arg)
 
 while (1) {
 if (running) {
+#if USE_RNGA
 rc = RNGA_GetRandomData(RNG, data, sizeof(uint32_t));
-if (rc == kStatus_Success) {
+#else
+rc = TRNG_GetRandomData(TRNG0, data, sizeof(uint32_t));
+#endif
+if (rc == 0) {
 os_mutex_pend(_cache_mu, OS_TIMEOUT_NEVER);
 for (i = 0; i < 4; i++) {
 rng_cache[rng_cache_in++] = data[i];
@@ -129,7 +162,7 @@ rnga_poller_handler(void *arg)
 }
 
 if ((rng_cache_in + 1) % sizeof(rng_cache) == 
rng_cache_out) {
-kinetis_rnga_stop();
+kinetis_trng_stop();
 break;
 }
 }
@@ -146,6 +179,9 @@ static int
 kinetis_trng_dev_open(struct os_dev *dev, uint32_t wait, void *arg)
 {
 struct trng_dev *trng;
+#if USE_TRNG
+trng_config_t default_config;
+#endif
 
 trng = (struct trng_dev *)dev;
 assert(trng);
@@ -154,9 +190,14 @@ kinetis_trng_dev_open(struct os_dev *dev, uint32_t wait, 
void *arg)
 rng_cache_out = 0;
 rng_cache_in = 0;
 
+#if USE_RNGA
 RNGA_Init(RNG);
+#elif USE_TRNG
+(void)TRNG_GetDefaultConfig(_config);
+TRNG_Init(TRNG0, _config);
+#endif
 
-kinetis_rnga_start();
+kinetis_trng_start();
 }
 
 return 0;
@@ -179,11 +220,11 @@ kinetis_trng_dev_init(struct os_dev *dev, void *arg)
 os_eventq_init(_evtq);
 os_mutex_init(_cache_mu);
 
-pstack = m

[mynewt-core] 01/05: trng: k64f: rename to trng_kinetis

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e1694f56ec604b9c85d2567530eeb5a53a147ffe
Author: Fabio Utzig 
AuthorDate: Tue Feb 9 07:10:25 2021 -0300

trng: k64f: rename to trng_kinetis

This makes it less specific, since the driver should also work on other
Kinetis families.

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k64f/pkg.yml   |  2 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c |  4 +--
 .../include/trng_kinetis/trng_kinetis.h}   |  8 +++---
 .../trng/{trng_k64f => trng_kinetis}/pkg.yml   |  4 +--
 .../src/trng_kinetis.c}| 32 +++---
 .../trng/{trng_k64f => trng_kinetis}/syscfg.yml|  2 +-
 6 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/hw/bsp/frdm-k64f/pkg.yml b/hw/bsp/frdm-k64f/pkg.yml
index 193337d..c1d234d 100644
--- a/hw/bsp/frdm-k64f/pkg.yml
+++ b/hw/bsp/frdm-k64f/pkg.yml
@@ -64,7 +64,7 @@ pkg.deps.UART_5:
 - "@apache-mynewt-core/hw/drivers/uart/uart_hal"
 
 pkg.deps.TRNG:
-- "@apache-mynewt-core/hw/drivers/trng/trng_k64f"
+- "@apache-mynewt-core/hw/drivers/trng/trng_kinetis"
 
 pkg.deps.CRYPTO:
 - "@apache-mynewt-core/hw/drivers/crypto/crypto_k64f"
diff --git a/hw/bsp/frdm-k64f/src/hal_bsp.c b/hw/bsp/frdm-k64f/src/hal_bsp.c
index 1f6c95e..84c5a97 100644
--- a/hw/bsp/frdm-k64f/src/hal_bsp.c
+++ b/hw/bsp/frdm-k64f/src/hal_bsp.c
@@ -30,7 +30,7 @@
 #include "hal/hal_flash.h"
 #if MYNEWT_VAL(TRNG)
 #include "trng/trng.h"
-#include "trng_k64f/trng_k64f.h"
+#include "trng_kinetis/trng_kinetis.h"
 #endif
 #if MYNEWT_VAL(CRYPTO)
 #include "crypto/crypto.h"
@@ -210,7 +210,7 @@ hal_bsp_init(void)
 #if MYNEWT_VAL(TRNG)
 rc = os_dev_create(_bsp_trng.dev, "trng",
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
-   k64f_trng_dev_init, NULL);
+   kinetis_trng_dev_init, NULL);
 assert(rc == 0);
 #endif
 
diff --git a/hw/drivers/trng/trng_k64f/include/trng_k64f/trng_k64f.h 
b/hw/drivers/trng/trng_kinetis/include/trng_kinetis/trng_kinetis.h
similarity index 86%
rename from hw/drivers/trng/trng_k64f/include/trng_k64f/trng_k64f.h
rename to hw/drivers/trng/trng_kinetis/include/trng_kinetis/trng_kinetis.h
index 069e80b..dc73bc4 100644
--- a/hw/drivers/trng/trng_k64f/include/trng_k64f/trng_k64f.h
+++ b/hw/drivers/trng/trng_kinetis/include/trng_kinetis/trng_kinetis.h
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#ifndef __TRNG_K64F_H__
-#define __TRNG_K64F_H__
+#ifndef __TRNG_KINETIS_H__
+#define __TRNG_KINETIS_H__
 
 #include "trng/trng.h"
 
@@ -26,10 +26,10 @@
 extern "C" {
 #endif
 
-int k64f_trng_dev_init(struct os_dev *dev, void *arg);
+int kinetis_trng_dev_init(struct os_dev *dev, void *arg);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* __TRNG_K64F_H__ */
+#endif /* __TRNG_KINETIS_H__ */
diff --git a/hw/drivers/trng/trng_k64f/pkg.yml 
b/hw/drivers/trng/trng_kinetis/pkg.yml
similarity index 92%
rename from hw/drivers/trng/trng_k64f/pkg.yml
rename to hw/drivers/trng/trng_kinetis/pkg.yml
index 9fbbcc1..e978db0 100644
--- a/hw/drivers/trng/trng_k64f/pkg.yml
+++ b/hw/drivers/trng/trng_kinetis/pkg.yml
@@ -17,8 +17,8 @@
 # under the License.
 #
 
-pkg.name: hw/drivers/trng/trng_k64f
-pkg.description: TRNG driver for K64F
+pkg.name: hw/drivers/trng/trng_kinetis
+pkg.description: TRNG driver for Kinetis
 pkg.author: "Apache Mynewt "
 pkg.homepage: "http://mynewt.apache.org/;
 pkg.keywords:
diff --git a/hw/drivers/trng/trng_k64f/src/trng_k64f.c 
b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
similarity index 83%
rename from hw/drivers/trng/trng_k64f/src/trng_k64f.c
rename to hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
index 91b924c..45d914c 100644
--- a/hw/drivers/trng/trng_k64f/src/trng_k64f.c
+++ b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
@@ -20,9 +20,9 @@
 #include 
 #include "fsl_rnga.h"
 #include "trng/trng.h"
-#include "trng_k64f/trng_k64f.h"
+#include "trng_kinetis/trng_kinetis.h"
 
-static uint8_t rng_cache[ MYNEWT_VAL(K64F_TRNG_CACHE_LEN) ];
+static uint8_t rng_cache[ MYNEWT_VAL(KINETIS_TRNG_CACHE_LEN) ];
 static uint16_t rng_cache_out;
 static uint16_t rng_cache_in;
 static struct os_mutex rng_cache_mu;
@@ -35,7 +35,7 @@ static struct os_eventq rng_evtq;
 static struct os_task poller_task;
 
 static inline void
-k64f_rnga_start(void)
+kinetis_rnga_start(void)
 {
 struct os_event evt;
 
@@ -48,14 +48,14 @@ k64f_rnga_start(void)
 }
 
 static inline void
-k64f_rnga_stop(void)
+kinetis_rnga_stop(void)
 {
RNGA_SetMode(RNG, kRNGA_ModeSleep);
running = false;
 }
 
 static size_t
-k64f_trng_read(struct trng_dev *trng, void *ptr, size_t size)
+kinetis_t

[mynewt-core] branch master updated (cbf4886 -> e53ca22)

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from cbf4886  Enable HW HASH usage on frdm-k82f board
 new e1694f5  trng: k64f: rename to trng_kinetis
 new eea15f7  trng: kinetis: update driver for newer families
 new de78169  hw: bsp: frdm-k82f: enable TRNG usage
 new 2ad881e  trng: kinetis: remove delay in poller
 new e53ca22  trng: kinetis: seed RNGA with SIM->UIDL

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/frdm-k64f/pkg.yml   |  2 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c |  4 +-
 hw/bsp/frdm-k82f/pkg.yml   |  3 +
 hw/bsp/frdm-k82f/src/hal_bsp.c | 18 -
 hw/bsp/frdm-k82f/syscfg.yml|  3 +
 .../include/trng_kinetis/trng_kinetis.h}   |  8 +-
 .../trng/{trng_k64f => trng_kinetis}/pkg.yml   |  4 +-
 .../src/trng_kinetis.c}| 91 --
 .../trng/{trng_k64f => trng_kinetis}/syscfg.yml| 12 ++-
 9 files changed, 109 insertions(+), 36 deletions(-)
 rename hw/drivers/trng/{trng_k64f/include/trng_k64f/trng_k64f.h => 
trng_kinetis/include/trng_kinetis/trng_kinetis.h} (86%)
 rename hw/drivers/trng/{trng_k64f => trng_kinetis}/pkg.yml (92%)
 rename hw/drivers/trng/{trng_k64f/src/trng_k64f.c => 
trng_kinetis/src/trng_kinetis.c} (61%)
 rename hw/drivers/trng/{trng_k64f => trng_kinetis}/syscfg.yml (72%)



[mynewt-core] 05/05: trng: kinetis: seed RNGA with SIM->UIDL

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e53ca22057ee66e7772aebc2ffb73ef70aa22b1a
Author: Fabio Utzig 
AuthorDate: Tue Feb 16 19:15:10 2021 -0300

trng: kinetis: seed RNGA with SIM->UIDL

This follows the recommendation from NXP SDK.

Signed-off-by: Fabio Utzig 
---
 hw/drivers/trng/trng_kinetis/src/trng_kinetis.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c 
b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
index 4f3821c..7f38cdf 100644
--- a/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
+++ b/hw/drivers/trng/trng_kinetis/src/trng_kinetis.c
@@ -191,6 +191,7 @@ kinetis_trng_dev_open(struct os_dev *dev, uint32_t wait, 
void *arg)
 
 #if USE_RNGA
 RNGA_Init(RNG);
+RNGA_Seed(RNG, SIM->UIDL);
 #elif USE_TRNG
 (void)TRNG_GetDefaultConfig(_config);
 TRNG_Init(TRNG0, _config);



[mynewt-mcumgr] branch master updated: Fix encoding usage for halffloat

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new b92aa0b  Fix encoding usage for halffloat
b92aa0b is described below

commit b92aa0b8c999afa285b83012cd5dd76e33a2c03a
Author: Fabio Utzig 
AuthorDate: Wed Feb 17 07:50:46 2021 -0300

Fix encoding usage for halffloat

`cbor_encode_half_float` was being called passing in the halffloat
(uint16_t) by value, but `cbor_encode_floating_point` accepts a `void *`
pointer. This is already done automatically for float and double
encoding, but must be done manually for halffloat.

Signed-off-by: Fabio Utzig 
---
 cborattr/src/cborattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cborattr/src/cborattr.c b/cborattr/src/cborattr.c
index b6aaadc..e5177d6 100644
--- a/cborattr/src/cborattr.c
+++ b/cborattr/src/cborattr.c
@@ -510,7 +510,7 @@ cbor_write_val(struct CborEncoder *enc, const struct 
cbor_out_val_t *val)
 
 #if FLOAT_SUPPORT
 case CborAttrHalfFloatType:
-rc = cbor_encode_half_float(enc, val->halffloat);
+rc = cbor_encode_half_float(enc, >halffloat);
 break;
 
 case CborAttrFloatType:



[mynewt-mcumgr] branch master updated: Bug #18312 Add support for half-floats to MCUMGR

2021-02-17 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new f21eef7  Bug #18312 Add support for half-floats to MCUMGR
f21eef7 is described below

commit f21eef72055ff53b46f620166039a6563cdf33b4
Author: Greg Leach 
AuthorDate: Mon Feb 15 12:43:08 2021 +

Bug #18312 Add support for half-floats to MCUMGR
---
 cborattr/include/cborattr/cborattr.h |  7 +++
 cborattr/src/cborattr.c  | 22 ++
 2 files changed, 29 insertions(+)

diff --git a/cborattr/include/cborattr/cborattr.h 
b/cborattr/include/cborattr/cborattr.h
index 30e2612..d025e64 100644
--- a/cborattr/include/cborattr/cborattr.h
+++ b/cborattr/include/cborattr/cborattr.h
@@ -48,6 +48,7 @@ typedef enum CborAttrType {
 CborAttrByteStringType,
 CborAttrTextStringType,
 CborAttrBooleanType,
+CborAttrHalfFloatType,
 CborAttrFloatType,
 CborAttrDoubleType,
 CborAttrArrayType,
@@ -85,6 +86,9 @@ struct cbor_array_t {
 struct {
 double *store;
 } reals;
+struct{
+uint16_t *store;
+} halffloats;
 struct {
 bool *store;
 } booleans;
@@ -99,6 +103,7 @@ struct cbor_attr_t {
 union {
 long long int *integer;
 long long unsigned int *uinteger;
+uint16_t *halffloat;
 double *real;
 float *fval;
 char *string;
@@ -116,6 +121,7 @@ struct cbor_attr_t {
 double real;
 bool boolean;
 float fval;
+uint16_t halffloat;
 } dflt;
 size_t len;
 bool nodefault;
@@ -139,6 +145,7 @@ struct cbor_out_val_t {
 long long unsigned int uinteger;
 double real;
 float fval;
+uint16_t halffloat;
 const char *string;
 bool boolean;
 struct {
diff --git a/cborattr/src/cborattr.c b/cborattr/src/cborattr.c
index 31131b7..b6aaadc 100644
--- a/cborattr/src/cborattr.c
+++ b/cborattr/src/cborattr.c
@@ -67,6 +67,11 @@ valid_attr_type(CborType ct, CborAttrType at)
 }
break;
 #if FLOAT_SUPPORT
+case CborAttrHalfFloatType:
+if (ct == CborHalfFloatType) {
+return 1;
+}
+break;
 case CborAttrFloatType:
 if (ct == CborFloatType) {
 return 1;
@@ -120,6 +125,9 @@ cbor_target_address(const struct cbor_attr_t *cursor,
 targetaddr = (char *)>addr.uinteger[offset];
 break;
 #if FLOAT_SUPPORT
+case CborAttrHalfFloatType:
+targetaddr = (char *)>addr.halffloat[offset];
+break;
 case CborAttrFloatType:
 targetaddr = (char *)>addr.fval[offset];
 break;
@@ -180,6 +188,9 @@ cbor_internal_read_object(CborValue *root_value,
 memcpy(lptr, >dflt.boolean, sizeof(bool));
 break;
 #if FLOAT_SUPPORT
+case CborAttrHalfFloatType:
+memcpy(lptr, >dflt.halffloat, sizeof(uint16_t));
+break;
 case CborAttrFloatType:
 memcpy(lptr, >dflt.fval, sizeof(float));
 break;
@@ -261,6 +272,9 @@ cbor_internal_read_object(CborValue *root_value,
 err |= cbor_value_get_uint64(_value, lptr);
 break;
 #if FLOAT_SUPPORT
+case CborAttrHalfFloatType:
+err |= cbor_value_get_half_float(_value, lptr);
+break;
 case CborAttrFloatType:
 err |= cbor_value_get_float(_value, lptr);
 break;
@@ -332,6 +346,10 @@ cbor_read_array(struct CborValue *value, const struct 
cbor_array_t *arr)
 err |= cbor_value_get_uint64(, lptr);
 break;
 #if FLOAT_SUPPORT
+case CborAttrHalfFloatType:
+lptr = >arr.halffloats.store[off];
+err |= cbor_value_get_half_float(, lptr);
+break;
 case CborAttrFloatType:
 case CborAttrDoubleType:
 lptr = >arr.reals.store[off];
@@ -491,6 +509,10 @@ cbor_write_val(struct CborEncoder *enc, const struct 
cbor_out_val_t *val)
 break;
 
 #if FLOAT_SUPPORT
+case CborAttrHalfFloatType:
+rc = cbor_encode_half_float(enc, val->halffloat);
+break;
+
 case CborAttrFloatType:
 rc = cbor_encode_float(enc, val->fval);
 break;



[mynewt-core] branch master updated (ab5d874 -> cbf4886)

2021-02-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from ab5d874  Merge pull request #2479 from 
andrzej-kaczmarek/cmac-retain-cm_error_dis_reg
 new 41c8c40  Rename hash_k64f to hash_kinetis
 new cbf4886  Enable HW HASH usage on frdm-k82f board

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/frdm-k64f/pkg.yml |  2 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c   |  4 ++--
 hw/bsp/frdm-k82f/pkg.yml |  3 +++
 hw/bsp/frdm-k82f/src/hal_bsp.c   | 13 +
 .../include/hash_context.h   |  0
 .../include/hash_kinetis/hash_kinetis.h} |  8 
 hw/drivers/hash/{hash_k64f => hash_kinetis}/pkg.yml  |  4 ++--
 .../hash_k64f.c => hash_kinetis/src/hash_kinetis.c}  | 20 ++--
 .../src/hash_kinetis_cau.c}  |  2 +-
 9 files changed, 36 insertions(+), 20 deletions(-)
 rename hw/drivers/hash/{hash_k64f => hash_kinetis}/include/hash_context.h 
(100%)
 rename hw/drivers/hash/{hash_k64f/include/hash_k64f/hash_k64f.h => 
hash_kinetis/include/hash_kinetis/hash_kinetis.h} (86%)
 rename hw/drivers/hash/{hash_k64f => hash_kinetis}/pkg.yml (91%)
 rename hw/drivers/hash/{hash_k64f/src/hash_k64f.c => 
hash_kinetis/src/hash_kinetis.c} (88%)
 rename hw/drivers/hash/{hash_k64f/src/hash_k64f_cau.c => 
hash_kinetis/src/hash_kinetis_cau.c} (99%)



[mynewt-core] 01/02: Rename hash_k64f to hash_kinetis

2021-02-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 41c8c40dd9c1c1b5316abc3b5524afb8d533872a
Author: Fabio Utzig 
AuthorDate: Mon Feb 8 12:41:55 2021 -0300

Rename hash_k64f to hash_kinetis

This makes it less specific, since the driver should also work on other
Kinetis families.

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k64f/pkg.yml |  2 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c   |  4 ++--
 .../include/hash_context.h   |  0
 .../include/hash_kinetis/hash_kinetis.h} |  8 
 hw/drivers/hash/{hash_k64f => hash_kinetis}/pkg.yml  |  4 ++--
 .../hash_k64f.c => hash_kinetis/src/hash_kinetis.c}  | 20 ++--
 .../src/hash_kinetis_cau.c}  |  2 +-
 7 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/hw/bsp/frdm-k64f/pkg.yml b/hw/bsp/frdm-k64f/pkg.yml
index 7143c45..193337d 100644
--- a/hw/bsp/frdm-k64f/pkg.yml
+++ b/hw/bsp/frdm-k64f/pkg.yml
@@ -73,4 +73,4 @@ pkg.deps.ENC_FLASH_DEV:
 - "@apache-mynewt-core/hw/drivers/flash/enc_flash/ef_crypto"
 
 pkg.deps.HASH:
-- "@apache-mynewt-core/hw/drivers/hash/hash_k64f"
+- "@apache-mynewt-core/hw/drivers/hash/hash_kinetis"
diff --git a/hw/bsp/frdm-k64f/src/hal_bsp.c b/hw/bsp/frdm-k64f/src/hal_bsp.c
index f79a1ba..1f6c95e 100644
--- a/hw/bsp/frdm-k64f/src/hal_bsp.c
+++ b/hw/bsp/frdm-k64f/src/hal_bsp.c
@@ -41,7 +41,7 @@
 #endif
 #if MYNEWT_VAL(HASH)
 #include "hash/hash.h"
-#include "hash_k64f/hash_k64f.h"
+#include "hash_kinetis/hash_kinetis.h"
 #endif
 #if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
 MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4) || MYNEWT_VAL(UART_5)
@@ -223,7 +223,7 @@ hal_bsp_init(void)
 
 #if MYNEWT_VAL(HASH)
 rc = os_dev_create(_bsp_hash.dev, "hash", OS_DEV_INIT_KERNEL,
-   OS_DEV_INIT_PRIO_DEFAULT, k64f_hash_dev_init, NULL);
+   OS_DEV_INIT_PRIO_DEFAULT, kinetis_hash_dev_init, NULL);
 assert(rc == 0);
 #endif
 
diff --git a/hw/drivers/hash/hash_k64f/include/hash_context.h 
b/hw/drivers/hash/hash_kinetis/include/hash_context.h
similarity index 100%
rename from hw/drivers/hash/hash_k64f/include/hash_context.h
rename to hw/drivers/hash/hash_kinetis/include/hash_context.h
diff --git a/hw/drivers/hash/hash_k64f/include/hash_k64f/hash_k64f.h 
b/hw/drivers/hash/hash_kinetis/include/hash_kinetis/hash_kinetis.h
similarity index 86%
rename from hw/drivers/hash/hash_k64f/include/hash_k64f/hash_k64f.h
rename to hw/drivers/hash/hash_kinetis/include/hash_kinetis/hash_kinetis.h
index 76100dc..d2a8b18 100644
--- a/hw/drivers/hash/hash_k64f/include/hash_k64f/hash_k64f.h
+++ b/hw/drivers/hash/hash_kinetis/include/hash_kinetis/hash_kinetis.h
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#ifndef __HASH_K64F_H__
-#define __HASH_K64F_H__
+#ifndef __HASH_KINETIS_H__
+#define __HASH_KINETIS_H__
 
 #include "hash/hash.h"
 
@@ -26,10 +26,10 @@
 extern "C" {
 #endif
 
-int k64f_hash_dev_init(struct os_dev *dev, void *arg);
+int kinetis_hash_dev_init(struct os_dev *dev, void *arg);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* __HASH_K64F_H__ */
+#endif /* __HASH_KINETIS_H__ */
diff --git a/hw/drivers/hash/hash_k64f/pkg.yml 
b/hw/drivers/hash/hash_kinetis/pkg.yml
similarity index 91%
rename from hw/drivers/hash/hash_k64f/pkg.yml
rename to hw/drivers/hash/hash_kinetis/pkg.yml
index 0a71c76..386899c 100644
--- a/hw/drivers/hash/hash_k64f/pkg.yml
+++ b/hw/drivers/hash/hash_kinetis/pkg.yml
@@ -17,8 +17,8 @@
 # under the License.
 #
 
-pkg.name: hw/drivers/hash/hash_k64f
-pkg.description: Hash driver for NXP K64F
+pkg.name: hw/drivers/hash/hash_kinetis
+pkg.description: Hash driver for NXP Kinetis family
 pkg.author: "Apache Mynewt "
 pkg.homepage: "http://mynewt.apache.org/;
 pkg.keywords:
diff --git a/hw/drivers/hash/hash_k64f/src/hash_k64f.c 
b/hw/drivers/hash/hash_kinetis/src/hash_kinetis.c
similarity index 88%
rename from hw/drivers/hash/hash_k64f/src/hash_k64f.c
rename to hw/drivers/hash/hash_kinetis/src/hash_kinetis.c
index dd48412..170e253 100644
--- a/hw/drivers/hash/hash_k64f/src/hash_k64f.c
+++ b/hw/drivers/hash/hash_kinetis/src/hash_kinetis.c
@@ -22,7 +22,7 @@
 #include 
 
 #include "hash/hash.h"
-#include "hash_k64f/hash_k64f.h"
+#include "hash_kinetis/hash_kinetis.h"
 
 static struct os_mutex gmtx;
 static uint32_t g_algos = HASH_ALGO_SHA256;
@@ -51,7 +51,7 @@ extern void cau_sha256_hash(const unsigned char *msg_data,
 unsigned int *sha256_state);
 
 static int
-k64f_hash_start(struct hash_dev *hash, void *ctx, uint16_t algo)
+kinetis_hash_start(struct hash_dev *hash, void *ctx, uint16_t algo)
 {
 struct hash_sha256_context *sha256ctx;
 
@@ -69,7 +

[mynewt-core] 02/02: Enable HW HASH usage on frdm-k82f board

2021-02-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit cbf4886a57ed4fe546302cdf0675ebc37d0cab47
Author: Fabio Utzig 
AuthorDate: Mon Feb 8 12:42:56 2021 -0300

Enable HW HASH usage on frdm-k82f board

Signed-off-by: Fabio Utzig 
---
 hw/bsp/frdm-k82f/pkg.yml   |  3 +++
 hw/bsp/frdm-k82f/src/hal_bsp.c | 13 +
 2 files changed, 16 insertions(+)

diff --git a/hw/bsp/frdm-k82f/pkg.yml b/hw/bsp/frdm-k82f/pkg.yml
index 778b4c7..0389789 100644
--- a/hw/bsp/frdm-k82f/pkg.yml
+++ b/hw/bsp/frdm-k82f/pkg.yml
@@ -62,3 +62,6 @@ pkg.deps.UART_4:
 
 pkg.deps.ENC_FLASH_DEV:
 - "@apache-mynewt-core/hw/drivers/flash/enc_flash/ef_crypto"
+
+pkg.deps.HASH:
+- "@apache-mynewt-core/hw/drivers/hash/hash_kinetis"
diff --git a/hw/bsp/frdm-k82f/src/hal_bsp.c b/hw/bsp/frdm-k82f/src/hal_bsp.c
index abf3af9..71162d2 100644
--- a/hw/bsp/frdm-k82f/src/hal_bsp.c
+++ b/hw/bsp/frdm-k82f/src/hal_bsp.c
@@ -31,6 +31,10 @@
 #if MYNEWT_VAL(ENC_FLASH_DEV)
 #include 
 #endif
+#if MYNEWT_VAL(HASH)
+#include "hash/hash.h"
+#include "hash_kinetis/hash_kinetis.h"
+#endif
 #if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
 MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4)
 #include "uart/uart.h"
@@ -98,6 +102,9 @@ static const struct nxp_hal_i2c_cfg hal_i2c3_cfg = {
 };
 #endif
 
+#if MYNEWT_VAL(HASH)
+static struct hash_dev os_bsp_hash;
+#endif
 
 /*
  * What memory to include in coredump.
@@ -222,6 +229,12 @@ hal_bsp_init(void)
 init_hardware();
 BOARD_BootClockRUN();
 
+#if MYNEWT_VAL(HASH)
+rc = os_dev_create(_bsp_hash.dev, "hash", OS_DEV_INIT_KERNEL,
+   OS_DEV_INIT_PRIO_DEFAULT, kinetis_hash_dev_init, NULL);
+assert(rc == 0);
+#endif
+
 #if MYNEWT_VAL(UART_0)
 rc = os_dev_create((struct os_dev *) _bsp_uart0, "uart0",
OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL);



[mynewt-mcumgr] branch master updated (130ae98 -> 35d290e)

2021-02-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git.


from 130ae98  Merge pull request #111 from utzig/fix-linked-list
 new c8151d8  zephyr: Rely on img_mgmt_find_best_area_id to select update 
partition
 new 35d290e  zephyr: Use flash_img_init_id instead of flash_img_init

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)



[mynewt-mcumgr] 01/02: zephyr: Rely on img_mgmt_find_best_area_id to select update partition

2021-02-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit c8151d8023f2f985c66a9dcecb4e741cf5306393
Author: Dominik Ermel 
AuthorDate: Thu Feb 11 12:08:22 2021 +

zephyr: Rely on img_mgmt_find_best_area_id to select update partition

The img_mgmt_find_best_area_id is supposed to figure out the best, which
also means possible, partition for software update.
Unfortunately in the code in many places the direct reference the to
FLASH_AREA_ID(image_1) is used, which may cause image_1 being
overwritten, even if other partition would be selected as the "best".

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index d6169b8..ef72c1e 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -194,14 +194,16 @@ img_mgmt_impl_erase_slot(void)
 bool empty;
 int rc;
 
-rc = zephyr_img_mgmt_flash_check_empty(FLASH_AREA_ID(image_1),
-   );
+/* Select non-active slot */
+const int best_id = img_mgmt_find_best_area_id();
+
+rc = zephyr_img_mgmt_flash_check_empty(best_id, );
 if (rc != 0) {
 return MGMT_ERR_EUNKNOWN;
 }
 
 if (!empty) {
-rc = boot_erase_img_bank(FLASH_AREA_ID(image_1));
+rc = boot_erase_img_bank(best_id);
 if (rc != 0) {
 return MGMT_ERR_EUNKNOWN;
 }
@@ -328,7 +330,7 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned 
int num_bytes)
 goto end;
 }
 
-rc = flash_area_open(FLASH_AREA_ID(image_1), );
+rc = flash_area_open(img_mgmt_find_best_area_id(), );
 if (rc != 0) {
 LOG_ERR("Can't bind to the flash area (err %d)", rc);
 rc = MGMT_ERR_EUNKNOWN;



[mynewt-mcumgr] 02/02: zephyr: Use flash_img_init_id instead of flash_img_init

2021-02-12 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 35d290eadf4414f4902da67e01b165a39e61080c
Author: Dominik Ermel 
AuthorDate: Thu Feb 11 12:14:41 2021 +

zephyr: Use flash_img_init_id instead of flash_img_init

Within mcumgr Zephyr port, the img_mgmt_find_best_area_id is used to
get information on the update flash ID, yet the call to the flash_img_init
selects such flash ID via value hardcoded during compilation. This may
lead to situation where the mcumgr library and flash_img_init may select
different partition for update.
This commit replaces call to flash_img_init with flash_img_init_id, which
takes flash area ID as a parameter, and uses img_mgmt_find_best_area_id
to get the ID.
This approach is better as img_mgmt_find_best_area_id, while searching for
empty image, will also check its boot status (pending, test, etc).

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index ef72c1e..777aad5 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -292,7 +292,7 @@ img_mgmt_impl_write_image_data(unsigned int offset, const 
void *data,
}
}
 #endif
-   rc = flash_img_init(ctx);
+   rc = flash_img_init_id(ctx, img_mgmt_find_best_area_id());
 
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;



[mynewt-core] branch master updated: Enable Mbed TLS self-tests which were not running

2021-02-11 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 461f880  Enable Mbed TLS self-tests which were not running
461f880 is described below

commit 461f8808954c9fcd4b13e0098232cc4913b020c3
Author: Fabio Utzig 
AuthorDate: Thu Feb 11 11:35:53 2021 -0300

Enable Mbed TLS self-tests which were not running

Enable extra self-tests from Mbed TLS. Added ARIA, CMAC, MD2, MD4 and
J-PAKE tests. The test order was sorted for easier reading.

Signed-off-by: Fabio Utzig 
---
 crypto/mbedtls/include/mbedtls/config.h   | 10 ++--
 crypto/mbedtls/include/mbedtls/config_mynewt.h| 17 +++
 crypto/mbedtls/selftest/pkg.yml   |  2 +-
 crypto/mbedtls/selftest/src/mbedtls_test.c| 59 ++-
 crypto/mbedtls/selftest/src/mbedtls_test.h| 29 ++-
 crypto/mbedtls/selftest/src/testcases/aria_test.c | 27 +++
 crypto/mbedtls/selftest/src/testcases/cmac.c  | 27 +++
 crypto/mbedtls/selftest/src/testcases/ecjpake.c   | 27 +++
 crypto/mbedtls/selftest/src/testcases/md2_test.c  | 27 +++
 crypto/mbedtls/selftest/src/testcases/md4_test.c  | 27 +++
 crypto/mbedtls/selftest/syscfg.yml|  5 ++
 crypto/mbedtls/syscfg.yml | 10 
 12 files changed, 225 insertions(+), 42 deletions(-)

diff --git a/crypto/mbedtls/include/mbedtls/config.h 
b/crypto/mbedtls/include/mbedtls/config.h
index ad0fa6a..9d5dbfa 100644
--- a/crypto/mbedtls/include/mbedtls/config.h
+++ b/crypto/mbedtls/include/mbedtls/config.h
@@ -2161,7 +2161,7 @@
  *  MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256
  *  MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384
  */
-//#define MBEDTLS_ARIA_C
+#define MBEDTLS_ARIA_C
 
 /**
  * \def MBEDTLS_CCM_C
@@ -2232,7 +2232,7 @@
  * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
  *
  */
-//#define MBEDTLS_CMAC_C
+#define MBEDTLS_CMAC_C
 
 /**
  * \def MBEDTLS_CTR_DRBG_C
@@ -2366,7 +2366,7 @@
  *
  * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C
  */
-//#define MBEDTLS_ECJPAKE_C
+#define MBEDTLS_ECJPAKE_C
 
 /**
  * \def MBEDTLS_ECP_C
@@ -2514,7 +2514,7 @@
  *it, and considering stronger message digests instead.
  *
  */
-//#define MBEDTLS_MD2_C
+#define MBEDTLS_MD2_C
 
 /**
  * \def MBEDTLS_MD4_C
@@ -2531,7 +2531,7 @@
  *it, and considering stronger message digests instead.
  *
  */
-//#define MBEDTLS_MD4_C
+#define MBEDTLS_MD4_C
 
 /**
  * \def MBEDTLS_MD5_C
diff --git a/crypto/mbedtls/include/mbedtls/config_mynewt.h 
b/crypto/mbedtls/include/mbedtls/config_mynewt.h
index 1d2ed0a..9620b9d 100644
--- a/crypto/mbedtls/include/mbedtls/config_mynewt.h
+++ b/crypto/mbedtls/include/mbedtls/config_mynewt.h
@@ -183,6 +183,10 @@ extern "C" {
 #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED
 #endif
 
+#if MYNEWT_VAL(MBEDTLS_ECJPAKE_C) == 0
+#undef MBEDTLS_ECJPAKE_C
+#endif
+
 #if MYNEWT_VAL(MBEDTLS_AES_ALT) == 0
 #undef MBEDTLS_AES_ALT
 #endif
@@ -202,6 +206,9 @@ extern "C" {
 #if MYNEWT_VAL(MBEDTLS_ARC4_C) == 0
 #undef MBEDTLS_ARC4_C
 #endif
+#if MYNEWT_VAL(MBEDTLS_ARIA_C) == 0
+#undef MBEDTLS_ARIA_C
+#endif
 #if MYNEWT_VAL(MBEDTLS_BLOWFISH_C) == 0
 #undef MBEDTLS_BLOWFISH_C
 #endif
@@ -227,6 +234,10 @@ extern "C" {
 #undef MBEDTLS_POLY1305_C
 #endif
 
+#if MYNEWT_VAL(MBEDTLS_CMAC_C) == 0
+#undef MBEDTLS_CMAC_C
+#endif
+
 #if MYNEWT_VAL(MBEDTLS_CIPHER_MODE_CBC) == 0
 #undef MBEDTLS_CIPHER_MODE_CBC
 #endif
@@ -258,6 +269,12 @@ extern "C" {
 #if MYNEWT_VAL(MBEDTLS_SHA256_C) == 0
 #undef MBEDTLS_SHA256_C
 #endif
+#if MYNEWT_VAL(MBEDTLS_MD2_C) == 0
+#undef MBEDTLS_MD2_C
+#endif
+#if MYNEWT_VAL(MBEDTLS_MD4_C) == 0
+#undef MBEDTLS_MD4_C
+#endif
 #if MYNEWT_VAL(MBEDTLS_MD5_C) == 0
 #undef MBEDTLS_MD5_C
 #endif
diff --git a/crypto/mbedtls/selftest/pkg.yml b/crypto/mbedtls/selftest/pkg.yml
index daf3e83..b84ebc1 100644
--- a/crypto/mbedtls/selftest/pkg.yml
+++ b/crypto/mbedtls/selftest/pkg.yml
@@ -17,7 +17,7 @@
 #
 pkg.name: crypto/mbedtls/selftest
 pkg.type: unittest
-pkg.description: "mbedtls unit tests."
+pkg.description: "Mbed TLS unit tests."
 pkg.author: "Apache Mynewt "
 pkg.homepage: "http://mynewt.apache.org/;
 pkg.keywords:
diff --git a/crypto/mbedtls/selftest/src/mbedtls_test.c 
b/crypto/mbedtls/selftest/src/mbedtls_test.c
index 77b0903..a8941cc 100644
--- a/crypto/mbedtls/selftest/src/mbedtls_test.c
+++ b/crypto/mbedtls/selftest/src/mbedtls_test.c
@@ -52,63 +52,74 @@
 #include "mbedtls/base64.h"
 #include "mbedtls/timing.h"
 
-TEST_CASE_DECL(sha1_test)
-TEST_CASE_DECL(sha256_test)
-TEST_CASE_DECL(sha512_test)
 TEST_CASE_DECL(aes_test)
 TEST_CASE_DECL(arc4_test)
+TEST_CASE_DECL(aria_test)
+TEST_CASE_DECL(base64_test)
 TEST_CASE_DECL(bignum_test)
+TEST_CASE_DECL(camellia

[mynewt-newt] branch master updated (d6256a3 -> dd8a134)

2021-02-10 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git.


from d6256a3  docs: deprecated Homebrew install command ruby command is 
deprecated and bash command should be used.
 add dd8a134  Update go.sum with correct sums

No new revisions were added by this update.

Summary of changes:
 go.sum | 2 ++
 1 file changed, 2 insertions(+)



[mynewt-core] branch master updated: [mailmap] Revert to logging @apache.org

2021-02-06 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 293663d  [mailmap] Revert to logging @apache.org
293663d is described below

commit 293663d1e032279a566d6f820fd680619338ffa6
Author: Fabio Utzig 
AuthorDate: Thu Feb 4 14:43:05 2021 -0300

[mailmap] Revert to logging @apache.org

Signed-off-by: Fabio Utzig 
---
 .mailmap | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.mailmap b/.mailmap
index d55c57e..bab2d7e 100644
--- a/.mailmap
+++ b/.mailmap
@@ -15,7 +15,7 @@ Christopher Collins  

 David G. Simmons 

 David Lee
<34385265+dlee...@users.noreply.github.com>
 David Lee
<34385265+dlee...@users.noreply.github.com>
-Fabio Utzig   
+Fabio Utzig  
 Francois Berder
 Gordon Klaus   

 Jacob Rosenthal   




[mynewt-core] branch master updated (ef0f504 -> 529235a)

2021-02-04 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from ef0f504  Merge pull request #2459 from vikrant-proxy/osdp-library
 add 529235a  [KINETIS] Turn pyocd into a reusable script

No new revisions were added by this update.

Summary of changes:
 hw/bsp/frdm-k64f/frdm-k64_debug.sh| 19 
 hw/bsp/frdm-k64f/frdm-k64_download.sh |  9 
 hw/scripts/{stlink.sh => pyocd.sh}| 42 +++
 3 files changed, 41 insertions(+), 29 deletions(-)
 copy hw/scripts/{stlink.sh => pyocd.sh} (70%)



[mynewt-core] branch master updated (5d44385 -> c446322)

2021-02-04 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 5d44385  Fixed MMC starting frequency
 add c446322  hw/mcu/stm: Add missing ld file for nucleo-l073rz BSP

No new revisions were added by this update.

Summary of changes:
 hw/mcu/stm/stm32l0xx/{stm32l072.ld => stm32l073.ld} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 copy hw/mcu/stm/stm32l0xx/{stm32l072.ld => stm32l073.ld} (100%)



[mynewt-mcumgr] branch master updated: mynewt: Fix strncpy warning

2021-01-31 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 552c6a5  mynewt: Fix strncpy warning
552c6a5 is described below

commit 552c6a529bec1ed7c653ef4e8915c94205bb
Author: Casper Meijn 
AuthorDate: Fri Jan 8 20:24:38 2021 +0100

mynewt: Fix strncpy warning

GCC complains about a strncpy call when build using build_profile speed.
This warning indicates a possible string truncation. The only proper
solution I could find was to decrease the buffer size and explicitly
set a zero byte.

Error: 
repos/apache-mynewt-mcumgr/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c: In 
function 'os_mgmt_impl_task_info':

repos/apache-mynewt-mcumgr/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c:92:5: 
error: 'strncpy' specified bound 32 equals destination size 
[-Werror=stringop-truncation]
   92 | strncpy(out_info->oti_name, task->t_name, sizeof 
out_info->oti_name);
  | 
^~~~
cc1: all warnings being treated as errors
---
 cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c 
b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
index 78f198b..4a0cdc4 100644
--- a/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
+++ b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
@@ -89,7 +89,8 @@ os_mgmt_impl_task_info(int idx, struct os_mgmt_task_info 
*out_info)
 out_info->oti_last_checkin = task->t_sanity_check.sc_checkin_last;
 out_info->oti_next_checkin = task->t_sanity_check.sc_checkin_last +
  task->t_sanity_check.sc_checkin_itvl;
-strncpy(out_info->oti_name, task->t_name, sizeof out_info->oti_name);
+strncpy(out_info->oti_name, task->t_name, sizeof out_info->oti_name - 1);
+out_info->oti_name[sizeof out_info->oti_name - 1] = '\0';
 
 return 0;
 }



[mynewt-mcumgr] branch master updated (74e77ad -> 85b35fc)

2021-01-30 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git.


from 74e77ad  zephyr: Add support for image ROM address verification
 add 85b35fc  mynewt: Remove unused define from sample

No new revisions were added by this update.

Summary of changes:
 samples/omp_svr/mynewt/src/main.c | 1 -
 1 file changed, 1 deletion(-)



[mynewt-mcumgr] branch master updated: zephyr: Add support for image ROM address verification

2020-12-18 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 74e77ad  zephyr: Add support for image ROM address verification
74e77ad is described below

commit 74e77ad08090c0e389a27118fdebe20783dca2e4
Author: Dominik Ermel 
AuthorDate: Thu Dec 10 15:17:04 2020 +

zephyr: Add support for image ROM address verification

The commit adds IMAGE_F_ROM_FIXED_ADDR flag that allows to use
ih_load_addr to identify the flash address the image is intendant to
start at.
The code, that supports this flag, will reject image before attempting
flash write if slot address differs from the base address of the image.
The feature can be used to mark Direct-XIP images with slot address
they are intended for.
The CONFIG_IMG_MGMT_REJECT_DIRECT_XIP_MISMATCHED_SLOT has been added
to turn the featre on.

Signed-off-by: Dominik Ermel 
---
 cmd/img_mgmt/include/img_mgmt/image.h  |  1 +
 cmd/img_mgmt/include/img_mgmt/img_mgmt.h   |  2 ++
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 20 
 cmd/img_mgmt/src/img_mgmt.c|  1 +
 4 files changed, 24 insertions(+)

diff --git a/cmd/img_mgmt/include/img_mgmt/image.h 
b/cmd/img_mgmt/include/img_mgmt/image.h
index 53ca7f6..6de917a 100644
--- a/cmd/img_mgmt/include/img_mgmt/image.h
+++ b/cmd/img_mgmt/include/img_mgmt/image.h
@@ -34,6 +34,7 @@ extern "C" {
 
 /** Image header flags. */
 #define IMAGE_F_NON_BOOTABLE0x0010 /* Split image app. */
+#define IMAGE_F_ROM_FIXED_ADDR  0x0100
 
 /** Image trailer TLV types. */
 #define IMAGE_TLV_SHA2560x10   /* SHA256 of image hdr and body */
diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt.h 
b/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
index 4385477..78e6ba5 100644
--- a/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
@@ -259,6 +259,7 @@ extern const char *img_mgmt_err_str_flash_open_failed;
 extern const char *img_mgmt_err_str_flash_erase_failed;
 extern const char *img_mgmt_err_str_flash_write_failed;
 extern const char *img_mgmt_err_str_downgrade;
+extern const char *img_mgmt_err_str_image_bad_flash_addr;
 #else
 #define img_mgmt_error_rsp(ctxt, rc, rsn) (rc)
 #define img_mgmt_err_str_app_reject   NULL
@@ -269,6 +270,7 @@ extern const char *img_mgmt_err_str_downgrade;
 #define img_mgmt_err_str_flash_erase_failed   NULL
 #define img_mgmt_err_str_flash_write_failed   NULL
 #define img_mgmt_err_str_downgradeNULL
+#define img_mgmt_err_str_image_bad_flash_addr NULL
 #endif
 
 #ifdef __cplusplus
diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index b4a4e3b..d6169b8 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -495,6 +495,26 @@ img_mgmt_impl_upload_inspect(const struct 
img_mgmt_upload_req *req,
 return MGMT_ERR_ENOMEM;
 }
 
+
+#if defined(CONFIG_IMG_MGMT_REJECT_DIRECT_XIP_MISMATCHED_SLOT)
+if (hdr->ih_flags & IMAGE_F_ROM_FIXED_ADDR) {
+rc = flash_area_open(action->area_id, );
+if (rc) {
+*errstr = img_mgmt_err_str_flash_open_failed;
+return MGMT_ERR_EUNKNOWN;
+}
+
+if (fa->fa_off != hdr->ih_load_addr) {
+*errstr = img_mgmt_err_str_image_bad_flash_addr;
+flash_area_close(fa);
+return MGMT_ERR_EINVAL;
+}
+
+flash_area_close(fa);
+}
+#endif
+
+
 if (req->upgrade) {
 /* User specified upgrade-only.  Make sure new image version is
  * greater than that of the currently running image.
diff --git a/cmd/img_mgmt/src/img_mgmt.c b/cmd/img_mgmt/src/img_mgmt.c
index 029b4cc..1a40ffc 100644
--- a/cmd/img_mgmt/src/img_mgmt.c
+++ b/cmd/img_mgmt/src/img_mgmt.c
@@ -72,6 +72,7 @@ const char *img_mgmt_err_str_flash_open_failed = "fa open 
fail";
 const char *img_mgmt_err_str_flash_erase_failed = "fa erase fail";
 const char *img_mgmt_err_str_flash_write_failed = "fa write fail";
 const char *img_mgmt_err_str_downgrade = "downgrade";
+const char *img_mgmt_err_str_image_bad_flash_addr = "img addr mismatch";
 #endif
 
 /**



[mynewt-site] branch master updated: Update landing BLE link to network page

2020-12-10 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-site.git


The following commit(s) were added to refs/heads/master by this push:
 new 5da0461  Update landing BLE link to network page
5da0461 is described below

commit 5da0461c132192cd1a7a90681c25f0702a20
Author: Fabio Utzig 
AuthorDate: Tue Dec 8 19:24:51 2020 -0300

Update landing BLE link to network page

Fix link that goes to empty page.

Signed-off-by: Fabio Utzig 
---
 custom-theme/landing.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/custom-theme/landing.html b/custom-theme/landing.html
index 1ccd375..f42338e 100644
--- a/custom-theme/landing.html
+++ b/custom-theme/landing.html
@@ -15,7 +15,7 @@
Full stack, host only, or controller only - your choice 

Maximum throughput of 2Mbps 
32+ concurrent connections, multiple connections in 
simulatenous central and peripheral roles 
-   More on NimBLE... 
+   More on NimBLE... 
 
LoRa PHY and LoRaWAN support 
 



[mynewt-newt] branch master updated: newt: Support legacy TLV option

2020-12-09 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
 new da16a62  newt: Support legacy TLV option
da16a62 is described below

commit da16a6226cad504ea8c700965f279b1d63592fac
Author: Andy Gross 
AuthorDate: Wed Nov 18 11:47:44 2020 -0600

newt: Support legacy TLV option

This patch adds support for generating images using legacy TLV values for
AES_NONCE and SECRET_ID.  This allows newer newt tool versions to be able to
create new application images for devices which only support legacy TLV 
values.

Signed-off-by: Andy Gross 
---
 go.mod  | 3 ++-
 newt/cli/image_cmds.go  | 8 ++--
 newt/cli/run_cmds.go| 4 ++--
 newt/imgprod/imgprod.go | 9 ++---
 newt/imgprod/v1.go  | 4 ++--
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/go.mod b/go.mod
index 4ea3030..9494e6f 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.13
 
 require (
github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
-   github.com/apache/mynewt-artifact v0.0.20
+   github.com/apache/mynewt-artifact v0.0.21
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/shirou/gopsutil v2.20.8+incompatible
@@ -16,3 +16,4 @@ require (
github.com/ugorji/go/codec v1.1.7
golang.org/x/crypto v0.0.0-2019062107-cc06ce4a13d4
 )
+
diff --git a/newt/cli/image_cmds.go b/newt/cli/image_cmds.go
index fb5373d..6da30a7 100644
--- a/newt/cli/image_cmds.go
+++ b/newt/cli/image_cmds.go
@@ -35,6 +35,7 @@ import (
 
 var useV1 bool
 var useV2 bool
+var useLegacyTLV bool
 var encKeyFilename string
 var encKeyIndex int
 var hdrPad int
@@ -136,10 +137,10 @@ func createImageRunCmd(cmd *cobra.Command, args []string) 
{
 
if useV1 {
err = imgprod.ProduceAllV1(b, ver, keys, encKeyFilename, 
encKeyIndex,
-   hdrPad, imagePad, sections)
+   hdrPad, imagePad, sections, useLegacyTLV)
} else {
err = imgprod.ProduceAll(b, ver, keys, encKeyFilename, 
encKeyIndex,
-   hdrPad, imagePad, sections)
+   hdrPad, imagePad, sections, useLegacyTLV)
}
if err != nil {
NewtUsage(nil, err)
@@ -205,6 +206,9 @@ func AddImageCommands(cmd *cobra.Command) {
createImageCmd.PersistentFlags().StringVarP(,
"sections", "S", "", "Section names for TLVs, comma delimited")
 
+   createImageCmd.PersistentFlags().BoolVarP(,
+   "legacy-tlvs", "L", false, "Use legacy TLV values for NONCE and 
SECRET_ID")
+
cmd.AddCommand(createImageCmd)
AddTabCompleteFn(createImageCmd, targetList)
 
diff --git a/newt/cli/run_cmds.go b/newt/cli/run_cmds.go
index cd7ce09..936dde8 100644
--- a/newt/cli/run_cmds.go
+++ b/newt/cli/run_cmds.go
@@ -106,10 +106,10 @@ func runRunCmd(cmd *cobra.Command, args []string) {
 
if useV1 {
err = imgprod.ProduceAllV1(b, ver, keys, 
encKeyFilename, encKeyIndex,
-   hdrPad, imagePad, sections)
+   hdrPad, imagePad, sections, 
useLegacyTLV)
} else {
err = imgprod.ProduceAll(b, ver, keys, 
encKeyFilename, encKeyIndex,
-   hdrPad, imagePad, sections)
+   hdrPad, imagePad, sections, 
useLegacyTLV)
}
if err != nil {
NewtUsage(nil, err)
diff --git a/newt/imgprod/imgprod.go b/newt/imgprod/imgprod.go
index 8b25f85..1e82977 100644
--- a/newt/imgprod/imgprod.go
+++ b/newt/imgprod/imgprod.go
@@ -54,6 +54,7 @@ type ImageProdOpts struct {
HdrPadint
ImagePad  int
DummyC*toolchain.Compiler
+   UseLegacyTLV  bool
 }
 
 type ProducedImage struct {
@@ -153,6 +154,7 @@ func produceApp(opts ImageProdOpts, loaderHash []byte) 
(ProducedImage, error) {
LoaderHash:loaderHash,
HdrPad:opts.HdrPad,
ImagePad:  opts.ImagePad,
+   UseLegacyTLV:  opts.UseLegacyTLV,
}
 
ri, err := image.GenerateImage(igo)
@@ -270,7 +272,7 @@ func ProduceManifest(opts manifest.ManifestCreateOpts) 
error {
 
 func OptsFromTgtBldr(b *builder.TargetBuilder, ver image.ImageVersion,
sigKeys []sec.PrivSignKey, encKeyFilename string, encKeyIndex int,
-   hdrPad int, imagePad int, sections []image.Section) (ImageProdOpts, 
error) {
+ 

[mynewt-documentation] branch master updated: Update banner release and add 1.8.0 to chooser

2020-12-09 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-documentation.git


The following commit(s) were added to refs/heads/master by this push:
 new bd68e10  Update banner release and add 1.8.0 to chooser
bd68e10 is described below

commit bd68e100b981ae05a1e40f4d9dd8504c22ecda1a
Author: Fabio Utzig 
AuthorDate: Tue Dec 8 19:22:15 2020 -0300

Update banner release and add 1.8.0 to chooser

Signed-off-by: Fabio Utzig 
---
 docs/themes/mynewt/main-banner.html | 2 +-
 docs/themes/mynewt/versions.html| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/docs/themes/mynewt/main-banner.html 
b/docs/themes/mynewt/main-banner.html
index 867efd7..0e661d1 100644
--- a/docs/themes/mynewt/main-banner.html
+++ b/docs/themes/mynewt/main-banner.html
@@ -8,7 +8,7 @@
 
 
 
-Latest News: Apache Mynewt 1.7.0, 
Apache NimBLE 1.2.0  released (August 4, 2019)
+Latest News: Apache Mynewt 1.8.0, 
Apache NimBLE 1.3.0  released (April 9, 2020)
 
 
 
diff --git a/docs/themes/mynewt/versions.html b/docs/themes/mynewt/versions.html
index 6c1f634..2736d0f 100644
--- a/docs/themes/mynewt/versions.html
+++ b/docs/themes/mynewt/versions.html
@@ -3,6 +3,9 @@
   
 Version: latest
   
+  
+Version: 1.8.0
+  
   
 Version: 1.7.0
   



[mynewt-mcumgr] branch master updated: Add image upload support for flash erased at 0

2020-12-01 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 449bee7  Add image upload support for flash erased at 0
449bee7 is described below

commit 449bee75750ea4430d299b8da28c4f39b07f8b08
Author: Fabio Utzig 
AuthorDate: Sun Nov 29 22:14:39 2020 -0300

Add image upload support for flash erased at 0

Add a new abstraction to the image port implementation to get the value
a flash device is erased to, and update the image manager to expect the
correct values when reading erased data at the image header, etc.

Signed-off-by: Fabio Utzig 
---
 cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h  |  3 +++
 cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c | 17 +
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 24 +++-
 cmd/img_mgmt/src/img_mgmt.c| 12 ++--
 4 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h 
b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
index cff7dfa..53f60bf 100644
--- a/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
@@ -154,6 +154,9 @@ int img_mgmt_impl_upload_inspect(const struct 
img_mgmt_upload_req *req,
  struct img_mgmt_upload_action *action,
  const char **errstr);
 
+#define ERASED_VAL_32(x) (((x) << 24) | ((x) << 16) | ((x) << 8) | (x))
+int img_mgmt_impl_erased_val(int slot, uint8_t *erased_val);
+
 int img_mgmt_impl_log_upload_start(int status);
 
 int img_mgmt_impl_log_upload_done(int status, const uint8_t *hashp);
diff --git a/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c 
b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
index b021638..8151001 100644
--- a/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
+++ b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
@@ -527,6 +527,23 @@ img_mgmt_impl_swap_type(void)
 }
 }
 
+int
+img_mgmt_impl_erased_val(int slot, uint8_t *erased_val)
+{
+const struct flash_area *fa;
+int rc;
+
+rc = flash_area_open(flash_area_id_from_image_slot(slot), );
+if (rc != 0) {
+  return MGMT_ERR_EUNKNOWN;
+}
+
+*erased_val = flash_area_erased_val(fa);
+flash_area_close(fa);
+
+return 0;
+}
+
 void
 img_mgmt_module_init(void)
 {
diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 5e178d3..b4a4e3b 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -49,6 +49,8 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool 
*out_empty)
 int bytes_to_read;
 int rc;
 int i;
+uint8_t erased_val;
+uint32_t erased_val_32;
 
 rc = flash_area_open(fa_id, );
 if (rc != 0) {
@@ -57,6 +59,9 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool 
*out_empty)
 
 assert(fa->fa_size % 4 == 0);
 
+erased_val = flash_area_erased_val(fa);
+erased_val_32 = ERASED_VAL_32(erased_val);
+
 end = fa->fa_size;
 for (addr = 0; addr < end; addr += sizeof data) {
 if (end - addr < sizeof data) {
@@ -72,7 +77,7 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool 
*out_empty)
 }
 
 for (i = 0; i < bytes_to_read / 4; i++) {
-if (data[i] != 0x) {
+if (data[i] != erased_val_32) {
 *out_empty = false;
 flash_area_close(fa);
 return 0;
@@ -552,3 +557,20 @@ img_mgmt_impl_upload_inspect(const struct 
img_mgmt_upload_req *req,
 action->proceed = true;
 return 0;
 }
+
+int
+img_mgmt_impl_erased_val(int slot, uint8_t *erased_val)
+{
+const struct flash_area *fa;
+int rc;
+
+rc = flash_area_open(zephyr_img_mgmt_flash_area_id(slot), );
+if (rc != 0) {
+  return MGMT_ERR_EUNKNOWN;
+}
+
+*erased_val = flash_area_erased_val(fa);
+flash_area_close(fa);
+
+return 0;
+}
diff --git a/cmd/img_mgmt/src/img_mgmt.c b/cmd/img_mgmt/src/img_mgmt.c
index 249ba2b..029b4cc 100644
--- a/cmd/img_mgmt/src/img_mgmt.c
+++ b/cmd/img_mgmt/src/img_mgmt.c
@@ -137,21 +137,29 @@ img_mgmt_read_info(int image_slot, struct image_version 
*ver, uint8_t *hash,
 size_t data_off;
 size_t data_end;
 bool hash_found;
+uint8_t erased_val;
+uint32_t erased_val_32;
 int rc;
 
+rc = img_mgmt_impl_erased_val(image_slot, _val);
+if (rc != 0) {
+return MGMT_ERR_EUNKNOWN;
+}
+
 rc = img_mgmt_impl_read(image_slot, 0, , sizeof hdr);
 if (rc != 0) {
 return MGMT_ERR_EUNKNOWN;
 }
 
 if (ver != NULL) {
-memset(ver, 0xff, sizeof(*ver));
+memset(ver, erased_val, sizeof(*ver));
 }
+erased_val_32 = ERASED_VAL_32(erased_val);

[mynewt-mcumgr] branch master updated: Implement shell management command handlers.

2020-11-07 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new a3d5117  Implement shell management command handlers.
a3d5117 is described below

commit a3d5117b0888ca52b967886467b5bb350028c4ba
Author: Brian Bradley 
AuthorDate: Wed Oct 21 11:26:11 2020 -0400

Implement shell management command handlers.

Only zephyr is supported here.

Signed-off-by: Brian Bradley 
---
 cmd/CMakeLists.txt |   1 +
 cmd/{ => shell_mgmt}/CMakeLists.txt|  13 ++-
 cmd/shell_mgmt/include/shell_mgmt/shell_mgmt.h |  43 +
 .../include/shell_mgmt/shell_mgmt_config.h |  43 +
 .../include/shell_mgmt/shell_mgmt_impl.h   |  57 
 cmd/shell_mgmt/port/zephyr/src/zephyr_shell_mgmt.c |  41 
 cmd/shell_mgmt/src/shell_mgmt.c| 103 +
 cmd/shell_mgmt/src/stubs.c |  38 
 8 files changed, 335 insertions(+), 4 deletions(-)

diff --git a/cmd/CMakeLists.txt b/cmd/CMakeLists.txt
index b527aa8..3c62484 100644
--- a/cmd/CMakeLists.txt
+++ b/cmd/CMakeLists.txt
@@ -19,3 +19,4 @@ add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_FS_MGMT   fs_mgmt)
 add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_IMG_MGMT  img_mgmt)
 add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_OS_MGMT   os_mgmt)
 add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_STAT_MGMT stat_mgmt)
+add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_SHELL_MGMT shell_mgmt)
diff --git a/cmd/CMakeLists.txt b/cmd/shell_mgmt/CMakeLists.txt
similarity index 76%
copy from cmd/CMakeLists.txt
copy to cmd/shell_mgmt/CMakeLists.txt
index b527aa8..1130be6 100644
--- a/cmd/CMakeLists.txt
+++ b/cmd/shell_mgmt/CMakeLists.txt
@@ -15,7 +15,12 @@
 # specific language governing permissions and limitations
 # under the License.
 
-add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_FS_MGMT   fs_mgmt)
-add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_IMG_MGMT  img_mgmt)
-add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_OS_MGMT   os_mgmt)
-add_subdirectory_ifdef(CONFIG_MCUMGR_CMD_STAT_MGMT stat_mgmt)
+target_include_directories(MCUMGR INTERFACE
+include
+)
+
+zephyr_library_sources(
+port/zephyr/src/zephyr_shell_mgmt.c
+src/shell_mgmt.c
+src/stubs.c
+)
diff --git a/cmd/shell_mgmt/include/shell_mgmt/shell_mgmt.h 
b/cmd/shell_mgmt/include/shell_mgmt/shell_mgmt.h
new file mode 100644
index 000..3f3bf16
--- /dev/null
+++ b/cmd/shell_mgmt/include/shell_mgmt/shell_mgmt.h
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_SHELL_MGMT_
+#define H_SHELL_MGMT_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Command IDs for shell management group.
+ */
+#define SHELL_MGMT_ID_EXEC   0
+
+/**
+ * @brief Registers the shell management command handler group.
+ */
+void
+shell_mgmt_register_group(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_SHELL_MGMT_ */
+
diff --git a/cmd/shell_mgmt/include/shell_mgmt/shell_mgmt_config.h 
b/cmd/shell_mgmt/include/shell_mgmt/shell_mgmt_config.h
new file mode 100644
index 000..60206d7
--- /dev/null
+++ b/cmd/shell_mgmt/include/shell_mgmt/shell_mgmt_config.h
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_SHELL_MGMT

[mynewt-mcumgr-cli] branch master updated: mynewt-mcumgr-cli: update to latest newt/newtmgr deps

2020-11-02 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr-cli.git


The following commit(s) were added to refs/heads/master by this push:
 new 0ba791a  mynewt-mcumgr-cli: update to latest newt/newtmgr deps
0ba791a is described below

commit 0ba791a8d336bc751598be3608439184b033
Author: Naveen Kaje 
AuthorDate: Wed Oct 28 10:26:33 2020 -0500

mynewt-mcumgr-cli: update to latest newt/newtmgr deps

Update the newt and newtmgr hashes to the latest.

Signed-off-by: Naveen Kaje naveen.k...@juul.com
---
 go.mod |  5 ++--
 go.sum | 96 --
 2 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/go.mod b/go.mod
index 730f94b..11c9f24 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module github.com/apache/mynewt-mcumgr-cli
 go 1.12
 
 require (
-   mynewt.apache.org/newt v0.0.0-20190805215728-4e771ee138aa
-   mynewt.apache.org/newtmgr v0.0.0-20190909210301-5029f07bf173
+   github.com/go-ble/ble v0.0.0-20181002102605-e78417b510a3 // indirect
+   mynewt.apache.org/newt v0.0.0-20201028015609-b57111dbd19f
+   mynewt.apache.org/newtmgr v0.0.0-20201028150837-60b2da78788c
 )
diff --git a/go.sum b/go.sum
index dd61b48..2a86b1d 100644
--- a/go.sum
+++ b/go.sum
@@ -1,78 +1,89 @@
 github.com/BurntSushi/toml v0.3.1/go.mod 
h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/JuulLabs-OSS/ble v0.0.0-20200716215611-d4fcc9d598bb 
h1:kIZ7fr8RxucJXNHifPxm71yiWuzpw0SmjlafMzoOd0U=
+github.com/JuulLabs-OSS/ble v0.0.0-20200716215611-d4fcc9d598bb/go.mod 
h1:6deIuswYSv6W1l3sM/nonw0OKWtIZCn7ZOWvIREoq2A=
+github.com/JuulLabs-OSS/cbgo v0.0.1/go.mod 
h1:L4YtGP+gnyD84w7+jN66ncspFRfOYB5aj9QSXaFHmBA=
 github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5/go.mod 
h1:w5D10RxC0NmPYxmQ438CC1S07zaC1zpvuNW7s5sUk2Q=
+github.com/abiosoft/ishell v2.0.0+incompatible/go.mod 
h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg=
 github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db 
h1:CjPUSXOiYptLbTdr1RceuZgSFDQ7U15ITERUGrUORx8=
 github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod 
h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530=
-github.com/apache/mynewt-artifact v0.0.3/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
+github.com/apache/mynewt-artifact v0.0.16/go.mod 
h1:vFUd47t74KPQMzSBhQ2qp5Hc7D29OU/Tl3xHtFwN3k8=
 github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod 
h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
-github.com/cheggaaa/pb v1.0.18 h1:G/DgkKaBP0V5lnBg/vx61nVxxAU+VqU5yMzSc0f2PPE=
-github.com/cheggaaa/pb v1.0.18/go.mod 
h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
+github.com/cheggaaa/pb v2.0.7+incompatible/go.mod 
h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
 github.com/chzyer/logex v1.1.10/go.mod 
h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
 github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3/go.mod 
h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
 github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod 
h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
 github.com/coreos/etcd v3.3.10+incompatible/go.mod 
h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/go-etcd v2.0.0+incompatible/go.mod 
h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
 github.com/coreos/go-semver v0.2.0/go.mod 
h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
+github.com/cosiner/argv v0.0.1/go.mod 
h1:p/NrK5tF6ICIly4qwEDsf6VDirFiWWz0FenfYBwJaKQ=
 github.com/cpuguy83/go-md2man v1.0.10/go.mod 
h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod 
h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
 github.com/davecgh/go-spew v1.1.0/go.mod 
h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1/go.mod 
h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/fatih/color v1.5.0 h1:vBh+kQp8lg9XPr56u1CPrWjFXtdphMoGWVHr9/1c+A0=
-github.com/fatih/color v1.5.0/go.mod 
h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
-github.com/fatih/structs v1.0.0 h1:BrX964Rv5uQ3wwS+KRUAJCBBw5PQmgJfJ6v4yly5QwU=
-github.com/fatih/structs v1.0.0/go.mod 
h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
+github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
+github.com/fatih/color v1.7.0/go.mod 
h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
+github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
+github.com/fatih/structs v1.1.0/go.mod 
h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 
h1:BMXYYRWTLOJKlh+lOBt6nUQgXAfB7oVIQt5cNreqSLI=
 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod 
h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M=
 github.com/fsnotify/fsnotify v1.4.7/go.mod 
h1:jwhsz4b93w/PPRr

[mynewt-mcumgr] branch master updated: Fix image erase command for partial slot-1 erase

2020-09-29 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 8ee7ad5  Fix image erase command for partial slot-1 erase
8ee7ad5 is described below

commit 8ee7ad55868e415a0837ec3baf7630be8609d9f2
Author: Nick Ward 
AuthorDate: Sun Sep 27 04:28:17 2020 +1000

Fix image erase command for partial slot-1 erase

This is a fix for devices in the field using mcuboot versions v1.6.0 or 
less.

If a firmware update is attempted with a corrupt image and a power outage or
reset occurs while the bootloader* is erasing the corrupt image then the
secondary (slot-1) can be left in a state where the bootloader has not
properly released slot-1 and a DFU transfer can no longer happen. Attempts
to execute the image erase command will fail with 6 (MGMT_ERR_EBADSTATE).

This commit fixes this issue by adding an additional requirement to 
determine
if a slot is 'in use': the image must also be valid. If this additional
requirement is not also met then the slot is considered not in use.

* The issue was originally discovered with Zephyr v1.14 LTS and mcuboot 
release
v3.1 and a fix for mcuboot has been applied here:
https://github.com/JuulLabs-OSS/mcuboot/pull/765
mcuboot commit: 42335be22bc8fb576845f41e6174f1921fcff5d9

A fix for mcumgr library in Zephyr v1.14 LTS is in progress here:
https://github.com/zephyrproject-rtos/zephyr/pull/26738

Note that previously this issue also affected the image upload command but
that has not been fixed in the code restructure in commit
8914f8755983bf5e08ce30a56e0c0660341978e5

Signed-off-by: Nick Ward 
---
 cmd/img_mgmt/src/img_mgmt.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/cmd/img_mgmt/src/img_mgmt.c b/cmd/img_mgmt/src/img_mgmt.c
index a8cfd56..249ba2b 100644
--- a/cmd/img_mgmt/src/img_mgmt.c
+++ b/cmd/img_mgmt/src/img_mgmt.c
@@ -285,12 +285,22 @@ img_mgmt_error_rsp(struct mgmt_ctxt *ctxt, int rc, const 
char *rsn)
 static int
 img_mgmt_erase(struct mgmt_ctxt *ctxt)
 {
+struct image_version ver;
 CborError err;
 int rc;
 
-if (img_mgmt_slot_in_use(1)) {
-/* No free slot. */
-return MGMT_ERR_EBADSTATE;
+/*
+ * First check if image info is valid.
+ * This check is done incase the flash area has a corrupted image.
+ */
+rc = img_mgmt_read_info(1, , NULL, NULL);
+
+if (rc == 0) {
+/* Image info is valid. */
+if (img_mgmt_slot_in_use(1)) {
+/* No free slot. */
+return MGMT_ERR_EBADSTATE;
+}
 }
 
 rc = img_mgmt_impl_erase_slot();



[mynewt-core] branch master updated: hw/bsp/pinetime: Setup 7 second watchdog

2020-09-26 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 5a55ea7  hw/bsp/pinetime: Setup 7 second watchdog
5a55ea7 is described below

commit 5a55ea78e0e95a21f06e9b848422b1eb5b2bb138
Author: Casper Meijn 
AuthorDate: Sat Sep 26 13:03:34 2020 +0200

hw/bsp/pinetime: Setup 7 second watchdog

Change the watchdog settings, as the new version of the
default bootloader for the PineTime also setup a watchdog with a 7
second interval. Without this change the processor will be reset a few
seconds after the application was started.
---
 hw/bsp/pinetime/syscfg.yml | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/bsp/pinetime/syscfg.yml b/hw/bsp/pinetime/syscfg.yml
index 97edf0e..7986de6 100644
--- a/hw/bsp/pinetime/syscfg.yml
+++ b/hw/bsp/pinetime/syscfg.yml
@@ -106,6 +106,10 @@ syscfg.vals:
 SPIFLASH_TCE_TYPICAL:   300 # Chip erase time (us)
 SPIFLASH_TCE_MAXIMUM:   1000 # Maximum chip erase time (us)
 
+# The default PineTime bootloader will setup a 7 second watchdog
+SANITY_INTERVAL: 5000
+WATCHDOG_INTERVAL: 7000
+
 syscfg.vals.BSP_BATTERY:
 # ADC needed for battery voltage
 ADC_0: 1



[mynewt-newtmgr] branch master updated: Update newtmgr_image.rst

2020-09-24 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 5b5173d  Update newtmgr_image.rst
5b5173d is described below

commit 5b5173d1d727f630923e9c7aa09303bf2742c067
Author: Rafa Couto 
AuthorDate: Mon Sep 21 03:50:30 2020 +0200

Update newtmgr_image.rst

Parameter blank separator
---
 docs/command_list/newtmgr_image.rst | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/docs/command_list/newtmgr_image.rst 
b/docs/command_list/newtmgr_image.rst
index dc1ed9e..598dfd1 100644
--- a/docs/command_list/newtmgr_image.rst
+++ b/docs/command_list/newtmgr_image.rst
@@ -67,7 +67,7 @@ Examples
 
++---+--+
 | Sub-command| Usage   
  | Explanation 

 |
 
++===+==+
-| confirm| ``newtmgr confirm-c profile01`` 
  | Makes the current image setup on a device permanent. Newtmgr 
connects to the device over a connection specified in the ``profile01`` 
connection profile. 
|
+| confirm| ``newtmgr confirm -c profile01``
  | Makes the current image setup on a device permanent. Newtmgr 
connects to the device over a connection specified in the ``profile01`` 
connection profile. 
|
 
++---+--+
 | confirm| ``newtmgr confirmbe9699809a049...73d77f-c profile01``   
  | Makes the image, identified by the ``be9699809a049...73d77f`` hash 
value, setup on a device permanent. Newtmgr connects to the device over a 
connection specified in the ``profile01`` connection profile.   |
 
++---+--+
@@ -77,17 +77,17 @@ Examples
 
++---+--+
 | coredownload   | ``newtmgr image coredownload mycore -e -c profile01``   
  | Downloads the core from a device, converts the core file into the 
ELF format, and saves it in the ``mycore`` file. Newtmgr connects to the device 
over a connection specified in the ``profile01`` connection profile.   |
 
++---+--+
-| coredownload   | ``newtmgr image coredownload mycore --offset 10 -n 30-c 
profile01``   | Downloads 30 bytes, starting at offset 10, of the core from a 
device and saves it in the ``mycore`` file. Newtmgr connects to the device over 
a connection specified in the ``profile01`` connection profile.|
+| coredownload   | ``newtmgr image coredownload mycore --offset 10 -n 30 -c 
profile01``  | Downloads 30 bytes, starting at offset 10, of the core from a 
device and saves it in the ``mycore`` file. Newtmgr connects to the device over 
a connection specified in the ``profile01`` connection profile

[mynewt-mcumgr] branch master updated: zephyr: constify struct device

2020-09-02 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 8d087a7  zephyr: constify struct device
8d087a7 is described below

commit 8d087a7e0e5485394419d10051606c92d68d2111
Author: Fabio Utzig 
AuthorDate: Wed Sep 2 12:58:49 2020 -0300

zephyr: constify struct device

Follow update done with:

https://github.com/zephyrproject-rtos/zephyr/pull/24873

That makes struct device const.

Signed-off-by: Fabio Utzig 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 484f75d..5e178d3 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -331,7 +331,7 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned 
int num_bytes)
 }
 
 /* align requested erase size to the erase-block-size */
-struct device *dev = flash_area_get_device(fa);
+const struct device *dev = flash_area_get_device(fa);
 struct flash_pages_info page;
 off_t page_offset = fa->fa_off + num_bytes - 1;
 
@@ -343,7 +343,7 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned 
int num_bytes)
 }
 
 size_t erase_size = page.start_offset + page.size - fa->fa_off;
-
+
 rc = flash_area_erase(fa, 0, erase_size);
 
 if (rc != 0) {



[mynewt-core] 01/02: apps/rust_blinky: Add blinky app using Rust language

2020-08-26 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 838cee6d153a9373dfe7f16ec0fd0dbe6eb8e8b5
Author: Casper Meijn 
AuthorDate: Sat Aug 22 15:03:06 2020 +0200

apps/rust_blinky: Add blinky app using Rust language

As explained in https://mynewt.apache.org/latest/tutorials/other/rust.html
---
 apps/rust_blinky/Cargo.toml | 27 ++
 apps/rust_blinky/cargo_build.sh | 36 +
 apps/rust_blinky/pkg.yml| 34 +++
 apps/rust_blinky/src/lib.rs | 51 +
 4 files changed, 148 insertions(+)

diff --git a/apps/rust_blinky/Cargo.toml b/apps/rust_blinky/Cargo.toml
new file mode 100644
index 000..1c583ae
--- /dev/null
+++ b/apps/rust_blinky/Cargo.toml
@@ -0,0 +1,27 @@
+#
+# Copyright 2020 Casper Meijn 
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+[package]
+name = "rust_blinky"
+version = "0.1.0"
+authors = ["Casper Meijn "]
+edition = "2018"
+
+[dependencies]
+panic-halt = "0.2.0"
+
+[lib]
+crate-type = ["staticlib"]
diff --git a/apps/rust_blinky/cargo_build.sh b/apps/rust_blinky/cargo_build.sh
new file mode 100755
index 000..2ae27a8
--- /dev/null
+++ b/apps/rust_blinky/cargo_build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+set -eu
+
+#
+# Copyright 2020 Casper Meijn 
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+if [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m0"' ]]; then
+  TARGET="thumbv6m-none-eabi"
+elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m3"' ]]; then
+  TARGET="thumbv7m-none-eabi"
+elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m4"' || ${MYNEWT_VAL_ARCH_NAME} == 
'"cortex_m7"' ]]; then
+  if [[ $MYNEWT_VAL_HARDFLOAT -eq 1 ]]; then
+TARGET="thumbv7em-none-eabihf"
+  else
+TARGET="thumbv7em-none-eabi"
+  fi
+else
+  echo "The ARCH_NAME ${MYNEWT_VAL_ARCH_NAME} is not supported"
+  exit 1
+fi
+
+cargo build --target="${TARGET}" --target-dir="${MYNEWT_PKG_BIN_DIR}"
+cp "${MYNEWT_PKG_BIN_DIR}"/${TARGET}/debug/*.a "${MYNEWT_PKG_BIN_ARCHIVE}"
diff --git a/apps/rust_blinky/pkg.yml b/apps/rust_blinky/pkg.yml
new file mode 100644
index 000..cace556
--- /dev/null
+++ b/apps/rust_blinky/pkg.yml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: "apps/rust_blinky"
+pkg.type: app
+pkg.description: "Example application which uses the Rust programming language"
+pkg.author: "Apache Mynewt "
+pkg.homepage: "http://mynewt.apache.org/;
+pkg.keywords:
+
+pkg.pre_build_cmds:
+'./cargo_build.sh': 1
+
+pkg.deps:
+- "@apache-mynewt-core/kernel/os"
+- "@apache-mynewt-core/sys/console/stub"
+- "@apache-mynewt-core/sys/log/stub"
+- "@apache-mynewt-core/sys/stats/stub"
diff --git a/apps/rust_blinky/src/lib.rs b/apps/rust_blinky/src/lib.rs
ne

[mynewt-core] 02/02: apps/rust_blinky: Use bindgen to convert C-header to Rust

2020-08-26 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 529d38f7d98b07de40b3c6c84ebe5edcb9415469
Author: Casper Meijn 
AuthorDate: Sun Aug 23 08:54:53 2020 +0200

apps/rust_blinky: Use bindgen to convert C-header to Rust

Use bindgen to generate Rust code from the actual C-header as used for
the C code. Then use the generated code in the Rust application to make
it compatible with all BSP.
---
 apps/rust_blinky/Cargo.toml  |  4 +++
 apps/rust_blinky/build.rs| 69 
 apps/rust_blinky/pkg.yml |  1 +
 apps/rust_blinky/src/bindings.rs | 23 ++
 apps/rust_blinky/src/lib.rs  | 39 ---
 apps/rust_blinky/wrapper.h   | 22 +
 6 files changed, 140 insertions(+), 18 deletions(-)

diff --git a/apps/rust_blinky/Cargo.toml b/apps/rust_blinky/Cargo.toml
index 1c583ae..6c95eae 100644
--- a/apps/rust_blinky/Cargo.toml
+++ b/apps/rust_blinky/Cargo.toml
@@ -22,6 +22,10 @@ edition = "2018"
 
 [dependencies]
 panic-halt = "0.2.0"
+cty = "0.2.1"
+
+[build-dependencies]
+bindgen = "0.54.0"
 
 [lib]
 crate-type = ["staticlib"]
diff --git a/apps/rust_blinky/build.rs b/apps/rust_blinky/build.rs
new file mode 100644
index 000..fffbcbe
--- /dev/null
+++ b/apps/rust_blinky/build.rs
@@ -0,0 +1,69 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ * Copyright 2020 Casper Meijn 
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern crate bindgen;
+
+use std::env;
+use std::path::PathBuf;
+use std::process::Command;
+use std::str;
+
+fn main() {
+let out_path = 
PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
+
+let mut builder = bindgen::Builder::default()
+.use_core()
+.derive_default(true)
+.ctypes_prefix("cty")
+.parse_callbacks(Box::new(bindgen::CargoCallbacks))
+.header("wrapper.h");
+println!("cargo:rerun-if-changed=wrapper.h");
+
+// If available, set the sysroot as mynewt would do
+if let Ok(cc_path) = env::var("MYNEWT_CC_PATH") {
+let cc_output = Command::new(cc_path)
+.arg("-print-sysroot")
+.output()
+.expect("failed to execute gcc");
+if !cc_output.status.success() {
+panic!("Error: C-compiler failed to provide sysroot");
+}
+let sysroot_path = str::from_utf8(_output.stdout).unwrap().trim();
+builder = builder.clang_arg(format!("--sysroot={}", sysroot_path));
+}
+
+// If available, set the include directories as mynewt would do
+if let Ok(include_path_list) = env::var("MYNEWT_INCLUDE_PATH") {
+for include_path in include_path_list.split(":") {
+builder = builder.clang_arg("--include-directory=".to_owned() + 
include_path);
+}
+}
+// If available, set the CFLAGS as mynewt would do
+if let Ok(cflag_list) = env::var("MYNEWT_CFLAGS") {
+for cflag in cflag_list.split(" ") {
+builder = builder.clang_arg(cflag);
+}
+}
+
+builder
+.generate()
+.map_err(|_| "Failed to generate")
+.unwrap()
+.write_to_file(out_path)
+.map_err(|e| format!("Failed to write output: {}", e))
+.unwrap();
+}
diff --git a/apps/rust_blinky/pkg.yml b/apps/rust_blinky/pkg.yml
index cace556..93f8dc4 100644
--- a/apps/rust_blinky/pkg.yml
+++ b/apps/rust_blinky/pkg.yml
@@ -29,6 +29,7 @@ pkg.pre_build_cmds:
 
 pkg.deps:
 - "@apache-mynewt-core/kernel/os"
+- "@apache-mynewt-core/hw/hal"
 - "@apache-mynewt-core/sys/console/stub"
 - "@apache-mynewt-core/sys/log/stub"
 - "@apache-mynewt-core/sys/stats/stub"
diff --git a/apps/rust_blinky/src/bindings.rs b/apps/rust_blinky/src/bindings.rs
new file mode 100644
index 000..814505e
--- /dev/null
+++ b/apps/rust_blinky/src/bindings.rs
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ * Copyright 2020 Casper Meijn 
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except

[mynewt-core] branch master updated (9609bf5 -> 529d38f)

2020-08-26 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 9609bf5  hw/mcu/dialog: Make 1V8 and 1V8P rails configurable
 new 838cee6  apps/rust_blinky: Add blinky app using Rust language
 new 529d38f  apps/rust_blinky: Use bindgen to convert C-header to Rust

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 apps/rust_blinky/Cargo.toml| 31 ++
 apps/rust_blinky/build.rs  | 69 ++
 apps/rust_blinky/cargo_build.sh| 36 +++
 apps/{flash_loader => rust_blinky}/pkg.yml | 13 ++--
 .../rust_blinky/src/bindings.rs|  8 ++-
 apps/rust_blinky/src/lib.rs| 54 +
 .../temp_nrf52.h => apps/rust_blinky/wrapper.h |  9 ++-
 7 files changed, 211 insertions(+), 9 deletions(-)
 create mode 100644 apps/rust_blinky/Cargo.toml
 create mode 100644 apps/rust_blinky/build.rs
 create mode 100755 apps/rust_blinky/cargo_build.sh
 copy apps/{flash_loader => rust_blinky}/pkg.yml (81%)
 copy hw/drivers/temp/temp_nrf52/include/temp_nrf52/temp_nrf52.h => 
apps/rust_blinky/src/bindings.rs (75%)
 create mode 100644 apps/rust_blinky/src/lib.rs
 copy hw/drivers/temp/temp_nrf52/include/temp_nrf52/temp_nrf52.h => 
apps/rust_blinky/wrapper.h (79%)



[mynewt-core] 01/02: hw/bsp/pinetime: Use spi flash for the second image

2020-08-09 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 91b54ee661d52bac09eb66bbb58ff08fb440276a
Author: Casper Meijn 
AuthorDate: Sun Aug 2 16:17:40 2020 +0200

hw/bsp/pinetime: Use spi flash for the second image

This makes it possible to double the size of the image.
To be compatible with other community firmwares the bootloader size is
increased. This causes the reboot log to shrink.
An extra SPI flash area is assigned for bootloader assets (for example
a boot logo).
The image could be increased by another 12kB, but I want to wait for
other firmwares to do that as well.
---
 hw/bsp/pinetime/boot-pinetime.ld |  2 +-
 hw/bsp/pinetime/bsp.yml  | 29 ++---
 hw/bsp/pinetime/pinetime.ld  |  2 +-
 hw/bsp/pinetime/pkg.yml  |  1 +
 hw/bsp/pinetime/src/hal_bsp.c| 21 ++---
 hw/bsp/pinetime/syscfg.yml   | 26 ++
 6 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/hw/bsp/pinetime/boot-pinetime.ld b/hw/bsp/pinetime/boot-pinetime.ld
index d1f1b99..85cd035 100644
--- a/hw/bsp/pinetime/boot-pinetime.ld
+++ b/hw/bsp/pinetime/boot-pinetime.ld
@@ -17,7 +17,7 @@
  */
 MEMORY
 {
-  FLASH (rx) : ORIGIN = 0x, LENGTH = 0x4000
+  FLASH (rx) : ORIGIN = 0x, LENGTH = 0x6000
   RAM (rwx) : ORIGIN = 0x2000, LENGTH = 0x1
 }
 
diff --git a/hw/bsp/pinetime/bsp.yml b/hw/bsp/pinetime/bsp.yml
index c89953d..ed9ccee 100644
--- a/hw/bsp/pinetime/bsp.yml
+++ b/hw/bsp/pinetime/bsp.yml
@@ -29,34 +29,41 @@ bsp.part2linkerscript: "hw/bsp/pinetime/split-pinetime.ld"
 bsp.downloadscript: "hw/bsp/pinetime/pinetime_download.sh"
 bsp.debugscript: "hw/bsp/pinetime/pinetime_debug.sh"
 
+# This flash layout is compatible with other community firmwares. It is based 
on: https://lupyuen.github.io/pinetime-rust-mynewt/articles/mcuboot
+#TODO: The image size could be increased by 12kB. This space is already 
reserved, but not yet used. This is to be compatible with other firmwares that 
use the image size of 464kB.
 bsp.flash_map:
 areas:
 # System areas.
 FLASH_AREA_BOOTLOADER:
 device: 0
 offset: 0x
-size: 16kB
+size: 24kB
 FLASH_AREA_IMAGE_0:
 device: 0
 offset: 0x8000
-size: 232kB
+size: 464kB
 FLASH_AREA_IMAGE_1:
-device: 0
-offset: 0x00042000
-size: 232kB
+device: 1
+offset: 0x0004
+size: 464kB
 FLASH_AREA_IMAGE_SCRATCH:
 device: 0
-offset: 0x0007c000
+offset: 0x0007f000
 size: 4kB
 
 # User areas.
 FLASH_AREA_REBOOT_LOG:
 user_id: 0
 device: 0
-offset: 0x4000
-size: 16kB
+offset: 0x6000
+size: 8kB
 FLASH_AREA_NFFS:
 user_id: 1
-device: 0
-offset: 0x0007d000
-size: 12kB
+device: 1
+offset: 0x000b7000
+size: 3364kB
+FLASH_AREA_BOOTLOADER_ASSETS:
+user_id: 2
+device: 1
+offset: 0x
+size: 256kB
diff --git a/hw/bsp/pinetime/pinetime.ld b/hw/bsp/pinetime/pinetime.ld
index 53baaed..b82bfcb 100644
--- a/hw/bsp/pinetime/pinetime.ld
+++ b/hw/bsp/pinetime/pinetime.ld
@@ -19,7 +19,7 @@
 
 MEMORY
 {
-  FLASH (rx) : ORIGIN = 0x8000, LENGTH = 0x3a000
+  FLASH (rx) : ORIGIN = 0x8000, LENGTH = 0x74000
   RAM (rwx) : ORIGIN = 0x2000, LENGTH = 0x1
 }
 
diff --git a/hw/bsp/pinetime/pkg.yml b/hw/bsp/pinetime/pkg.yml
index f119444..1423b61 100644
--- a/hw/bsp/pinetime/pkg.yml
+++ b/hw/bsp/pinetime/pkg.yml
@@ -35,6 +35,7 @@ pkg.deps:
 - '@apache-mynewt-core/hw/mcu/nordic/nrf52xxx'
 - '@apache-mynewt-core/kernel/os'
 - '@apache-mynewt-core/libc/baselibc'
+- "@apache-mynewt-core/hw/drivers/flash/spiflash"
 
 pkg.deps.BSP_CHARGER:
 - '@apache-mynewt-core/hw/drivers/chg_ctrl/sgm4056'
diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 0ff8c68..307282d 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -37,6 +37,9 @@
 #include "adc_nrf52/adc_nrf52.h"
 #include 
 #endif
+#if MYNEWT_VAL(SPIFLASH)
+#include 
+#endif
 
 /** What memory to include in coredump. */
 static const struct hal_bsp_mem_dump dump_cfg[] = {
@@ -53,6 +56,15 @@ hal_bsp_core_dump(int *area_cnt)
 return dump_cfg;
 }
 
+static const struct hal_flash *flash_devs[] = {
+/* MCU internal flash. */
+[0] = _flash_dev,
+#if MYNEWT_VAL(SPIFLASH)
+/* External SPI Flash. */
+[1] = _dev.hal,
+#endif
+};
+
 /**
  * Retrieves the flash device with the specif

[mynewt-core] 02/02: hw/bsp/pinetime: Use bus driver for flash and display

2020-08-09 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 9360debc22b961ca7abbdbab697c61480f8ae15d
Author: Casper Meijn 
AuthorDate: Sat Aug 8 10:48:09 2020 +0200

hw/bsp/pinetime: Use bus driver for flash and display

Use the bus driver for the SPI flash, so that the SPI display can be
operated in parallel.
---
 hw/bsp/pinetime/src/hal_bsp.c | 48 +++
 hw/bsp/pinetime/syscfg.yml|  8 
 2 files changed, 56 insertions(+)

diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 307282d..d7dcb46 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -56,6 +56,18 @@ hal_bsp_core_dump(int *area_cnt)
 return dump_cfg;
 }
 
+#if MYNEWT_VAL(SPIFLASH)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+struct bus_spi_node_cfg flash_spi_cfg = {
+.node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS),
+.pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN),
+.mode = BUS_SPI_MODE_3,
+.data_order = HAL_SPI_MSB_FIRST,
+.freq = MYNEWT_VAL(SPIFLASH_BAUDRATE),
+};
+#endif
+#endif
+
 static const struct hal_flash *flash_devs[] = {
 /* MCU internal flash. */
 [0] = _flash_dev,
@@ -169,15 +181,51 @@ hal_bsp_charger_init(void)
 }
 #endif
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static struct bus_spi_node hal_bsp_display_spi;
+struct bus_spi_node_cfg hal_bsp_display_spi_cfg = {
+.node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS),
+.pin_cs = LCD_CHIP_SELECT_PIN,
+.mode = BUS_SPI_MODE_3,
+.data_order = HAL_SPI_MSB_FIRST,
+.freq = 8000,
+};
+
+static void
+hal_bsp_display_spi_init(void)
+{
+int rc;
+
+rc = bus_spi_node_create("spidisplay", _bsp_display_spi, 
_bsp_display_spi_cfg, NULL);
+assert(rc == 0);
+}
+#endif
+
 void
 hal_bsp_init(void)
 {
+int rc;
+
+(void)rc;
+
 /* Make sure system clocks have started. */
 hal_system_clock_start();
 
 /* Create all available nRF52840 peripherals */
 nrf52_periph_create();
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+/* Create display spi node */
+hal_bsp_display_spi_init();
+
+#if MYNEWT_VAL(SPIFLASH)
+/* Create external flash dev */
+rc = spiflash_create_spi_dev(_dev.dev,
+ MYNEWT_VAL(BSP_FLASH_SPI_NAME), 
_spi_cfg);
+assert(rc == 0);
+#endif
+#endif
+
 #if MYNEWT_VAL(BSP_CHARGER)
 /* Create charge controller */
 hal_bsp_charger_init();
diff --git a/hw/bsp/pinetime/syscfg.yml b/hw/bsp/pinetime/syscfg.yml
index bcb6e8d..97edf0e 100644
--- a/hw/bsp/pinetime/syscfg.yml
+++ b/hw/bsp/pinetime/syscfg.yml
@@ -29,6 +29,14 @@ syscfg.defs:
 description: 'Setup charger driver in the BSP'
 value: 1
 
+syscfg.defs.BUS_DRIVER_PRESENT:
+BSP_FLASH_SPI_NAME:
+description: 'SPIFLASH device name'
+value: '"spiflash0"'
+BSP_FLASH_SPI_BUS:
+description: 'bus name SPIFLASH is connected to'
+value: '"spi0"'
+
 syscfg.vals.BOOT_LOADER:
 BSP_BATTERY: 0
 BSP_CHARGER: 0



[mynewt-core] branch master updated (585bc6c -> 9360deb)

2020-08-09 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


from 585bc6c  docs: sysinit and sysdown
 new 91b54ee  hw/bsp/pinetime: Use spi flash for the second image
 new 9360deb  hw/bsp/pinetime: Use bus driver for flash and display

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/pinetime/boot-pinetime.ld |  2 +-
 hw/bsp/pinetime/bsp.yml  | 29 ++---
 hw/bsp/pinetime/pinetime.ld  |  2 +-
 hw/bsp/pinetime/pkg.yml  |  1 +
 hw/bsp/pinetime/src/hal_bsp.c| 69 
 hw/bsp/pinetime/syscfg.yml   | 34 
 6 files changed, 117 insertions(+), 20 deletions(-)



[mynewt-mcumgr] branch master updated: zephyr: Add file open flags to fs_open calls

2020-07-24 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 32827ad  zephyr: Add file open flags to fs_open calls
32827ad is described below

commit 32827ad6db87042c0979c18eeef2afa7714391e5
Author: Dominik Ermel 
AuthorDate: Tue Jul 14 23:02:37 2020 +

zephyr: Add file open flags to fs_open calls

With addition of open flags to fs_open calls, all invocations that do
not provide them require change.

Signed-off-by: Dominik Ermel 
---
 cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c 
b/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
index 66af8c4..f3eb2e4 100644
--- a/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
+++ b/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
@@ -49,9 +49,9 @@ fs_mgmt_impl_read(const char *path, size_t offset, size_t len,
 ssize_t bytes_read;
 int rc;
 
-rc = fs_open(, path);
+rc = fs_open(, path, FS_O_READ);
 if (rc != 0) {
-return MGMT_ERR_EUNKNOWN;
+return MGMT_ERR_ENOENT;
 }
 
 rc = fs_seek(, offset, FS_SEEK_SET);
@@ -123,7 +123,7 @@ fs_mgmt_impl_write(const char *path, size_t offset, const 
void *data,
 }
 }
 
-rc = fs_open(, path);
+rc = fs_open(, path, FS_O_CREATE | FS_O_WRITE);
 if (rc != 0) {
 return MGMT_ERR_EUNKNOWN;
 }



[mynewt-mcumgr] branch master updated (9951119 -> 434462a)

2020-07-24 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git.


from 9951119  cmd/img_mgmt/port/zephyr: off_t print format fix
 add 434462a  cmd/img_mgmt/port/zephyr: fix logging erase_size

No new revisions were added by this update.

Summary of changes:
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)



[mynewt-mcumgr] branch master updated: cmd/img_mgmt/port/zephyr: off_t print format fix

2020-07-23 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git


The following commit(s) were added to refs/heads/master by this push:
 new 9951119  cmd/img_mgmt/port/zephyr: off_t print format fix
9951119 is described below

commit 9951119477823e8fdd6a664605426383e027174c
Author: Jordan Yates 
AuthorDate: Wed Jul 15 11:22:01 2020 +1000

cmd/img_mgmt/port/zephyr: off_t print format fix

Fix print format specifier which throws warnings when minimal libc is
not used. The base type of off_t varies depending on whether minimal
libc is used. Minimal libc defines off_t as int, while
gcc-arm-eabi-2020-q2 for example defines it as a long.

The value is explicitly cast to a long and the long format specifier
used to fix the warning.

Signed-off-by: Jordan Yates 
---
 cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c 
b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index c14727b..f41ba9a 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -333,10 +333,11 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned 
int num_bytes)
 /* align requested erase size to the erase-block-size */
 struct device *dev = flash_area_get_device(fa);
 struct flash_pages_info page;
+off_t page_offset = fa->fa_off + num_bytes - 1;
 
-rc = flash_get_page_info_by_offs(dev, fa->fa_off + num_bytes -1, );
+rc = flash_get_page_info_by_offs(dev, page_offset, );
 if (rc != 0) {
-LOG_ERR("bad offset (0x%x)", fa->fa_off + num_bytes -1);
+LOG_ERR("bad offset (0x%lx)", (long)page_offset);
 rc = MGMT_ERR_EUNKNOWN;
 goto end_fa;
 }



[mynewt-documentation] branch master updated: Add more rust target explanations

2020-07-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-documentation.git


The following commit(s) were added to refs/heads/master by this push:
 new aaa2505  Add more rust target explanations
aaa2505 is described below

commit aaa25052faa07bf108873337e56b8336d73ef3e9
Author: Fabio Utzig 
AuthorDate: Thu Jun 4 13:58:08 2020 -0300

Add more rust target explanations
---
 docs/tutorials/other/rust.rst | 33 -
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/docs/tutorials/other/rust.rst b/docs/tutorials/other/rust.rst
index 704de86..c8df081 100644
--- a/docs/tutorials/other/rust.rst
+++ b/docs/tutorials/other/rust.rst
@@ -208,17 +208,40 @@ Next we need a script for running ``cargo`` and moving 
the library to the correc
 place. Create a new file named ``apps/blinky/cargo_build.sh`` with the 
following contents:
 
 .. code-block:: bash
-:emphasize-lines: 1-5
+:emphasize-lines: 1-21
 
 #!/bin/bash
+
 set -eu
-TARGET="thumbv7m-none-eabi"
+
+if [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m0"' ]]; then
+  TARGET="thumbv6m-none-eabi"
+elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m3"' ]]; then
+  TARGET="thumbv7m-none-eabi"
+elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m4"' || 
${MYNEWT_VAL_ARCH_NAME} == '"cortex_m7"' ]]; then
+  if [[ $MYNEWT_VAL_HARDFLOAT -eq 1 ]]; then
+TARGET="thumbv7em-none-eabihf"
+  else
+TARGET="thumbv7em-none-eabi"
+  fi
+else
+  echo "The ARCH_NAME ${MYNEWT_VAL_ARCH_NAME} is not supported"
+  exit 1
+fi
+
 cargo build --target="${TARGET}" --target-dir="${MYNEWT_PKG_BIN_DIR}"
 cp "${MYNEWT_PKG_BIN_DIR}"/${TARGET}/debug/*.a "${MYNEWT_PKG_BIN_ARCHIVE}"
 
 The script first sets the name of the target as the Rust compiler knows it. 
Sadly
 this is not the same as the names mynewt uses. You need to choose the same 
type of
-compiler as mynewt uses. For nrf52 you need ``thumbv7m-none-eabi``.
+compiler as mynewt uses. The following targets are available depending on the
+MCU type:
+
+* ``thumbv6m-none-eabi`` - use this for Cortex-M0 and Cortex-M0+.
+* ``thumbv7m-none-eabi`` - use this for Cortex-M3.
+* ``thumbv7em-none-eabi`` - use this for Cortex-M4 and Cortex-M7.
+* ``thumbv7em-none-eabihf`` - use this for Cortex-M4 and Cortex-M7 with the
+  ``HARDFLOAT`` syscfg enabled.
 
 Then it runs ``cargo build`` with
 the target directory set to a path that ``newt`` provides. Lastly it copies 
the 
@@ -257,14 +280,14 @@ Now we are ready to build a firmware! Remove ``main.c`` 
and start the build:
 
 $ rm apps/blinky/src/main.c
 $ newt build nrf52_blinky
-
+
 If this command complains about a target may not be installed, then you need 
to 
 install it. You need the same toolchain as configured earlier for the 
``TARGET``
 variable:
 
 .. code-block:: console
 
-$ rustup target add thumbv7m-none-eabi
+$ rustup target add 
 
 Conclusion
 ~~



[mynewt-newt] branch master updated: Add Cflags and Include paths to pre_build_cmds environment

2020-07-19 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
 new db720bd  Add Cflags and Include paths to pre_build_cmds environment
db720bd is described below

commit db720bde8f92083cc4745495d779df4a99cf6a7e
Author: Casper Meijn 
AuthorDate: Sun Jul 5 09:11:56 2020 +0200

Add Cflags and Include paths to pre_build_cmds environment

Add the CFLAGS and INCLUDE_PATH as used by newt to the environment when
starting a pre_build_cmd. I need this to execute rust bindgen correctly.
This program will parse the mynewt headers and generate rust code from
that and therefore it needs the correct c-flags and include paths.
---
 newt/builder/buildutil.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/newt/builder/buildutil.go b/newt/builder/buildutil.go
index 1687f62..9fe2ecb 100644
--- a/newt/builder/buildutil.go
+++ b/newt/builder/buildutil.go
@@ -315,5 +315,8 @@ func (b *Builder) EnvVars(imageSlot int) 
(map[string]string, error) {
env[k] = v
}
 
+   env["MYNEWT_INCLUDE_PATH"] = strings.Join(b.compilerInfo.Includes, ":")
+   env["MYNEWT_CFLAGS"] = strings.Join(b.compilerInfo.Cflags, " ")
+
return env, nil
 }



[mynewt-documentation] branch master updated: Use the nordic_pca10040 BSP

2020-07-16 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-documentation.git


The following commit(s) were added to refs/heads/master by this push:
 new b943c9d  Use the nordic_pca10040 BSP
b943c9d is described below

commit b943c9dde576a39a762502b22cd482510cdbdc6a
Author: Mike V 
AuthorDate: Thu Jul 16 16:26:33 2020 -0700

Use the nordic_pca10040 BSP

nrf52dk is no longer the correct BSP for the nRF52 board
---
 docs/tutorials/blinky/nRF52.rst | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/tutorials/blinky/nRF52.rst b/docs/tutorials/blinky/nRF52.rst
index f8b4ce9..2356b6d 100644
--- a/docs/tutorials/blinky/nRF52.rst
+++ b/docs/tutorials/blinky/nRF52.rst
@@ -75,7 +75,7 @@ the correct bsp for the board you are using.
 
 $ newt target create nrf52_boot
 $ newt target set nrf52_boot app=@mcuboot/boot/mynewt
-$ newt target set nrf52_boot bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+$ newt target set nrf52_boot bsp=@apache-mynewt-core/hw/bsp/nordic_pca10040
 $ newt target set nrf52_boot build_profile=optimized
 
 Run the following ``newt target`` commands to create a target for the
@@ -86,7 +86,7 @@ Blinky application. We name the target ``nrf52_blinky``.
 
 $ newt target create nrf52_blinky
 $ newt target set nrf52_blinky app=apps/blinky
-$ newt target set nrf52_blinky bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+$ newt target set nrf52_blinky 
bsp=@apache-mynewt-core/hw/bsp/nordic_pca10040
 $ newt target set nrf52_blinky build_profile=debug
 
 You can run the ``newt target show`` command to verify the target
@@ -97,11 +97,11 @@ settings:
 $ newt target show
 targets/nrf52_blinky
 app=apps/blinky
-bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+bsp=@apache-mynewt-core/hw/bsp/nordic_pca10040
 build_profile=debug
 targets/nrf52_boot
 app=@mcuboot/boot/mynewt
-bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+bsp=@apache-mynewt-core/hw/bsp/nordic_pca10040
 build_profile=optimized
 
 Build the Target Executables



[mynewt-core] branch master updated: Fix I2C receive for STM32F1

2020-07-15 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new ad6786b  Fix I2C receive for STM32F1
ad6786b is described below

commit ad6786bac77c6237a26f79f0a573542c1cb97bcb
Author: J. Ipanienko 
AuthorDate: Wed Jul 15 13:13:30 2020 -0700

Fix I2C receive for STM32F1

STM32F1 needs workarounds for silicon errors.
Workaround stolen from ST HAL I2C driver.
---
 .../stm/stm32_common/src/stm32_driver_mod_i2c_v1.c | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/hw/mcu/stm/stm32_common/src/stm32_driver_mod_i2c_v1.c 
b/hw/mcu/stm/stm32_common/src/stm32_driver_mod_i2c_v1.c
index 83eee17..dcc359e 100644
--- a/hw/mcu/stm/stm32_common/src/stm32_driver_mod_i2c_v1.c
+++ b/hw/mcu/stm/stm32_common/src/stm32_driver_mod_i2c_v1.c
@@ -684,6 +684,11 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
   /* Disable Acknowledge */
   hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
 
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Disable all active IRQs around ADDR clearing and STOP programming 
because the EV6_3
+  software sequence must complete before the current byte end of transfer 
*/
+  __disable_irq();
+#endif
   /* Clear ADDR flag */
   __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
 
@@ -692,9 +697,30 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
 /* Generate Stop */
 hi2c->Instance->CR1 |= I2C_CR1_STOP;
   }
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Re-enable IRQs */
+  __enable_irq();
+#endif
 }
 else if(hi2c->XferSize == 2U)
 {
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Enable Pos */
+  hi2c->Instance->CR1 |= I2C_CR1_POS;
+
+  /* Disable all active IRQs around ADDR clearing and STOP programming 
because the EV6_3
+  software sequence must complete before the current byte end of transfer 
*/
+  __disable_irq();
+
+  /* Clear ADDR flag */
+  __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
+
+  /* Disable Acknowledge */
+  hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
+
+  /* Re-enable IRQs */
+  __enable_irq();
+#else
   /* Disable Acknowledge */
   hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
 
@@ -703,6 +729,7 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
 
   /* Clear ADDR flag */
   __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
+#endif
 }
 else
 {
@@ -747,6 +774,12 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
 return HAL_TIMEOUT;
   }
 
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Disable all active IRQs around ADDR clearing and STOP programming 
because the EV6_3
+ software sequence must complete before the current byte end of 
transfer */
+  __disable_irq();
+#endif
+
   if (LastOp)
   {
 /* Generate Stop */
@@ -758,6 +791,11 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
   hi2c->XferSize--;
   hi2c->XferCount--;
 
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Re-enable IRQs */
+  __enable_irq();
+#endif
+
   /* Read data from DR */
   (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
   hi2c->XferSize--;
@@ -775,6 +813,11 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
   /* Disable Acknowledge */
   hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
 
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Disable all active IRQs around ADDR clearing and STOP programming 
because the EV6_3
+ software sequence must complete before the current byte end of 
transfer */
+  __disable_irq();
+#endif
   /* Read data from DR */
   (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
   hi2c->XferSize--;
@@ -783,6 +826,10 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
   /* Wait until BTF flag is set */
   if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BTF, RESET, Timeout, 
tickstart) != HAL_OK)
   {
+#if MYNEWT_VAL(MCU_STM32F1)
+/* Re-enable IRQs */
+__enable_irq();
+#endif
 return HAL_TIMEOUT;
   }
 
@@ -797,6 +844,10 @@ HAL_StatusTypeDef 
HAL_I2C_Master_Receive_Custom(I2C_HandleTypeDef *hi2c,
   hi2c->XferSize--;
   hi2c->XferCount--;
 
+#if MYNEWT_VAL(MCU_STM32F1)
+  /* Re-enable IRQs */
+  __enable_irq();
+#endif
   /* Read data from DR */
   (*hi2c->pBuffPtr++) = hi2c->Instance->DR;
   hi2c->XferSize--;



[mynewt-documentation] branch master updated: nRF tutorials: fix table formatting, and syntax errors in interim examples (#99)

2020-07-05 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-documentation.git


The following commit(s) were added to refs/heads/master by this push:
 new 8a04d76  nRF tutorials: fix table formatting, and syntax errors in 
interim examples (#99)
8a04d76 is described below

commit 8a04d7649bdf534c3451ad2fdd2c914a11316839
Author: Michael Farrell 
AuthorDate: Mon Jul 6 03:38:57 2020 +1000

nRF tutorials: fix table formatting, and syntax errors in interim examples 
(#99)

* Fix table formatting and typos in interim examples for nRF

* Simplify emphasis per @caspermeijn comment
---
 docs/tutorials/ble/eddystone.rst | 83 +++-
 docs/tutorials/ble/ibeacon.rst   | 78 ++---
 2 files changed, 59 insertions(+), 102 deletions(-)

diff --git a/docs/tutorials/ble/eddystone.rst b/docs/tutorials/ble/eddystone.rst
index b362cc9..d6cc862 100644
--- a/docs/tutorials/ble/eddystone.rst
+++ b/docs/tutorials/ble/eddystone.rst
@@ -70,14 +70,15 @@ We achieve this by configuring the NimBLE host with a 
callback function
 that gets called when sync takes place:
 
 .. code-block:: console
-:emphasize-lines: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,23
+:emphasize-lines: 1-17,24
 
 static void 
 ble_app_set_addr() 
 { }
 
 static void 
-ble_app_advertise(); { }
+ble_app_advertise()
+{ }
 
 static void 
 ble_app_on_sync(void) 
@@ -138,7 +139,7 @@ identifying information, and they are expected to change 
frequently.
 assert(rc == 0);
 }
 
-static void ble_app_advertise(); 
+static void ble_app_advertise()
 { }
 
 static void ble_app_on_sync(void) 
@@ -250,55 +251,33 @@ advertising is to be done. The default values are mostly 
fine for our
 simple beaconing application. We will pass the following values to this
 function:
 
-+--+--+--+
-| Parameter| Value| Notes|
-+==+==+==+
-| own\_addr\_t | BLE\_OWN | Use the  |
-| ype  | \_ADDR\_ | nRPA we  |
-|  | RANDOM   | generate |
-|  |  | d|
-|  |  | earlier. |
-+--+--+--+
-| direct\_addr | NULL | We are   |
-|  |  | broadcas |
-|  |  | ting,|
-|  |  | not  |
-|  |  | targetin |
-|  |  | g|
-|  |  | a peer.  |
-+--+--+--+
-| duration\_ms | BLE\_HS\ | Advertis |
-|  | _FOREVER | e|
-|  |  | indefini |
-|  |  | tely.|
-+--+--+--+
-| adv\_params  | defaults | Can be   |
-|  |  | used to  |
-|  |  | specify  |
-|  |  | low  |
-|  |  | level|
-|  |  | advertis |
-|  |  | ing  |
-|  |  | paramete |
-|  |  | rs.  |
-+--+--+--+
-| cb   | NULL | We are   |
-|  |  | non-conn |
-|  |  | ectable, |
-|  |  | so no|
-|  |  | need for |
-|  |  | an event |
-|  |  | callback |
-|  |  | .|
-+--+--+--+
-| cb\_arg  | NULL | No   |
-|  |  | callback |
-|  |  | implies  |
-|  |  | no   |
-|  |  | callback |
-|  |  | argument |
-|  |  | .|
-+--+--+--+
++-+++
+| Parameter   | Value  | Notes  |
++=+++
+| own\_addr\_type | BLE\_OWN\_ADDR\_RANDOM | Use the nRPA we|
+| || generated earlier. |
++-+++
+| direct\_addr| NULL   | We are |
+| || broadcasting, not  |
+| || targeting a peer.  |
++-+++
+| duration\_ms| BLE\_HS\_FOREVER   | Advertise  |
+| || indefinitely.  |
++-+++
+| adv\_params | defaults   | Can be used to |
+| || specify low level

[mynewt-core] branch master updated: crypto: mbedtls_aes_alt: add API implementation, input validation, fix initialization and data types

2020-06-25 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new f5ad4b9  crypto: mbedtls_aes_alt: add API implementation, input 
validation, fix initialization and data types
f5ad4b9 is described below

commit f5ad4b9fe73eeeb2c65742507aa6a0c538a3288b
Author: Naveen Kaje 
AuthorDate: Fri May 22 16:48:22 2020 -0500

crypto: mbedtls_aes_alt: add API implementation, input validation, fix 
initialization and data types

1. add alt implementation mbedtls_aes_setkey_dec() to complete mbedtls 
dependency.

2. The mbedtls_cipher_update() in mbedtls invokes the ecb_func
function (via function pointer) and expects 0 when encryption
is successful. Returning the the length resutls in wrong interpretation
of the result. Fix this.

3. The mbedtls_aes_context's keylen member should be unsigned int
to be consistent with the datatype passed in, or else this results
in overflow for AES_256_KEY_LEN (32).

4. Add checks to validate input.

Signed-off-by: Naveen Kaje 
---
 hw/drivers/crypto/include/crypto/aes_alt.h |  5 ++-
 hw/drivers/crypto/src/mbedtls_aes_alt.c| 49 +-
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/hw/drivers/crypto/include/crypto/aes_alt.h 
b/hw/drivers/crypto/include/crypto/aes_alt.h
index db6cd6d..abbc4b5 100644
--- a/hw/drivers/crypto/include/crypto/aes_alt.h
+++ b/hw/drivers/crypto/include/crypto/aes_alt.h
@@ -30,11 +30,10 @@ extern "C" {
 
 #include 
 
-typedef struct mbedtls_aes_context
-{
+typedef struct mbedtls_aes_context {
 struct crypto_dev *crypto;
 uint8_t key[AES_MAX_KEY_LEN];
-uint8_t keylen;
+unsigned int keylen;
 } mbedtls_aes_context;
 
 void mbedtls_aes_init(mbedtls_aes_context *ctx);
diff --git a/hw/drivers/crypto/src/mbedtls_aes_alt.c 
b/hw/drivers/crypto/src/mbedtls_aes_alt.c
index 9bf102f..cf46d82 100644
--- a/hw/drivers/crypto/src/mbedtls_aes_alt.c
+++ b/hw/drivers/crypto/src/mbedtls_aes_alt.c
@@ -23,6 +23,7 @@
 
 #include "crypto/crypto.h"
 #include "crypto/aes_alt.h"
+#include "mbedtls/aes.h"
 
 void
 mbedtls_aes_init(mbedtls_aes_context *ctx)
@@ -40,9 +41,9 @@ mbedtls_aes_free(mbedtls_aes_context *ctx)
 memset(ctx, 0, sizeof(*ctx));
 }
 
-int
-mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
-unsigned int keybits)
+static int
+mbedtls_aes_setkey(mbedtls_aes_context *ctx, const unsigned char *key,
+   unsigned int keybits)
 {
 switch (keybits) {
 case AES_128_KEY_LEN * 8:
@@ -53,15 +54,49 @@ mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const 
unsigned char *key,
 return 0;
 }
 
-return -1;
+return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+}
+
+static int
+mbedtls_aes_validate_input(mbedtls_aes_context *ctx, const unsigned char *key,
+   unsigned int keybits)
+{
+assert(ctx);
+
+if (key == NULL) {
+return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+}
+
+return 0;
+}
+
+int
+mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
+   unsigned int keybits)
+{
+int ret = mbedtls_aes_validate_input(ctx, key, keybits);
+
+if (ret != 0) {
+return ret;
+}
+
+return mbedtls_aes_setkey(ctx, key, keybits);
+}
+
+int
+mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
+   unsigned int keybits)
+{
+return mbedtls_aes_setkey_enc(ctx, key, keybits);
 }
 
 int
 mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode,
-const unsigned char input[16], unsigned char output[16])
+  const unsigned char input[16], unsigned char output[16])
 {
-return crypto_encrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
-(const uint8_t *)input, (uint8_t *)output, AES_BLOCK_LEN);
+int ret = crypto_encrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
+ (const uint8_t *)input, (uint8_t 
*)output, AES_BLOCK_LEN);
+return (ret == AES_BLOCK_LEN) ? 0 : -1;
 }
 
 #endif /* MYNEWT_VAL(MBEDTLS_AES_ALT) */



[mynewt-core] 01/02: stm32: fix invalid uart access

2020-06-08 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit cc7241affe6d32e73ecc6aa0f237c4f2c965c958
Author: Fabio Utzig 
AuthorDate: Wed Jun 3 20:29:38 2020 -0300

stm32: fix invalid uart access

This fixes and invalid access when only UART_1, or UART_2 are enabled.

The uarts structure in memory is allocated according to the number of
uarts enabled. When only UART_2 is enabled for example, only 1 element
of uarts is enabled, but when trying to access it the index 2 was being
used. This commit adds a helper function that fixes the indexing.
---
 hw/mcu/stm/stm32_common/src/hal_uart.c | 76 +-
 1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/hw/mcu/stm/stm32_common/src/hal_uart.c 
b/hw/mcu/stm/stm32_common/src/hal_uart.c
index 06dc771..eb1ab62 100644
--- a/hw/mcu/stm/stm32_common/src/hal_uart.c
+++ b/hw/mcu/stm/stm32_common/src/hal_uart.c
@@ -38,6 +38,34 @@ struct hal_uart {
 const struct stm32_uart_cfg *u_cfg;
 };
 static struct hal_uart uarts[UART_CNT];
+static struct hal_uart *
+uart_by_port(int port)
+{
+int index;
+
+(void)index;
+(void)uarts;
+
+index = 0;
+#if MYNEWT_VAL(UART_0)
+if (port == 0) {
+return [index];
+}
+index++;
+#endif
+#if MYNEWT_VAL(UART_1)
+if (port == 1) {
+return [index];
+}
+index++;
+#endif
+#if MYNEWT_VAL(UART_2)
+if (port == 2) {
+return [index];
+}
+#endif
+return NULL;
+};
 
 struct hal_uart_irq {
 struct hal_uart *ui_uart;
@@ -86,11 +114,8 @@ hal_uart_init_cbs(int port, hal_uart_tx_char tx_func, 
hal_uart_tx_done tx_done,
 {
 struct hal_uart *u;
 
-if (port < 0 || port >= UART_CNT) {
-return -1;
-}
-u = [port];
-if (u->u_open) {
+u = uart_by_port(port);
+if (!u || u->u_open) {
 return -1;
 }
 u->u_rx_func = rx_func;
@@ -162,8 +187,8 @@ hal_uart_start_rx(int port)
 int sr;
 int rc;
 
-u = [port];
-if (u->u_rx_stall) {
+u = uart_by_port(port);
+if (u && u->u_rx_stall) {
 __HAL_DISABLE_INTERRUPTS(sr);
 rc = u->u_rx_func(u->u_func_arg, u->u_rx_data);
 if (rc == 0) {
@@ -180,12 +205,14 @@ hal_uart_start_tx(int port)
 struct hal_uart *u;
 int sr;
 
-u = [port];
-__HAL_DISABLE_INTERRUPTS(sr);
-u->u_regs->CR1 &= ~USART_CR1_TCIE;
-u->u_regs->CR1 |= USART_CR1_TXEIE;
-u->u_tx_end = 0;
-__HAL_ENABLE_INTERRUPTS(sr);
+u = uart_by_port(port);
+if (u) {
+__HAL_DISABLE_INTERRUPTS(sr);
+u->u_regs->CR1 &= ~USART_CR1_TCIE;
+u->u_regs->CR1 |= USART_CR1_TXEIE;
+u->u_tx_end = 0;
+__HAL_ENABLE_INTERRUPTS(sr);
+}
 }
 
 void
@@ -194,11 +221,8 @@ hal_uart_blocking_tx(int port, uint8_t data)
 struct hal_uart *u;
 USART_TypeDef *regs;
 
-if (port < 0 || port >= UART_CNT) {
-return;
-}
-u = [port];
-if (!u->u_open) {
+u = uart_by_port(port);
+if (!u || u->u_open) {
 return;
 }
 
@@ -360,12 +384,8 @@ hal_uart_config(int port, int32_t baudrate, uint8_t 
databits, uint8_t stopbits,
 GPIO_InitTypeDef gpio;
 #endif
 
-if (port < 0 || port >= UART_CNT) {
-return -1;
-}
-
-u = [port];
-if (u->u_open) {
+u = uart_by_port(port);
+if (!u || u->u_open) {
 return -1;
 }
 cfg = u->u_cfg;
@@ -513,10 +533,10 @@ hal_uart_init(int port, void *arg)
 {
 struct hal_uart *u;
 
-if (port < 0 || port >= UART_CNT) {
+u = uart_by_port(port);
+if (!u) {
 return -1;
 }
-u = [port];
 u->u_cfg = (const struct stm32_uart_cfg *)arg;
 
 return 0;
@@ -527,10 +547,10 @@ hal_uart_close(int port)
 {
 struct hal_uart *u;
 
-if (port < 0 || port >= UART_CNT) {
+u = uart_by_port(port);
+if (!u) {
 return -1;
 }
-u = [port];
 
 u->u_open = 0;
 u->u_regs->CR1 = 0;



[mynewt-core] 02/02: bsp: nucleo-f439zi add UART_1 pins

2020-06-08 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 046ff785bed948bbb812e0a1df79ffa219a56230
Author: Fabio Utzig 
AuthorDate: Sat Jun 6 07:19:00 2020 -0300

bsp: nucleo-f439zi add UART_1 pins

Allow use of USART_1, which uses HW USART2, located on CN9 connector.
---
 hw/bsp/nucleo-f439zi/src/hal_bsp.c | 14 ++
 hw/bsp/nucleo-f439zi/syscfg.yml|  2 ++
 2 files changed, 16 insertions(+)

diff --git a/hw/bsp/nucleo-f439zi/src/hal_bsp.c 
b/hw/bsp/nucleo-f439zi/src/hal_bsp.c
index 7ccce33..5c62516 100644
--- a/hw/bsp/nucleo-f439zi/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f439zi/src/hal_bsp.c
@@ -86,6 +86,20 @@ const struct stm32_uart_cfg os_bsp_uart0_cfg = {
 };
 #endif
 
+#if MYNEWT_VAL(UART_1)
+const struct stm32_uart_cfg os_bsp_uart1_cfg = {
+.suc_uart = USART2,
+.suc_rcc_reg = >APB1ENR,
+.suc_rcc_dev = RCC_APB1ENR_USART2EN,
+.suc_pin_tx = MYNEWT_VAL(UART_1_PIN_TX),
+.suc_pin_rx = MYNEWT_VAL(UART_1_PIN_RX),
+.suc_pin_rts = MYNEWT_VAL(UART_1_PIN_RTS),
+.suc_pin_cts = MYNEWT_VAL(UART_1_PIN_CTS),
+.suc_pin_af = GPIO_AF7_USART2,
+.suc_irqn = USART2_IRQn
+};
+#endif
+
 #if MYNEWT_VAL(ETH_0)
 const struct stm32_eth_cfg os_bsp_eth0_cfg = {
 /*
diff --git a/hw/bsp/nucleo-f439zi/syscfg.yml b/hw/bsp/nucleo-f439zi/syscfg.yml
index af88585..90b830d 100644
--- a/hw/bsp/nucleo-f439zi/syscfg.yml
+++ b/hw/bsp/nucleo-f439zi/syscfg.yml
@@ -49,6 +49,8 @@ syscfg.vals:
 STM32_DATA_CACHE_ENABLE: 1
 UART_0_PIN_TX: 'MCU_GPIO_PORTD(8)'
 UART_0_PIN_RX: 'MCU_GPIO_PORTD(9)'
+UART_1_PIN_TX: 'MCU_GPIO_PORTD(5)'
+UART_1_PIN_RX: 'MCU_GPIO_PORTD(6)'
 SPI_0_PIN_SS: 'MCU_GPIO_PORTA(4)'
 SPI_0_PIN_SCK: 'MCU_GPIO_PORTB(3)'
 SPI_0_PIN_MISO: 'MCU_GPIO_PORTB(4)'



  1   2   3   4   5   6   7   >