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-mcumgr.git
commit 71f5c182d815d27f5300b300864394f90162d286 Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Wed Jan 17 17:15:59 2018 -0800 Mynewt support. --- cmd/fs_mgmt/pkg.yml | 27 ++++ cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c | 106 ++++++++++++ cmd/fs_mgmt/syscfg.yml | 40 +++++ cmd/img_mgmt/pkg.yml | 30 ++++ cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c | 214 +++++++++++++++++++++++++ cmd/img_mgmt/syscfg.yml | 26 +++ cmd/os_mgmt/pkg.yml | 27 ++++ cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c | 116 ++++++++++++++ cmd/os_mgmt/syscfg.yml | 26 +++ repository.yml | 25 +++ 10 files changed, 637 insertions(+) diff --git a/cmd/fs_mgmt/pkg.yml b/cmd/fs_mgmt/pkg.yml new file mode 100644 index 0000000..9452cc6 --- /dev/null +++ b/cmd/fs_mgmt/pkg.yml @@ -0,0 +1,27 @@ +# +# 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: cmd/fs_mgmt +pkg.description: 'File system command handlers for mcumgr.' +pkg.author: "Apache Mynewt <d...@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - '@apache-mynewt-core/fs/fs' diff --git a/cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c b/cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c new file mode 100644 index 0000000..632bd1e --- /dev/null +++ b/cmd/fs_mgmt/port/mynewt/src/mynewt_fs_mgmt.c @@ -0,0 +1,106 @@ +/* + * 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 "mgmt/mgmt.h" +#include "fs_mgmt/fs_mgmt_impl.h" +#include "fs/fs.h" + +int +fs_mgmt_impl_filelen(const char *path, size_t *out_len) +{ + struct fs_file *file; + int rc; + + rc = fs_open(path, FS_ACCESS_READ, &file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = fs_filelen(file, &out_len); + fs_close(file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} + +int +fs_mgmt_impl_read(const char *path, size_t offset, size_t len, + void *out_data, size_t *out_len) +{ + struct fs_file *file; + uint32_t bytes_read; + int rc; + + rc = fs_open(path, FS_ACCESS_READ, &file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = fs_seek(file, offset); + if (rc != 0) { + goto done; + } + + rc = fs_read(file, len, file_data, &bytes_read); + if (rc != 0) { + goto done; + } + + *out_len = bytes_read; + +done: + fs_close(file); + + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} + +int +fs_mgmt_impl_write(const char *path, size_t offset, const void *data, + size_t len) +{ + struct fs_file *file; + uint8_t access; + int rc; + + access = FS_ACCESS_WRITE; + if (offset == 0) { + access |= FS_ACCESS_TRUNCATE; + } else { + access |= FS_ACCESS_APPEND; + } + + rc = fs_open(path, access, &file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = fs_write(file, data, len); + fs_close(file); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} diff --git a/cmd/fs_mgmt/syscfg.yml b/cmd/fs_mgmt/syscfg.yml new file mode 100644 index 0000000..888c84a --- /dev/null +++ b/cmd/fs_mgmt/syscfg.yml @@ -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. +# + +syscfg.defs: + FS_MGMT_UL_CHUNK_SIZE: + description: > + Limits the maximum chunk size in file uploads. A buffer of this + size gets allocated on the stack during handling of a file upload + command. + value: 512 + + FS_MGMT_DL_CHUNK_SIZE: + description: > + Limits the maximum chunk size in file downloads. A buffer of this + size gets allocated on the stack during handling of a file download + command. + value: 512 + + FS_MGMT_PATH_SIZE: + description: > + Limits the maximum path length in file operations. A buffer of + this size gets allocated on the stack during handling of file + upload and download commands. + value: 64 diff --git a/cmd/img_mgmt/pkg.yml b/cmd/img_mgmt/pkg.yml new file mode 100644 index 0000000..fd27c07 --- /dev/null +++ b/cmd/img_mgmt/pkg.yml @@ -0,0 +1,30 @@ +# +# 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: cmd/img_mgmt +pkg.description: 'Image management command handlers for mcumgr.' +pkg.author: "Apache Mynewt <d...@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - '@apache-mynewt-core/boot/split' + - '@apache-mynewt-core/encoding/base64' + - '@apache-mynewt-core/sys/flash_map' + - '@mynewt-mcumgr/mgmt' diff --git a/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c new file mode 100644 index 0000000..c645d1b --- /dev/null +++ b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c @@ -0,0 +1,214 @@ +/* + * 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 "sysinit/sysinit.h" +#include "mgmt/mgmt.h" +#include "img_mgmt/img_mgmt_impl.h" +#include "img_mgmt/img_mgmt.h" +#include "img_mgmt_priv.h" + +int +img_mgmt_impl_erase_slot(void) +{ + const struct flash_area *fa; + bool empty; + int rc; + + rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = flash_area_is_empty(fa, &empty); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + if (!empty) { + rc = flash_area_erase(fa, 0, fa->fa_size); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + } + + return 0; +} + +int +img_mgmt_impl_write_pending(int slot, bool permanent) +{ + uint32_t image_flags; + uint8_t state_flags; + int split_app_active; + int rc; + + state_flags = imgmgr_state_flags(slot); + split_app_active = split_app_active_get(); + + /* 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)) { + + return MGMT_ERR_EBADSTATE; + } + + rc = imgr_read_info(slot, NULL, NULL, &image_flags); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + if (!(image_flags & IMAGE_F_NON_BOOTABLE)) { + /* Unified image or loader. */ + if (!split_app_active) { + /* No change in split status. */ + rc = boot_set_pending(permanent); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + } else { + /* Currently loader + app; testing loader-only. */ + if (permanent) { + rc = split_write_split(SPLIT_MODE_LOADER); + } else { + rc = split_write_split(SPLIT_MODE_TEST_LOADER); + } + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + } + } else { + /* Testing split 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; + } + } + + return 0; +} + +int +img_mgmt_impl_write_confirmed(void) +{ + /* Confirm the unified image or loader in slot 0. */ + rc = boot_set_confirmed(); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + /* If a split app in slot 1 is active, confirm it as well. */ + if (split_app_active_get()) { + rc = split_write_split(SPLIT_MODE_APP); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + } else { + rc = split_write_split(SPLIT_MODE_LOADER); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + } + + return 0; +} + +int +img_mgmt_impl_read(int slot, unsigned int offset, void *dst, + unsigned int num_bytes) +{ + const struct flash_area *fa; + int area_id; + int rc; + + area_id = flash_area_id_from_image_slot(image_slot); + rc = flash_area_open(area_id, &fa); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = flash_area_read(fa, offset, dst, num_bytes); + flash_area_close(fa); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} + +int +img_mgmt_impl_write_image_data(unsigned int offset, const void *data, + unsigned int num_bytes, bool last) +{ + const struct flash_area *fa; + int rc; + + rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + rc = flash_area_write(fa, offset, data, num_bytes); + flash_area_close(fa); + if (rc != 0) { + return MGMT_ERR_EUNKNOWN; + } + + return 0; +} + +int +img_mgmt_impl_swap_type(void) +{ + switch (boot_swap_type()) { + case BOOT_SWAP_TYPE_NONE: + return IMG_MGMT_SWAP_TYPE_NONE; + case BOOT_SWAP_TYPE_TEST: + return IMG_MGMT_SWAP_TYPE_TEST; + case BOOT_SWAP_TYPE_PERM: + return IMG_MGMT_SWAP_TYPE_PERM; + case BOOT_SWAP_TYPE_REVERT: + return IMG_MGMT_SWAP_TYPE_REVERT; + default: + assert(0); + return IMG_MGMT_SWAP_TYPE_NONE; + } +} + +void +img_mgmt_module_init(void) +{ + int rc; + + /* Ensure this function only gets called by sysinit. */ + SYSINIT_ASSERT_ACTIVE(); + + rc = img_mgmt_register_group(); + SYSINIT_PANIC_ASSERT(rc == 0); + +#if MYNEWT_VAL(IMGMGR_CLI) + rc = imgr_cli_register(); + SYSINIT_PANIC_ASSERT(rc == 0); +#endif +} diff --git a/cmd/img_mgmt/syscfg.yml b/cmd/img_mgmt/syscfg.yml new file mode 100644 index 0000000..ac4095f --- /dev/null +++ b/cmd/img_mgmt/syscfg.yml @@ -0,0 +1,26 @@ +# +# 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. +# + +syscfg.defs: + IMG_MGMT_UL_CHUNK_SIZE: + description: > + Limits the maximum chunk size in image uploads. A buffer of this + size gets allocated on the stack during handling of a image upload + command. + value: 512 diff --git a/cmd/os_mgmt/pkg.yml b/cmd/os_mgmt/pkg.yml new file mode 100644 index 0000000..c1389c4 --- /dev/null +++ b/cmd/os_mgmt/pkg.yml @@ -0,0 +1,27 @@ +# +# 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: cmd/os_mgmt +pkg.description: 'OS management command handlers for mcumgr.' +pkg.author: "Apache Mynewt <d...@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - '@apache-mynewt-core/kernel/os' diff --git a/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c new file mode 100644 index 0000000..ccb94f0 --- /dev/null +++ b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c @@ -0,0 +1,116 @@ +/* + * 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 "hal/hal_system.h" +#include "hal/hal_watchdog.h" +#include "os/os.h" +#if MYNEWT_VAL(LOG_SOFT_RESET) +#include "reboot/log_reboot.h" +#endif +#include "os_mgmt/os_mgmt_impl.h" + +static struct os_callout mynewt_os_mgmt_reset_callout; + +static void +mynewt_os_mgmt_reset_tmo(struct os_event *ev) +{ + /* Tickle watchdog just before re-entering bootloader. Depending on what + * the system has been doing lately, the watchdog timer might be close to + * firing. + */ + hal_watchdog_tickle(); + hal_system_reset(); +} + +static uint16_t +mynewt_os_mgmt_stack_usage(const struct os_task *task) +{ + const os_stack_t *bottom; + const os_stack_t *top; + + top = task->t_stacktop; + bottom = task->t_stacktop - task->t_stacksize; + while (bottom < top) { + if (*bottom != OS_STACK_PATTERN) { + break; + } + ++bottom; + } + + return task->t_stacktop - bottom; +} + +static const struct os_task * +mynewt_os_mgmt_task_at(int idx) +{ + const struct os_task *task; + int i; + + task = STAILQ_FIRST(&g_os_task_list); + for (i = 0; i < idx; i++) { + if (task == NULL) { + break; + } + + task = STAILQ_NEXT(task, t_os_task_list); + } + + return task; +} + +int +os_mgmt_impl_task_info(int idx, struct os_mgmt_task_info *out_info) +{ + const struct os_task *task; + + task = mynewt_os_mgmt_task_at(idx); + if (task == NULL) { + return MGMT_ERR_ENOENT; + } + + out_info->oti_prio = task->t_prio; + out_info->oti_taskid = task->t_taskid; + out_info->oti_state = task->t_state; + out_info->oti_stkusage = mynewt_os_mgmt_stack_usage(task); + out_info->oti_stksize = task->t_stacksize; + out_info->oti_cswcnt = task->t_ctx_sw_cnt; + out_info->oti_runtime = task->t_run_time; + 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); + + return 0; +} + +int +os_mgmt_impl_reset(unsigned int delay_ms) +{ + int rc; + + os_callout_init(&mynewt_os_mgmt_reset_callout, mgmt_evq_get(), + nmgr_reset_tmo, NULL); + +#if MYNEWT_VAL(LOG_SOFT_RESET) + log_reboot(HAL_RESET_REQUESTED); +#endif + os_callout_reset(&nmgr_reset_callout, delay_ms * OS_TICKS_PER_SEC / 1000); + + return 0; +} diff --git a/cmd/os_mgmt/syscfg.yml b/cmd/os_mgmt/syscfg.yml new file mode 100644 index 0000000..7ecb7c0 --- /dev/null +++ b/cmd/os_mgmt/syscfg.yml @@ -0,0 +1,26 @@ +# +# 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. +# + +syscfg.defs: + OS_MGMT_RESET_MS: + description: > + When a reset command is received, the system waits this many + milliseconds before performing the reset. This delay allows time + for the mcumgr response to be delivered. + value: 250 diff --git a/repository.yml b/repository.yml new file mode 100644 index 0000000..c2495ce --- /dev/null +++ b/repository.yml @@ -0,0 +1,25 @@ +# +# 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. +# + +repo.name: mynewt-mcumgr +repo.versions: + "0.0.0": "master" + + "0-latest": "0.0.0" + "0-dev": "0.0.0" -- To stop receiving notification emails like this one, please contact "commits@mynewt.apache.org" <commits@mynewt.apache.org>.