You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/05/19 16:51:16 UTC

[04/18] incubator-mynewt-core git commit: sys/coredump; initial coredumping. Intermediate commit.

sys/coredump; initial coredumping. Intermediate commit.


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/a7d054c1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a7d054c1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a7d054c1

Branch: refs/heads/develop
Commit: a7d054c1c171785cbd925ebe12e35d3d9aad4843
Parents: cdfe810
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:20:18 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 sys/coredump/include/coredump/coredump.h | 51 +++++++++++++++
 sys/coredump/pkg.yml                     | 30 +++++++++
 sys/coredump/src/coredump.c              | 94 +++++++++++++++++++++++++++
 3 files changed, 175 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d054c1/sys/coredump/include/coredump/coredump.h
----------------------------------------------------------------------
diff --git a/sys/coredump/include/coredump/coredump.h b/sys/coredump/include/coredump/coredump.h
new file mode 100644
index 0000000..1cf8b9b
--- /dev/null
+++ b/sys/coredump/include/coredump/coredump.h
@@ -0,0 +1,51 @@
+/**
+ * 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 __COREDUMP_H__
+#define __COREDUMP_H__
+
+#include <inttypes.h>
+
+#define COREDUMP_MAGIC              0x690c47c3
+
+/*
+ * Coredump TLV types.
+ */
+#define COREDUMP_TLV_IMAGE          1   /* SHA256 of image creating this */
+#define COREDUMP_TLV_MEM            2   /* Memory dump */
+#define COREDUMP_TLV_REGS           3   /* CPU registers */
+
+struct coredump_tlv {
+    uint8_t ct_type;
+    uint8_t _pad;
+    uint16_t ct_len;
+    uint32_t ct_off;
+};
+
+/*
+ * Corefile header.  All fields are in little endian byte order.
+ */
+struct coredump_header {
+    uint32_t ch_magic;
+    uint32_t ch_size;                   /* Size of everything */
+};
+
+void dump_core(void *regs, int regs_sz);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d054c1/sys/coredump/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/coredump/pkg.yml b/sys/coredump/pkg.yml
new file mode 100644
index 0000000..cb8787d
--- /dev/null
+++ b/sys/coredump/pkg.yml
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: sys/coredump
+pkg.description: Coredumps.
+pkg.keywords:
+    - flash
+    - core
+    - crash
+
+pkg.deps:
+    - hw/hal
+pkg.features:
+    - COREDUMP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d054c1/sys/coredump/src/coredump.c
----------------------------------------------------------------------
diff --git a/sys/coredump/src/coredump.c b/sys/coredump/src/coredump.c
new file mode 100644
index 0000000..97ef749
--- /dev/null
+++ b/sys/coredump/src/coredump.c
@@ -0,0 +1,94 @@
+/**
+ * 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 <bsp/bsp.h>
+
+#include <hal/flash_map.h>
+#include <bootutil/image.h>
+#include <imgmgr/imgmgr.h>
+#include <coredump/coredump.h>
+
+static void
+dump_core_tlv(const struct flash_area *fa, uint32_t *off,
+  struct coredump_tlv *tlv, void *data)
+{
+    flash_area_write(fa, *off, tlv, sizeof(*tlv));
+    *off += sizeof(*tlv);
+
+    flash_area_write(fa, *off, data, tlv->ct_len);
+    *off += tlv->ct_len;
+}
+
+extern char *__vector_tbl_reloc__, *__StackTop;
+
+void
+dump_core(void *regs, int regs_sz)
+{
+    struct coredump_header hdr;
+    struct coredump_tlv tlv;
+    const struct flash_area *fa;
+    struct image_version ver;
+    uint8_t hash[IMGMGR_HASH_LEN];
+    uint32_t off;
+
+    if (flash_area_open(FLASH_AREA_CORE, &fa)) {
+        return;
+    }
+
+    if (flash_area_read(fa, 0, &hdr, sizeof(hdr))) {
+        return;
+    }
+    if (hdr.ch_magic == COREDUMP_MAGIC) {
+        /*
+         * Don't override corefile.
+         */
+        return;
+    }
+
+    if (flash_area_erase(fa, 0, fa->fa_size)) {
+        return;
+    }
+
+    /*
+     * First put in data, followed by the header.
+     */
+    tlv.ct_type = COREDUMP_TLV_REGS;
+    tlv._pad = 0;
+    tlv.ct_len = regs_sz;
+    tlv.ct_off = 0;
+
+    off = sizeof(hdr);
+    dump_core_tlv(fa, &off, &tlv, regs);
+
+    if (imgr_read_info(bsp_imgr_current_slot(), &ver, hash) == 0) {
+        tlv.ct_type = COREDUMP_TLV_IMAGE;
+        tlv.ct_len = IMGMGR_HASH_LEN;
+
+        dump_core_tlv(fa, &off, &tlv, hash);
+    }
+
+    tlv.ct_type = COREDUMP_TLV_MEM;
+    tlv.ct_len = (uint32_t)&__StackTop - (uint32_t)&__vector_tbl_reloc__;
+    tlv.ct_off = (uint32_t)&__vector_tbl_reloc__;
+    dump_core_tlv(fa, &off, &tlv, &__vector_tbl_reloc__);
+
+    hdr.ch_magic = COREDUMP_MAGIC;
+    hdr.ch_size = off;
+
+    flash_area_write(fa, 0, &hdr, sizeof(hdr));
+}