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 2015/11/19 03:02:43 UTC

[1/4] incubator-mynewt-larva git commit: Add a routine for native targets, which can parse command line arguments to program. Use this to pass in file name for flash image.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 148a95ec9 -> 3289b68bc


Add a routine for native targets, which can parse command line
arguments to program. Use this to pass in file name for
flash image.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/8e907874
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/8e907874
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/8e907874

Branch: refs/heads/master
Commit: 8e907874fc6ab242db5256b6b3c59442641882c5
Parents: 148a95e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 18 17:54:11 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 18 17:54:11 2015 -0800

----------------------------------------------------------------------
 hw/mcu/native/include/mcu/mcu_sim.h | 23 ++++++++++++++++
 hw/mcu/native/src/hal_flash.c       | 11 ++++++++
 hw/mcu/native/src/hal_system.c      | 45 +++++++++++++++++++++++++++++++-
 3 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8e907874/hw/mcu/native/include/mcu/mcu_sim.h
----------------------------------------------------------------------
diff --git a/hw/mcu/native/include/mcu/mcu_sim.h b/hw/mcu/native/include/mcu/mcu_sim.h
new file mode 100644
index 0000000..7ab0842
--- /dev/null
+++ b/hw/mcu/native/include/mcu/mcu_sim.h
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 __MCU_SIM_H__
+#define __MCU_SIM_H__
+
+extern char *native_flash_file;
+
+void mcu_sim_parse_args(int argc, char **argv);
+
+#endif /* __MCU_SIM_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8e907874/hw/mcu/native/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_flash.c b/hw/mcu/native/src/hal_flash.c
index b33f906..5251e5b 100644
--- a/hw/mcu/native/src/hal_flash.c
+++ b/hw/mcu/native/src/hal_flash.c
@@ -18,8 +18,11 @@
 #include <assert.h>
 #include <string.h>
 #include <inttypes.h>
+#include <stdlib.h>
 #include "hal/hal_flash_int.h"
+#include "mcu/mcu_sim.h"
 
+char *native_flash_file;
 static FILE *file;
 
 static int native_flash_init(void);
