diff options
author | px4dev <px4@purgatory.org> | 2012-10-13 00:08:02 -0700 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-10-13 00:08:02 -0700 |
commit | 0ccaa1330bf0bcb6fd7ab6b966470f8e2f6c4275 (patch) | |
tree | de4f04aac9a97274d706d564fc61e798ac1033ab /apps/system | |
parent | d62ec78ab835153ef3ba480a5a4110465ba34372 (diff) | |
parent | e4ccbe7508fd31b76790986fc654dc588efb9dfe (diff) | |
download | px4-firmware-0ccaa1330bf0bcb6fd7ab6b966470f8e2f6c4275.tar.gz px4-firmware-0ccaa1330bf0bcb6fd7ab6b966470f8e2f6c4275.tar.bz2 px4-firmware-0ccaa1330bf0bcb6fd7ab6b966470f8e2f6c4275.zip |
Merge branch 'master' of file:///Users/Shared/NuttX
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5231 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/system')
-rw-r--r-- | apps/system/Kconfig | 20 | ||||
-rw-r--r-- | apps/system/Make.defs | 17 | ||||
-rw-r--r-- | apps/system/Makefile | 2 | ||||
-rw-r--r-- | apps/system/free/free.c | 80 | ||||
-rw-r--r-- | apps/system/i2c/Makefile | 2 | ||||
-rw-r--r-- | apps/system/install/install.c | 606 | ||||
-rw-r--r-- | apps/system/readline/readline.c | 2 |
7 files changed, 414 insertions, 315 deletions
diff --git a/apps/system/Kconfig b/apps/system/Kconfig index 44bf5a2e6..d4d434665 100644 --- a/apps/system/Kconfig +++ b/apps/system/Kconfig @@ -3,7 +3,7 @@ # see misc/tools/kconfig-language.txt. # -menu "Custom free memory command" +menu "Custom Free Memory Command" source "$APPSDIR/system/free/Kconfig" endmenu @@ -15,6 +15,22 @@ menu "FLASH Program Installation" source "$APPSDIR/system/install/Kconfig" endmenu -menu "readline() support" +menu "readline()" source "$APPSDIR/system/readline/Kconfig" endmenu + +menu "Power Off" +source "$APPSDIR/system/poweroff/Kconfig" +endmenu + +menu "RAMTRON" +source "$APPSDIR/system/ramtron/Kconfig" +endmenu + +menu "SD Card" +source "$APPSDIR/system/sdcard/Kconfig" +endmenu + +menu "Sysinfo" +source "$APPSDIR/system/sysinfo/Kconfig" +endmenu diff --git a/apps/system/Make.defs b/apps/system/Make.defs index a4aea2d31..3d10f84e5 100644 --- a/apps/system/Make.defs +++ b/apps/system/Make.defs @@ -49,3 +49,20 @@ endif ifeq ($(CONFIG_SYSTEM_READLINE),y) CONFIGURED_APPS += system/readline endif + +ifeq ($(CONFIG_SYSTEM_POWEROFF),y) +CONFIGURED_APPS += system/poweroff +endif + +ifeq ($(CONFIG_SYSTEM_RAMTRON),y) +CONFIGURED_APPS += system/ramtron +endif + +ifeq ($(CONFIG_SYSTEM_SDCARD),y) +CONFIGURED_APPS += system/sdcard +endif + +ifeq ($(CONFIG_SYSTEM_SYSINFO),y) +CONFIGURED_APPS += system/sysinfo +endif + diff --git a/apps/system/Makefile b/apps/system/Makefile index 73eb60d15..d64bb54c6 100644 --- a/apps/system/Makefile +++ b/apps/system/Makefile @@ -37,7 +37,7 @@ # Sub-directories containing system task -SUBDIRS = free i2c install readline +SUBDIRS = free i2c install readline poweroff ramtron sdcard sysinfo # Create the list of installed runtime modules (INSTALLED_DIRS) diff --git a/apps/system/free/free.c b/apps/system/free/free.c index 3d9698ecb..c44cd5e22 100644 --- a/apps/system/free/free.c +++ b/apps/system/free/free.c @@ -33,57 +33,65 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include <nuttx/config.h> #include <nuttx/progmem.h> #include <stdio.h> #include <stdlib.h> - /**************************************************************************** * Private Functions ****************************************************************************/ - -/* \todo Max block size only works on uniform prog mem */ - -void free_getprogmeminfo(struct mallinfo * mem) + +/* TODO Max block size only works on uniform prog mem */ + +static void free_getprogmeminfo(struct mallinfo * mem) { - uint16_t page = 0, stpage = 0xFFFF; - uint16_t pagesize = 0; - int status; - - mem->arena = 0; - mem->fordblks = 0; - mem->uordblks = 0; - mem->mxordblk = 0; - - for (status=0, page=0; status >= 0; page++) { - - status = up_progmem_ispageerased(page); - pagesize = up_progmem_pagesize(page); - - mem->arena += pagesize; - - /* Is this beginning of new free space section */ - if (status == 0) { - if (stpage == 0xFFFF) stpage = page; - mem->fordblks += pagesize; + uint16_t page = 0, stpage = 0xFFFF; + uint16_t pagesize = 0; + int status; + + mem->arena = 0; + mem->fordblks = 0; + mem->uordblks = 0; + mem->mxordblk = 0; + + for (status=0, page=0; status >= 0; page++) + { + status = up_progmem_ispageerased(page); + pagesize = up_progmem_pagesize(page); + + mem->arena += pagesize; + + /* Is this beginning of new free space section */ + + if (status == 0) + { + if (stpage == 0xFFFF) stpage = page; + mem->fordblks += pagesize; } - else if (status != 0) { - mem->uordblks += pagesize; - - if (stpage != 0xFFFF && up_progmem_isuniform()) { - stpage = page - stpage; - if (stpage > mem->mxordblk) - mem->mxordblk = stpage; - stpage = 0xFFFF; + else if (status != 0) + { + mem->uordblks += pagesize; + + if (stpage != 0xFFFF && up_progmem_isuniform()) + { + stpage = page - stpage; + if (stpage > mem->mxordblk) + { + mem->mxordblk = stpage; + } + stpage = 0xFFFF; } } } - - mem->mxordblk *= pagesize; -} + mem->mxordblk *= pagesize; +} /**************************************************************************** * Public Functions diff --git a/apps/system/i2c/Makefile b/apps/system/i2c/Makefile index 845c149f6..00db91bb7 100644 --- a/apps/system/i2c/Makefile +++ b/apps/system/i2c/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/system/i2c +# apps/system/i2c/Makefile # # Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <gnutt@nuttx.org> diff --git a/apps/system/install/install.c b/apps/system/install/install.c index 2f11c6434..fd14b7a6f 100644 --- a/apps/system/install/install.c +++ b/apps/system/install/install.c @@ -33,6 +33,10 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include <nuttx/config.h> #include <nuttx/progmem.h> #include <sys/stat.h> @@ -43,9 +47,8 @@ #include <string.h> #include <errno.h> - /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ #define ACTION_INSTALL 0x01 @@ -55,12 +58,11 @@ #define INSTALL_PROGRAMBLOCKSIZE 1024 - /**************************************************************************** * Private data ****************************************************************************/ -const char *install_help = +static const char *install_help = "Installs XIP program into flash and creates a start-up script in the\n" "destination directory.\n\n" "Usage:\t%s [options] source-file.xip destination-directory\n\n" @@ -72,341 +74,397 @@ const char *install_help = "\t--force\t\t\tReplaces existing installation\n" "\t--start <page>\t\tInstalls application at or after <page>\n" "\t--margin <pages>\tLeave some free space after the kernel (default 16)\n"; - -const char *install_script_text = + +static const char *install_script_text = "# XIP stacksize=%x priority=%x size=%x\n"; - -const char *install_script_exec = + +static const char *install_script_exec = "exec 0x%x\n"; - - + /**************************************************************************** * Private functions ****************************************************************************/ -int install_getstartpage(int startpage, int pagemargin, int desiredsize) +static int install_getstartpage(int startpage, int pagemargin, int desiredsize) { - uint16_t page = 0, stpage = 0xFFFF; - uint16_t pagesize = 0; - int maxlen = -1; - int maxlen_start = 0xFFFF; - int status; - - for (status=0, page=0; status >= 0; page++) { - - status = up_progmem_ispageerased(page); - pagesize = up_progmem_pagesize(page); - - /* Is this beginning of new free space section */ - if (status == 0) { - if (stpage == 0xFFFF) stpage = page; + uint16_t page = 0, stpage = 0xffff; + uint16_t pagesize = 0; + int maxlen = -1; + int maxlen_start = 0xffff; + int status; + + for (status=0, page=0; status >= 0; page++) + { + status = up_progmem_ispageerased(page); + pagesize = up_progmem_pagesize(page); + + /* Is this beginning of new free space section */ + + if (status == 0) + { + if (stpage == 0xffff) stpage = page; } - else if (status != 0) { - - if (stpage != 0xFFFF) { - - if ( (page - stpage) > maxlen) { + else if (status != 0) + { + if (stpage != 0xffff) + { + if ((page - stpage) > maxlen) + { + if (maxlen==-1) + { + /* First time found sth? */ + + stpage += pagemargin; + maxlen = 0; + } - if (maxlen==-1) { /* First time found sth? */ - stpage += pagemargin; - maxlen = 0; + if(stpage < startpage) + { + stpage = startpage; } - - if(stpage < startpage) - stpage = startpage; - - if (page > stpage) { - maxlen = page - stpage; - maxlen_start = stpage; + + if (page > stpage) + { + maxlen = page - stpage; + maxlen_start = stpage; } - - if (maxlen*pagesize >= desiredsize) { - /* printf("Found page at %d ... %d\n", stpage, page); */ - return maxlen_start*pagesize; + + if (maxlen*pagesize >= desiredsize) + { + /* printf("Found page at %d ... %d\n", stpage, page); */ + return maxlen_start*pagesize; } } - - stpage = 0xFFFF; + + stpage = 0xffff; } } } - - /* Requested space is not available */ - - return -1; -} + /* Requested space is not available */ + + return -1; +} -int install_programflash(int startaddr, const char *source) +static int install_programflash(int startaddr, const char *source) { - int status; - int count; - int totalsize = 0; - char *buf; - FILE *fp; - - if ( (buf = malloc(INSTALL_PROGRAMBLOCKSIZE)) == NULL ) - return -errno; - - if ( (fp=fopen(source, "r")) ) { - do { - count = fread(buf, 1, INSTALL_PROGRAMBLOCKSIZE, fp); - - if ( (status = up_progmem_write(startaddr, buf, count)) < 0) { - totalsize = status; - break; + int status; + int count; + int totalsize = 0; + char *buf; + FILE *fp; + + if ((buf = malloc(INSTALL_PROGRAMBLOCKSIZE)) == NULL) + { + return -ENOMEM; + } + + if ((fp = fopen(source, "r"))) + { + do + { + count = fread(buf, 1, INSTALL_PROGRAMBLOCKSIZE, fp); + + if ((status = up_progmem_write(startaddr, buf, count)) < 0) + { + totalsize = status; + break; } - - startaddr += count; - totalsize += count; + + startaddr += count; + totalsize += count; } - while(count); + while(count); + } + else + { + totalsize = -errno; } - else totalsize = -errno; - - fclose(fp); - free(buf); - - return totalsize; -} + fclose(fp); + free(buf); -void install_getscriptname(char *scriptname, const char *progname, const char *destdir) -{ - const char * progonly; - - /* I.e. as /usr/bin */ - strcpy(scriptname, destdir); - - /* extract from i.e. /sdcard/demo -> /demo, together with / */ - progonly = strrchr(progname, '/'); - strcat(scriptname, progonly); + return totalsize; } - -int install_getprogsize(const char *progname) +static void install_getscriptname(char *scriptname, const char *progname, const char *destdir) { - struct stat fileinfo; - - if ( stat(progname, &fileinfo) < 0 ) - return -1; - - return fileinfo.st_size; + const char * progonly; + + /* I.e. as /usr/bin */ + + strcpy(scriptname, destdir); + + /* extract from i.e. /sdcard/demo -> /demo, together with / */ + + progonly = strrchr(progname, '/'); + strcat(scriptname, progonly); } +static int install_getprogsize(const char *progname) +{ + struct stat fileinfo; + + if (stat(progname, &fileinfo) < 0) + { + return -1; + } + + return fileinfo.st_size; +} -int install_alreadyexists(const char *scriptname) +static int install_alreadyexists(const char *scriptname) { - FILE *fp; - - if ( (fp=fopen(scriptname, "r"))==NULL ) - return 0; - - fclose(fp); + FILE *fp; + + if ((fp = fopen(scriptname, "r")) == NULL) + { + return 0; + } + + fclose(fp); return 1; } - -int install_createscript(int addr, int stacksize, int progsize, - int priority, const char *scriptname) +static int install_createscript(int addr, int stacksize, int progsize, + int priority, const char *scriptname) { - FILE *fp; - - if ( (fp=fopen(scriptname, "w+"))==NULL ) - return -errno; - - fprintf(fp, install_script_text, stacksize, priority, progsize); - fprintf(fp, install_script_exec, addr); - - fflush(fp); - fclose(fp); - - return 0; -} + FILE *fp; + + if ((fp = fopen(scriptname, "w+")) == NULL) + { + return -errno; + } + fprintf(fp, install_script_text, stacksize, priority, progsize); + fprintf(fp, install_script_exec, addr); -int install_getlasthexvalue(FILE *fp, char delimiter) + fflush(fp); + fclose(fp); + + return 0; +} + +static int install_getlasthexvalue(FILE *fp, char delimiter) { - char buf[128]; - char *p; - - if (fgets(buf, 127, fp)) { - if ( (p = strrchr(buf, delimiter)) ) { - return strtol(p+1, NULL, 16); + char buf[128]; + char *p; + + if (fgets(buf, 127, fp)) + { + if ((p = strrchr(buf, delimiter))) + { + return strtol(p+1, NULL, 16); } } - return -1; -} + return -1; +} -int install_remove(const char *scriptname) +static int install_remove(const char *scriptname) { - FILE *fp; - int progsize, addr, freedsize; - uint16_t page; - int status = 0; - - /* Parse script */ - - if ( (fp=fopen(scriptname, "r")) ) { - progsize = install_getlasthexvalue(fp,'='); - addr = install_getlasthexvalue(fp,' '); - freedsize = progsize; + FILE *fp; + int progsize, addr, freedsize; + uint16_t page; + int status = 0; + + /* Parse script */ + + if ((fp = fopen(scriptname, "r"))) + { + progsize = install_getlasthexvalue(fp,'='); + addr = install_getlasthexvalue(fp,' '); + freedsize = progsize; + } + else + { + return -errno; + } + + fclose(fp); + + /* Remove pages */ + + if (progsize <= 0 || addr <= 0) + { + return -EIO; } - else return -errno; - - fclose(fp); - - /* Remove pages */ - - if (progsize <= 0 || addr <= 0) - return -EIO; - - do { - if ((page = up_progmem_getpage(addr)) < 0) { - status = -page; - break; + + do + { + if ((page = up_progmem_getpage(addr)) < 0) + { + status = -page; + break; } - - if ( up_progmem_erasepage(page) < 0) { - status = -page; - break; + + if (up_progmem_erasepage(page) < 0) + { + status = -page; + break; } - - addr += up_progmem_pagesize(page); - progsize -= up_progmem_pagesize(page); - - } while(progsize > 0); - - if (status < 0) return status; - - /* Remove script file */ - - if (unlink(scriptname) < 0) return -errno; - - return freedsize; + + addr += up_progmem_pagesize(page); + progsize -= up_progmem_pagesize(page); + + } + while(progsize > 0); + + if (status < 0) + { + return status; + } + + /* Remove script file */ + + if (unlink(scriptname) < 0) + { + return -errno; + } + + return freedsize; } /**************************************************************************** - * Start + * Public Functions ****************************************************************************/ int install_main(int argc, char *argv[]) { - int i; - int progsize; - int scrsta; - int stacksize = 4096; - int priority = SCHED_PRIORITY_DEFAULT; - int pagemargin = 16; - int startpage = 0; - int startaddr = 0; - int action = ACTION_INSTALL; - char scriptname[128]; - - /* Supported? */ - - if ( !up_progmem_isuniform() ) { - fprintf(stderr, "Error: install supports uniform organization only.\n"); - return -1; + int i; + int progsize; + int scrsta; + int stacksize = 4096; + int priority = SCHED_PRIORITY_DEFAULT; + int pagemargin = 16; + int startpage = 0; + int startaddr = 0; + int action = ACTION_INSTALL; + char scriptname[128]; + + /* Supported? */ + + if (!up_progmem_isuniform()) + { + fprintf(stderr, "Error: install supports uniform organization only.\n"); + return -1; } - - /* Parse arguments */ - - for (i=1; i<argc; i++) { - if (argv[i][0]=='-' && argv[i][1]=='-' && i<=argc) { - - if (strcmp(argv[i]+2, "stack")==0) { - stacksize = atoi(argv[++i]); + + /* Parse arguments */ + + for (i=1; i<argc; i++) + { + if (argv[i][0]=='-' && argv[i][1]=='-' && i<=argc) + { + if (strcmp(argv[i]+2, "stack")==0) + { + stacksize = atoi(argv[++i]); } - else if (strcmp(argv[i]+2, "priority")==0) { - priority = atoi(argv[++i]); + else if (strcmp(argv[i]+2, "priority")==0) + { + priority = atoi(argv[++i]); } - else if (strcmp(argv[i]+2, "start")==0) { - startpage = atoi(argv[++i]); + else if (strcmp(argv[i]+2, "start")==0) + { + startpage = atoi(argv[++i]); } - else if (strcmp(argv[i]+2, "margin")==0) { - pagemargin = atoi(argv[++i]); + else if (strcmp(argv[i]+2, "margin")==0) + { + pagemargin = atoi(argv[++i]); } - else if (strcmp(argv[i]+2, "remove")==0) { - action = ACTION_REMOVE; + else if (strcmp(argv[i]+2, "remove")==0) + { + action = ACTION_REMOVE; } - else if (strcmp(argv[i]+2, "force")==0) { - action = ACTION_REINSTALL; + else if (strcmp(argv[i]+2, "force")==0) + { + action = ACTION_REINSTALL; } - else fprintf(stderr, "Unknown option: %s\n", argv[i]); + else fprintf(stderr, "Unknown option: %s\n", argv[i]); + } + else + { + break; } - else break; } - - /* Do the job */ - - switch(action & 1) { - - case ACTION_REMOVE: - if (i > argc-1) { - action = ACTION_INSUFPARAM; - break; /* are there sufficient parameters */ - } - if ( (scrsta=install_remove(argv[i])) < 0) { - fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta) ); + + /* Do the job */ + + switch(action & 1) + { + case ACTION_REMOVE: + if (i > argc-1) + { + action = ACTION_INSUFPARAM; + break; /* are there sufficient parameters */ + } + + if ((scrsta=install_remove(argv[i])) < 0) + { + fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta)); + return -1; + } + + printf("Removed %s and freed %d bytes\n", argv[i], scrsta); + return 0; + + case ACTION_INSTALL: + if (i > argc-2) + { + action = ACTION_INSUFPARAM; + break; /* are there sufficient parameters */ + } + + install_getscriptname(scriptname, argv[i], argv[i+1]); + + /* script-exists? */ + + if (install_alreadyexists(scriptname) == 1) + { + if (action != ACTION_REINSTALL) + { + fprintf(stderr, "Program with that name already exists.\n"); + return -EEXIST; + } + + if ((scrsta = install_remove(scriptname)) < 0) + { + fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta)); return -1; - } - printf("Removed %s and freed %d bytes\n", argv[i], scrsta); - return 0; - - - case ACTION_INSTALL: - if (i > argc-2) { - action = ACTION_INSUFPARAM; - break; /* are there sufficient parameters */ - } - - install_getscriptname(scriptname, argv[i], argv[i+1]); - - // script-exists? - if (install_alreadyexists(scriptname)==1) { - - if (action != ACTION_REINSTALL) { - fprintf(stderr, "Program with that name already exists.\n"); - return -EEXIST; - } - - if ( (scrsta=install_remove(scriptname)) < 0) { - fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta) ); - return -1; - } - - printf("Replacing %s\n", scriptname); - } - - startaddr = install_getstartpage(startpage, pagemargin, install_getprogsize(argv[i]) ); - if (startpage < 0) { - fprintf(stderr, "Not enough memory\n"); - return -ENOMEM; - } - - if ( (progsize = install_programflash(startaddr, argv[i])) <= 0) { - fprintf(stderr, "Error writing program memory: %s\n" + } + + printf("Replacing %s\n", scriptname); + } + + startaddr = install_getstartpage(startpage, pagemargin, install_getprogsize(argv[i])); + if (startpage < 0) + { + fprintf(stderr, "Not enough memory\n"); + return -ENOMEM; + } + + if ((progsize = install_programflash(startaddr, argv[i])) <= 0) + { + fprintf(stderr, "Error writing program memory: %s\n" "Note: Flash pages are not released, so you may try again and program will be\n" - " written in other pages.\n", strerror(-progsize) ); - - return -EIO; - } - if ( (scrsta = install_createscript(startaddr, stacksize, progsize, - priority, scriptname)) < 0) { - fprintf(stderr, "Error writing program script at %s: %s\n", - argv[i+1], strerror(-scrsta) ); - return -EIO; - } - - printf("Installed application of size %d bytes to program memory [%xh - %xh].\n", + " written in other pages.\n", strerror(-progsize)); + return -EIO; + } + + if ((scrsta = install_createscript(startaddr, stacksize, progsize, + priority, scriptname)) < 0) + { + fprintf(stderr, "Error writing program script at %s: %s\n", + argv[i+1], strerror(-scrsta)); + return -EIO; + } + + printf("Installed application of size %d bytes to program memory [%xh - %xh].\n", progsize, startaddr, startaddr + progsize); - - return 0; + return 0; } - - fprintf(stderr, install_help, argv[0], argv[0]); - return -1; + + fprintf(stderr, install_help, argv[0], argv[0]); + return -1; } diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index ec2dc1c0a..f64049ed7 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -1,5 +1,5 @@ /**************************************************************************** - * lib/stdio/lib_fgets.c + * apps/system/readline/readline.c * * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> |