apps/system/progmem: Remove this utility. It makes illegal direct calls into the OS.
This commit is contained in:
parent
e363b27b09
commit
a579bab48a
@ -38,13 +38,13 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/progmem.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/fs/smart.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
@ -38,9 +38,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/progmem.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
11
system/progmem/.gitignore
vendored
11
system/progmem/.gitignore
vendored
@ -1,11 +0,0 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
||||
/*.obj
|
@ -1,14 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config SYSTEM_INSTALL
|
||||
tristate "FLASH Program Installation"
|
||||
default n
|
||||
---help---
|
||||
Enable support for the FLASH installation tool.
|
||||
|
||||
if SYSTEM_INSTALL
|
||||
endif
|
||||
|
@ -1,40 +0,0 @@
|
||||
############################################################################
|
||||
# apps/system/progmem/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# 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.
|
||||
# 3. Neither the name NuttX 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 COPYRIGHT HOLDERS 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
|
||||
# COPYRIGHT OWNER 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_SYSTEM_INSTALL),)
|
||||
CONFIGURED_APPS += system/progmem
|
||||
endif
|
||||
|
@ -1,56 +0,0 @@
|
||||
############################################################################
|
||||
# apps/system/progmem/Makefile
|
||||
#
|
||||
# Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
# Copyright (C) 2012, 2016, 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Uros Platise <uros.platise@isotel.eu>
|
||||
# Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# 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.
|
||||
# 3. Neither the name NuttX 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 COPYRIGHT HOLDERS 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
|
||||
# COPYRIGHT OWNER 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# TODO, this makefile should run make under the app dirs, instead of
|
||||
# sourcing the Make.defs!
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
# Install PROGMEM Application
|
||||
|
||||
APPNAME = progmem
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 1024
|
||||
|
||||
MAINSRC = progmem.c
|
||||
|
||||
CONFIG_XYZ_PROGNAME ?= progmem$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_XYZ_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_SYSTEM_INSTALL
|
||||
|
||||
include $(APPDIR)/Application.mk
|
@ -1,26 +0,0 @@
|
||||
|
||||
Install Program
|
||||
===============
|
||||
|
||||
Source: NuttX
|
||||
Author: Uros Platise
|
||||
Date: 7. May 2011
|
||||
|
||||
This application installs XIP application by placing it directly into
|
||||
the program memory (flash) area into free area and creates a start-up
|
||||
script into selected directory (i.e. /usr/bin/progname).
|
||||
|
||||
Usage:
|
||||
progmem [--stack RequiredStackSpace] [--priority Priority]
|
||||
source-file destination-directory
|
||||
|
||||
If stackspace is not given default stack space of 4096 Bytes is used.
|
||||
If priority is not given system default is used.
|
||||
|
||||
Additional options:
|
||||
|
||||
--remove destination-file i.e. install --remove /usr/bin/myapp
|
||||
--force to replace existing installation
|
||||
--start <page> install app at or after <page>
|
||||
--margin <pages> leave some free space after the kernel
|
||||
Default is 16 pages so kernel may grow.
|
@ -1,476 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/system/progmem/progmem.c
|
||||
*
|
||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
* Author: Uros Platise <uros.platise@isotel.eu>
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name NuttX 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 COPYRIGHT HOLDERS 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
|
||||
* COPYRIGHT OWNER 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/progmem.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ACTION_INSTALL 0x01
|
||||
#define ACTION_REMOVE 0x00
|
||||
#define ACTION_REINSTALL 0x03
|
||||
#define ACTION_INSUFPARAM 0x80
|
||||
|
||||
#define INSTALL_PROGRAMBLOCKSIZE 1024
|
||||
|
||||
/****************************************************************************
|
||||
* Private data
|
||||
****************************************************************************/
|
||||
|
||||
static const char *progmem_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"
|
||||
"Example:\n\t%s --stack 1024 /sdcard/demo.xip /usr/bin\n\n"
|
||||
"Options:\n"
|
||||
"\t--stack <required_stack_space>\n"
|
||||
"\t--priority <priority>\n"
|
||||
"\t--remove <dest-file>\tRemoves installed application\n"
|
||||
"\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";
|
||||
|
||||
static const char *progmem_script_text =
|
||||
"# XIP stacksize=%x priority=%x size=%x\n";
|
||||
|
||||
static const char *progmem_script_exec =
|
||||
"exec 0x%x\n";
|
||||
|
||||
/****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
static int progmem_getstartpage(int startpage, int pagemargin,
|
||||
int desiredsize)
|
||||
{
|
||||
size_t page = 0, stpage = 0xffff;
|
||||
size_t pagesize = 0;
|
||||
int maxlen = -1;
|
||||
int maxlen_start = 0xffff;
|
||||
ssize_t 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)
|
||||
{
|
||||
if (maxlen==-1)
|
||||
{
|
||||
/* First time found sth? */
|
||||
|
||||
stpage += pagemargin;
|
||||
maxlen = 0;
|
||||
}
|
||||
|
||||
if (stpage < startpage)
|
||||
{
|
||||
stpage = startpage;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
stpage = 0xffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Requested space is not available */
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int progmem_programflash(int startaddr, const char *source)
|
||||
{
|
||||
ssize_t status;
|
||||
size_t count;
|
||||
ssize_t 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;
|
||||
}
|
||||
while (count);
|
||||
}
|
||||
else
|
||||
{
|
||||
totalsize = -errno;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
free(buf);
|
||||
|
||||
return totalsize;
|
||||
}
|
||||
|
||||
static void progmem_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);
|
||||
}
|
||||
|
||||
static int progmem_getprogsize(const char *progname)
|
||||
{
|
||||
struct stat fileinfo;
|
||||
|
||||
if (stat(progname, &fileinfo) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fileinfo.st_size;
|
||||
}
|
||||
|
||||
static int progmem_alreadyexists(const char *scriptname)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(scriptname, "r")) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int progmem_createscript(int addr, int stacksize, int progsize,
|
||||
int priority, const char *scriptname)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(scriptname, "w+")) == NULL)
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
fprintf(fp, progmem_script_text, stacksize, priority, progsize);
|
||||
fprintf(fp, progmem_script_exec, addr);
|
||||
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int progmem_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);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int progmem_remove(const char *scriptname)
|
||||
{
|
||||
FILE *fp;
|
||||
int progsize, addr, freedsize;
|
||||
ssize_t page;
|
||||
int status = 0;
|
||||
|
||||
/* Parse script */
|
||||
|
||||
if ((fp = fopen(scriptname, "r")))
|
||||
{
|
||||
progsize = progmem_getlasthexvalue(fp,'=');
|
||||
addr = progmem_getlasthexvalue(fp,' ');
|
||||
freedsize = progsize;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BUILD_MODULE
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int progmem_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
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: progmem supports uniform organization only.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Parse arguments */
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (i <= argc && argv[i][0]=='-' && argv[i][1]=='-')
|
||||
{
|
||||
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, "start")==0)
|
||||
{
|
||||
startpage = 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, "force")==0)
|
||||
{
|
||||
action = ACTION_REINSTALL;
|
||||
}
|
||||
else fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
||||
}
|
||||
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=progmem_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 */
|
||||
}
|
||||
|
||||
progmem_getscriptname(scriptname, argv[i], argv[i+1]);
|
||||
|
||||
/* script-exists? */
|
||||
|
||||
if (progmem_alreadyexists(scriptname) == 1)
|
||||
{
|
||||
if (action != ACTION_REINSTALL)
|
||||
{
|
||||
fprintf(stderr, "Program with that name already exists.\n");
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
if ((scrsta = progmem_remove(scriptname)) < 0)
|
||||
{
|
||||
fprintf(stderr, "Could not remove program: %s\n", strerror(-scrsta));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Replacing %s\n", scriptname);
|
||||
}
|
||||
|
||||
startaddr = progmem_getstartpage(startpage, pagemargin, progmem_getprogsize(argv[i]));
|
||||
if (startpage < 0)
|
||||
{
|
||||
fprintf(stderr, "Not enough memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if ((progsize = progmem_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 = progmem_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;
|
||||
}
|
||||
|
||||
fprintf(stderr, progmem_help, argv[0], argv[0]);
|
||||
return -1;
|
||||
}
|
@ -38,7 +38,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/progmem.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user