@@ -244,6 +247,14 @@ native_flash_erase_sector(uint32_t sector_address)
 static int
 native_flash_init(void)
 {
+    if (native_flash_file) {
+        file = fopen(native_flash_file, "r+");
+        if (!file) {
+            file = fopen(native_flash_file, "w+");
+            assert(file);
+            flash_native_erase(0, native_flash_dev.hf_size);
+        }
+    }
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8e907874/hw/mcu/native/src/hal_system.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_system.c b/hw/mcu/native/src/hal_system.c
index 230faa2..96f7a6d 100644
--- a/hw/mcu/native/src/hal_system.c
+++ b/hw/mcu/native/src/hal_system.c
@@ -4,7 +4,7 @@
  * Licensed 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
@@ -13,11 +13,54 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
 
 #include "hal/hal_system.h"
+#include "mcu/mcu_sim.h"
 
 void
 system_reset(void)
 {
     while(1);
 }
+
+/*
+ * When running projects within simulator, it's useful to be able to
+ * pass operating info as parameters to simulator program.
+ * This routine is meant to parse those.
+ */
+static void
+usage(char *progname, int rc)
+{
+    const char msg[] =
+      "Usage: %s [-f flash_file]\n"
+      "     -f flash_file tells where binary flash file is located. It gets\n"
+      "        created if it doesn't already exist.\n";
+
+    write(fileno(stderr), msg, strlen(msg));
+    exit(rc);
+}
+
+void
+mcu_sim_parse_args(int argc, char **argv)
+{
+    int ch;
+    char *progname = argv[0];
+
+    while ((ch = getopt(argc, argv, "hf:")) != -1) {
+        switch (ch) {
+        case 'f':
+            native_flash_file = optarg;
+            break;
+        case 'h':
+            usage(progname, 0);
+            break;
+        default:
+            usage(progname, -1);
+            break;
+        }
+    }
+}


[4/4] incubator-mynewt-larva git commit: Add test project which uses lua egg.

Posted by ma...@apache.org.
Add test project which uses lua egg.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/3289b68b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/3289b68b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/3289b68b

Branch: refs/heads/master
Commit: 3289b68bc01cec1f0e0ef9a360eb87717e76449d
Parents: 1fbd70e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 18 18:01:09 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 18 18:01:09 2015 -0800

----------------------------------------------------------------------
 project/luatest/luatest.yml |   8 +++
 project/luatest/src/main.c  | 120 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3289b68b/project/luatest/luatest.yml
----------------------------------------------------------------------
diff --git a/project/luatest/luatest.yml b/project/luatest/luatest.yml
new file mode 100644
index 0000000..4513258
--- /dev/null
+++ b/project/luatest/luatest.yml
@@ -0,0 +1,8 @@
+project.name: luatest
+project.eggs:
+    - libs/os
+    - libs/elua/elua_base
+    - libs/shell
+    - libs/console/full
+    - libs/util
+    - libs/nffs

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3289b68b/project/luatest/src/main.c
----------------------------------------------------------------------
diff --git a/project/luatest/src/main.c b/project/luatest/src/main.c
new file mode 100755
index 0000000..44e0d10
--- /dev/null
+++ b/project/luatest/src/main.c
@@ -0,0 +1,120 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <os/os.h>
+#include <hal/hal_flash.h>
+#include <console/console.h>
+#include <shell/shell.h>
+#include <elua_base/elua.h>
+#include <nffs/nffs.h>
+#include <util/flash_map.h>
+#ifdef ARCH_sim
+#include <mcu/mcu_sim.h>
+#endif
+
+/* Init all tasks */
+int init_tasks(void);
+
+/* Shell */
+#define SHELL_TASK_PRIO      (8)
+#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(8192))
+static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
+static struct shell_cmd lua_shell_cmd;
+
+/* NFFS */
+#define NFFS_AREA_MAX		16
+
+static int
+lua_cmd(int argc, char **argv)
+{
+    lua_main(argc, argv);
+    return 0;
+}
+
+static void
+create_script_file(void)
+{
+    char filename[] = "/foobar";
+    char script[] = "print \"eat my shorts\"\n";
+    struct nffs_file *nf;
+    int rc;
+
+    rc = nffs_open(filename, NFFS_ACCESS_READ, &nf);
+    if (rc) {
+        rc = nffs_open(filename, NFFS_ACCESS_WRITE, &nf);
+        assert(rc == 0);
+        rc = nffs_write(nf, script, strlen(script));
+        assert(rc == 0);
+    }
+    nffs_close(nf);
+}
+
+/**
+ * main
+ *
+ * The main function for the project. This function initializes the os, calls
+ * init_tasks to initialize tasks (and possibly other objects), then starts the
+ * OS. We should not return from os start.
+ *
+ * @return int NOTE: this function should never return!
+ */
+int
+main(int argc, char **argv)
+{
+    int rc;
+    struct nffs_area_desc descs[NFFS_AREA_MAX];
+    int cnt;
+
+#ifdef ARCH_sim
+    mcu_sim_parse_args(argc, argv);
+#endif
+
+    rc = hal_flash_init();
+    assert(rc == 0);
+
+    /* Initialize OS */
+    os_init();
+
+    /* Init tasks */
+    shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE);
+    console_init(shell_console_rx_cb);
+
+    rc = shell_cmd_register(&lua_shell_cmd, "lua", lua_cmd);
+    assert(rc == 0);
+
+    nffs_init();
+
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
+    assert(rc == 0);
+
+    if (nffs_detect(descs) == NFFS_ECORRUPT) {
+        rc = nffs_format(descs);
+        assert(rc == 0);
+    }
+
+    create_script_file();
+
+    /* Start the OS */
+    os_start();
+
+    /* os start should never return. If it does, this should be an error */
+    assert(0);
+
+    return rc;
+}
+


[3/4] incubator-mynewt-larva git commit: Parse command line args for blinky too.

Posted by ma...@apache.org.
Parse command line args for blinky too.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/1fbd70ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/1fbd70ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/1fbd70ee

Branch: refs/heads/master
Commit: 1fbd70ee7f4257a9d6a27454500e70110736016f
Parents: 36edded
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 18 17:59:17 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 18 17:59:17 2015 -0800

----------------------------------------------------------------------
 project/blinky/src/main.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/1fbd70ee/project/blinky/src/main.c
----------------------------------------------------------------------
diff --git a/project/blinky/src/main.c b/project/blinky/src/main.c
index 9296193..0ca3998 100755
--- a/project/blinky/src/main.c
+++ b/project/blinky/src/main.c
@@ -16,12 +16,15 @@
 #include "os/os.h"
 #include "bsp/bsp.h"
 #include "hal/hal_gpio.h"
