This is an automated email from the ASF dual-hosted git repository. ccollins 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 ec2f15a boot/split: use util/scfg for config ec2f15a is described below commit ec2f15a934092c42e90fa5c3a03533b9d3c25e52 Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Thu Feb 6 17:10:11 2020 -0800 boot/split: use util/scfg for config --- boot/split/pkg.yml | 1 + boot/split/src/split.c | 35 +++++++++++- boot/split/src/split_config.c | 126 ------------------------------------------ boot/split/src/split_priv.h | 38 ------------- 4 files changed, 34 insertions(+), 166 deletions(-) diff --git a/boot/split/pkg.yml b/boot/split/pkg.yml index ddd779a..3b10457 100644 --- a/boot/split/pkg.yml +++ b/boot/split/pkg.yml @@ -26,6 +26,7 @@ pkg.keywords: pkg.deps: - "@apache-mynewt-core/sys/config" + - "@apache-mynewt-core/util/scfg" pkg.req_apis: - bootloader diff --git a/boot/split/src/split.c b/boot/split/src/split.c index 894613e..d7b5b8d 100644 --- a/boot/split/src/split.c +++ b/boot/split/src/split.c @@ -22,8 +22,8 @@ #include "bootutil/bootutil.h" #include "bootutil/image.h" #include "config/config.h" +#include "scfg/scfg.h" #include "split/split.h" -#include "split_priv.h" #define LOADER_IMAGE_SLOT 0 #define SPLIT_IMAGE_SLOT 1 @@ -32,6 +32,19 @@ static int8_t split_mode_cur; static int8_t split_app_active; +static struct scfg_group split_scfg = { + .settings = (const struct scfg_setting[]) { + { + .name = "status", + .val = &split_mode_cur, + .type = CONF_INT8, + }, + + /* No more settings. */ + { 0 }, + }, +}; + void split_app_init(void) { @@ -40,7 +53,7 @@ split_app_init(void) /* Ensure this function only gets called by sysinit. */ SYSINIT_ASSERT_ACTIVE(); - rc = split_conf_init(); + rc = scfg_register(&split_scfg, "split"); assert(rc == 0); } @@ -101,6 +114,24 @@ split_mode_set(split_mode_t split_mode) return 0; } +int +split_write_split(split_mode_t split_mode) +{ + int rc; + + rc = split_mode_set(split_mode); + if (rc != 0) { + return rc; + } + + rc = scfg_save_val(&split_scfg, &split_mode_cur); + if (rc != 0) { + return rc; + } + + return 0; +} + /** * This validates and provides the loader image data * diff --git a/boot/split/src/split_config.c b/boot/split/src/split_config.c deleted file mode 100644 index 2bc7980..0000000 --- a/boot/split/src/split_config.c +++ /dev/null @@ -1,126 +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. - */ - - -#include <assert.h> -#include <string.h> -#include <config/config.h> -#include <split/split.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); -static int split_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt); - -static struct conf_handler split_conf_handler = { - .ch_name = "split", - .ch_get = split_conf_get, - .ch_set = split_conf_set, - .ch_commit = split_conf_commit, - .ch_export = split_conf_export -}; - -int -split_conf_init(void) -{ - int rc; - - rc = conf_register(&split_conf_handler); - - return rc; -} - - -static char * -split_conf_get(int argc, char **argv, char *buf, int max_len) -{ - split_mode_t split_mode; - - if (argc == 1) { - if (!strcmp(argv[0], "status")) { - split_mode = split_mode_get(); - return conf_str_from_value(CONF_INT8, &split_mode, buf, max_len); - } - } - return NULL; -} - -static int -split_conf_set(int argc, char **argv, char *val) -{ - split_mode_t split_mode; - int rc; - - if (argc == 1) { - if (!strcmp(argv[0], "status")) { - rc = CONF_VALUE_SET(val, CONF_INT8, split_mode); - if (rc != 0) { - return rc; - } - - rc = split_mode_set(split_mode); - if (rc != 0) { - return rc; - } - - return 0; - } - } - return -1; -} - -static int -split_conf_commit(void) -{ - return 0; -} - -static int -split_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt) -{ - split_mode_t split_mode; - char buf[4]; - - split_mode = split_mode_get(); - conf_str_from_value(CONF_INT8, &split_mode, buf, sizeof(buf)); - func("split/status", buf); - return 0; -} - -int -split_write_split(split_mode_t split_mode) -{ - char str[CONF_STR_FROM_BYTES_LEN(sizeof(split_mode_t))]; - int rc; - - rc = split_mode_set(split_mode); - if (rc != 0) { - return rc; - } - - if (!conf_str_from_value(CONF_INT8, &split_mode, str, sizeof(str))) { - return -1; - } - return conf_save_one("split/status", str); -} diff --git a/boot/split/src/split_priv.h b/boot/split/src/split_priv.h deleted file mode 100644 index d526616..0000000 --- a/boot/split/src/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 - -#include "bootutil/bootutil.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int split_conf_init(void); -int split_mgmt_register(void); -int split_read_split(split_mode_t *split); - -#ifdef __cplusplus -} -#endif - -#endif /* SPLIT_PRIV_H */ -