You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/12/21 18:50:32 UTC
incubator-mynewt-core git commit: MYNEWT-519 img_mgmt - Allow
test+confirm as 1 act
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 19f534b80 -> 4bfe5ef86
MYNEWT-519 img_mgmt - Allow test+confirm as 1 act
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4bfe5ef8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4bfe5ef8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4bfe5ef8
Branch: refs/heads/develop
Commit: 4bfe5ef867af8285737afdf082c76a02a93c36bc
Parents: 19f534b
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Dec 21 10:50:07 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Dec 21 10:50:07 2016 -0800
----------------------------------------------------------------------
encoding/base64/include/base64/hex.h | 2 +-
encoding/base64/src/hex.c | 2 +-
mgmt/imgmgr/include/imgmgr/imgmgr.h | 7 +-
mgmt/imgmgr/src/imgmgr_cli.c | 121 ++++++++++++++++++++++--------
mgmt/imgmgr/src/imgmgr_state.c | 34 ++++-----
5 files changed, 113 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4bfe5ef8/encoding/base64/include/base64/hex.h
----------------------------------------------------------------------
diff --git a/encoding/base64/include/base64/hex.h b/encoding/base64/include/base64/hex.h
index f8a8e03..8ebae77 100644
--- a/encoding/base64/include/base64/hex.h
+++ b/encoding/base64/include/base64/hex.h
@@ -24,7 +24,7 @@ extern "C" {
#endif
char *hex_format(void *src_v, int src_len, char *dst, int dst_len);
-int hex_parse(char *src, int src_len, void *dst_v, int dst_len);
+int hex_parse(const char *src, int src_len, void *dst_v, int dst_len);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4bfe5ef8/encoding/base64/src/hex.c
----------------------------------------------------------------------
diff --git a/encoding/base64/src/hex.c b/encoding/base64/src/hex.c
index f81a137..0ff3209 100644
--- a/encoding/base64/src/hex.c
+++ b/encoding/base64/src/hex.c
@@ -66,7 +66,7 @@ hex_format(void *src_v, int src_len, char *dst, int dst_len)
* @return -1 on failure; number of bytes of input
*/
int
-hex_parse(char *src, int src_len, void *dst_v, int dst_len)
+hex_parse(const char *src, int src_len, void *dst_v, int dst_len)
{
int i;
uint8_t *dst = (uint8_t *)dst_v;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4bfe5ef8/mgmt/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/include/imgmgr/imgmgr.h b/mgmt/imgmgr/include/imgmgr/imgmgr.h
index a6bed55..6494283 100644
--- a/mgmt/imgmgr/include/imgmgr/imgmgr.h
+++ b/mgmt/imgmgr/include/imgmgr/imgmgr.h
@@ -38,6 +38,10 @@ extern "C" {
#define IMGMGR_HASH_LEN 32
+#define IMGMGR_STATE_F_PENDING 0x01
+#define IMGMGR_STATE_F_CONFIRMED 0x02
+#define IMGMGR_STATE_F_ACTIVE 0x04
+
extern int boot_current_slot;
void imgmgr_module_init(void);
@@ -66,7 +70,8 @@ int imgr_my_version(struct image_version *ver);
uint8_t imgmgr_state_flags(int query_slot);
int imgmgr_state_slot_in_use(int slot);
-int imgmgr_state_test_slot(int slot);
+int imgmgr_state_set_pending(int slot, int permanent);
+int imgmgr_state_confirm(void);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4bfe5ef8/mgmt/imgmgr/src/imgmgr_cli.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_cli.c b/mgmt/imgmgr/src/imgmgr_cli.c
index fff834d..c2f3f5c 100644
--- a/mgmt/imgmgr/src/imgmgr_cli.c
+++ b/mgmt/imgmgr/src/imgmgr_cli.c
@@ -23,6 +23,7 @@
#include <string.h>
+#include <defs/error.h>
#include <flash_map/flash_map.h>
#include <hal/hal_bsp.h>
@@ -45,6 +46,43 @@ static struct shell_cmd shell_imgr_cmd = {
};
static void
+imgr_cli_too_few_args(void)
+{
+ console_printf("Too few args\n");
+}
+
+static const char *
+imgr_cli_flags_str(uint32_t image_flags, uint8_t state_flags)
+{
+ static char buf[8];
+ char *p;
+
+ memset(buf, ' ', sizeof buf);
+ p = buf;
+
+ if (state_flags & IMGMGR_STATE_F_ACTIVE) {
+ *p = 'a';
+ }
+ p++;
+ if (!(image_flags & IMAGE_F_NON_BOOTABLE)) {
+ *p = 'b';
+ }
+ p++;
+ if (state_flags & IMGMGR_STATE_F_CONFIRMED) {
+ *p = 'c';
+ }
+ p++;
+ if (state_flags & IMGMGR_STATE_F_PENDING) {
+ *p = 'p';
+ }
+ p++;
+
+ *p = '\0';
+
+ return buf;
+}
+
+static void
imgr_cli_show_slot(int slot)
{
uint8_t hash[IMGMGR_HASH_LEN]; /* SHA256 hash */
@@ -52,59 +90,71 @@ imgr_cli_show_slot(int slot)
struct image_version ver;
char ver_str[IMGMGR_NMGR_MAX_VER];
uint32_t flags;
+ uint8_t state_flags;
if (imgr_read_info(slot, &ver, hash, &flags)) {
return;
}
+ state_flags = imgmgr_state_flags(slot);
+
(void)imgr_ver_str(&ver, ver_str);
- console_printf("%8s: %s %c\n",
+ console_printf("%8s: %s %s\n",
ver_str, hex_format(hash, IMGMGR_HASH_LEN, hash_str, sizeof(hash_str)),
- flags & IMAGE_F_NON_BOOTABLE ? ' ' : 'b');
+ imgr_cli_flags_str(flags, state_flags));
}
-static void
-imgr_cli_boot_get(void)
+static int
+imgr_cli_hash_parse(const char *arg, int *out_slot)
{
- int rc;
+ uint8_t hash[IMGMGR_HASH_LEN];
+ struct image_version ver;
int slot;
+ int rc;
- /*
- * Display test image (if set)
- */
- rc = boot_vect_read_test(&slot);
- if (rc == 0) {
- imgr_cli_show_slot(slot);
- } else {
- console_printf("No test img set\n");
- return;
+ rc = hex_parse(arg, strlen(arg), hash, sizeof hash);
+ if (rc != sizeof hash) {
+ console_printf("Invalid hash: %s\n", arg);
+ return SYS_EINVAL;
}
+
+ slot = imgr_find_by_hash(hash, &ver);
+ if (slot == -1) {
+ console_printf("Unknown img\n");
+ return SYS_ENOENT;
+ }
+
+ *out_slot = slot;
+ return 0;
}
static void
-imgr_cli_boot_set(char *hash_str)
+imgr_cli_set_pending(char *hash_str, int permanent)
{
- uint8_t hash[IMGMGR_HASH_LEN];
- struct image_version ver;
int slot;
int rc;
- if (hex_parse(hash_str, strlen(hash_str), hash, sizeof(hash)) !=
- sizeof(hash)) {
- console_printf("Invalid hash %s\n", hash_str);
+ rc = imgr_cli_hash_parse(hash_str, &slot);
+ if (rc != 0) {
return;
}
- slot = imgr_find_by_hash(hash, &ver);
- if (slot == -1) {
- console_printf("Unknown img\n");
+ rc = imgmgr_state_set_pending(slot, permanent);
+ if (rc) {
+ console_printf("Error setting image to pending; rc=%d\n", rc);
return;
}
+}
- rc = imgmgr_state_test_slot(slot);
- if (rc) {
- console_printf("Error setting image to pending; rc=%d\n", rc);
+static void
+imgr_cli_confirm(void)
+{
+ int rc;
+
+ rc = imgmgr_state_confirm();
+ if (rc != 0) {
+ console_printf("Error confirming image state; rc=%d\n", rc);
return;
}
}
@@ -115,21 +165,26 @@ imgr_cli_cmd(int argc, char **argv)
int i;
if (argc < 2) {
- console_printf("Too few args\n");
+ imgr_cli_too_few_args();
return 0;
}
if (!strcmp(argv[1], "list")) {
for (i = 0; i < 2; i++) {
imgr_cli_show_slot(i);
}
- } else if (!strcmp(argv[1], "boot")) {
- if (argc > 2) {
- imgr_cli_boot_set(argv[2]);
+ } else if (!strcmp(argv[1], "test")) {
+ if (argc < 3) {
+ imgr_cli_too_few_args();
+ return 0;
+ } else {
+ imgr_cli_set_pending(argv[2], 0);
+ }
+ } else if (!strcmp(argv[1], "confirm")) {
+ if (argc < 3) {
+ imgr_cli_confirm();
} else {
- imgr_cli_boot_get();
+ imgr_cli_set_pending(argv[2], 1);
}
- } else if (!strcmp(argv[1], "ver")) {
- imgr_cli_show_slot(boot_current_slot);
} else {
console_printf("Unknown cmd\n");
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4bfe5ef8/mgmt/imgmgr/src/imgmgr_state.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_state.c b/mgmt/imgmgr/src/imgmgr_state.c
index 99bcb31..739145e 100644
--- a/mgmt/imgmgr/src/imgmgr_state.c
+++ b/mgmt/imgmgr/src/imgmgr_state.c
@@ -28,10 +28,6 @@
#include "imgmgr/imgmgr.h"
#include "imgmgr_priv.h"
-#define IMGMGR_STATE_F_PENDING 0x01
-#define IMGMGR_STATE_F_CONFIRMED 0x02
-#define IMGMGR_STATE_F_ACTIVE 0x04
-
uint8_t
imgmgr_state_flags(int query_slot)
{
@@ -133,7 +129,7 @@ imgmgr_state_slot_in_use(int slot)
}
int
-imgmgr_state_test_slot(int slot)
+imgmgr_state_set_pending(int slot, int permanent)
{
uint32_t image_flags;
uint8_t state_flags;
@@ -143,8 +139,8 @@ imgmgr_state_test_slot(int slot)
state_flags = imgmgr_state_flags(slot);
split_app_active = split_app_active_get();
- /* Unconfirmed slots are always testable. A confirmed slot can only be
- * tested if it is a loader in a split image setup.
+ /* Unconfirmed slots are always runable. A confirmed slot can only be
+ * run if it is a loader in a split image setup.
*/
if (state_flags & IMGMGR_STATE_F_CONFIRMED &&
(slot != 0 || !split_app_active)) {
@@ -161,17 +157,25 @@ imgmgr_state_test_slot(int slot)
/* Unified image or loader. */
if (!split_app_active) {
/* No change in split status. */
- rc = boot_set_pending();
+ rc = boot_set_pending(permanent);
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
}
} else {
/* Currently loader + app; testing loader-only. */
- rc = split_write_split(SPLIT_MODE_TEST_LOADER);
+ if (permanent) {
+ rc = split_write_split(SPLIT_MODE_LOADER);
+ } else {
+ rc = split_write_split(SPLIT_MODE_TEST_LOADER);
+ }
}
} else {
/* Testing split app. */
- rc = split_write_split(SPLIT_MODE_TEST_APP);
+ if (permanent) {
+ rc = split_write_split(SPLIT_MODE_APP);
+ } else {
+ rc = split_write_split(SPLIT_MODE_TEST_APP);
+ }
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
}
@@ -180,7 +184,7 @@ imgmgr_state_test_slot(int slot)
return 0;
}
-static int
+int
imgmgr_state_confirm(void)
{
int rc;
@@ -331,19 +335,15 @@ imgmgr_state_write(struct mgmt_cbuf *cb)
rc = MGMT_ERR_EINVAL;
goto err;
}
- if ((hash_len != 0) && confirm) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- if (!confirm) {
+ if (hash_len != 0) {
slot = imgr_find_by_hash(hash, NULL);
if (slot < 0) {
rc = MGMT_ERR_EINVAL;
goto err;
}
- rc = imgmgr_state_test_slot(slot);
+ rc = imgmgr_state_set_pending(slot, confirm);
if (rc != 0) {
goto err;
}