-#include "console/console.h" 
+#include "console/console.h"
 #include "shell/shell.h"
 #include "util/log.h"
-#include "util/stats.h" 
+#include "util/stats.h"
 #include <assert.h>
 #include <string.h>
+#ifdef ARCH_sim
+#include <mcu/mcu_sim.h>
+#endif
 
 /* Init all tasks */
 volatile int tasks_initialized;
@@ -135,11 +138,15 @@ init_tasks(void)
  * @return int NOTE: this function should never return!
  */
 int
-main(void)
+main(int argc, char **argv)
 {
     uint8_t entry[128];
     int rc;
 
+#ifdef ARCH_sim
+    mcu_sim_parse_args(argc, argv);
+#endif
+
     cbmem_init(&log_mem, log_buf, sizeof(log_buf));
     util_log_cbmem_handler_init(&log_mem_handler, &log_mem);
     util_log_register("log", &my_log, &log_mem_handler);


[2/4] incubator-mynewt-larva git commit: -d option to ffs2native, which takes in directory name as arg, and append files from it to NFFS. Can use this to create flash images when testing other targets.

Posted by ma...@apache.org.
-d option to ffs2native, which takes in directory name as arg,
and append files from it to NFFS. Can use this to create flash
images when testing other targets.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/36eddede
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/36eddede
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/36eddede

Branch: refs/heads/master
Commit: 36eddede58ee03ca510fc40a3982f958c58537dc
Parents: 8e90787
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 18 17:56:28 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 18 17:56:28 2015 -0800

----------------------------------------------------------------------
 project/ffs2native/ffs2native.yml |   1 +
 project/ffs2native/src/main.c     | 151 +++++++++++++++++++++++++++------
 2 files changed, 128 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/36eddede/project/ffs2native/ffs2native.yml
----------------------------------------------------------------------
diff --git a/project/ffs2native/ffs2native.yml b/project/ffs2native/ffs2native.yml
index 633b552..e1cbc96 100644
--- a/project/ffs2native/ffs2native.yml
+++ b/project/ffs2native/ffs2native.yml
@@ -2,4 +2,5 @@ project.name: ffs2native
 project.eggs: 
     - libs/os
     - libs/nffs
+    - libs/console/full
     - hw/hal

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/36eddede/project/ffs2native/src/main.c
----------------------------------------------------------------------
diff --git a/project/ffs2native/src/main.c b/project/ffs2native/src/main.c
index aefeea0..b960482 100644
--- a/project/ffs2native/src/main.c
+++ b/project/ffs2native/src/main.c
@@ -4,7 +4,7 @@
  * Licensed 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
@@ -23,16 +23,24 @@
 #include <assert.h>
 #include <stdio.h>
 #include <inttypes.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <strings.h>
 #include "../src/nffs_priv.h"
-#include "os/queue.h"
-#include "nffs/nffs.h"
-#include "hal/hal_flash.h"
+#include <os/queue.h>
+#include <nffs/nffs.h>
+#include <hal/hal_flash.h>
+#include <util/flash_map.h>
+#ifdef ARCH_sim
+#include <mcu/mcu_sim.h>
+#endif
+
+static const char *copy_in_dir;
+
+#define MAX_AREAS	16
+static struct nffs_area_desc area_descs[MAX_AREAS];
 
-static const struct nffs_area_desc area_descs[] = {
-    { 0x00020000, 128 * 1024 },
-    { 0x00040000, 128 * 1024 },
-    { 0, 0 },
-};
+static void usage(int rc);
 
 static void
 copyfs(FILE *fp)
@@ -41,14 +49,14 @@ copyfs(FILE *fp)
     int rc;
     int c;
 
-    dst_addr = area_descs[0].fad_offset;
+    dst_addr = area_descs[0].nad_offset;
     while (1) {
         c = getc(fp);
         if (c == EOF) {
             return;
         }
 
-        rc = flash_write(dst_addr, &c, 1);
+        rc = hal_flash_write(area_descs[0].nad_flash_id, dst_addr, &c, 1);
         assert(rc == 0);
 
         dst_addr++;
@@ -67,15 +75,15 @@ print_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
     rc = nffs_inode_from_entry(&inode, inode_entry);
     assert(rc == 0);
 
-    nffs_flash_loc_expand(inode_entry->fie_hash_entry.fhe_flash_loc,
+    nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
                          &area_idx, &area_offset);
 
     rc = nffs_flash_read(area_idx,
                          area_offset + sizeof (struct nffs_disk_inode),
-                         name, inode.fi_filename_len);
+                         name, inode.ni_filename_len);
     assert(rc == 0);
 
-    name[inode.fi_filename_len] = '\0';
+    name[inode.ni_filename_len] = '\0';
 
     printf("%*s%s\n", indent, "", name);
 }
