Fix running newtmgr when building for mcuboot
This enables mynewt to use mcuboot as a remote repository, which is only
required when using newtmgr to manage images. Since mcuboot has slightly
changed the trailer format, newtmgr built against the bundled mynewt
bootloader writes the magic and flags to the wrong location.
To build a mynewt app the wants to run with mcuboot as the bootloader
and requires newtmgr one needs to change the app's pkg.yml dependencies
as follows:
- - boot/bootutil
+ - "@mcuboot/boot/bootutil"
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/include/bootutil/sha256.h b/boot/bootutil/include/bootutil/sha256.h
index 6dd02c7..cc52b07 100644
--- a/boot/bootutil/include/bootutil/sha256.h
+++ b/boot/bootutil/include/bootutil/sha256.h
@@ -29,12 +29,8 @@
#ifndef __BOOTUTIL_CRYPTO_H_
#define __BOOTUTIL_CRYPTO_H_
-/* FIXME: The test below will only work as long as the app name is
- * "mynewt", building for mynewt could export some __linux__, __APPLE__
- * style macro!
- */
-#ifdef APP_mynewt
-#include "mynewt/config.h"
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
#endif
#if defined(MCUBOOT_USE_MBED_TLS) && defined(MCUBOOT_USE_TINYCRYPT)
diff --git a/boot/bootutil/pkg.yml b/boot/bootutil/pkg.yml
index 2ad4724..1569dea 100644
--- a/boot/bootutil/pkg.yml
+++ b/boot/bootutil/pkg.yml
@@ -25,7 +25,14 @@
- boot
- bootloader
+pkg.apis:
+ - bootloader
+
+pkg.cflags:
+ - "-DMCUBOOT_MYNEWT"
+
pkg.deps:
+ - "@mcuboot/boot/mynewt/mcuboot_config"
- "@apache-mynewt-core/hw/hal"
- "@apache-mynewt-core/crypto/mbedtls"
- "@apache-mynewt-core/kernel/os"
diff --git a/boot/bootutil/src/image_ec.c b/boot/bootutil/src/image_ec.c
index 4b47122..aa4880a 100644
--- a/boot/bootutil/src/image_ec.c
+++ b/boot/bootutil/src/image_ec.c
@@ -19,8 +19,8 @@
#include <string.h>
-#ifdef APP_mynewt
-#include "mynewt/config.h"
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
#endif
#ifdef MCUBOOT_SIGN_EC
diff --git a/boot/bootutil/src/image_ec256.c b/boot/bootutil/src/image_ec256.c
index 59cda9e..e0e4f73 100644
--- a/boot/bootutil/src/image_ec256.c
+++ b/boot/bootutil/src/image_ec256.c
@@ -19,8 +19,8 @@
#include <string.h>
-#ifdef APP_mynewt
-#include "mynewt/config.h"
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
#endif
#ifdef MCUBOOT_SIGN_EC256
diff --git a/boot/bootutil/src/image_rsa.c b/boot/bootutil/src/image_rsa.c
index aade44e..03b8624 100644
--- a/boot/bootutil/src/image_rsa.c
+++ b/boot/bootutil/src/image_rsa.c
@@ -19,8 +19,8 @@
#include <string.h>
-#ifdef APP_mynewt
-#include "mynewt/config.h"
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
#endif
#ifdef MCUBOOT_SIGN_RSA
diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c
index 2741c37..be856fd 100644
--- a/boot/bootutil/src/image_validate.c
+++ b/boot/bootutil/src/image_validate.c
@@ -28,8 +28,8 @@
#include "bootutil/sha256.h"
#include "bootutil/sign_key.h"
-#ifdef APP_mynewt
-#include "mynewt/config.h"
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
#endif
#ifdef MCUBOOT_SIGN_RSA
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index ca75a96..9de7188 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -37,8 +37,8 @@
#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
#include "bootutil/bootutil_log.h"
-#ifdef APP_mynewt
-#include "mynewt/config.h"
+#ifdef MCUBOOT_MYNEWT
+#include "mcuboot_config/mcuboot_config.h"
#endif
static struct boot_loader_state boot_data;
diff --git a/boot/mynewt/include/mynewt/config.h b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h
similarity index 91%
rename from boot/mynewt/include/mynewt/config.h
rename to boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h
index 5d282b7..416bf9e 100644
--- a/boot/mynewt/include/mynewt/config.h
+++ b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h
@@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-#ifndef __BOOT_CONFIG_H__
-#define __BOOT_CONFIG_H__
+#ifndef __MCUBOOT_CONFIG_H__
+#define __MCUBOOT_CONFIG_H__
-#include "syscfg/syscfg.h"
+#include <syscfg/syscfg.h>
#if MYNEWT_VAL(BOOT_SERIAL)
#define MCUBOOT_SERIAL 1
@@ -49,4 +49,4 @@
#define MCUBOOT_OVERWRITE_ONLY 1
#endif
-#endif /* __BOOT_CONFIG_H__ */
+#endif /* __MCUBOOT_CONFIG_H__ */
diff --git a/boot/mynewt/mcuboot_config/pkg.yml b/boot/mynewt/mcuboot_config/pkg.yml
new file mode 100644
index 0000000..33ba332
--- /dev/null
+++ b/boot/mynewt/mcuboot_config/pkg.yml
@@ -0,0 +1,23 @@
+#
+# 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: boot/mynewt/mcuboot_config
+pkg.description: "Mynewt's mcuboot configuration"
+pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
diff --git a/boot/mynewt/mcuboot_config/syscfg.yml b/boot/mynewt/mcuboot_config/syscfg.yml
new file mode 100644
index 0000000..a8087f7
--- /dev/null
+++ b/boot/mynewt/mcuboot_config/syscfg.yml
@@ -0,0 +1,45 @@
+# 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.
+#
+
+# Package: boot/mynewt/mcuboot_config
+
+syscfg.defs:
+ BOOTUTIL_VALIDATE_SLOT0:
+ description: 'Validate image at slot 0 on each boot.'
+ value: 0
+ BOOTUTIL_SIGN_RSA:
+ description: 'Images are signed using RSA2048.'
+ value: 0
+ BOOTUTIL_RSA_PKCS1_15:
+ description: 'Sign using old PKCS#1 1.5 (otherwise uses PSS)'
+ value: 0
+ BOOTUTIL_SIGN_EC:
+ description: 'Images are signed using ECDSA NIST P-224.'
+ value: 0
+ BOOTUTIL_SIGN_EC256:
+ description: 'Images are signed using ECDSA NIST P-256.'
+ value: 0
+ BOOTUTIL_USE_MBED_TLS:
+ description: 'Use mbed TLS for crypto operations.'
+ value: 1
+ BOOTUTIL_USE_TINYCRYPT:
+ description: 'Use tinycrypt for crypto operations.'
+ value: 0
+ BOOTUTIL_OVERWRITE_ONLY:
+ description: 'Non-swapping upgrades, copy from slot 1 to slot 0 only.'
+ value: 0
diff --git a/boot/mynewt/pkg.yml b/boot/mynewt/pkg.yml
index 0c55674..1d563b8 100644
--- a/boot/mynewt/pkg.yml
+++ b/boot/mynewt/pkg.yml
@@ -26,6 +26,7 @@
- loader
pkg.deps:
+ - "@mcuboot/boot/mynewt/mcuboot_config"
- "@mcuboot/boot/bootutil"
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/sys/console/stub"
diff --git a/boot/mynewt/syscfg.yml b/boot/mynewt/syscfg.yml
index a1e23cb..0ab9a14 100644
--- a/boot/mynewt/syscfg.yml
+++ b/boot/mynewt/syscfg.yml
@@ -25,30 +25,6 @@
BOOT_SERIAL:
description: 'Support image upgrade over serial within bootloader'
value: 0
- BOOTUTIL_VALIDATE_SLOT0:
- description: 'Validate image at slot 0 on each boot.'
- value: 0
- BOOTUTIL_SIGN_RSA:
- description: 'Images are signed using RSA2048.'
- value: 0
- BOOTUTIL_RSA_PKCS1_15:
- description: 'Sign using old PKCS#1 1.5 (otherwise uses PSS)'
- value: 0
- BOOTUTIL_SIGN_EC:
- description: 'Images are signed using ECDSA NIST P-224.'
- value: 0
- BOOTUTIL_SIGN_EC256:
- description: 'Images are signed using ECDSA NIST P-256.'
- value: 0
- BOOTUTIL_USE_MBED_TLS:
- description: 'Use mbed TLS for crypto operations.'
- value: 0
- BOOTUTIL_USE_TINYCRYPT:
- description: 'Use tinycrypt for crypto operations.'
- value: 0
- BOOTUTIL_OVERWRITE_ONLY:
- description: 'Non-swapping upgrades, copy from slot 1 to slot 0 only.'
- value: 0
syscfg.vals:
SYSINIT_CONSTRAIN_INIT: 0