Move split_mode from boot/split to boot/bootutil. To allow the split status to be reported in the generic "image list" command, non-split-images and split-images alike need access to the current split mode. Non-split-images don't have access to the boot/split library, but they have access to bootutil.
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/bd99cef5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bd99cef5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bd99cef5 Branch: refs/heads/develop Commit: bd99cef58e523d1ba66d46d6ff2405d2a14c3732 Parents: d0d87ab Author: Christopher Collins <ccoll...@apache.org> Authored: Mon Oct 10 13:32:36 2016 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Mon Oct 10 14:11:28 2016 -0700 ---------------------------------------------------------------------- boot/bootutil/include/bootutil/bootutil_misc.h | 13 ++++++ boot/bootutil/pkg.yml | 1 + boot/bootutil/src/bootutil_misc.c | 19 +++++++++ boot/bootutil/src/loader.c | 1 - boot/split/include/split/split.h | 7 ---- boot/split/include/split/split_priv.h | 38 ----------------- boot/split/src/split.c | 14 +++---- boot/split/src/split_config.c | 46 ++++++++++++--------- boot/split/src/split_netmgr.c | 13 ++---- boot/split/src/split_priv.h | 40 ++++++++++++++++++ 10 files changed, 108 insertions(+), 84 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/bootutil/include/bootutil/bootutil_misc.h ---------------------------------------------------------------------- diff --git a/boot/bootutil/include/bootutil/bootutil_misc.h b/boot/bootutil/include/bootutil/bootutil_misc.h index 3df048e..ead86d5 100644 --- a/boot/bootutil/include/bootutil/bootutil_misc.h +++ b/boot/bootutil/include/bootutil/bootutil_misc.h @@ -20,10 +20,20 @@ #ifndef __BOOTUTIL_MISC_H_ #define __BOOTUTIL_MISC_H_ +#include <inttypes.h> + #ifdef __cplusplus extern "C" { #endif +typedef enum { + SPLIT_NONE = 0, + SPLIT_TEST, + SPLIT_RUN, +} boot_split_mode_t; + +extern int8_t boot_split_mode; + int boot_vect_read_test(int *slot); int boot_vect_read_main(int *slot); int boot_vect_write_test(int slot); @@ -31,6 +41,9 @@ int boot_vect_write_main(void); void boot_set_image_slot_split(void); +boot_split_mode_t boot_split_mode_get(void); +int boot_split_mode_set(boot_split_mode_t split_mode); + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/bootutil/pkg.yml ---------------------------------------------------------------------- diff --git a/boot/bootutil/pkg.yml b/boot/bootutil/pkg.yml index 060898e..ca9dbf7 100644 --- a/boot/bootutil/pkg.yml +++ b/boot/bootutil/pkg.yml @@ -29,4 +29,5 @@ pkg.deps: - hw/hal - crypto/mbedtls - kernel/os + - sys/defs - sys/flash_map http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/bootutil/src/bootutil_misc.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c index 8440159..9f7d055 100644 --- a/boot/bootutil/src/bootutil_misc.c +++ b/boot/bootutil/src/bootutil_misc.c @@ -23,6 +23,7 @@ #include "syscfg/syscfg.h" #include "sysflash/sysflash.h" +#include "defs/error.h" #include "hal/hal_bsp.h" #include "hal/hal_flash.h" #include "flash_map/flash_map.h" @@ -33,6 +34,7 @@ #include "bootutil_priv.h" int boot_current_slot; +int8_t boot_split_mode; /* * Read the image trailer from a given slot. @@ -330,3 +332,20 @@ boot_set_image_slot_split(void) { boot_current_slot = 1; } + +boot_split_mode_t +boot_split_mode_get(void) +{ + return boot_split_mode; +} + +int +boot_split_mode_set(boot_split_mode_t split_mode) +{ + if (split_mode < 0 || split_mode > SPLIT_RUN) { + return EINVAL; + } + + boot_split_mode = split_mode; + return 0; +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/bootutil/src/loader.c ---------------------------------------------------------------------- diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c index 8a8045c..b3bfde8 100644 --- a/boot/bootutil/src/loader.c +++ b/boot/bootutil/src/loader.c @@ -49,7 +49,6 @@ static struct boot_status boot_state; static int boot_erase_area(int area_idx, uint32_t sz); static uint32_t boot_copy_sz(int max_idx, int *cnt); - int boot_build_request(struct boot_req *preq, int area_descriptor_max) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/split/include/split/split.h ---------------------------------------------------------------------- diff --git a/boot/split/include/split/split.h b/boot/split/include/split/split.h index ede0f28..ac90ced 100644 --- a/boot/split/include/split/split.h +++ b/boot/split/include/split/split.h @@ -27,13 +27,6 @@ extern "C" { #define SPLIT_NMGR_OP_SPLIT 0 typedef enum { - SPLIT_NONE, - SPLIT_TEST, - SPLIT_RUN, -} split_mode_t; - - -typedef enum { SPLIT_INVALID, SPLIT_NOT_MATCHING, SPLIT_MATCHING, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/split/include/split/split_priv.h ---------------------------------------------------------------------- diff --git a/boot/split/include/split/split_priv.h b/boot/split/include/split/split_priv.h deleted file mode 100644 index d051587..0000000 --- a/boot/split/include/split/split_priv.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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 SPLIT_PRIV_H -#define SPLIT_PRIV_H - -#ifdef __cplusplus -extern "C" { -#endif - -int split_conf_init(void); -int split_nmgr_register(void); -int split_read_split(split_mode_t *split); -int split_write_split(split_mode_t mode); -split_status_t split_check_status(void); - -#ifdef __cplusplus -} -#endif - -#endif /* SPLIT_PRIV_H */ - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/split/src/split.c ---------------------------------------------------------------------- diff --git a/boot/split/src/split.c b/boot/split/src/split.c index 8b91256..e3ae1c6 100644 --- a/boot/split/src/split.c +++ b/boot/split/src/split.c @@ -23,7 +23,7 @@ #include "bootutil/loader.h" #include "imgmgr/imgmgr.h" #include "split/split.h" -#include "split/split_priv.h" +#include "split_priv.h" #define LOADER_IMAGE_SLOT 0 #define SPLIT_IMAGE_SLOT 1 @@ -68,23 +68,19 @@ split_check_status(void) int split_app_go(void **entry, int toboot) { - split_mode_t split; + boot_split_mode_t split_mode; int rc; if (toboot) { - /* if we can't read this, then we don't boot an app */ - rc = split_read_split(&split); - if(rc) { - return -1; - } + split_mode = boot_split_mode_get(); /* if we are told not to, then we don't boot an app */ - if (split == SPLIT_NONE) { + if (split_mode == SPLIT_NONE) { return -1; } /* if this is a one-time test, reset the split mode */ - if (split == SPLIT_TEST) { + if (split_mode == SPLIT_TEST) { split_write_split(SPLIT_NONE); } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/split/src/split_config.c ---------------------------------------------------------------------- diff --git a/boot/split/src/split_config.c b/boot/split/src/split_config.c index 57332da..a8f9cfa 100644 --- a/boot/split/src/split_config.c +++ b/boot/split/src/split_config.c @@ -3,13 +3,12 @@ #include <string.h> #include <config/config.h> #include <split/split.h> -#include <split/split_priv.h> +#include <split_priv.h> #define LOADER_IMAGE_SLOT 0 #define SPLIT_IMAGE_SLOT 1 #define SPLIT_TOTAL_IMAGES 2 - static char *split_conf_get(int argc, char **argv, char *buf, int max_len); static int split_conf_set(int argc, char **argv, char *val); static int split_conf_commit(void); @@ -17,14 +16,12 @@ static int split_conf_export(void (*func)(char *name, char *val), enum conf_expo static struct conf_handler split_conf_handler = { .ch_name = "split", - .ch_get =split_conf_get, + .ch_get = split_conf_get, .ch_set = split_conf_set, .ch_commit = split_conf_commit, .ch_export = split_conf_export }; -static int8_t split_status; - int split_conf_init(void) { @@ -39,9 +36,12 @@ split_conf_init(void) static char * split_conf_get(int argc, char **argv, char *buf, int max_len) { + boot_split_mode_t split_mode; + if (argc == 1) { if (!strcmp(argv[0], "status")) { - return conf_str_from_value(CONF_INT8, &split_status, buf, max_len); + split_mode = boot_split_mode_get(); + return conf_str_from_value(CONF_INT8, &split_mode, buf, max_len); } } return NULL; @@ -50,9 +50,18 @@ split_conf_get(int argc, char **argv, char *buf, int max_len) static int split_conf_set(int argc, char **argv, char *val) { + boot_split_mode_t split_mode; + int rc; + if (argc == 1) { if (!strcmp(argv[0], "status")) { - return CONF_VALUE_SET(val, CONF_INT8, split_status); + split_mode = boot_split_mode_get(); + rc = CONF_VALUE_SET(val, CONF_INT8, split_mode); + if (rc != 0) { + return rc; + } + + boot_split_mode_set(split_mode); } } return -1; @@ -67,29 +76,28 @@ split_conf_commit(void) static int split_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt) { + boot_split_mode_t split_mode; char buf[4]; - conf_str_from_value(CONF_INT8, &split_status, buf, sizeof(buf)); + split_mode = boot_split_mode_get(); + conf_str_from_value(CONF_INT8, &split_mode, buf, sizeof(buf)); func("split/status", buf); return 0; } int -split_read_split(split_mode_t *split) +split_write_split(boot_split_mode_t split_mode) { - *split = (split_mode_t) split_status; - return 0; -} + char str[CONF_STR_FROM_BYTES_LEN(sizeof(boot_split_mode_t))]; + int rc; -int -split_write_split(split_mode_t split) -{ - char str[CONF_STR_FROM_BYTES_LEN(sizeof(split_mode_t))]; + rc = boot_split_mode_set(split_mode); + if (rc != 0) { + return rc; + } - split_status = (int8_t) split; - if (!conf_str_from_value(CONF_INT8, &split_status, str, sizeof(str))) { + if (!conf_str_from_value(CONF_INT8, &split_mode, str, sizeof(str))) { return -1; } return conf_save_one("split/status", str); } - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/split/src/split_netmgr.c ---------------------------------------------------------------------- diff --git a/boot/split/src/split_netmgr.c b/boot/split/src/split_netmgr.c index 4ac9b4b..fa65ad7 100644 --- a/boot/split/src/split_netmgr.c +++ b/boot/split/src/split_netmgr.c @@ -22,7 +22,7 @@ #include <bootutil/bootutil_misc.h> #include <bootutil/image.h> #include <split/split.h> -#include <split/split_priv.h> +#include <split_priv.h> static int imgr_splitapp_read(struct mgmt_jbuf *njb); @@ -53,9 +53,7 @@ split_nmgr_register(void) int imgr_splitapp_read(struct mgmt_jbuf *njb) { - int rc; int x; - split_mode_t split; struct json_encoder *enc; struct json_value jv; @@ -63,12 +61,7 @@ imgr_splitapp_read(struct mgmt_jbuf *njb) json_encode_object_start(enc); - rc = split_read_split(&split); - if (!rc) { - x = split; - } else { - x = SPLIT_NONE; - } + x = boot_split_mode_get(); JSON_VALUE_INT(&jv, x) json_encode_object_entry(enc, "splitMode", &jv); @@ -127,7 +120,7 @@ imgr_splitapp_write(struct mgmt_jbuf *njb) goto err; } - rc = split_write_split((split_mode_t) split_mode); + rc = split_write_split(split_mode); if (rc) { rc = MGMT_ERR_EINVAL; goto err; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd99cef5/boot/split/src/split_priv.h ---------------------------------------------------------------------- diff --git a/boot/split/src/split_priv.h b/boot/split/src/split_priv.h new file mode 100644 index 0000000..2c9706d --- /dev/null +++ b/boot/split/src/split_priv.h @@ -0,0 +1,40 @@ +/** + * 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 SPLIT_PRIV_H +#define SPLIT_PRIV_H + +#include "bootutil/bootutil_misc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int split_conf_init(void); +int split_nmgr_register(void); +int split_read_split(boot_split_mode_t *split); +int split_write_split(boot_split_mode_t mode); +split_status_t split_check_status(void); + +#ifdef __cplusplus +} +#endif + +#endif /* SPLIT_PRIV_H */ +