@@ -87,8 +95,8 @@ process_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
 
     print_inode_entry(inode_entry, indent);
 
-    if (nffs_hash_id_is_dir(inode_entry->fie_hash_entry.fhe_id)) {
-        SLIST_FOREACH(child, &inode_entry->fie_child_list, fie_sibling_next) {
+    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
+        SLIST_FOREACH(child, &inode_entry->nie_child_list, nie_sibling_next) {
             process_inode_entry(child, indent + 2);
         }
     }
@@ -100,25 +108,120 @@ printfs(void)
     process_inode_entry(nffs_root_dir, 0);
 }
 
-int
-main(int argc, char **argv)
+void
+copy_in_file(char *src, char *dst)
 {
+    struct nffs_file *nf;
     FILE *fp;
     int rc;
+    char data[32];
 
-    assert(argc >= 2);
+    rc = nffs_open(dst, NFFS_ACCESS_WRITE, &nf);
+    assert(rc == 0);
 
-    fp = fopen(argv[1], "rb");
-    assert(fp != NULL);
+    fp = fopen(src, "r");
+    if (!fp) {
+        perror("fopen()");
+        assert(0);
+    }
+    while ((rc = fread(data, 1, sizeof(data), fp))) {
+        rc = nffs_write(nf, data, rc);
+        assert(rc == 0);
+    }
+    rc = nffs_close(nf);
+    assert(rc == 0);
+}
 
-    copyfs(fp);
+void
+copy_in_directory(const char *src, const char *dst)
+{
+    DIR *dr;
+    struct dirent *entry;
+    char src_name[1024];
+    char dst_name[1024];
+    int rc;
 
-    rc = nffs_init();
+    dr = opendir(src);
+    if (!dr) {
+        perror("opendir");
+        usage(1);
+    }
+    while ((entry = readdir(dr))) {
+            snprintf(src_name, sizeof(src_name), "%s/%s", src, entry->d_name);
+            snprintf(dst_name, sizeof(dst_name), "%s/%s", dst, entry->d_name);
+        if (entry->d_type == DT_DIR &&
+          !strcmp(entry->d_name, ".") && !strcmp(entry->d_name, "..")) {
+            copy_in_directory(src_name, dst_name);
+            rc = nffs_mkdir(dst_name);
+            assert(rc == 0);
+        } else if (entry->d_type == DT_REG) {
+            copy_in_file(src_name, dst_name);
+        } else {
+            printf("Skipping %s\n", src_name);
+        }
+    }
+    closedir(dr);
+}
+
+static void
+usage(int rc)
+{
+    printf("Improper use\n");
+    exit(rc);
+}
+
+int
+main(int argc, char **argv)
+{
+    FILE *fp;
+    int rc;
+    int ch;
+    int cnt;
+
+    while ((ch = getopt(argc, argv, "c:d:f:")) != -1) {
+        switch (ch) {
+        case 'c':
+            fp = fopen(optarg, "rb");
+            assert(fp != NULL);
+            copyfs(fp);
+            fclose(fp);
+            break;
+        case 'd':
+            copy_in_dir = optarg;
+            break;
+        case 'f':
+            native_flash_file = optarg;
+            break;
+        case '?':
+        default:
+            usage(0);
+        }
+    }
+
+    os_init();
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, area_descs);
     assert(rc == 0);
 
-    rc = nffs_detect(area_descs);
+    rc = hal_flash_init();
     assert(rc == 0);
 
+    rc = nffs_init();
+    assert(rc == 0);
+
+    if (copy_in_dir) {
+        /*
+         * Build filesystem from contents of directory
+         */
+        rc = nffs_format(area_descs);
+        assert(rc == 0);
+        copy_in_directory(copy_in_dir, "/");
+    } else {
+        rc = nffs_detect(area_descs);
+        if (rc) {
+            printf("nffs_detect() failed\n");
+            exit(0);
+        }
+    }
     printfs();
 
     return 0;