You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/10/11 12:24:25 UTC
[1/2] incubator-mynewt-core git commit: final re-org of directories
-- removing the lib/ directory.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 8fbd28852 -> bed47f0ab
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
new file mode 100644
index 0000000..28a6ff0
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -0,0 +1,476 @@
+/**
+ * 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 <os/endian.h>
+
+#include <limits.h>
+#include <assert.h>
+#include <string.h>
+
+#include "sysinit/sysinit.h"
+#include "sysflash/sysflash.h"
+#include "hal/hal_bsp.h"
+#include "flash_map/flash_map.h"
+#include "json/json.h"
+#include "base64/base64.h"
+#include "bootutil/image.h"
+#include "bootutil/bootutil_misc.h"
+#include "mgmt/mgmt.h"
+
+#include "imgmgr/imgmgr.h"
+#include "imgmgr_priv.h"
+
+static int imgr_list2(struct mgmt_jbuf *);
+static int imgr_upload(struct mgmt_jbuf *);
+
+static const struct mgmt_handler imgr_nmgr_handlers[] = {
+ [IMGMGR_NMGR_OP_LIST] = {
+ .mh_read = NULL,
+ .mh_write = NULL
+ },
+ [IMGMGR_NMGR_OP_UPLOAD] = {
+ .mh_read = NULL,
+ .mh_write = imgr_upload
+ },
+ [IMGMGR_NMGR_OP_BOOT] = {
+ .mh_read = NULL,
+ .mh_write = NULL
+ },
+ [IMGMGR_NMGR_OP_FILE] = {
+#if MYNEWT_VAL(IMGMGR_FS)
+ .mh_read = imgr_file_download,
+ .mh_write = imgr_file_upload
+#else
+ .mh_read = NULL,
+ .mh_write = NULL
+#endif
+ },
+ [IMGMGR_NMGR_OP_LIST2] = {
+ .mh_read = imgr_list2,
+ .mh_write = NULL
+ },
+ [IMGMGR_NMGR_OP_BOOT2] = {
+ .mh_read = imgr_boot2_read,
+ .mh_write = imgr_boot2_write
+ },
+ [IMGMGR_NMGR_OP_CORELIST] = {
+#if MYNEWT_VAL(IMGMGR_COREDUMP)
+ .mh_read = imgr_core_list,
+ .mh_write = NULL
+#else
+ .mh_read = NULL,
+ .mh_write = NULL
+#endif
+ },
+ [IMGMGR_NMGR_OP_CORELOAD] = {
+#if MYNEWT_VAL(IMGMGR_COREDUMP)
+ .mh_read = imgr_core_load,
+ .mh_write = imgr_core_erase,
+#else
+ .mh_read = NULL,
+ .mh_write = NULL
+#endif
+ }
+};
+
+#define IMGR_HANDLER_CNT \
+ sizeof(imgr_nmgr_handlers) / sizeof(imgr_nmgr_handlers[0])
+
+static struct mgmt_group imgr_nmgr_group = {
+ .mg_handlers = (struct mgmt_handler *)imgr_nmgr_handlers,
+ .mg_handlers_count = IMGR_HANDLER_CNT,
+ .mg_group_id = MGMT_GROUP_ID_IMAGE,
+};
+
+struct imgr_state imgr_state;
+
+/*
+ * Read version and build hash from image located slot "image_slot". Note:
+ * this is a slot index, not a flash area ID.
+ *
+ * Returns -1 if area is not readable.
+ * Returns 0 if image in slot is ok, and version string is valid.
+ * Returns 1 if there is not a full image.
+ * Returns 2 if slot is empty. XXXX not there yet
+ */
+int
+imgr_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
+ uint32_t *flags)
+{
+ struct image_header *hdr;
+ struct image_tlv *tlv;
+ int rc = -1;
+ int rc2;
+ const struct flash_area *fa;
+ uint8_t data[sizeof(struct image_header)];
+ uint32_t data_off, data_end;
+ int area_id;
+
+ area_id = flash_area_id_from_image_slot(image_slot);
+
+ hdr = (struct image_header *)data;
+ rc2 = flash_area_open(area_id, &fa);
+ if (rc2) {
+ return -1;
+ }
+ rc2 = flash_area_read(fa, 0, hdr, sizeof(*hdr));
+ if (rc2) {
+ goto end;
+ }
+ memset(ver, 0xff, sizeof(*ver));
+ if (hdr->ih_magic == IMAGE_MAGIC) {
+ memcpy(ver, &hdr->ih_ver, sizeof(*ver));
+ } else if (hdr->ih_magic == 0xffffffff) {
+ rc = 2;
+ goto end;
+ } else {
+ rc = 1;
+ goto end;
+ }
+
+ if(flags) {
+ *flags = hdr->ih_flags;
+ }
+ /*
+ * Build ID is in a TLV after the image.
+ */
+ data_off = hdr->ih_hdr_size + hdr->ih_img_size;
+ data_end = data_off + hdr->ih_tlv_size;
+
+ if (data_end > fa->fa_size) {
+ rc = 1;
+ goto end;
+ }
+ tlv = (struct image_tlv *)data;
+ while (data_off + sizeof(*tlv) <= data_end) {
+ rc2 = flash_area_read(fa, data_off, tlv, sizeof(*tlv));
+ if (rc2) {
+ goto end;
+ }
+ if (tlv->it_type == 0xff && tlv->it_len == 0xffff) {
+ break;
+ }
+ if (tlv->it_type != IMAGE_TLV_SHA256 ||
+ tlv->it_len != IMGMGR_HASH_LEN) {
+ data_off += sizeof(*tlv) + tlv->it_len;
+ continue;
+ }
+ data_off += sizeof(*tlv);
+ if (hash) {
+ if (data_off + IMGMGR_HASH_LEN > data_end) {
+ goto end;
+ }
+ rc2 = flash_area_read(fa, data_off, hash, IMGMGR_HASH_LEN);
+ if (rc2) {
+ goto end;
+ }
+ }
+ rc = 0;
+ goto end;
+ }
+ rc = 1;
+end:
+ flash_area_close(fa);
+ return rc;
+}
+
+int
+imgr_my_version(struct image_version *ver)
+{
+ return imgr_read_info(boot_current_slot, ver, NULL, NULL);
+}
+
+/*
+ * Finds image given version number. Returns the slot number image is in,
+ * or -1 if not found.
+ */
+int
+imgr_find_by_ver(struct image_version *find, uint8_t *hash)
+{
+ int i;
+ struct image_version ver;
+
+ for (i = 0; i < 2; i++) {
+ if (imgr_read_info(i, &ver, hash, NULL) != 0) {
+ continue;
+ }
+ if (!memcmp(find, &ver, sizeof(ver))) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+/*
+ * Finds image given hash of the image. Returns the slot number image is in,
+ * or -1 if not found.
+ */
+int
+imgr_find_by_hash(uint8_t *find, struct image_version *ver)
+{
+ int i;
+ uint8_t hash[IMGMGR_HASH_LEN];
+
+ for (i = 0; i < 2; i++) {
+ if (imgr_read_info(i, ver, hash, NULL) != 0) {
+ continue;
+ }
+ if (!memcmp(hash, find, IMGMGR_HASH_LEN)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+static int
+imgr_list2(struct mgmt_jbuf *njb)
+{
+ struct json_encoder *enc;
+ int i;
+ int rc;
+ uint32_t flags;
+ struct image_version ver;
+ uint8_t hash[IMGMGR_HASH_LEN]; /* SHA256 hash */
+ struct json_value jv;
+ char vers_str[IMGMGR_NMGR_MAX_VER];
+ char hash_str[IMGMGR_HASH_STR + 1];
+ int ver_len;
+
+ enc = &njb->mjb_enc;
+
+ json_encode_object_start(enc);
+ json_encode_array_name(enc, "images");
+ json_encode_array_start(enc);
+ for (i = 0; i < 2; i++) {
+ rc = imgr_read_info(i, &ver, hash, &flags);
+ if (rc != 0) {
+ continue;
+ }
+ json_encode_object_start(enc);
+
+ JSON_VALUE_INT(&jv, i);
+ json_encode_object_entry(enc, "slot", &jv);
+
+ ver_len = imgr_ver_str(&ver, vers_str);
+ JSON_VALUE_STRINGN(&jv, vers_str, ver_len);
+ json_encode_object_entry(enc, "version", &jv);
+
+ base64_encode(hash, IMGMGR_HASH_LEN, hash_str, 1);
+ JSON_VALUE_STRING(&jv, hash_str);
+ json_encode_object_entry(enc, "hash", &jv);
+
+ JSON_VALUE_BOOL(&jv, !(flags & IMAGE_F_NON_BOOTABLE));
+ json_encode_object_entry(enc, "bootable", &jv);
+
+ json_encode_object_finish(enc);
+ }
+ json_encode_array_finish(enc);
+ json_encode_object_finish(enc);
+
+ return 0;
+}
+
+static int
+imgr_upload(struct mgmt_jbuf *njb)
+{
+ char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
+ long long unsigned int off = UINT_MAX;
+ long long unsigned int size = UINT_MAX;
+ const struct json_attr_t off_attr[4] = {
+ [0] = {
+ .attribute = "off",
+ .type = t_uinteger,
+ .addr.uinteger = &off,
+ .nodefault = true
+ },
+ [1] = {
+ .attribute = "data",
+ .type = t_string,
+ .addr.string = img_data,
+ .len = sizeof(img_data)
+ },
+ [2] = {
+ .attribute = "len",
+ .type = t_uinteger,
+ .addr.uinteger = &size,
+ .nodefault = true
+ }
+ };
+ struct image_version ver;
+ struct image_header *hdr;
+ struct json_encoder *enc;
+ struct json_value jv;
+ int area_id;
+ int active;
+ int best;
+ int rc;
+ int len;
+ int i;
+
+ rc = json_read_object(&njb->mjb_buf, off_attr);
+ if (rc || off == UINT_MAX) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+ len = strlen(img_data);
+ if (len) {
+ len = base64_decode(img_data, img_data);
+ if (len < 0) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+ }
+
+ if (off == 0) {
+ if (len < sizeof(struct image_header)) {
+ /*
+ * Image header is the first thing in the image.
+ */
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+ hdr = (struct image_header *)img_data;
+ if (hdr->ih_magic != IMAGE_MAGIC) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+
+ /*
+ * New upload.
+ */
+ imgr_state.upload.off = 0;
+ imgr_state.upload.size = size;
+ active = boot_current_slot;
+ best = -1;
+
+ for (i = 0; i < 2; i++) {
+ rc = imgr_read_info(i, &ver, NULL, NULL);
+ if (rc < 0) {
+ continue;
+ }
+ if (rc == 0) {
+ /*
+ * Image in slot is ok.
+ */
+ if (active == i) {
+ /*
+ * Slot is currently active one. Can't upload to this.
+ */
+ continue;
+ } else {
+ /*
+ * Not active slot, but image is ok. Use it if there are
+ * no better candidates.
+ */
+ best = i;
+ }
+ continue;
+ }
+ best = i;
+ break;
+ }
+ if (best >= 0) {
+ area_id = flash_area_id_from_image_slot(best);
+ if (imgr_state.upload.fa) {
+ flash_area_close(imgr_state.upload.fa);
+ imgr_state.upload.fa = NULL;
+ }
+ rc = flash_area_open(area_id, &imgr_state.upload.fa);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+ if (IMAGE_SIZE(hdr) > imgr_state.upload.fa->fa_size) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+ /*
+ * XXX only erase if needed.
+ */
+ rc = flash_area_erase(imgr_state.upload.fa, 0,
+ imgr_state.upload.fa->fa_size);
+ } else {
+ /*
+ * No slot where to upload!
+ */
+ rc = MGMT_ERR_ENOMEM;
+ goto err;
+ }
+ } else if (off != imgr_state.upload.off) {
+ /*
+ * Invalid offset. Drop the data, and respond with the offset we're
+ * expecting data for.
+ */
+ goto out;
+ }
+
+ if (!imgr_state.upload.fa) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+ if (len) {
+ rc = flash_area_write(imgr_state.upload.fa, imgr_state.upload.off,
+ img_data, len);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err_close;
+ }
+ imgr_state.upload.off += len;
+ if (imgr_state.upload.size == imgr_state.upload.off) {
+ /* Done */
+ flash_area_close(imgr_state.upload.fa);
+ imgr_state.upload.fa = NULL;
+ }
+ }
+out:
+ enc = &njb->mjb_enc;
+
+ json_encode_object_start(enc);
+
+ JSON_VALUE_INT(&jv, MGMT_ERR_EOK);
+ json_encode_object_entry(enc, "rc", &jv);
+
+ JSON_VALUE_UINT(&jv, imgr_state.upload.off);
+ json_encode_object_entry(enc, "off", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+err_close:
+ flash_area_close(imgr_state.upload.fa);
+ imgr_state.upload.fa = NULL;
+err:
+ mgmt_jbuf_setoerr(njb, rc);
+ return 0;
+}
+
+void
+imgmgr_module_init(void)
+{
+ int rc;
+
+ rc = mgmt_group_register(&imgr_nmgr_group);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+#if MYNEWT_VAL(IMGMGR_CLI)
+ rc = imgr_cli_register();
+ SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+
+ boot_vect_write_main();
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_boot.c b/mgmt/imgmgr/src/imgmgr_boot.c
new file mode 100644
index 0000000..b89ce87
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr_boot.c
@@ -0,0 +1,147 @@
+/**
+ * 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 <os/os.h>
+#include <os/endian.h>
+
+#include <limits.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <mgmt/mgmt.h>
+#include <bootutil/image.h>
+#include <bootutil/bootutil_misc.h>
+#include <json/json.h>
+#include <base64/base64.h>
+#include <hal/hal_bsp.h>
+
+#include "imgmgr/imgmgr.h"
+#include "imgmgr_priv.h"
+
+static void
+imgr_hash_jsonstr(struct json_encoder *enc, char *key, uint8_t *hash)
+{
+ struct json_value jv;
+ char hash_str[IMGMGR_HASH_STR + 1];
+
+ base64_encode(hash, IMGMGR_HASH_LEN, hash_str, 1);
+ JSON_VALUE_STRING(&jv, hash_str);
+ json_encode_object_entry(enc, key, &jv);
+}
+
+int
+imgr_boot2_read(struct mgmt_jbuf *njb)
+{
+ int rc;
+ struct json_encoder *enc;
+ struct image_version ver;
+ struct json_value jv;
+ uint8_t hash[IMGMGR_HASH_LEN];
+ int slot;
+
+ enc = &njb->mjb_enc;
+
+ json_encode_object_start(enc);
+
+ rc = boot_vect_read_test(&slot);
+ if (!rc) {
+ rc = imgr_read_info(slot, &ver, hash, NULL);
+ if (rc >= 0) {
+ imgr_hash_jsonstr(enc, "test", hash);
+ }
+ }
+
+ rc = boot_vect_read_main(&slot);
+ if (!rc) {
+ rc = imgr_read_info(slot, &ver, hash, NULL);
+ if (rc >= 0) {
+ imgr_hash_jsonstr(enc, "main", hash);
+ }
+ }
+
+ rc = imgr_read_info(boot_current_slot, &ver, hash, NULL);
+ if (!rc) {
+ imgr_hash_jsonstr(enc, "active", hash);
+ }
+
+ JSON_VALUE_INT(&jv, MGMT_ERR_EOK);
+ json_encode_object_entry(enc, "rc", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+}
+
+int
+imgr_boot2_write(struct mgmt_jbuf *njb)
+{
+ char hash_str[IMGMGR_HASH_STR + 1];
+ uint8_t hash[IMGMGR_HASH_LEN];
+ const struct json_attr_t boot_write_attr[2] = {
+ [0] = {
+ .attribute = "test",
+ .type = t_string,
+ .addr.string = hash_str,
+ .len = sizeof(hash_str),
+ },
+ [1] = {
+ .attribute = NULL
+ }
+ };
+ struct json_encoder *enc;
+ struct json_value jv;
+ int rc;
+ struct image_version ver;
+
+ rc = json_read_object(&njb->mjb_buf, boot_write_attr);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+
+ base64_decode(hash_str, hash);
+ rc = imgr_find_by_hash(hash, &ver);
+ if (rc >= 0) {
+ rc = boot_vect_write_test(rc);
+ if (rc) {
+ rc = MGMT_ERR_EUNKNOWN;
+ goto err;
+ }
+ rc = 0;
+ } else {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+
+ enc = &njb->mjb_enc;
+
+ json_encode_object_start(enc);
+
+ JSON_VALUE_INT(&jv, MGMT_ERR_EOK);
+ json_encode_object_entry(&njb->mjb_enc, "rc", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+
+err:
+ mgmt_jbuf_setoerr(njb, rc);
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr_cli.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_cli.c b/mgmt/imgmgr/src/imgmgr_cli.c
new file mode 100644
index 0000000..ebc2353
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr_cli.c
@@ -0,0 +1,141 @@
+/**
+ * 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 "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(IMGMGR_CLI)
+
+#include <string.h>
+
+#include <flash_map/flash_map.h>
+#include <hal/hal_bsp.h>
+
+#include <shell/shell.h>
+#include <console/console.h>
+
+#include <bootutil/image.h>
+#include <bootutil/bootutil_misc.h>
+
+#include <base64/hex.h>
+
+#include "imgmgr/imgmgr.h"
+#include "imgmgr_priv.h"
+
+static int imgr_cli_cmd(int argc, char **argv);
+
+static struct shell_cmd shell_imgr_cmd = {
+ .sc_cmd = "imgr",
+ .sc_cmd_func = imgr_cli_cmd
+};
+
+static void
+imgr_cli_show_slot(int slot)
+{
+ uint8_t hash[IMGMGR_HASH_LEN]; /* SHA256 hash */
+ char hash_str[IMGMGR_HASH_LEN * 2 + 1];
+ struct image_version ver;
+ char ver_str[IMGMGR_NMGR_MAX_VER];
+ uint32_t flags;
+
+ if (imgr_read_info(slot, &ver, hash, &flags)) {
+ return;
+ }
+
+ (void)imgr_ver_str(&ver, ver_str);
+
+ console_printf("%8s: %s %c\n",
+ ver_str, hex_format(hash, IMGMGR_HASH_LEN, hash_str, sizeof(hash_str)),
+ flags & IMAGE_F_NON_BOOTABLE ? ' ' : 'b');
+}
+
+static void
+imgr_cli_boot_get(void)
+{
+ int rc;
+ int slot;
+
+ /*
+ * 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;
+ }
+}
+
+static void
+imgr_cli_boot_set(char *hash_str)
+{
+ uint8_t hash[IMGMGR_HASH_LEN];
+ struct image_version ver;
+ int rc;
+
+ if (hex_parse(hash_str, strlen(hash_str), hash, sizeof(hash)) !=
+ sizeof(hash)) {
+ console_printf("Invalid hash %s\n", hash_str);
+ return;
+ }
+ rc = imgr_find_by_hash(hash, &ver);
+ if (rc < 0) {
+ console_printf("Unknown img\n");
+ return;
+ }
+ rc = boot_vect_write_test(rc);
+ if (rc) {
+ console_printf("Can't make img active\n");
+ return;
+ }
+}
+
+static int
+imgr_cli_cmd(int argc, char **argv)
+{
+ int i;
+
+ if (argc < 2) {
+ console_printf("Too few args\n");
+ 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 {
+ imgr_cli_boot_get();
+ }
+ } else if (!strcmp(argv[1], "ver")) {
+ imgr_cli_show_slot(boot_current_slot);
+ } else {
+ console_printf("Unknown cmd\n");
+ }
+ return 0;
+}
+
+int
+imgr_cli_register(void)
+{
+ return shell_cmd_register(&shell_imgr_cmd);
+}
+#endif /* MYNEWT_VAL(IMGMGR_CLI) */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_coredump.c b/mgmt/imgmgr/src/imgmgr_coredump.c
new file mode 100644
index 0000000..b9d131a
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr_coredump.c
@@ -0,0 +1,182 @@
+/**
+ * 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 "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(IMGMGR_COREDUMP)
+
+#include <limits.h>
+
+#include "sysflash/sysflash.h"
+#include "flash_map/flash_map.h"
+#include "mgmt/mgmt.h"
+#include "coredump/coredump.h"
+#include "base64/base64.h"
+
+#include "imgmgr/imgmgr.h"
+#include "imgmgr_priv.h"
+
+int
+imgr_core_list(struct mgmt_jbuf *njb)
+{
+ const struct flash_area *fa;
+ struct coredump_header hdr;
+ struct json_encoder *enc;
+ struct json_value jv;
+ int rc;
+
+ rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ } else {
+ rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
+ if (rc != 0) {
+ rc = MGMT_ERR_EINVAL;
+ } else if (hdr.ch_magic != COREDUMP_MAGIC) {
+ rc = MGMT_ERR_ENOENT;
+ } else {
+ rc = 0;
+ }
+ }
+
+ enc = &njb->mjb_enc;
+
+ json_encode_object_start(enc);
+ JSON_VALUE_INT(&jv, rc);
+ json_encode_object_entry(enc, "rc", &jv);
+ json_encode_object_finish(enc);
+
+ return 0;
+}
+
+int
+imgr_core_load(struct mgmt_jbuf *njb)
+{
+ unsigned long long off = UINT_MAX;
+ const struct json_attr_t dload_attr[2] = {
+ [0] = {
+ .attribute = "off",
+ .type = t_uinteger,
+ .addr.uinteger = &off
+ }
+ };
+ int rc;
+ int sz;
+ const struct flash_area *fa;
+ char data[IMGMGR_NMGR_MAX_MSG];
+ char encoded[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
+ struct coredump_header *hdr;
+ struct json_encoder *enc;
+ struct json_value jv;
+
+ hdr = (struct coredump_header *)data;
+
+ rc = json_read_object(&njb->mjb_buf, dload_attr);
+ if (rc || off == UINT_MAX) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+
+ rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+
+ rc = flash_area_read(fa, 0, hdr, sizeof(*hdr));
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err_close;
+ }
+ if (hdr->ch_magic != COREDUMP_MAGIC) {
+ rc = MGMT_ERR_ENOENT;
+ goto err_close;
+ }
+ if (off > hdr->ch_size) {
+ off = hdr->ch_size;
+ }
+ sz = hdr->ch_size - off;
+ if (sz > sizeof(data)) {
+ sz = sizeof(data);
+ }
+
+ rc = flash_area_read(fa, off, data, sz);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err_close;
+ }
+
+ sz = base64_encode(data, sz, encoded, 1);
+
+ enc = &njb->mjb_enc;
+
+ json_encode_object_start(enc);
+ JSON_VALUE_INT(&jv, 0);
+ json_encode_object_entry(enc, "rc", &jv);
+
+ JSON_VALUE_INT(&jv, off);
+ json_encode_object_entry(enc, "off", &jv);
+
+ JSON_VALUE_STRINGN(&jv, encoded, sz);
+ json_encode_object_entry(enc, "data", &jv);
+ json_encode_object_finish(enc);
+
+ flash_area_close(fa);
+ return 0;
+
+err_close:
+ flash_area_close(fa);
+err:
+ mgmt_jbuf_setoerr(njb, rc);
+ return 0;
+}
+
+/*
+ * Erase the area if it has a coredump, or the header is empty.
+ */
+int
+imgr_core_erase(struct mgmt_jbuf *njb)
+{
+ struct coredump_header hdr;
+ const struct flash_area *fa;
+ int rc;
+
+ rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ goto err;
+ }
+
+ rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
+ if (rc == 0 &&
+ (hdr.ch_magic == COREDUMP_MAGIC || hdr.ch_magic == 0xffffffff)) {
+ rc = flash_area_erase(fa, 0, fa->fa_size);
+ if (rc) {
+ rc = MGMT_ERR_EINVAL;
+ }
+ }
+ rc = 0;
+
+ flash_area_close(fa);
+err:
+ mgmt_jbuf_setoerr(njb, rc);
+ return 0;
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr_fs.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_fs.c b/mgmt/imgmgr/src/imgmgr_fs.c
new file mode 100644
index 0000000..d44fd55
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr_fs.c
@@ -0,0 +1,240 @@
+/**
+ * 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 "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(IMGMGR_FS)
+
+#include <limits.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "os/os.h"
+#include "os/endian.h"
+#include "newtmgr/newtmgr.h"
+#include "bootutil/image.h"
+#include "fs/fs.h"
+#include "json/json.h"
+#include "base64/base64.h"
+#include "bsp/bsp.h"
+
+#include "imgmgr/imgmgr.h"
+#include "imgmgr_priv.h"
+
+int
+imgr_file_download(struct nmgr_jbuf *njb)
+{
+ long long unsigned int off = UINT_MAX;
+ char tmp_str[IMGMGR_NMGR_MAX_NAME + 1];
+ char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
+ const struct json_attr_t dload_attr[3] = {
+ [0] = {
+ .attribute = "off",
+ .type = t_uinteger,
+ .addr.uinteger = &off
+ },
+ [1] = {
+ .attribute = "name",
+ .type = t_string,
+ .addr.string = tmp_str,
+ .len = sizeof(tmp_str)
+ }
+ };
+ int rc;
+ uint32_t out_len;
+ struct fs_file *file;
+ struct json_encoder *enc;
+ struct json_value jv;
+
+ rc = json_read_object(&njb->njb_buf, dload_attr);
+ if (rc || off == UINT_MAX) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+
+ rc = fs_open(tmp_str, FS_ACCESS_READ, &file);
+ if (rc || !file) {
+ rc = NMGR_ERR_ENOMEM;
+ goto err;
+ }
+
+ rc = fs_seek(file, off);
+ if (rc) {
+ rc = NMGR_ERR_EUNKNOWN;
+ goto err_close;
+ }
+ rc = fs_read(file, 32, tmp_str, &out_len);
+ if (rc) {
+ rc = NMGR_ERR_EUNKNOWN;
+ goto err_close;
+ }
+
+ out_len = base64_encode(tmp_str, out_len, img_data, 1);
+
+ enc = &njb->njb_enc;
+
+ json_encode_object_start(enc);
+
+ JSON_VALUE_UINT(&jv, off);
+ json_encode_object_entry(enc, "off", &jv);
+ JSON_VALUE_STRINGN(&jv, img_data, out_len);
+ json_encode_object_entry(enc, "data", &jv);
+ if (off == 0) {
+ rc = fs_filelen(file, &out_len);
+ JSON_VALUE_UINT(&jv, out_len);
+ json_encode_object_entry(enc, "len", &jv);
+ }
+ fs_close(file);
+
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(&njb->njb_enc, "rc", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+
+err_close:
+ fs_close(file);
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+ return 0;
+}
+
+int
+imgr_file_upload(struct nmgr_jbuf *njb)
+{
+ char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
+ char file_name[IMGMGR_NMGR_MAX_NAME + 1];
+ long long unsigned int off = UINT_MAX;
+ long long unsigned int size = UINT_MAX;
+ const struct json_attr_t off_attr[5] = {
+ [0] = {
+ .attribute = "off",
+ .type = t_uinteger,
+ .addr.uinteger = &off,
+ .nodefault = true
+ },
+ [1] = {
+ .attribute = "data",
+ .type = t_string,
+ .addr.string = img_data,
+ .len = sizeof(img_data)
+ },
+ [2] = {
+ .attribute = "len",
+ .type = t_uinteger,
+ .addr.uinteger = &size,
+ .nodefault = true
+ },
+ [3] = {
+ .attribute = "name",
+ .type = t_string,
+ .addr.string = file_name,
+ .len = sizeof(file_name)
+ }
+ };
+ struct json_encoder *enc;
+ struct json_value jv;
+ int rc;
+ int len;
+
+ rc = json_read_object(&njb->njb_buf, off_attr);
+ if (rc || off == UINT_MAX) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ len = strlen(img_data);
+ if (len) {
+ len = base64_decode(img_data, img_data);
+ if (len < 0) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ }
+
+ if (off == 0) {
+ /*
+ * New upload.
+ */
+ imgr_state.upload.off = 0;
+ imgr_state.upload.size = size;
+
+ if (!strlen(file_name)) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ if (imgr_state.upload.file) {
+ fs_close(imgr_state.upload.file);
+ imgr_state.upload.file = NULL;
+ }
+ rc = fs_open(file_name, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
+ &imgr_state.upload.file);
+ if (rc) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ } else if (off != imgr_state.upload.off) {
+ /*
+ * Invalid offset. Drop the data, and respond with the offset we're
+ * expecting data for.
+ */
+ goto out;
+ }
+
+ if (!imgr_state.upload.file) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ if (len) {
+ rc = fs_write(imgr_state.upload.file, img_data, len);
+ if (rc) {
+ rc = NMGR_ERR_EINVAL;
+ goto err_close;
+ }
+ imgr_state.upload.off += len;
+ if (imgr_state.upload.size == imgr_state.upload.off) {
+ /* Done */
+ fs_close(imgr_state.upload.file);
+ imgr_state.upload.file = NULL;
+ }
+ }
+out:
+ enc = &njb->njb_enc;
+
+ json_encode_object_start(enc);
+
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(&njb->njb_enc, "rc", &jv);
+
+ JSON_VALUE_UINT(&jv, imgr_state.upload.off);
+ json_encode_object_entry(enc, "off", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+
+err_close:
+ fs_close(imgr_state.upload.file);
+ imgr_state.upload.file = NULL;
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+ return 0;
+}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_priv.h b/mgmt/imgmgr/src/imgmgr_priv.h
new file mode 100644
index 0000000..bdf1449
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr_priv.h
@@ -0,0 +1,122 @@
+/**
+ * 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 __IMGMGR_PRIV_H_
+#define __IMGMGR_PRIV_H_
+
+#include <stdint.h>
+#include "syscfg/syscfg.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define IMGMGR_MAX_IMGS 2
+
+#define IMGMGR_HASH_STR 48
+
+/*
+ * When accompanied by image, it's this structure followed by data.
+ * Response contains just the offset.
+ */
+struct imgmgr_upload_cmd {
+ uint32_t iuc_off;
+};
+
+/*
+ * Response to list:
+ * {
+ * "images":[ <version1>, <version2>]
+ * }
+ *
+ *
+ * Request to boot to version:
+ * {
+ * "test":<version>
+ * }
+ *
+ *
+ * Response to boot read:
+ * {
+ * "test":<version>,
+ * "main":<version>,
+ * "active":<version>
+ * }
+ *
+ *
+ * Request to image upload:
+ * {
+ * "off":<offset>,
+ * "len":<img_size> inspected when off = 0
+ * "data":<base64encoded binary>
+ * }
+ *
+ *
+ * Response to upload:
+ * {
+ * "off":<offset>
+ * }
+ *
+ *
+ * Request to image upload:
+ * {
+ * "off":<offset>
+ * "name":<filename> inspected when off = 0
+ * "len":<file_size> inspected when off = 0
+ * "data":<base64encoded binary>
+ * }
+ */
+
+struct mgmt_jbuf;
+struct nmgr_hdr;
+struct os_mbuf;
+struct fs_file;
+
+struct imgr_state {
+ struct {
+ uint32_t off;
+ uint32_t size;
+ const struct flash_area *fa;
+#if MYNEWT_VAL(IMGMGR_FS)
+ struct fs_file *file;
+#endif
+ } upload;
+};
+
+extern struct imgr_state imgr_state;
+
+struct nmgr_jbuf;
+int imgr_boot2_read(struct mgmt_jbuf *);
+int imgr_boot2_write(struct mgmt_jbuf *);
+int imgr_file_upload(struct mgmt_jbuf *);
+int imgr_file_download(struct mgmt_jbuf *);
+int imgr_core_list(struct mgmt_jbuf *);
+int imgr_core_load(struct mgmt_jbuf *);
+int imgr_core_erase(struct mgmt_jbuf *);
+int imgr_splitapp_read(struct mgmt_jbuf *);
+int imgr_splitapp_write(struct mgmt_jbuf *);
+int imgr_find_by_ver(struct image_version *find, uint8_t *hash);
+int imgr_find_by_hash(uint8_t *find, struct image_version *ver);
+int imgr_cli_register(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __IMGMGR_PRIV_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/src/imgmgr_util.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_util.c b/mgmt/imgmgr/src/imgmgr_util.c
new file mode 100644
index 0000000..a97a627
--- /dev/null
+++ b/mgmt/imgmgr/src/imgmgr_util.c
@@ -0,0 +1,90 @@
+/**
+ * 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 <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <bootutil/image.h>
+#include <imgmgr/imgmgr.h>
+
+int
+imgr_ver_parse(char *src, struct image_version *ver)
+{
+ unsigned long ul;
+ char *tok;
+ char *nxt;
+ char *ep;
+
+ memset(ver, 0, sizeof(*ver));
+
+ nxt = src;
+ tok = strsep(&nxt, ".");
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
+ return -1;
+ }
+ ver->iv_major = ul;
+ if (nxt == NULL) {
+ return 0;
+ }
+ tok = strsep(&nxt, ".");
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
+ return -1;
+ }
+ ver->iv_minor = ul;
+ if (nxt == NULL) {
+ return 0;
+ }
+
+ tok = strsep(&nxt, ".");
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
+ return -1;
+ }
+ ver->iv_revision = ul;
+ if (nxt == NULL) {
+ return 0;
+ }
+
+ tok = nxt;
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
+ return -1;
+ }
+ ver->iv_build_num = ul;
+
+ return 0;
+}
+
+int
+imgr_ver_str(struct image_version *ver, char *dst)
+{
+ if (ver->iv_build_num) {
+ return sprintf(dst, "%u.%u.%u.%lu",
+ ver->iv_major, ver->iv_minor, ver->iv_revision,
+ (unsigned long)ver->iv_build_num);
+ } else {
+ return sprintf(dst, "%u.%u.%u",
+ ver->iv_major, ver->iv_minor, ver->iv_revision);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/syscfg.yml
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/syscfg.yml b/mgmt/imgmgr/syscfg.yml
new file mode 100644
index 0000000..eea7a06
--- /dev/null
+++ b/mgmt/imgmgr/syscfg.yml
@@ -0,0 +1,14 @@
+# Package: mgmt/imgmgr
+
+syscfg.defs:
+ IMGMGR_FS:
+ description: 'TBD'
+ value: 0
+ IMGMGR_COREDUMP:
+ description: 'TBD'
+ value: 0
+ IMGMGR_CLI:
+ description: 'TBD'
+ value: 0
+ restrictions:
+ - SHELL_TASK
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/newtmgr/nmgr_os/pkg.yml
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/pkg.yml b/mgmt/newtmgr/nmgr_os/pkg.yml
index 3de13de..2812f60 100644
--- a/mgmt/newtmgr/nmgr_os/pkg.yml
+++ b/mgmt/newtmgr/nmgr_os/pkg.yml
@@ -25,8 +25,8 @@ pkg.keywords:
pkg.deps:
- hw/hal
+ - time/datetime
- kernel/os
- encoding/json
- - libs/util
- sys/reboot
- mgmt/mgmt
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index ed9ed6b..1ce0ec3 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -28,7 +28,7 @@
#include <mgmt/mgmt.h>
#include <console/console.h>
-#include <util/datetime.h>
+#include <datetime/datetime.h>
#include <reboot/log_reboot.h>
#include "nmgr_os/nmgr_os.h"
@@ -235,7 +235,7 @@ nmgr_datetime_get(struct mgmt_jbuf *njb)
/* Display the current datetime */
rc = os_gettimeofday(&tv, &tz);
assert(rc == 0);
- rc = format_datetime(&tv, &tz, buf, DATETIME_BUFSIZE);
+ rc = datetime_format(&tv, &tz, buf, DATETIME_BUFSIZE);
if (rc) {
rc = OS_EINVAL;
goto err;
@@ -279,7 +279,7 @@ nmgr_datetime_set(struct mgmt_jbuf *njb)
}
/* Set the current datetime */
- rc = parse_datetime(buf, &tv, &tz);
+ rc = datetime_parse(buf, &tv, &tz);
if (!rc) {
rc = os_settimeofday(&tv, &tz);
if (rc) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/oicmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/pkg.yml b/mgmt/oicmgr/pkg.yml
index 06caa21..fd9dd46 100644
--- a/mgmt/oicmgr/pkg.yml
+++ b/mgmt/oicmgr/pkg.yml
@@ -28,7 +28,6 @@ pkg.deps:
- net/oic
- encoding/json
- mgmt/newtmgr/nmgr_os
- - libs/util
- test/testutil
- sys/shell
- sys/reboot
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/net/ip/inet_def_service/pkg.yml
----------------------------------------------------------------------
diff --git a/net/ip/inet_def_service/pkg.yml b/net/ip/inet_def_service/pkg.yml
index 2780694..033291c 100644
--- a/net/ip/inet_def_service/pkg.yml
+++ b/net/ip/inet_def_service/pkg.yml
@@ -29,7 +29,6 @@ pkg.keywords:
pkg.deps:
- net/ip/mn_socket
- kernel/os
- - libs/util
pkg.reqs:
- console
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/net/ip/mn_socket/pkg.yml
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/pkg.yml b/net/ip/mn_socket/pkg.yml
index ca4ee99..1bc813f 100644
--- a/net/ip/mn_socket/pkg.yml
+++ b/net/ip/mn_socket/pkg.yml
@@ -27,4 +27,3 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/util
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/net/nimble/host/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/pkg.yml b/net/nimble/host/pkg.yml
index 35099bf..9ab8ebd 100644
--- a/net/nimble/host/pkg.yml
+++ b/net/nimble/host/pkg.yml
@@ -29,7 +29,6 @@ pkg.deps:
- sys/log
- sys/stats
- kernel/os
- - libs/util
- net/nimble
pkg.deps.BLE_SM:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index d8b81eb..61a210b 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -22,7 +22,7 @@
#include <errno.h>
#include "bsp/bsp.h"
#include "os/os.h"
-#include "util/mem.h"
+#include "mem/mem.h"
#include "nimble/nimble_opt.h"
#include "host/ble_hs_adv.h"
#include "ble_hs_priv.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
index effe2c3..874ca58 100644
--- a/net/nimble/transport/ram/src/ble_hci_ram.c
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -23,7 +23,7 @@
#include "syscfg/syscfg.h"
#include "sysinit/sysinit.h"
#include "os/os.h"
-#include "util/mem.h"
+#include "mem/mem.h"
#include "nimble/ble.h"
#include "nimble/ble_hci_trans.h"
#include "transport/ram/ble_hci_ram.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/net/wifi/wifi_mgmt/pkg.yml
----------------------------------------------------------------------
diff --git a/net/wifi/wifi_mgmt/pkg.yml b/net/wifi/wifi_mgmt/pkg.yml
index 657bcd5..9ee4eba 100644
--- a/net/wifi/wifi_mgmt/pkg.yml
+++ b/net/wifi/wifi_mgmt/pkg.yml
@@ -24,6 +24,5 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- "@apache-mynewt-core/kernel/os"
- - "@apache-mynewt-core/libs/util"
pkg.deps.WIFI_MGMT_CLI:
- libs/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/config/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/config/pkg.yml b/sys/config/pkg.yml
index 8765597..9a154e0 100644
--- a/sys/config/pkg.yml
+++ b/sys/config/pkg.yml
@@ -24,7 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- - libs/util
- encoding/base64
pkg.deps.CONFIG_CLI:
- sys/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/coredump/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/coredump/pkg.yml b/sys/coredump/pkg.yml
index 5efc419..f55c368 100644
--- a/sys/coredump/pkg.yml
+++ b/sys/coredump/pkg.yml
@@ -27,5 +27,5 @@ pkg.keywords:
pkg.deps:
- hw/hal
- boot/bootutil
- - libs/imgmgr
+ - mgmt/imgmgr
- sys/flash_map
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/id/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/id/pkg.yml b/sys/id/pkg.yml
index 2f09293..c74d9b2 100644
--- a/sys/id/pkg.yml
+++ b/sys/id/pkg.yml
@@ -29,7 +29,6 @@ pkg.keywords:
pkg.deps:
- hw/hal
- kernel/os
- - libs/util
- sys/config
- encoding/base64
pkg.deps.ID_CLI:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/reboot/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/reboot/pkg.yml b/sys/reboot/pkg.yml
index 1f7849e..ca4fcbe 100644
--- a/sys/reboot/pkg.yml
+++ b/sys/reboot/pkg.yml
@@ -27,8 +27,7 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/imgmgr
- - libs/util
+ - mgmt/imgmgr
- sys/config
- sys/flash_map
- sys/log
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/shell/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/shell/pkg.yml b/sys/shell/pkg.yml
index 8f63506..02d9810 100644
--- a/sys/shell/pkg.yml
+++ b/sys/shell/pkg.yml
@@ -25,8 +25,8 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/util
- encoding/base64
+ - time/datetime
- util/crc
pkg.req_apis:
- console
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/shell/src/shell_os.c
----------------------------------------------------------------------
diff --git a/sys/shell/src/shell_os.c b/sys/shell/src/shell_os.c
index 283d429..a332f28 100644
--- a/sys/shell/src/shell_os.c
+++ b/sys/shell/src/shell_os.c
@@ -6,7 +6,7 @@
* 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,
@@ -28,9 +28,9 @@
#include <assert.h>
#include <string.h>
-#include <util/datetime.h>
+#include <datetime/datetime.h>
-int
+int
shell_os_tasks_display_cmd(int argc, char **argv)
{
struct os_task *prev_task;
@@ -64,7 +64,7 @@ shell_os_tasks_display_cmd(int argc, char **argv)
console_printf(" %s (prio: %u, tid: %u, lcheck: %lu, ncheck: %lu, "
"flags: 0x%x, ssize: %u, susage: %u, cswcnt: %lu, "
"tot_run_time: %lums)\n",
- oti.oti_name, oti.oti_prio, oti.oti_taskid,
+ oti.oti_name, oti.oti_prio, oti.oti_taskid,
(unsigned long)oti.oti_last_checkin,
(unsigned long)oti.oti_next_checkin, oti.oti_flags,
oti.oti_stksize, oti.oti_stkusage, (unsigned long)oti.oti_cswcnt,
@@ -79,7 +79,7 @@ shell_os_tasks_display_cmd(int argc, char **argv)
return (0);
}
-int
+int
shell_os_mpool_display_cmd(int argc, char **argv)
{
struct os_mempool *mp;
@@ -116,7 +116,7 @@ shell_os_mpool_display_cmd(int argc, char **argv)
}
if (name && !found) {
- console_printf("Couldn't find a memory pool with name %s\n",
+ console_printf("Couldn't find a memory pool with name %s\n",
name);
}
@@ -137,12 +137,12 @@ shell_os_date_cmd(int argc, char **argv)
/* Display the current datetime */
rc = os_gettimeofday(&tv, &tz);
assert(rc == 0);
- rc = format_datetime(&tv, &tz, buf, sizeof(buf));
+ rc = datetime_format(&tv, &tz, buf, sizeof(buf));
assert(rc == 0);
console_printf("%s\n", buf);
} else if (argc == 1) {
/* Set the current datetime */
- rc = parse_datetime(*argv, &tv, &tz);
+ rc = datetime_parse(*argv, &tv, &tz);
if (rc == 0) {
rc = os_settimeofday(&tv, &tz);
} else {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/stats/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/stats/pkg.yml b/sys/stats/pkg.yml
index 235ac91..5d122dd 100644
--- a/sys/stats/pkg.yml
+++ b/sys/stats/pkg.yml
@@ -26,7 +26,6 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/util
pkg.deps.STATS_CLI:
- sys/shell
pkg.deps.STATS_NEWTMGR:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/sys/sysinit/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/sysinit/pkg.yml b/sys/sysinit/pkg.yml
index 84cfdf9..2b1c3bc 100644
--- a/sys/sysinit/pkg.yml
+++ b/sys/sysinit/pkg.yml
@@ -26,4 +26,3 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/util
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/test/flash_test/pkg.yml
----------------------------------------------------------------------
diff --git a/test/flash_test/pkg.yml b/test/flash_test/pkg.yml
index 365705c..1e04f15 100644
--- a/test/flash_test/pkg.yml
+++ b/test/flash_test/pkg.yml
@@ -24,7 +24,6 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/util
- hw/hal
pkg.req_apis:
- console
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/time/datetime/include/datetime/datetime.h
----------------------------------------------------------------------
diff --git a/time/datetime/include/datetime/datetime.h b/time/datetime/include/datetime/datetime.h
new file mode 100644
index 0000000..ff08a9f
--- /dev/null
+++ b/time/datetime/include/datetime/datetime.h
@@ -0,0 +1,58 @@
+/**
+ * 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 __UTIL_DATETIME_H
+#define __UTIL_DATETIME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct os_timeval;
+struct os_timezone;
+
+#define DATETIME_BUFSIZE 33
+
+/*
+ * Format the time specified by 'utctime' and 'tz' as per RFC 3339 in
+ * the 'output' string. The size of the buffer pointed to by 'output'
+ * is specified by 'olen'.
+ *
+ * Returns 0 on success and non-zero on failure.
+ */
+int datetime_format(const struct os_timeval *utctime,
+ const struct os_timezone *tz, char *output, int olen);
+
+/*
+ * Parse 'input' in the Internet date/time format specified by RFC 3339.
+ * https://www.ietf.org/rfc/rfc3339.txt
+ *
+ * We deviate from the RFC in that if the 'time offset' is left unspecified
+ * then we default to UTC time.
+ *
+ * Return 0 if 'input' could be parsed successfully and non-zero otherwise.
+ * 'utctime' and 'tz' are updated if 'input' was parsed successfully.
+ */
+int datetime_parse(const char *input, struct os_timeval *utctime,
+ struct os_timezone *tz);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UTIL_DATETIME_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/time/datetime/pkg.yml
----------------------------------------------------------------------
diff --git a/time/datetime/pkg.yml b/time/datetime/pkg.yml
new file mode 100644
index 0000000..998eb0c
--- /dev/null
+++ b/time/datetime/pkg.yml
@@ -0,0 +1,29 @@
+#
+# 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: time/datetime
+pkg.description: Library containing miscellaneous utilities.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - date
+ - datetime
+
+pkg.deps:
+ - kernel/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/time/datetime/src/datetime.c
----------------------------------------------------------------------
diff --git a/time/datetime/src/datetime.c b/time/datetime/src/datetime.c
new file mode 100644
index 0000000..e7ffe68
--- /dev/null
+++ b/time/datetime/src/datetime.c
@@ -0,0 +1,429 @@
+/**
+ * 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.
+ */
+
+/*-
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1982, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: Utah $Hdr: clock.c 1.18 91/01/21$
+ * from: @(#)clock.c 8.2 (Berkeley) 1/12/94
+ * from: NetBSD: clock_subr.c,v 1.6 2001/07/07 17:04:02 thorpej Exp
+ * and
+ * from: src/sys/i386/isa/clock.c,v 1.176 2001/09/04
+ */
+
+#include <os/os_time.h>
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <datetime/datetime.h>
+
+struct clocktime {
+ int year; /* year (4 digit year) */
+ int mon; /* month (1 - 12) */
+ int day; /* day (1 - 31) */
+ int hour; /* hour (0 - 23) */
+ int min; /* minute (0 - 59) */
+ int sec; /* second (0 - 59) */
+ int dow; /* day of week (0 - 6; 0 = Sunday) */
+ int usec; /* micro seconds */
+};
+
+#define days_in_year(y) (leapyear(y) ? 366 : 365)
+
+#define FEBRUARY 2
+#define days_in_month(y, m) \
+ (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))
+
+/* Day of week. Days are counted from 1/1/1970, which was a Thursday */
+#define day_of_week(days) (((days) + 4) % 7)
+
+static const int month_days[12] = {
+ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+
+#define POSIX_BASE_YEAR 1970
+#define SECDAY (24 * 60 * 60)
+
+/*
+ * This inline avoids some unnecessary modulo operations
+ * as compared with the usual macro:
+ * ( ((year % 4) == 0 &&
+ * (year % 100) != 0) ||
+ * ((year % 400) == 0) )
+ * It is otherwise equivalent.
+ */
+static int
+leapyear(int year)
+{
+ int rv = 0;
+
+ if ((year & 3) == 0) {
+ rv = 1;
+ if ((year % 100) == 0) {
+ rv = 0;
+ if ((year % 400) == 0)
+ rv = 1;
+ }
+ }
+ return (rv);
+}
+
+static int
+clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
+{
+ int i, year, days;
+
+ year = ct->year;
+
+ /* Sanity checks. */
+ if (year < POSIX_BASE_YEAR ||
+ ct->mon < 1 || ct->mon > 12 ||
+ ct->day < 1 || ct->day > days_in_month(year, ct->mon) ||
+ ct->hour < 0 || ct->hour > 23 ||
+ ct->min < 0 || ct->min > 59 ||
+ ct->sec < 0 || ct->sec > 59 ||
+ ct->usec < 0 || ct->usec > 999999) {
+ return (-1);
+ }
+
+ /*
+ * Compute days since start of time
+ * First from years, then from months.
+ */
+ days = 0;
+ for (i = POSIX_BASE_YEAR; i < year; i++)
+ days += days_in_year(i);
+
+ /* Months */
+ for (i = 1; i < ct->mon; i++)
+ days += days_in_month(year, i);
+ days += (ct->day - 1);
+
+ tv->tv_sec = (((int64_t)days * 24 + ct->hour) * 60 + ct->min) * 60 +
+ ct->sec;
+ tv->tv_usec = ct->usec;
+
+ return (0);
+}
+
+static int
+timeval_to_clocktime(const struct os_timeval *tv, const struct os_timezone *tz,
+ struct clocktime *ct)
+{
+ int i, year, days;
+ int64_t rsec; /* remainder seconds */
+ int64_t secs;
+
+ secs = tv->tv_sec;
+ if (tz != NULL) {
+ /* Convert utctime to localtime */
+ secs -= tz->tz_minuteswest * 60;
+ secs += tz->tz_dsttime ? 3600 : 0;
+ }
+
+ if (secs < 0 || tv->tv_usec < 0 || tv->tv_usec > 999999) {
+ return (-1);
+ }
+
+ days = secs / SECDAY;
+ rsec = secs % SECDAY;
+
+ ct->dow = day_of_week(days);
+
+ /* Subtract out whole years, counting them in i. */
+ for (year = POSIX_BASE_YEAR; days >= days_in_year(year); year++)
+ days -= days_in_year(year);
+ ct->year = year;
+
+ /* Subtract out whole months, counting them in i. */
+ for (i = 1; days >= days_in_month(year, i); i++)
+ days -= days_in_month(year, i);
+ ct->mon = i;
+
+ /* Days are what is left over (+1) from all that. */
+ ct->day = days + 1;
+
+ /* Hours, minutes, seconds are easy */
+ ct->hour = rsec / 3600;
+ rsec = rsec % 3600;
+ ct->min = rsec / 60;
+ rsec = rsec % 60;
+ ct->sec = rsec;
+ ct->usec = tv->tv_usec;
+
+ return (0);
+}
+
+static const char *
+parse_number(const char *str, int digits, int *val)
+{
+ const char *cp;
+ const char *end;
+
+ *val = 0;
+ cp = str;
+ end = str + digits;
+ while (cp < end) {
+ if (!isdigit((int) *cp)) {
+ return (NULL);
+ }
+ *val *= 10;
+ *val += (*cp - '0');
+ cp++;
+ }
+ return (end);
+}
+
+/*
+ * Parse the datetime string in RFC 3339 format. Some examples of valid
+ * datetime strings are:
+ * 2016-03-02T22:44:00 UTC time (implicit)
+ * 2016-03-02T22:44:00Z UTC time (explicit)
+ * 2016-03-02T22:44:00-08:00 PST timezone
+ * 2016-03-02T22:44:00.1 fractional seconds
+ * 2016-03-02T22:44:00.101+05:30 fractional seconds with timezone
+ */
+int
+datetime_parse(const char *input, struct os_timeval *tv, struct os_timezone *tz)
+{
+ int digits, sign;
+ int off_hour, off_min;
+ const char *cp;
+ const char *ep;
+ struct clocktime ct;
+
+ bzero(&ct, sizeof(struct clocktime));
+ bzero(tv, sizeof(struct os_timeval));
+ bzero(tz, sizeof(struct os_timezone)); /* default to UTC time */
+
+ cp = input;
+ cp = parse_number(cp, 4, &ct.year);
+ if (cp == NULL || *cp != '-') {
+ goto err;
+ }
+
+ cp = parse_number(cp + 1, 2, &ct.mon);
+ if (cp == NULL || *cp != '-') {
+ goto err;
+ }
+
+ cp = parse_number(cp + 1, 2, &ct.day);
+ if (cp == NULL || *cp != 'T') {
+ goto err;
+ }
+
+ cp = parse_number(cp + 1, 2, &ct.hour);
+ if (cp == NULL || *cp != ':') {
+ goto err;
+ }
+
+ cp = parse_number(cp + 1, 2, &ct.min);
+ if (cp == NULL || *cp != ':') {
+ goto err;
+ }
+
+ cp = parse_number(cp + 1, 2, &ct.sec);
+ if (cp == NULL) {
+ goto err;
+ }
+
+ /* parse fractional seconds if specified */
+ if (*cp == '.') {
+ ep = ++cp;
+ while (isdigit((int) *ep)) {
+ ep++;
+ }
+ digits = ep - cp;
+ if (digits <= 0 || digits > 6) {
+ goto err;
+ }
+
+ cp = parse_number(cp, digits, &ct.usec);
+ if (cp == NULL) {
+ goto err;
+ }
+
+ /*
+ * The number of digits in the fractional seconds determines
+ * the resolution.
+ *
+ * .1 1 part out of 10 100000 usec
+ * .01 1 part out of 100 10000 usec
+ * .001 1 part out of 1000 1000 usec
+ * .0001 1 part out of 10000 100 usec
+ * .00001 1 part out of 100000 10 usec
+ * .000001 1 part out of 1000000 1 usec
+ */
+ while (digits++ < 6) {
+ ct.usec *= 10;
+ }
+ }
+
+ if (*cp == 'Z' || *cp == 'z') {
+ cp++;
+ } else if (*cp == '+' || *cp == '-') {
+ sign = (*cp == '+') ? +1 : -1;
+ cp = parse_number(cp + 1, 2, &off_hour);
+ if (cp == NULL || *cp != ':') {
+ goto err;
+ }
+
+ cp = parse_number(cp + 1, 2, &off_min);
+ if (cp == NULL) {
+ goto err;
+ }
+
+ if (off_hour < 0 || off_hour > 23 || off_min < 0 || off_min > 59) {
+ goto err;
+ }
+
+ /*
+ * Allow time zone offsets of up to 18 hours from the GMT.
+ * https://docs.oracle.com/javase/8/docs/api/java/time/ZoneOffset.html
+ */
+ tz->tz_minuteswest = off_hour * 60 + off_min;
+ if (tz->tz_minuteswest > 18 * 60) {
+ goto err;
+ }
+
+ /*
+ * Positive GMT offsets (i.e. timezones to the east of GMT) are
+ * represented with a negative 'tz_minuteswest' value.
+ */
+ if (sign > 0) {
+ tz->tz_minuteswest = -tz->tz_minuteswest;
+ }
+ } else {
+ /*
+ * 'time offset' is not specified so date/time defaults to UTC.
+ */
+ }
+
+ if (*cp != '\0') {
+ goto err;
+ }
+
+ if (clocktime_to_timeval(&ct, tv) != 0) {
+ goto err;
+ }
+
+ /* Convert localtime to utctime */
+ tv->tv_sec += tz->tz_minuteswest * 60;
+ tv->tv_sec -= tz->tz_dsttime ? 3600 : 0;
+ return (0);
+err:
+ return (-1);
+}
+
+int
+datetime_format(const struct os_timeval *tv, const struct os_timezone *tz,
+ char *ostr, int olen)
+{
+ char *cp;
+ int rc, rlen, minswest;
+ int off_hour, off_min, sign;
+ struct clocktime ct;
+
+ rc = timeval_to_clocktime(tv, tz, &ct);
+ if (rc != 0) {
+ goto err;
+ }
+
+ cp = ostr;
+ rlen = olen;
+
+ rc = snprintf(cp, rlen, "%04d-%02d-%02dT%02d:%02d:%02d",
+ ct.year, ct.mon, ct.day, ct.hour, ct.min, ct.sec);
+ cp += rc;
+ rlen -= rc;
+ if (rc < 0 || rlen <= 0) {
+ goto err;
+ }
+
+ if (ct.usec != 0) {
+ rc = snprintf(cp, rlen, ".%06d", ct.usec);
+ cp += rc;
+ rlen -= rc;
+ if (rc < 0 || rlen <= 0) {
+ goto err;
+ }
+ }
+
+ if (tz != NULL) {
+ minswest = tz->tz_minuteswest;
+ if (tz->tz_dsttime) {
+ minswest -= 60;
+ }
+ } else {
+ minswest = 0;
+ }
+
+ if (minswest < 0) {
+ sign = '+';
+ minswest = -minswest;
+ } else {
+ sign = '-';
+ }
+
+ off_hour = minswest / 60;
+ off_min = minswest % 60;
+ if (off_hour || off_min) {
+ rc = snprintf(cp, rlen, "%c%02d:%02d", sign, off_hour, off_min);
+ cp += rc;
+ rlen -= rc;
+ if (rc < 0 || rlen <= 0) {
+ goto err;
+ }
+ }
+ return (0);
+
+err:
+ return (-1);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/util/mem/include/mem/mem.h
----------------------------------------------------------------------
diff --git a/util/mem/include/mem/mem.h b/util/mem/include/mem/mem.h
new file mode 100644
index 0000000..c7f548f
--- /dev/null
+++ b/util/mem/include/mem/mem.h
@@ -0,0 +1,49 @@
+/**
+ * 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 H_UTIL_MEM_
+#define H_UTIL_MEM_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct os_mempool;
+struct os_mbuf_pool;
+
+int mem_malloc_mempool(struct os_mempool *mempool, int num_blocks,
+ int block_size, char *name, void **out_buf);
+
+int mem_malloc_mbuf_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf);
+int mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf);
+int mem_init_mbuf_pool(void *mem, struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/util/mem/pkg.yml
----------------------------------------------------------------------
diff --git a/util/mem/pkg.yml b/util/mem/pkg.yml
new file mode 100644
index 0000000..2e95516
--- /dev/null
+++ b/util/mem/pkg.yml
@@ -0,0 +1,28 @@
+#
+# 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: util/mem
+pkg.description: Library containing miscellaneous utilities.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - mempool
+
+pkg.deps:
+ - kernel/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/util/mem/src/mem.c
----------------------------------------------------------------------
diff --git a/util/mem/src/mem.c b/util/mem/src/mem.c
new file mode 100644
index 0000000..7cbe3d5
--- /dev/null
+++ b/util/mem/src/mem.c
@@ -0,0 +1,166 @@
+/**
+ * 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 "os/os.h"
+
+/**
+ * Mallocs a block of memory and initializes a mempool to use it.
+ *
+ * @param mempool The mempool to initialize.
+ * @param num_blocks The total number of memory blocks in the
+ * mempool.
+ * @param block_size The size of each mempool entry.
+ * @param name The name to give the mempool.
+ * @param out_buf On success, this points to the malloced memory.
+ * Pass NULL if you don't need this
+ * information.
+ *
+ * @return 0 on success;
+ * OS_ENOMEM on malloc failure;
+ * Other OS code on unexpected error.
+ */
+int
+mem_malloc_mempool(struct os_mempool *mempool, int num_blocks, int block_size,
+ char *name, void **out_buf)
+{
+ void *buf;
+ int rc;
+
+ block_size = OS_ALIGN(block_size, OS_ALIGNMENT);
+
+ if (num_blocks > 0) {
+ buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
+ if (buf == NULL) {
+ return OS_ENOMEM;
+ }
+ } else {
+ buf = NULL;
+ }
+
+ rc = os_mempool_init(mempool, num_blocks, block_size, buf, name);
+ if (rc != 0) {
+ free(buf);
+ return rc;
+ }
+
+ if (out_buf != NULL) {
+ *out_buf = buf;
+ }
+
+ return 0;
+}
+
+/**
+ * Mallocs a block of memory and initializes an mbuf pool to use it. The
+ * specified block_size indicates the size of an mbuf acquired from the pool if
+ * it does not contain a pkthdr.
+ *
+ * @param mempool The mempool to initialize.
+ * @param mbuf_pool The mbuf pool to initialize.
+ * @param num_blocks The total number of mbufs in the pool.
+ * @param block_size The size of each mbuf.
+ * @param name The name to give the mempool.
+ * @param out_buf On success, this points to the malloced memory.
+ * Pass NULL if you don't need this
+ * information.
+ *
+ * @return 0 on success;
+ * OS_ENOMEM on malloc failure;
+ * Other OS code on unexpected error.
+ */
+int
+mem_malloc_mbuf_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf)
+{
+ void *buf;
+ int rc;
+
+ block_size = OS_ALIGN(block_size + sizeof (struct os_mbuf), OS_ALIGNMENT);
+
+ rc = mem_malloc_mempool(mempool, num_blocks, block_size, name, &buf);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
+ if (rc != 0) {
+ free(buf);
+ return rc;
+ }
+
+ if (out_buf != NULL) {
+ *out_buf = buf;
+ }
+
+ return 0;
+}
+
+/**
+ * Mallocs a block of memory and initializes an mbuf pool to use it. The
+ * specified block_size indicates the size of an mbuf acquired from the pool if
+ * it contains a pkthdr.
+ *
+ * @param mempool The mempool to initialize.
+ * @param mbuf_pool The mbuf pool to initialize.
+ * @param num_blocks The total number of mbufs in the pool.
+ * @param block_size The size of each mbuf.
+ * @param name The name to give the mempool.
+ * @param out_buf On success, this points to the malloced memory.
+ * Pass NULL if you don't need this
+ * information.
+ *
+ * @return 0 on success;
+ * OS_ENOMEM on malloc failure;
+ * Other OS code on unexpected error.
+ */
+int
+mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf)
+{
+ int rc;
+
+ rc = mem_malloc_mbuf_pool(mempool, mbuf_pool, num_blocks,
+ block_size + sizeof (struct os_mbuf_pkthdr),
+ name, out_buf);
+ return rc;
+}
+
+int
+mem_init_mbuf_pool(void *mem, struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name)
+{
+ int rc;
+
+ rc = os_mempool_init(mempool, num_blocks, block_size, mem, name);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
[2/2] incubator-mynewt-core git commit: final re-org of directories
-- removing the lib/ directory.
Posted by st...@apache.org.
final re-org of directories -- removing the lib/ directory.
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/bed47f0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bed47f0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bed47f0a
Branch: refs/heads/develop
Commit: bed47f0ab918984a09b898d61b3e2a477001f21e
Parents: 8fbd288
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Oct 11 14:23:34 2016 +0200
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Oct 11 14:23:34 2016 +0200
----------------------------------------------------------------------
apps/boot/pkg.yml | 1 -
apps/ocf_sample/pkg.yml | 1 -
apps/slinky/pkg.yml | 3 +-
apps/splitty/pkg.yml | 3 +-
apps/test/pkg.yml | 1 -
kernel/os/include/os/os.h | 3 +
kernel/os/pkg.yml | 2 +-
kernel/os/src/os_msys_init.c | 2 +-
kernel/os/src/os_time.c | 1 -
libs/imgmgr/include/imgmgr/imgmgr.h | 72 ----
libs/imgmgr/pkg.yml | 45 ---
libs/imgmgr/src/imgmgr.c | 476 ------------------------
libs/imgmgr/src/imgmgr_boot.c | 147 --------
libs/imgmgr/src/imgmgr_cli.c | 141 -------
libs/imgmgr/src/imgmgr_coredump.c | 182 ---------
libs/imgmgr/src/imgmgr_fs.c | 240 ------------
libs/imgmgr/src/imgmgr_priv.h | 122 ------
libs/imgmgr/src/imgmgr_util.c | 90 -----
libs/imgmgr/syscfg.yml | 14 -
libs/util/include/util/datetime.h | 58 ---
libs/util/include/util/mem.h | 49 ---
libs/util/include/util/util.h | 32 --
libs/util/pkg.yml | 30 --
libs/util/src/datetime.c | 429 ---------------------
libs/util/src/mem.c | 166 ---------
mgmt/imgmgr/include/imgmgr/imgmgr.h | 72 ++++
mgmt/imgmgr/pkg.yml | 45 +++
mgmt/imgmgr/src/imgmgr.c | 476 ++++++++++++++++++++++++
mgmt/imgmgr/src/imgmgr_boot.c | 147 ++++++++
mgmt/imgmgr/src/imgmgr_cli.c | 141 +++++++
mgmt/imgmgr/src/imgmgr_coredump.c | 182 +++++++++
mgmt/imgmgr/src/imgmgr_fs.c | 240 ++++++++++++
mgmt/imgmgr/src/imgmgr_priv.h | 122 ++++++
mgmt/imgmgr/src/imgmgr_util.c | 90 +++++
mgmt/imgmgr/syscfg.yml | 14 +
mgmt/newtmgr/nmgr_os/pkg.yml | 2 +-
mgmt/newtmgr/nmgr_os/src/newtmgr_os.c | 6 +-
mgmt/oicmgr/pkg.yml | 1 -
net/ip/inet_def_service/pkg.yml | 1 -
net/ip/mn_socket/pkg.yml | 1 -
net/nimble/host/pkg.yml | 1 -
net/nimble/host/src/ble_gap.c | 2 +-
net/nimble/transport/ram/src/ble_hci_ram.c | 2 +-
net/wifi/wifi_mgmt/pkg.yml | 1 -
sys/config/pkg.yml | 1 -
sys/coredump/pkg.yml | 2 +-
sys/id/pkg.yml | 1 -
sys/reboot/pkg.yml | 3 +-
sys/shell/pkg.yml | 2 +-
sys/shell/src/shell_os.c | 16 +-
sys/stats/pkg.yml | 1 -
sys/sysinit/pkg.yml | 1 -
test/flash_test/pkg.yml | 1 -
time/datetime/include/datetime/datetime.h | 58 +++
time/datetime/pkg.yml | 29 ++
time/datetime/src/datetime.c | 429 +++++++++++++++++++++
util/mem/include/mem/mem.h | 49 +++
util/mem/pkg.yml | 28 ++
util/mem/src/mem.c | 166 +++++++++
59 files changed, 2312 insertions(+), 2331 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/apps/boot/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/boot/pkg.yml b/apps/boot/pkg.yml
index f290b1d..83567ad 100644
--- a/apps/boot/pkg.yml
+++ b/apps/boot/pkg.yml
@@ -28,7 +28,6 @@ pkg.keywords:
pkg.deps:
- boot/bootutil
- kernel/os
- - libs/util
- sys/console/stub
pkg.deps.BOOT_SERIAL.OVERWRITE:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/apps/ocf_sample/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/pkg.yml b/apps/ocf_sample/pkg.yml
index 2ffe3de..b865ea3 100644
--- a/apps/ocf_sample/pkg.yml
+++ b/apps/ocf_sample/pkg.yml
@@ -26,7 +26,6 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - libs/util
- sys/log
- net/oic
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/apps/slinky/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/slinky/pkg.yml b/apps/slinky/pkg.yml
index 4f1df54..f0785b9 100644
--- a/apps/slinky/pkg.yml
+++ b/apps/slinky/pkg.yml
@@ -27,13 +27,12 @@ pkg.keywords:
pkg.deps:
- sys/console/full
- test/flash_test
- - libs/imgmgr
+ - mgmt/imgmgr
- mgmt/newtmgr
- mgmt/newtmgr/transport/nmgr_shell
- kernel/os
- boot/bootutil
- sys/shell
- - libs/util
- sys/config
- sys/id
- sys/log
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/apps/splitty/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/splitty/pkg.yml b/apps/splitty/pkg.yml
index a0e0a6a..32ce40b 100644
--- a/apps/splitty/pkg.yml
+++ b/apps/splitty/pkg.yml
@@ -26,13 +26,12 @@ pkg.keywords:
pkg.deps:
- sys/console/full
- - libs/imgmgr
+ - mgmt/imgmgr
- mgmt/newtmgr
- mgmt/newtmgr/transport/nmgr_shell
- kernel/os
- boot/bootutil
- sys/shell
- - libs/util
- sys/config
- sys/id
- sys/log
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/apps/test/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/test/pkg.yml b/apps/test/pkg.yml
index ff3d3fd..e5cdf6a 100644
--- a/apps/test/pkg.yml
+++ b/apps/test/pkg.yml
@@ -32,5 +32,4 @@ pkg.deps:
- kernel/os
- test/testreport
- test/testutil
- - libs/util
- sys/config
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/kernel/os/include/os/os.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os.h b/kernel/os/include/os/os.h
index c8e1e1a..a889d76 100644
--- a/kernel/os/include/os/os.h
+++ b/kernel/os/include/os/os.h
@@ -44,6 +44,9 @@ extern "C" {
)
+#define CTASSERT(x) typedef int __ctasssert ## __LINE__[(x) ? 1 : -1]
+
+
/**
* Whether or not the operating system has been started. Set to
* 1 right before first task is run.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/kernel/os/pkg.yml
----------------------------------------------------------------------
diff --git a/kernel/os/pkg.yml b/kernel/os/pkg.yml
index 0faf0af..896ed5e 100644
--- a/kernel/os/pkg.yml
+++ b/kernel/os/pkg.yml
@@ -25,7 +25,7 @@ pkg.keywords:
pkg.deps:
- sys/sysinit
- - libs/util
+ - util/mem
pkg.req_apis:
- console
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/kernel/os/src/os_msys_init.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_msys_init.c b/kernel/os/src/os_msys_init.c
index fe0d569..d482d33 100644
--- a/kernel/os/src/os_msys_init.c
+++ b/kernel/os/src/os_msys_init.c
@@ -21,7 +21,7 @@
#include "sysinit/sysinit.h"
#include "syscfg/syscfg.h"
#include "os/os_mempool.h"
-#include "util/mem.h"
+#include "mem/mem.h"
#include "os_priv.h"
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/kernel/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_time.c b/kernel/os/src/os_time.c
index 4ef439f..adc1e68 100644
--- a/kernel/os/src/os_time.c
+++ b/kernel/os/src/os_time.c
@@ -17,7 +17,6 @@
* under the License.
*/
-#include <util/util.h>
#include <assert.h>
#include "os/os.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/include/imgmgr/imgmgr.h b/libs/imgmgr/include/imgmgr/imgmgr.h
deleted file mode 100644
index 4ec754c..0000000
--- a/libs/imgmgr/include/imgmgr/imgmgr.h
+++ /dev/null
@@ -1,72 +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 _IMGMGR_H_
-#define _IMGMGR_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define IMGMGR_NMGR_OP_LIST 0
-#define IMGMGR_NMGR_OP_UPLOAD 1
-#define IMGMGR_NMGR_OP_BOOT 2
-#define IMGMGR_NMGR_OP_FILE 3
-#define IMGMGR_NMGR_OP_LIST2 4
-#define IMGMGR_NMGR_OP_BOOT2 5
-#define IMGMGR_NMGR_OP_CORELIST 6
-#define IMGMGR_NMGR_OP_CORELOAD 7
-
-#define IMGMGR_NMGR_MAX_MSG 400
-#define IMGMGR_NMGR_MAX_NAME 64
-#define IMGMGR_NMGR_MAX_VER 25 /* 255.255.65535.4294967295\0 */
-
-#define IMGMGR_HASH_LEN 32
-
-extern int boot_current_slot;
-
-void imgmgr_module_init(void);
-
-struct image_version;
-
-/*
- * Parse version string in src, and fill in ver.
- */
-int imgr_ver_parse(char *src, struct image_version *ver);
-
-/*
- * Take version and convert it to string in dst.
- */
-int imgr_ver_str(struct image_version *ver, char *dst);
-
-/*
- * Given flash_map slot id, read in image_version and/or image hash.
- */
-int imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash, uint32_t *flags);
-
-/*
- * Returns version number of current image (if available).
- */
-int imgr_my_version(struct image_version *ver);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _IMGMGR_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/imgmgr/pkg.yml b/libs/imgmgr/pkg.yml
deleted file mode 100644
index 69ae49d..0000000
--- a/libs/imgmgr/pkg.yml
+++ /dev/null
@@ -1,45 +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.
-#
-
-pkg.name: libs/imgmgr
-pkg.description: Library for image uploading.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-
-pkg.deps:
- - boot/bootutil
- - encoding/base64
- - mgmt/mgmt
- - sys/flash_map
-
-pkg.req_apis:
- - newtmgr
-
-pkg.deps.IMGMGR_FS:
- - fs/fs
-
-pkg.deps.IMGMGR_COREDUMP:
- - sys/coredump
-
-pkg.deps.IMGMGR_SHELL:
- - sys/shell
-
-pkg.init_function: imgmgr_module_init
-pkg.init_stage: 5
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
deleted file mode 100644
index 28a6ff0..0000000
--- a/libs/imgmgr/src/imgmgr.c
+++ /dev/null
@@ -1,476 +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 <os/endian.h>
-
-#include <limits.h>
-#include <assert.h>
-#include <string.h>
-
-#include "sysinit/sysinit.h"
-#include "sysflash/sysflash.h"
-#include "hal/hal_bsp.h"
-#include "flash_map/flash_map.h"
-#include "json/json.h"
-#include "base64/base64.h"
-#include "bootutil/image.h"
-#include "bootutil/bootutil_misc.h"
-#include "mgmt/mgmt.h"
-
-#include "imgmgr/imgmgr.h"
-#include "imgmgr_priv.h"
-
-static int imgr_list2(struct mgmt_jbuf *);
-static int imgr_upload(struct mgmt_jbuf *);
-
-static const struct mgmt_handler imgr_nmgr_handlers[] = {
- [IMGMGR_NMGR_OP_LIST] = {
- .mh_read = NULL,
- .mh_write = NULL
- },
- [IMGMGR_NMGR_OP_UPLOAD] = {
- .mh_read = NULL,
- .mh_write = imgr_upload
- },
- [IMGMGR_NMGR_OP_BOOT] = {
- .mh_read = NULL,
- .mh_write = NULL
- },
- [IMGMGR_NMGR_OP_FILE] = {
-#if MYNEWT_VAL(IMGMGR_FS)
- .mh_read = imgr_file_download,
- .mh_write = imgr_file_upload
-#else
- .mh_read = NULL,
- .mh_write = NULL
-#endif
- },
- [IMGMGR_NMGR_OP_LIST2] = {
- .mh_read = imgr_list2,
- .mh_write = NULL
- },
- [IMGMGR_NMGR_OP_BOOT2] = {
- .mh_read = imgr_boot2_read,
- .mh_write = imgr_boot2_write
- },
- [IMGMGR_NMGR_OP_CORELIST] = {
-#if MYNEWT_VAL(IMGMGR_COREDUMP)
- .mh_read = imgr_core_list,
- .mh_write = NULL
-#else
- .mh_read = NULL,
- .mh_write = NULL
-#endif
- },
- [IMGMGR_NMGR_OP_CORELOAD] = {
-#if MYNEWT_VAL(IMGMGR_COREDUMP)
- .mh_read = imgr_core_load,
- .mh_write = imgr_core_erase,
-#else
- .mh_read = NULL,
- .mh_write = NULL
-#endif
- }
-};
-
-#define IMGR_HANDLER_CNT \
- sizeof(imgr_nmgr_handlers) / sizeof(imgr_nmgr_handlers[0])
-
-static struct mgmt_group imgr_nmgr_group = {
- .mg_handlers = (struct mgmt_handler *)imgr_nmgr_handlers,
- .mg_handlers_count = IMGR_HANDLER_CNT,
- .mg_group_id = MGMT_GROUP_ID_IMAGE,
-};
-
-struct imgr_state imgr_state;
-
-/*
- * Read version and build hash from image located slot "image_slot". Note:
- * this is a slot index, not a flash area ID.
- *
- * Returns -1 if area is not readable.
- * Returns 0 if image in slot is ok, and version string is valid.
- * Returns 1 if there is not a full image.
- * Returns 2 if slot is empty. XXXX not there yet
- */
-int
-imgr_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
- uint32_t *flags)
-{
- struct image_header *hdr;
- struct image_tlv *tlv;
- int rc = -1;
- int rc2;
- const struct flash_area *fa;
- uint8_t data[sizeof(struct image_header)];
- uint32_t data_off, data_end;
- int area_id;
-
- area_id = flash_area_id_from_image_slot(image_slot);
-
- hdr = (struct image_header *)data;
- rc2 = flash_area_open(area_id, &fa);
- if (rc2) {
- return -1;
- }
- rc2 = flash_area_read(fa, 0, hdr, sizeof(*hdr));
- if (rc2) {
- goto end;
- }
- memset(ver, 0xff, sizeof(*ver));
- if (hdr->ih_magic == IMAGE_MAGIC) {
- memcpy(ver, &hdr->ih_ver, sizeof(*ver));
- } else if (hdr->ih_magic == 0xffffffff) {
- rc = 2;
- goto end;
- } else {
- rc = 1;
- goto end;
- }
-
- if(flags) {
- *flags = hdr->ih_flags;
- }
- /*
- * Build ID is in a TLV after the image.
- */
- data_off = hdr->ih_hdr_size + hdr->ih_img_size;
- data_end = data_off + hdr->ih_tlv_size;
-
- if (data_end > fa->fa_size) {
- rc = 1;
- goto end;
- }
- tlv = (struct image_tlv *)data;
- while (data_off + sizeof(*tlv) <= data_end) {
- rc2 = flash_area_read(fa, data_off, tlv, sizeof(*tlv));
- if (rc2) {
- goto end;
- }
- if (tlv->it_type == 0xff && tlv->it_len == 0xffff) {
- break;
- }
- if (tlv->it_type != IMAGE_TLV_SHA256 ||
- tlv->it_len != IMGMGR_HASH_LEN) {
- data_off += sizeof(*tlv) + tlv->it_len;
- continue;
- }
- data_off += sizeof(*tlv);
- if (hash) {
- if (data_off + IMGMGR_HASH_LEN > data_end) {
- goto end;
- }
- rc2 = flash_area_read(fa, data_off, hash, IMGMGR_HASH_LEN);
- if (rc2) {
- goto end;
- }
- }
- rc = 0;
- goto end;
- }
- rc = 1;
-end:
- flash_area_close(fa);
- return rc;
-}
-
-int
-imgr_my_version(struct image_version *ver)
-{
- return imgr_read_info(boot_current_slot, ver, NULL, NULL);
-}
-
-/*
- * Finds image given version number. Returns the slot number image is in,
- * or -1 if not found.
- */
-int
-imgr_find_by_ver(struct image_version *find, uint8_t *hash)
-{
- int i;
- struct image_version ver;
-
- for (i = 0; i < 2; i++) {
- if (imgr_read_info(i, &ver, hash, NULL) != 0) {
- continue;
- }
- if (!memcmp(find, &ver, sizeof(ver))) {
- return i;
- }
- }
- return -1;
-}
-
-/*
- * Finds image given hash of the image. Returns the slot number image is in,
- * or -1 if not found.
- */
-int
-imgr_find_by_hash(uint8_t *find, struct image_version *ver)
-{
- int i;
- uint8_t hash[IMGMGR_HASH_LEN];
-
- for (i = 0; i < 2; i++) {
- if (imgr_read_info(i, ver, hash, NULL) != 0) {
- continue;
- }
- if (!memcmp(hash, find, IMGMGR_HASH_LEN)) {
- return i;
- }
- }
- return -1;
-}
-
-static int
-imgr_list2(struct mgmt_jbuf *njb)
-{
- struct json_encoder *enc;
- int i;
- int rc;
- uint32_t flags;
- struct image_version ver;
- uint8_t hash[IMGMGR_HASH_LEN]; /* SHA256 hash */
- struct json_value jv;
- char vers_str[IMGMGR_NMGR_MAX_VER];
- char hash_str[IMGMGR_HASH_STR + 1];
- int ver_len;
-
- enc = &njb->mjb_enc;
-
- json_encode_object_start(enc);
- json_encode_array_name(enc, "images");
- json_encode_array_start(enc);
- for (i = 0; i < 2; i++) {
- rc = imgr_read_info(i, &ver, hash, &flags);
- if (rc != 0) {
- continue;
- }
- json_encode_object_start(enc);
-
- JSON_VALUE_INT(&jv, i);
- json_encode_object_entry(enc, "slot", &jv);
-
- ver_len = imgr_ver_str(&ver, vers_str);
- JSON_VALUE_STRINGN(&jv, vers_str, ver_len);
- json_encode_object_entry(enc, "version", &jv);
-
- base64_encode(hash, IMGMGR_HASH_LEN, hash_str, 1);
- JSON_VALUE_STRING(&jv, hash_str);
- json_encode_object_entry(enc, "hash", &jv);
-
- JSON_VALUE_BOOL(&jv, !(flags & IMAGE_F_NON_BOOTABLE));
- json_encode_object_entry(enc, "bootable", &jv);
-
- json_encode_object_finish(enc);
- }
- json_encode_array_finish(enc);
- json_encode_object_finish(enc);
-
- return 0;
-}
-
-static int
-imgr_upload(struct mgmt_jbuf *njb)
-{
- char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
- long long unsigned int off = UINT_MAX;
- long long unsigned int size = UINT_MAX;
- const struct json_attr_t off_attr[4] = {
- [0] = {
- .attribute = "off",
- .type = t_uinteger,
- .addr.uinteger = &off,
- .nodefault = true
- },
- [1] = {
- .attribute = "data",
- .type = t_string,
- .addr.string = img_data,
- .len = sizeof(img_data)
- },
- [2] = {
- .attribute = "len",
- .type = t_uinteger,
- .addr.uinteger = &size,
- .nodefault = true
- }
- };
- struct image_version ver;
- struct image_header *hdr;
- struct json_encoder *enc;
- struct json_value jv;
- int area_id;
- int active;
- int best;
- int rc;
- int len;
- int i;
-
- rc = json_read_object(&njb->mjb_buf, off_attr);
- if (rc || off == UINT_MAX) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- len = strlen(img_data);
- if (len) {
- len = base64_decode(img_data, img_data);
- if (len < 0) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- }
-
- if (off == 0) {
- if (len < sizeof(struct image_header)) {
- /*
- * Image header is the first thing in the image.
- */
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- hdr = (struct image_header *)img_data;
- if (hdr->ih_magic != IMAGE_MAGIC) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
-
- /*
- * New upload.
- */
- imgr_state.upload.off = 0;
- imgr_state.upload.size = size;
- active = boot_current_slot;
- best = -1;
-
- for (i = 0; i < 2; i++) {
- rc = imgr_read_info(i, &ver, NULL, NULL);
- if (rc < 0) {
- continue;
- }
- if (rc == 0) {
- /*
- * Image in slot is ok.
- */
- if (active == i) {
- /*
- * Slot is currently active one. Can't upload to this.
- */
- continue;
- } else {
- /*
- * Not active slot, but image is ok. Use it if there are
- * no better candidates.
- */
- best = i;
- }
- continue;
- }
- best = i;
- break;
- }
- if (best >= 0) {
- area_id = flash_area_id_from_image_slot(best);
- if (imgr_state.upload.fa) {
- flash_area_close(imgr_state.upload.fa);
- imgr_state.upload.fa = NULL;
- }
- rc = flash_area_open(area_id, &imgr_state.upload.fa);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- if (IMAGE_SIZE(hdr) > imgr_state.upload.fa->fa_size) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- /*
- * XXX only erase if needed.
- */
- rc = flash_area_erase(imgr_state.upload.fa, 0,
- imgr_state.upload.fa->fa_size);
- } else {
- /*
- * No slot where to upload!
- */
- rc = MGMT_ERR_ENOMEM;
- goto err;
- }
- } else if (off != imgr_state.upload.off) {
- /*
- * Invalid offset. Drop the data, and respond with the offset we're
- * expecting data for.
- */
- goto out;
- }
-
- if (!imgr_state.upload.fa) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
- if (len) {
- rc = flash_area_write(imgr_state.upload.fa, imgr_state.upload.off,
- img_data, len);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err_close;
- }
- imgr_state.upload.off += len;
- if (imgr_state.upload.size == imgr_state.upload.off) {
- /* Done */
- flash_area_close(imgr_state.upload.fa);
- imgr_state.upload.fa = NULL;
- }
- }
-out:
- enc = &njb->mjb_enc;
-
- json_encode_object_start(enc);
-
- JSON_VALUE_INT(&jv, MGMT_ERR_EOK);
- json_encode_object_entry(enc, "rc", &jv);
-
- JSON_VALUE_UINT(&jv, imgr_state.upload.off);
- json_encode_object_entry(enc, "off", &jv);
-
- json_encode_object_finish(enc);
-
- return 0;
-err_close:
- flash_area_close(imgr_state.upload.fa);
- imgr_state.upload.fa = NULL;
-err:
- mgmt_jbuf_setoerr(njb, rc);
- return 0;
-}
-
-void
-imgmgr_module_init(void)
-{
- int rc;
-
- rc = mgmt_group_register(&imgr_nmgr_group);
- SYSINIT_PANIC_ASSERT(rc == 0);
-
-#if MYNEWT_VAL(IMGMGR_CLI)
- rc = imgr_cli_register();
- SYSINIT_PANIC_ASSERT(rc == 0);
-#endif
-
- boot_vect_write_main();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
deleted file mode 100644
index b89ce87..0000000
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ /dev/null
@@ -1,147 +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 <os/os.h>
-#include <os/endian.h>
-
-#include <limits.h>
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-
-#include <mgmt/mgmt.h>
-#include <bootutil/image.h>
-#include <bootutil/bootutil_misc.h>
-#include <json/json.h>
-#include <base64/base64.h>
-#include <hal/hal_bsp.h>
-
-#include "imgmgr/imgmgr.h"
-#include "imgmgr_priv.h"
-
-static void
-imgr_hash_jsonstr(struct json_encoder *enc, char *key, uint8_t *hash)
-{
- struct json_value jv;
- char hash_str[IMGMGR_HASH_STR + 1];
-
- base64_encode(hash, IMGMGR_HASH_LEN, hash_str, 1);
- JSON_VALUE_STRING(&jv, hash_str);
- json_encode_object_entry(enc, key, &jv);
-}
-
-int
-imgr_boot2_read(struct mgmt_jbuf *njb)
-{
- int rc;
- struct json_encoder *enc;
- struct image_version ver;
- struct json_value jv;
- uint8_t hash[IMGMGR_HASH_LEN];
- int slot;
-
- enc = &njb->mjb_enc;
-
- json_encode_object_start(enc);
-
- rc = boot_vect_read_test(&slot);
- if (!rc) {
- rc = imgr_read_info(slot, &ver, hash, NULL);
- if (rc >= 0) {
- imgr_hash_jsonstr(enc, "test", hash);
- }
- }
-
- rc = boot_vect_read_main(&slot);
- if (!rc) {
- rc = imgr_read_info(slot, &ver, hash, NULL);
- if (rc >= 0) {
- imgr_hash_jsonstr(enc, "main", hash);
- }
- }
-
- rc = imgr_read_info(boot_current_slot, &ver, hash, NULL);
- if (!rc) {
- imgr_hash_jsonstr(enc, "active", hash);
- }
-
- JSON_VALUE_INT(&jv, MGMT_ERR_EOK);
- json_encode_object_entry(enc, "rc", &jv);
-
- json_encode_object_finish(enc);
-
- return 0;
-}
-
-int
-imgr_boot2_write(struct mgmt_jbuf *njb)
-{
- char hash_str[IMGMGR_HASH_STR + 1];
- uint8_t hash[IMGMGR_HASH_LEN];
- const struct json_attr_t boot_write_attr[2] = {
- [0] = {
- .attribute = "test",
- .type = t_string,
- .addr.string = hash_str,
- .len = sizeof(hash_str),
- },
- [1] = {
- .attribute = NULL
- }
- };
- struct json_encoder *enc;
- struct json_value jv;
- int rc;
- struct image_version ver;
-
- rc = json_read_object(&njb->mjb_buf, boot_write_attr);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
-
- base64_decode(hash_str, hash);
- rc = imgr_find_by_hash(hash, &ver);
- if (rc >= 0) {
- rc = boot_vect_write_test(rc);
- if (rc) {
- rc = MGMT_ERR_EUNKNOWN;
- goto err;
- }
- rc = 0;
- } else {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
-
- enc = &njb->mjb_enc;
-
- json_encode_object_start(enc);
-
- JSON_VALUE_INT(&jv, MGMT_ERR_EOK);
- json_encode_object_entry(&njb->mjb_enc, "rc", &jv);
-
- json_encode_object_finish(enc);
-
- return 0;
-
-err:
- mgmt_jbuf_setoerr(njb, rc);
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr_cli.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_cli.c b/libs/imgmgr/src/imgmgr_cli.c
deleted file mode 100644
index ebc2353..0000000
--- a/libs/imgmgr/src/imgmgr_cli.c
+++ /dev/null
@@ -1,141 +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 "syscfg/syscfg.h"
-
-#if MYNEWT_VAL(IMGMGR_CLI)
-
-#include <string.h>
-
-#include <flash_map/flash_map.h>
-#include <hal/hal_bsp.h>
-
-#include <shell/shell.h>
-#include <console/console.h>
-
-#include <bootutil/image.h>
-#include <bootutil/bootutil_misc.h>
-
-#include <base64/hex.h>
-
-#include "imgmgr/imgmgr.h"
-#include "imgmgr_priv.h"
-
-static int imgr_cli_cmd(int argc, char **argv);
-
-static struct shell_cmd shell_imgr_cmd = {
- .sc_cmd = "imgr",
- .sc_cmd_func = imgr_cli_cmd
-};
-
-static void
-imgr_cli_show_slot(int slot)
-{
- uint8_t hash[IMGMGR_HASH_LEN]; /* SHA256 hash */
- char hash_str[IMGMGR_HASH_LEN * 2 + 1];
- struct image_version ver;
- char ver_str[IMGMGR_NMGR_MAX_VER];
- uint32_t flags;
-
- if (imgr_read_info(slot, &ver, hash, &flags)) {
- return;
- }
-
- (void)imgr_ver_str(&ver, ver_str);
-
- console_printf("%8s: %s %c\n",
- ver_str, hex_format(hash, IMGMGR_HASH_LEN, hash_str, sizeof(hash_str)),
- flags & IMAGE_F_NON_BOOTABLE ? ' ' : 'b');
-}
-
-static void
-imgr_cli_boot_get(void)
-{
- int rc;
- int slot;
-
- /*
- * 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;
- }
-}
-
-static void
-imgr_cli_boot_set(char *hash_str)
-{
- uint8_t hash[IMGMGR_HASH_LEN];
- struct image_version ver;
- int rc;
-
- if (hex_parse(hash_str, strlen(hash_str), hash, sizeof(hash)) !=
- sizeof(hash)) {
- console_printf("Invalid hash %s\n", hash_str);
- return;
- }
- rc = imgr_find_by_hash(hash, &ver);
- if (rc < 0) {
- console_printf("Unknown img\n");
- return;
- }
- rc = boot_vect_write_test(rc);
- if (rc) {
- console_printf("Can't make img active\n");
- return;
- }
-}
-
-static int
-imgr_cli_cmd(int argc, char **argv)
-{
- int i;
-
- if (argc < 2) {
- console_printf("Too few args\n");
- 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 {
- imgr_cli_boot_get();
- }
- } else if (!strcmp(argv[1], "ver")) {
- imgr_cli_show_slot(boot_current_slot);
- } else {
- console_printf("Unknown cmd\n");
- }
- return 0;
-}
-
-int
-imgr_cli_register(void)
-{
- return shell_cmd_register(&shell_imgr_cmd);
-}
-#endif /* MYNEWT_VAL(IMGMGR_CLI) */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_coredump.c b/libs/imgmgr/src/imgmgr_coredump.c
deleted file mode 100644
index b9d131a..0000000
--- a/libs/imgmgr/src/imgmgr_coredump.c
+++ /dev/null
@@ -1,182 +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 "syscfg/syscfg.h"
-
-#if MYNEWT_VAL(IMGMGR_COREDUMP)
-
-#include <limits.h>
-
-#include "sysflash/sysflash.h"
-#include "flash_map/flash_map.h"
-#include "mgmt/mgmt.h"
-#include "coredump/coredump.h"
-#include "base64/base64.h"
-
-#include "imgmgr/imgmgr.h"
-#include "imgmgr_priv.h"
-
-int
-imgr_core_list(struct mgmt_jbuf *njb)
-{
- const struct flash_area *fa;
- struct coredump_header hdr;
- struct json_encoder *enc;
- struct json_value jv;
- int rc;
-
- rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- } else {
- rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
- if (rc != 0) {
- rc = MGMT_ERR_EINVAL;
- } else if (hdr.ch_magic != COREDUMP_MAGIC) {
- rc = MGMT_ERR_ENOENT;
- } else {
- rc = 0;
- }
- }
-
- enc = &njb->mjb_enc;
-
- json_encode_object_start(enc);
- JSON_VALUE_INT(&jv, rc);
- json_encode_object_entry(enc, "rc", &jv);
- json_encode_object_finish(enc);
-
- return 0;
-}
-
-int
-imgr_core_load(struct mgmt_jbuf *njb)
-{
- unsigned long long off = UINT_MAX;
- const struct json_attr_t dload_attr[2] = {
- [0] = {
- .attribute = "off",
- .type = t_uinteger,
- .addr.uinteger = &off
- }
- };
- int rc;
- int sz;
- const struct flash_area *fa;
- char data[IMGMGR_NMGR_MAX_MSG];
- char encoded[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
- struct coredump_header *hdr;
- struct json_encoder *enc;
- struct json_value jv;
-
- hdr = (struct coredump_header *)data;
-
- rc = json_read_object(&njb->mjb_buf, dload_attr);
- if (rc || off == UINT_MAX) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
-
- rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
-
- rc = flash_area_read(fa, 0, hdr, sizeof(*hdr));
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err_close;
- }
- if (hdr->ch_magic != COREDUMP_MAGIC) {
- rc = MGMT_ERR_ENOENT;
- goto err_close;
- }
- if (off > hdr->ch_size) {
- off = hdr->ch_size;
- }
- sz = hdr->ch_size - off;
- if (sz > sizeof(data)) {
- sz = sizeof(data);
- }
-
- rc = flash_area_read(fa, off, data, sz);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err_close;
- }
-
- sz = base64_encode(data, sz, encoded, 1);
-
- enc = &njb->mjb_enc;
-
- json_encode_object_start(enc);
- JSON_VALUE_INT(&jv, 0);
- json_encode_object_entry(enc, "rc", &jv);
-
- JSON_VALUE_INT(&jv, off);
- json_encode_object_entry(enc, "off", &jv);
-
- JSON_VALUE_STRINGN(&jv, encoded, sz);
- json_encode_object_entry(enc, "data", &jv);
- json_encode_object_finish(enc);
-
- flash_area_close(fa);
- return 0;
-
-err_close:
- flash_area_close(fa);
-err:
- mgmt_jbuf_setoerr(njb, rc);
- return 0;
-}
-
-/*
- * Erase the area if it has a coredump, or the header is empty.
- */
-int
-imgr_core_erase(struct mgmt_jbuf *njb)
-{
- struct coredump_header hdr;
- const struct flash_area *fa;
- int rc;
-
- rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- goto err;
- }
-
- rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
- if (rc == 0 &&
- (hdr.ch_magic == COREDUMP_MAGIC || hdr.ch_magic == 0xffffffff)) {
- rc = flash_area_erase(fa, 0, fa->fa_size);
- if (rc) {
- rc = MGMT_ERR_EINVAL;
- }
- }
- rc = 0;
-
- flash_area_close(fa);
-err:
- mgmt_jbuf_setoerr(njb, rc);
- return 0;
-}
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr_fs.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_fs.c b/libs/imgmgr/src/imgmgr_fs.c
deleted file mode 100644
index d44fd55..0000000
--- a/libs/imgmgr/src/imgmgr_fs.c
+++ /dev/null
@@ -1,240 +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 "syscfg/syscfg.h"
-
-#if MYNEWT_VAL(IMGMGR_FS)
-
-#include <limits.h>
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "os/os.h"
-#include "os/endian.h"
-#include "newtmgr/newtmgr.h"
-#include "bootutil/image.h"
-#include "fs/fs.h"
-#include "json/json.h"
-#include "base64/base64.h"
-#include "bsp/bsp.h"
-
-#include "imgmgr/imgmgr.h"
-#include "imgmgr_priv.h"
-
-int
-imgr_file_download(struct nmgr_jbuf *njb)
-{
- long long unsigned int off = UINT_MAX;
- char tmp_str[IMGMGR_NMGR_MAX_NAME + 1];
- char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
- const struct json_attr_t dload_attr[3] = {
- [0] = {
- .attribute = "off",
- .type = t_uinteger,
- .addr.uinteger = &off
- },
- [1] = {
- .attribute = "name",
- .type = t_string,
- .addr.string = tmp_str,
- .len = sizeof(tmp_str)
- }
- };
- int rc;
- uint32_t out_len;
- struct fs_file *file;
- struct json_encoder *enc;
- struct json_value jv;
-
- rc = json_read_object(&njb->njb_buf, dload_attr);
- if (rc || off == UINT_MAX) {
- rc = NMGR_ERR_EINVAL;
- goto err;
- }
-
- rc = fs_open(tmp_str, FS_ACCESS_READ, &file);
- if (rc || !file) {
- rc = NMGR_ERR_ENOMEM;
- goto err;
- }
-
- rc = fs_seek(file, off);
- if (rc) {
- rc = NMGR_ERR_EUNKNOWN;
- goto err_close;
- }
- rc = fs_read(file, 32, tmp_str, &out_len);
- if (rc) {
- rc = NMGR_ERR_EUNKNOWN;
- goto err_close;
- }
-
- out_len = base64_encode(tmp_str, out_len, img_data, 1);
-
- enc = &njb->njb_enc;
-
- json_encode_object_start(enc);
-
- JSON_VALUE_UINT(&jv, off);
- json_encode_object_entry(enc, "off", &jv);
- JSON_VALUE_STRINGN(&jv, img_data, out_len);
- json_encode_object_entry(enc, "data", &jv);
- if (off == 0) {
- rc = fs_filelen(file, &out_len);
- JSON_VALUE_UINT(&jv, out_len);
- json_encode_object_entry(enc, "len", &jv);
- }
- fs_close(file);
-
- JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
- json_encode_object_entry(&njb->njb_enc, "rc", &jv);
-
- json_encode_object_finish(enc);
-
- return 0;
-
-err_close:
- fs_close(file);
-err:
- nmgr_jbuf_setoerr(njb, rc);
- return 0;
-}
-
-int
-imgr_file_upload(struct nmgr_jbuf *njb)
-{
- char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
- char file_name[IMGMGR_NMGR_MAX_NAME + 1];
- long long unsigned int off = UINT_MAX;
- long long unsigned int size = UINT_MAX;
- const struct json_attr_t off_attr[5] = {
- [0] = {
- .attribute = "off",
- .type = t_uinteger,
- .addr.uinteger = &off,
- .nodefault = true
- },
- [1] = {
- .attribute = "data",
- .type = t_string,
- .addr.string = img_data,
- .len = sizeof(img_data)
- },
- [2] = {
- .attribute = "len",
- .type = t_uinteger,
- .addr.uinteger = &size,
- .nodefault = true
- },
- [3] = {
- .attribute = "name",
- .type = t_string,
- .addr.string = file_name,
- .len = sizeof(file_name)
- }
- };
- struct json_encoder *enc;
- struct json_value jv;
- int rc;
- int len;
-
- rc = json_read_object(&njb->njb_buf, off_attr);
- if (rc || off == UINT_MAX) {
- rc = NMGR_ERR_EINVAL;
- goto err;
- }
- len = strlen(img_data);
- if (len) {
- len = base64_decode(img_data, img_data);
- if (len < 0) {
- rc = NMGR_ERR_EINVAL;
- goto err;
- }
- }
-
- if (off == 0) {
- /*
- * New upload.
- */
- imgr_state.upload.off = 0;
- imgr_state.upload.size = size;
-
- if (!strlen(file_name)) {
- rc = NMGR_ERR_EINVAL;
- goto err;
- }
- if (imgr_state.upload.file) {
- fs_close(imgr_state.upload.file);
- imgr_state.upload.file = NULL;
- }
- rc = fs_open(file_name, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
- &imgr_state.upload.file);
- if (rc) {
- rc = NMGR_ERR_EINVAL;
- goto err;
- }
- } else if (off != imgr_state.upload.off) {
- /*
- * Invalid offset. Drop the data, and respond with the offset we're
- * expecting data for.
- */
- goto out;
- }
-
- if (!imgr_state.upload.file) {
- rc = NMGR_ERR_EINVAL;
- goto err;
- }
- if (len) {
- rc = fs_write(imgr_state.upload.file, img_data, len);
- if (rc) {
- rc = NMGR_ERR_EINVAL;
- goto err_close;
- }
- imgr_state.upload.off += len;
- if (imgr_state.upload.size == imgr_state.upload.off) {
- /* Done */
- fs_close(imgr_state.upload.file);
- imgr_state.upload.file = NULL;
- }
- }
-out:
- enc = &njb->njb_enc;
-
- json_encode_object_start(enc);
-
- JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
- json_encode_object_entry(&njb->njb_enc, "rc", &jv);
-
- JSON_VALUE_UINT(&jv, imgr_state.upload.off);
- json_encode_object_entry(enc, "off", &jv);
-
- json_encode_object_finish(enc);
-
- return 0;
-
-err_close:
- fs_close(imgr_state.upload.file);
- imgr_state.upload.file = NULL;
-err:
- nmgr_jbuf_setoerr(njb, rc);
- return 0;
-}
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_priv.h b/libs/imgmgr/src/imgmgr_priv.h
deleted file mode 100644
index bdf1449..0000000
--- a/libs/imgmgr/src/imgmgr_priv.h
+++ /dev/null
@@ -1,122 +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 __IMGMGR_PRIV_H_
-#define __IMGMGR_PRIV_H_
-
-#include <stdint.h>
-#include "syscfg/syscfg.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define IMGMGR_MAX_IMGS 2
-
-#define IMGMGR_HASH_STR 48
-
-/*
- * When accompanied by image, it's this structure followed by data.
- * Response contains just the offset.
- */
-struct imgmgr_upload_cmd {
- uint32_t iuc_off;
-};
-
-/*
- * Response to list:
- * {
- * "images":[ <version1>, <version2>]
- * }
- *
- *
- * Request to boot to version:
- * {
- * "test":<version>
- * }
- *
- *
- * Response to boot read:
- * {
- * "test":<version>,
- * "main":<version>,
- * "active":<version>
- * }
- *
- *
- * Request to image upload:
- * {
- * "off":<offset>,
- * "len":<img_size> inspected when off = 0
- * "data":<base64encoded binary>
- * }
- *
- *
- * Response to upload:
- * {
- * "off":<offset>
- * }
- *
- *
- * Request to image upload:
- * {
- * "off":<offset>
- * "name":<filename> inspected when off = 0
- * "len":<file_size> inspected when off = 0
- * "data":<base64encoded binary>
- * }
- */
-
-struct mgmt_jbuf;
-struct nmgr_hdr;
-struct os_mbuf;
-struct fs_file;
-
-struct imgr_state {
- struct {
- uint32_t off;
- uint32_t size;
- const struct flash_area *fa;
-#if MYNEWT_VAL(IMGMGR_FS)
- struct fs_file *file;
-#endif
- } upload;
-};
-
-extern struct imgr_state imgr_state;
-
-struct nmgr_jbuf;
-int imgr_boot2_read(struct mgmt_jbuf *);
-int imgr_boot2_write(struct mgmt_jbuf *);
-int imgr_file_upload(struct mgmt_jbuf *);
-int imgr_file_download(struct mgmt_jbuf *);
-int imgr_core_list(struct mgmt_jbuf *);
-int imgr_core_load(struct mgmt_jbuf *);
-int imgr_core_erase(struct mgmt_jbuf *);
-int imgr_splitapp_read(struct mgmt_jbuf *);
-int imgr_splitapp_write(struct mgmt_jbuf *);
-int imgr_find_by_ver(struct image_version *find, uint8_t *hash);
-int imgr_find_by_hash(uint8_t *find, struct image_version *ver);
-int imgr_cli_register(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __IMGMGR_PRIV_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/src/imgmgr_util.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_util.c b/libs/imgmgr/src/imgmgr_util.c
deleted file mode 100644
index a97a627..0000000
--- a/libs/imgmgr/src/imgmgr_util.c
+++ /dev/null
@@ -1,90 +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 <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <bootutil/image.h>
-#include <imgmgr/imgmgr.h>
-
-int
-imgr_ver_parse(char *src, struct image_version *ver)
-{
- unsigned long ul;
- char *tok;
- char *nxt;
- char *ep;
-
- memset(ver, 0, sizeof(*ver));
-
- nxt = src;
- tok = strsep(&nxt, ".");
- ul = strtoul(tok, &ep, 10);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
- return -1;
- }
- ver->iv_major = ul;
- if (nxt == NULL) {
- return 0;
- }
- tok = strsep(&nxt, ".");
- ul = strtoul(tok, &ep, 10);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
- return -1;
- }
- ver->iv_minor = ul;
- if (nxt == NULL) {
- return 0;
- }
-
- tok = strsep(&nxt, ".");
- ul = strtoul(tok, &ep, 10);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
- return -1;
- }
- ver->iv_revision = ul;
- if (nxt == NULL) {
- return 0;
- }
-
- tok = nxt;
- ul = strtoul(tok, &ep, 10);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
- return -1;
- }
- ver->iv_build_num = ul;
-
- return 0;
-}
-
-int
-imgr_ver_str(struct image_version *ver, char *dst)
-{
- if (ver->iv_build_num) {
- return sprintf(dst, "%u.%u.%u.%lu",
- ver->iv_major, ver->iv_minor, ver->iv_revision,
- (unsigned long)ver->iv_build_num);
- } else {
- return sprintf(dst, "%u.%u.%u",
- ver->iv_major, ver->iv_minor, ver->iv_revision);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/imgmgr/syscfg.yml
----------------------------------------------------------------------
diff --git a/libs/imgmgr/syscfg.yml b/libs/imgmgr/syscfg.yml
deleted file mode 100644
index 2b67f7d..0000000
--- a/libs/imgmgr/syscfg.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-# Package: libs/imgmgr
-
-syscfg.defs:
- IMGMGR_FS:
- description: 'TBD'
- value: 0
- IMGMGR_COREDUMP:
- description: 'TBD'
- value: 0
- IMGMGR_CLI:
- description: 'TBD'
- value: 0
- restrictions:
- - SHELL_TASK
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/util/include/util/datetime.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/datetime.h b/libs/util/include/util/datetime.h
deleted file mode 100644
index 5c433c3..0000000
--- a/libs/util/include/util/datetime.h
+++ /dev/null
@@ -1,58 +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 __UTIL_DATETIME_H
-#define __UTIL_DATETIME_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct os_timeval;
-struct os_timezone;
-
-#define DATETIME_BUFSIZE 33
-
-/*
- * Format the time specified by 'utctime' and 'tz' as per RFC 3339 in
- * the 'output' string. The size of the buffer pointed to by 'output'
- * is specified by 'olen'.
- *
- * Returns 0 on success and non-zero on failure.
- */
-int format_datetime(const struct os_timeval *utctime,
- const struct os_timezone *tz, char *output, int olen);
-
-/*
- * Parse 'input' in the Internet date/time format specified by RFC 3339.
- * https://www.ietf.org/rfc/rfc3339.txt
- *
- * We deviate from the RFC in that if the 'time offset' is left unspecified
- * then we default to UTC time.
- *
- * Return 0 if 'input' could be parsed successfully and non-zero otherwise.
- * 'utctime' and 'tz' are updated if 'input' was parsed successfully.
- */
-int parse_datetime(const char *input, struct os_timeval *utctime,
- struct os_timezone *tz);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __UTIL_DATETIME_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/util/include/util/mem.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/mem.h b/libs/util/include/util/mem.h
deleted file mode 100644
index c7f548f..0000000
--- a/libs/util/include/util/mem.h
+++ /dev/null
@@ -1,49 +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 H_UTIL_MEM_
-#define H_UTIL_MEM_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct os_mempool;
-struct os_mbuf_pool;
-
-int mem_malloc_mempool(struct os_mempool *mempool, int num_blocks,
- int block_size, char *name, void **out_buf);
-
-int mem_malloc_mbuf_pool(struct os_mempool *mempool,
- struct os_mbuf_pool *mbuf_pool, int num_blocks,
- int block_size, char *name,
- void **out_buf);
-int mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
- struct os_mbuf_pool *mbuf_pool, int num_blocks,
- int block_size, char *name,
- void **out_buf);
-int mem_init_mbuf_pool(void *mem, struct os_mempool *mempool,
- struct os_mbuf_pool *mbuf_pool, int num_blocks,
- int block_size, char *name);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/util/include/util/util.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/util.h b/libs/util/include/util/util.h
deleted file mode 100644
index 202b547..0000000
--- a/libs/util/include/util/util.h
+++ /dev/null
@@ -1,32 +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 __UTIL_H__
-#define __UTIL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define CTASSERT(x) typedef int __ctasssert ## __LINE__[(x) ? 1 : -1]
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __UTIL_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/util/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/util/pkg.yml b/libs/util/pkg.yml
deleted file mode 100644
index 9957805..0000000
--- a/libs/util/pkg.yml
+++ /dev/null
@@ -1,30 +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.
-#
-
-pkg.name: libs/util
-pkg.description: Library containing miscellaneous utilities.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
- - base64
- - circular buffer
-
-pkg.deps:
- - hw/hal
- - kernel/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/util/src/datetime.c
----------------------------------------------------------------------
diff --git a/libs/util/src/datetime.c b/libs/util/src/datetime.c
deleted file mode 100644
index fe4fb38..0000000
--- a/libs/util/src/datetime.c
+++ /dev/null
@@ -1,429 +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.
- */
-
-/*-
- * Copyright (c) 1988 University of Utah.
- * Copyright (c) 1982, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Utah $Hdr: clock.c 1.18 91/01/21$
- * from: @(#)clock.c 8.2 (Berkeley) 1/12/94
- * from: NetBSD: clock_subr.c,v 1.6 2001/07/07 17:04:02 thorpej Exp
- * and
- * from: src/sys/i386/isa/clock.c,v 1.176 2001/09/04
- */
-
-#include <os/os_time.h>
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <util/datetime.h>
-
-struct clocktime {
- int year; /* year (4 digit year) */
- int mon; /* month (1 - 12) */
- int day; /* day (1 - 31) */
- int hour; /* hour (0 - 23) */
- int min; /* minute (0 - 59) */
- int sec; /* second (0 - 59) */
- int dow; /* day of week (0 - 6; 0 = Sunday) */
- int usec; /* micro seconds */
-};
-
-#define days_in_year(y) (leapyear(y) ? 366 : 365)
-
-#define FEBRUARY 2
-#define days_in_month(y, m) \
- (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))
-
-/* Day of week. Days are counted from 1/1/1970, which was a Thursday */
-#define day_of_week(days) (((days) + 4) % 7)
-
-static const int month_days[12] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-#define POSIX_BASE_YEAR 1970
-#define SECDAY (24 * 60 * 60)
-
-/*
- * This inline avoids some unnecessary modulo operations
- * as compared with the usual macro:
- * ( ((year % 4) == 0 &&
- * (year % 100) != 0) ||
- * ((year % 400) == 0) )
- * It is otherwise equivalent.
- */
-static int
-leapyear(int year)
-{
- int rv = 0;
-
- if ((year & 3) == 0) {
- rv = 1;
- if ((year % 100) == 0) {
- rv = 0;
- if ((year % 400) == 0)
- rv = 1;
- }
- }
- return (rv);
-}
-
-static int
-clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
-{
- int i, year, days;
-
- year = ct->year;
-
- /* Sanity checks. */
- if (year < POSIX_BASE_YEAR ||
- ct->mon < 1 || ct->mon > 12 ||
- ct->day < 1 || ct->day > days_in_month(year, ct->mon) ||
- ct->hour < 0 || ct->hour > 23 ||
- ct->min < 0 || ct->min > 59 ||
- ct->sec < 0 || ct->sec > 59 ||
- ct->usec < 0 || ct->usec > 999999) {
- return (-1);
- }
-
- /*
- * Compute days since start of time
- * First from years, then from months.
- */
- days = 0;
- for (i = POSIX_BASE_YEAR; i < year; i++)
- days += days_in_year(i);
-
- /* Months */
- for (i = 1; i < ct->mon; i++)
- days += days_in_month(year, i);
- days += (ct->day - 1);
-
- tv->tv_sec = (((int64_t)days * 24 + ct->hour) * 60 + ct->min) * 60 +
- ct->sec;
- tv->tv_usec = ct->usec;
-
- return (0);
-}
-
-static int
-timeval_to_clocktime(const struct os_timeval *tv, const struct os_timezone *tz,
- struct clocktime *ct)
-{
- int i, year, days;
- int64_t rsec; /* remainder seconds */
- int64_t secs;
-
- secs = tv->tv_sec;
- if (tz != NULL) {
- /* Convert utctime to localtime */
- secs -= tz->tz_minuteswest * 60;
- secs += tz->tz_dsttime ? 3600 : 0;
- }
-
- if (secs < 0 || tv->tv_usec < 0 || tv->tv_usec > 999999) {
- return (-1);
- }
-
- days = secs / SECDAY;
- rsec = secs % SECDAY;
-
- ct->dow = day_of_week(days);
-
- /* Subtract out whole years, counting them in i. */
- for (year = POSIX_BASE_YEAR; days >= days_in_year(year); year++)
- days -= days_in_year(year);
- ct->year = year;
-
- /* Subtract out whole months, counting them in i. */
- for (i = 1; days >= days_in_month(year, i); i++)
- days -= days_in_month(year, i);
- ct->mon = i;
-
- /* Days are what is left over (+1) from all that. */
- ct->day = days + 1;
-
- /* Hours, minutes, seconds are easy */
- ct->hour = rsec / 3600;
- rsec = rsec % 3600;
- ct->min = rsec / 60;
- rsec = rsec % 60;
- ct->sec = rsec;
- ct->usec = tv->tv_usec;
-
- return (0);
-}
-
-static const char *
-parse_number(const char *str, int digits, int *val)
-{
- const char *cp;
- const char *end;
-
- *val = 0;
- cp = str;
- end = str + digits;
- while (cp < end) {
- if (!isdigit((int) *cp)) {
- return (NULL);
- }
- *val *= 10;
- *val += (*cp - '0');
- cp++;
- }
- return (end);
-}
-
-/*
- * Parse the datetime string in RFC 3339 format. Some examples of valid
- * datetime strings are:
- * 2016-03-02T22:44:00 UTC time (implicit)
- * 2016-03-02T22:44:00Z UTC time (explicit)
- * 2016-03-02T22:44:00-08:00 PST timezone
- * 2016-03-02T22:44:00.1 fractional seconds
- * 2016-03-02T22:44:00.101+05:30 fractional seconds with timezone
- */
-int
-parse_datetime(const char *input, struct os_timeval *tv, struct os_timezone *tz)
-{
- int digits, sign;
- int off_hour, off_min;
- const char *cp;
- const char *ep;
- struct clocktime ct;
-
- bzero(&ct, sizeof(struct clocktime));
- bzero(tv, sizeof(struct os_timeval));
- bzero(tz, sizeof(struct os_timezone)); /* default to UTC time */
-
- cp = input;
- cp = parse_number(cp, 4, &ct.year);
- if (cp == NULL || *cp != '-') {
- goto err;
- }
-
- cp = parse_number(cp + 1, 2, &ct.mon);
- if (cp == NULL || *cp != '-') {
- goto err;
- }
-
- cp = parse_number(cp + 1, 2, &ct.day);
- if (cp == NULL || *cp != 'T') {
- goto err;
- }
-
- cp = parse_number(cp + 1, 2, &ct.hour);
- if (cp == NULL || *cp != ':') {
- goto err;
- }
-
- cp = parse_number(cp + 1, 2, &ct.min);
- if (cp == NULL || *cp != ':') {
- goto err;
- }
-
- cp = parse_number(cp + 1, 2, &ct.sec);
- if (cp == NULL) {
- goto err;
- }
-
- /* parse fractional seconds if specified */
- if (*cp == '.') {
- ep = ++cp;
- while (isdigit((int) *ep)) {
- ep++;
- }
- digits = ep - cp;
- if (digits <= 0 || digits > 6) {
- goto err;
- }
-
- cp = parse_number(cp, digits, &ct.usec);
- if (cp == NULL) {
- goto err;
- }
-
- /*
- * The number of digits in the fractional seconds determines
- * the resolution.
- *
- * .1 1 part out of 10 100000 usec
- * .01 1 part out of 100 10000 usec
- * .001 1 part out of 1000 1000 usec
- * .0001 1 part out of 10000 100 usec
- * .00001 1 part out of 100000 10 usec
- * .000001 1 part out of 1000000 1 usec
- */
- while (digits++ < 6) {
- ct.usec *= 10;
- }
- }
-
- if (*cp == 'Z' || *cp == 'z') {
- cp++;
- } else if (*cp == '+' || *cp == '-') {
- sign = (*cp == '+') ? +1 : -1;
- cp = parse_number(cp + 1, 2, &off_hour);
- if (cp == NULL || *cp != ':') {
- goto err;
- }
-
- cp = parse_number(cp + 1, 2, &off_min);
- if (cp == NULL) {
- goto err;
- }
-
- if (off_hour < 0 || off_hour > 23 || off_min < 0 || off_min > 59) {
- goto err;
- }
-
- /*
- * Allow time zone offsets of up to 18 hours from the GMT.
- * https://docs.oracle.com/javase/8/docs/api/java/time/ZoneOffset.html
- */
- tz->tz_minuteswest = off_hour * 60 + off_min;
- if (tz->tz_minuteswest > 18 * 60) {
- goto err;
- }
-
- /*
- * Positive GMT offsets (i.e. timezones to the east of GMT) are
- * represented with a negative 'tz_minuteswest' value.
- */
- if (sign > 0) {
- tz->tz_minuteswest = -tz->tz_minuteswest;
- }
- } else {
- /*
- * 'time offset' is not specified so date/time defaults to UTC.
- */
- }
-
- if (*cp != '\0') {
- goto err;
- }
-
- if (clocktime_to_timeval(&ct, tv) != 0) {
- goto err;
- }
-
- /* Convert localtime to utctime */
- tv->tv_sec += tz->tz_minuteswest * 60;
- tv->tv_sec -= tz->tz_dsttime ? 3600 : 0;
- return (0);
-err:
- return (-1);
-}
-
-int
-format_datetime(const struct os_timeval *tv, const struct os_timezone *tz,
- char *ostr, int olen)
-{
- char *cp;
- int rc, rlen, minswest;
- int off_hour, off_min, sign;
- struct clocktime ct;
-
- rc = timeval_to_clocktime(tv, tz, &ct);
- if (rc != 0) {
- goto err;
- }
-
- cp = ostr;
- rlen = olen;
-
- rc = snprintf(cp, rlen, "%04d-%02d-%02dT%02d:%02d:%02d",
- ct.year, ct.mon, ct.day, ct.hour, ct.min, ct.sec);
- cp += rc;
- rlen -= rc;
- if (rc < 0 || rlen <= 0) {
- goto err;
- }
-
- if (ct.usec != 0) {
- rc = snprintf(cp, rlen, ".%06d", ct.usec);
- cp += rc;
- rlen -= rc;
- if (rc < 0 || rlen <= 0) {
- goto err;
- }
- }
-
- if (tz != NULL) {
- minswest = tz->tz_minuteswest;
- if (tz->tz_dsttime) {
- minswest -= 60;
- }
- } else {
- minswest = 0;
- }
-
- if (minswest < 0) {
- sign = '+';
- minswest = -minswest;
- } else {
- sign = '-';
- }
-
- off_hour = minswest / 60;
- off_min = minswest % 60;
- if (off_hour || off_min) {
- rc = snprintf(cp, rlen, "%c%02d:%02d", sign, off_hour, off_min);
- cp += rc;
- rlen -= rc;
- if (rc < 0 || rlen <= 0) {
- goto err;
- }
- }
- return (0);
-
-err:
- return (-1);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/libs/util/src/mem.c
----------------------------------------------------------------------
diff --git a/libs/util/src/mem.c b/libs/util/src/mem.c
deleted file mode 100644
index 7cbe3d5..0000000
--- a/libs/util/src/mem.c
+++ /dev/null
@@ -1,166 +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 "os/os.h"
-
-/**
- * Mallocs a block of memory and initializes a mempool to use it.
- *
- * @param mempool The mempool to initialize.
- * @param num_blocks The total number of memory blocks in the
- * mempool.
- * @param block_size The size of each mempool entry.
- * @param name The name to give the mempool.
- * @param out_buf On success, this points to the malloced memory.
- * Pass NULL if you don't need this
- * information.
- *
- * @return 0 on success;
- * OS_ENOMEM on malloc failure;
- * Other OS code on unexpected error.
- */
-int
-mem_malloc_mempool(struct os_mempool *mempool, int num_blocks, int block_size,
- char *name, void **out_buf)
-{
- void *buf;
- int rc;
-
- block_size = OS_ALIGN(block_size, OS_ALIGNMENT);
-
- if (num_blocks > 0) {
- buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
- if (buf == NULL) {
- return OS_ENOMEM;
- }
- } else {
- buf = NULL;
- }
-
- rc = os_mempool_init(mempool, num_blocks, block_size, buf, name);
- if (rc != 0) {
- free(buf);
- return rc;
- }
-
- if (out_buf != NULL) {
- *out_buf = buf;
- }
-
- return 0;
-}
-
-/**
- * Mallocs a block of memory and initializes an mbuf pool to use it. The
- * specified block_size indicates the size of an mbuf acquired from the pool if
- * it does not contain a pkthdr.
- *
- * @param mempool The mempool to initialize.
- * @param mbuf_pool The mbuf pool to initialize.
- * @param num_blocks The total number of mbufs in the pool.
- * @param block_size The size of each mbuf.
- * @param name The name to give the mempool.
- * @param out_buf On success, this points to the malloced memory.
- * Pass NULL if you don't need this
- * information.
- *
- * @return 0 on success;
- * OS_ENOMEM on malloc failure;
- * Other OS code on unexpected error.
- */
-int
-mem_malloc_mbuf_pool(struct os_mempool *mempool,
- struct os_mbuf_pool *mbuf_pool, int num_blocks,
- int block_size, char *name,
- void **out_buf)
-{
- void *buf;
- int rc;
-
- block_size = OS_ALIGN(block_size + sizeof (struct os_mbuf), OS_ALIGNMENT);
-
- rc = mem_malloc_mempool(mempool, num_blocks, block_size, name, &buf);
- if (rc != 0) {
- return rc;
- }
-
- rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
- if (rc != 0) {
- free(buf);
- return rc;
- }
-
- if (out_buf != NULL) {
- *out_buf = buf;
- }
-
- return 0;
-}
-
-/**
- * Mallocs a block of memory and initializes an mbuf pool to use it. The
- * specified block_size indicates the size of an mbuf acquired from the pool if
- * it contains a pkthdr.
- *
- * @param mempool The mempool to initialize.
- * @param mbuf_pool The mbuf pool to initialize.
- * @param num_blocks The total number of mbufs in the pool.
- * @param block_size The size of each mbuf.
- * @param name The name to give the mempool.
- * @param out_buf On success, this points to the malloced memory.
- * Pass NULL if you don't need this
- * information.
- *
- * @return 0 on success;
- * OS_ENOMEM on malloc failure;
- * Other OS code on unexpected error.
- */
-int
-mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
- struct os_mbuf_pool *mbuf_pool, int num_blocks,
- int block_size, char *name,
- void **out_buf)
-{
- int rc;
-
- rc = mem_malloc_mbuf_pool(mempool, mbuf_pool, num_blocks,
- block_size + sizeof (struct os_mbuf_pkthdr),
- name, out_buf);
- return rc;
-}
-
-int
-mem_init_mbuf_pool(void *mem, struct os_mempool *mempool,
- struct os_mbuf_pool *mbuf_pool, int num_blocks,
- int block_size, char *name)
-{
- int rc;
-
- rc = os_mempool_init(mempool, num_blocks, block_size, mem, name);
- if (rc != 0) {
- return rc;
- }
-
- rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/include/imgmgr/imgmgr.h b/mgmt/imgmgr/include/imgmgr/imgmgr.h
new file mode 100644
index 0000000..4ec754c
--- /dev/null
+++ b/mgmt/imgmgr/include/imgmgr/imgmgr.h
@@ -0,0 +1,72 @@
+/**
+ * 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 _IMGMGR_H_
+#define _IMGMGR_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define IMGMGR_NMGR_OP_LIST 0
+#define IMGMGR_NMGR_OP_UPLOAD 1
+#define IMGMGR_NMGR_OP_BOOT 2
+#define IMGMGR_NMGR_OP_FILE 3
+#define IMGMGR_NMGR_OP_LIST2 4
+#define IMGMGR_NMGR_OP_BOOT2 5
+#define IMGMGR_NMGR_OP_CORELIST 6
+#define IMGMGR_NMGR_OP_CORELOAD 7
+
+#define IMGMGR_NMGR_MAX_MSG 400
+#define IMGMGR_NMGR_MAX_NAME 64
+#define IMGMGR_NMGR_MAX_VER 25 /* 255.255.65535.4294967295\0 */
+
+#define IMGMGR_HASH_LEN 32
+
+extern int boot_current_slot;
+
+void imgmgr_module_init(void);
+
+struct image_version;
+
+/*
+ * Parse version string in src, and fill in ver.
+ */
+int imgr_ver_parse(char *src, struct image_version *ver);
+
+/*
+ * Take version and convert it to string in dst.
+ */
+int imgr_ver_str(struct image_version *ver, char *dst);
+
+/*
+ * Given flash_map slot id, read in image_version and/or image hash.
+ */
+int imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash, uint32_t *flags);
+
+/*
+ * Returns version number of current image (if available).
+ */
+int imgr_my_version(struct image_version *ver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _IMGMGR_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bed47f0a/mgmt/imgmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/pkg.yml b/mgmt/imgmgr/pkg.yml
new file mode 100644
index 0000000..d514670
--- /dev/null
+++ b/mgmt/imgmgr/pkg.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.
+#
+
+pkg.name: mgmt/imgmgr
+pkg.description: Library for image uploading.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - boot/bootutil
+ - encoding/base64
+ - mgmt/mgmt
+ - sys/flash_map
+
+pkg.req_apis:
+ - newtmgr
+
+pkg.deps.IMGMGR_FS:
+ - fs/fs
+
+pkg.deps.IMGMGR_COREDUMP:
+ - sys/coredump
+
+pkg.deps.IMGMGR_SHELL:
+ - sys/shell
+
+pkg.init_function: imgmgr_module_init
+pkg.init_stage: 5