Resync new repository with old repo r5166

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-09-17 18:18:44 +00:00
commit 57623d42eb
5691 changed files with 1361853 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
############################################################################
# Config.mk
# Strip quotes from Kconfig strings.
#
# Author: Richard Cochran
#
# 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.
#
############################################################################
# These are configuration variables that are quoted by configuration tool
# but which must be unquoated when used in the build system.
CONFIG_ARCH := $(patsubst "%",%,$(strip $(CONFIG_ARCH)))
CONFIG_ARCH_CHIP := $(patsubst "%",%,$(strip $(CONFIG_ARCH_CHIP)))
CONFIG_ARCH_BOARD := $(patsubst "%",%,$(strip $(CONFIG_ARCH_BOARD)))
+67
View File
@@ -0,0 +1,67 @@
############################################################################
# Makefile.export
#
# Copyright (C) 2011 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.
#
############################################################################
include $(TOPDIR)/.config
include $(EXPORTDIR)/Make.defs
ifdef ARCHSCRIPT
LDPATH = ${shell echo "$(ARCHSCRIPT)" | sed -e "s/^-T[ ]*//g"}
LDNAME = ${shell basename ${LDPATH}}
LDDIR = ${shell dirname ${LDPATH}}
endif
ARCHSUBDIR = "arch/$(CONFIG_ARCH)/src"
ARCHDIR ="$(TOPDIR)/$(ARCHSUBDIR)"
all: $(EXPORTDIR)/makeinfo.sh
default: all
.PHONY: clean
$(EXPORTDIR)/makeinfo.sh: $(TOPDIR)/.config $(EXPORTDIR)/Make.defs
@echo "#!/bin/bash" > $(EXPORTDIR)/makeinfo.sh
@echo "" >> $(EXPORTDIR)/makeinfo.sh
@echo "ARCHSUBDIR=\"$(ARCHSUBDIR)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "ARCHDIR=\"$(ARCHDIR)\"" >> $(EXPORTDIR)/makeinfo.sh
ifdef ARCHSCRIPT
@echo "LDNAME=\"$(LDNAME)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "LDDIR=\"$(LDDIR)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "LDPATH=\"$(LDPATH)\"" >> $(EXPORTDIR)/makeinfo.sh
endif
@echo "ARCHCFLAGS=\"$(ARCHCFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "ARCHCXXFLAGS=\"$(ARCHCXXFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "CROSSDEV=\"$(CROSSDEV)\"" >> $(EXPORTDIR)/makeinfo.sh
@chmod 755 $(EXPORTDIR)/makeinfo.sh
clean:
@rm -f $(EXPORTDIR)/makeinfo.sh
+77
View File
@@ -0,0 +1,77 @@
############################################################################
# Makefile.host
#
# Copyright (C) 2007, 2008, 2011-2012 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.
#
############################################################################
all: mkconfig mkversion mksyscall bdf-converter
default: mkconfig mksyscall
.PHONY: clean
# Add CFLAGS=-g on the make command line build debug versions
CFLAGS = -O2 -Wall -I.
# mkconfig - Convert a .config file into a C config.h file
mkconfig: mkconfig.c cfgparser.c
@gcc $(CFLAGS) -o mkconfig mkconfig.c cfgparser.c
# cmpconfig - Compare the contents of two configuration files
cmpconfig: cmpconfig.c
@gcc $(CFLAGS) -o cmpconfig cmpconfig.c
# mkversion - Convert a .version file into a C version.h file
mkversion: mkconfig.c cfgparser.c
@gcc $(CFLAGS) -o mkversion mkversion.c cfgparser.c
# mksyscall - Convert a CSV file into syscall stubs and proxies
mksyscall: mksyscall.c csvparser.c
@gcc $(CFLAGS) -o mksyscall mksyscall.c csvparser.c
# mksymtab - Convert a CSV file into a symbol table
mksymtab: mksymtab.c csvparser.c
@gcc $(CFLAGS) -o mksymtab mksymtab.c csvparser.c
# bdf-converter - Converts a BDF font to the NuttX font format
bdf-converter: bdf-converter.c
@gcc $(CFLAGS) -o bdf-converter bdf-converter.c
clean:
@rm -f *.o *.a *~ .*.swp
@rm -f mkconfig mksyscall mkversion bdf-converter
@rm -f mkconfig.exe mksyscall.exe mkversion.exe bdf-converter.exe
+352
View File
@@ -0,0 +1,352 @@
tools/README.txt
^^^^^^^^^^^^^^^^
This README file addresses the contents of the NuttX tools/ directory.
The tools/ directory contains miscellaneous scripts and host C programs
that are necessary parts of the the NuttX build system. These files
include:
README.txt
This file
configure.sh
This is a bash script that is used to configure NuttX for a given
target board. See configs/README.txt or Documentation/NuttxPortingGuide.html
for a description of how to configure NuttX with this script.
discover.py
Example script for discovering devices in the local network.
It is the counter part to apps/netutils/discover
mkconfig.c, cfgparser.c, and cfgparser.h
These are Cs file that are used to build mkconfig program. The mkconfig
program is used during the initial NuttX build.
When you configure NuttX, you will copy a configuration file called .config
in the top level NuttX directory (See configs/README.txt or
Documentation/NuttxPortingGuide.html). The first time you make NuttX,
the top-level makefile will build the mkconfig executable from mkconfig.c
(using Makefile.host). The top-level Makefile will then execute the
mkconfig program to convert the .config file in the top level directory
into include/nuttx/config.h. config.h is a another version of the
NuttX configuration that can be included by C files.
cmdconfig.c
This C file can be used to build a utility for comparing two NuttX
configuration files.
mkexport.sh and Makefile.export
These implement part of the top-level Makefile's 'export' target. That
target will bundle up all of the NuttX libraries, header files, and the
startup object into an export-able, binary NuttX distribution. The
Makefile.export is used only by the mkexport.sh script to parse out
options from the top-level Make.defs file.
mkfsdata.pl
This perl script is used to build the "fake" file system and CGI support
as needed for the apps/netutils/webserver. It is currently used only
by the Makefile at apps/examples/uip. That example serves as an example
of how to configure the uIP webserver "fake" file system.
NOTE: This perl script comes from uIP and was (probably) written
by Adam Dunkels. uIP has a license that is compatible with NuttX.
mkversion.c, cfgparser.c, and cfgparser.h
This is C file that is used to build mkversion program. The mkversion
program is used during the initial NuttX build.
When you build NuttX there should be a version file called .version in
the top level NuttX directory (See Documentation/NuttxPortingGuide.html).
The first time you make NuttX, the top-level makefile will build th
mkversion executable from mkversion.c (using Makefile.host). The top-
level Makefile will then execute the mkversion program to convert the
.version file in the top level directory into include/nuttx/version.h.
version.h provides version information that can be included by C files.
mksyscall.c, cvsparser.c, and cvsparser.h
This is a C file that is used to build mksyscall program. The mksyscall
program is used during the initial NuttX build by the logic in the top-
level syscall/ directory.
If you build NuttX as a separately compiled, monolithic kernel and separate
applications, then there is a syscall layer that is used to get from the
user application space to the NuttX kernel space. In the user application
"proxies" for each of the kernel functions are provided. The proxies have
the same function signature as the kernel function, but only execute a
system call.
Within the kernel, there are "stubs" for each of the system calls. The
stubs receive the marshalled system call data, and perform the actually
kernel function call (in kernel-mode) on behalf of the proxy function.
Information about the stubs and proxies is maintained in a comma separated
value (CSV) file in the syscall/ directory. The mksyscall program will
accept this CVS file as input and generate all of the required proxy or
stub files as output. See syscall/README.txt for additonal information.
mksymtab.c, cvsparser.c, and cvsparser.h
This is a C file that is used to build symbol tables from common-separated
value (CSV) files. This tool is not used during the NuttX build, but
can be used as needed to generate files.
USAGE: ./mksymtab <cvs-file> <symtab-file>
Where:
<cvs-file> : The path to the input CSV file
<symtab-file>: The path to the output symbol table file
-d : Enable debug output
Example:
cd nuttx/tools
cat ../syscall/syscall.csv ../lib/lib.csv | sort >tmp.csv
./mksymtab.exe tmp.csv tmp.c
pic32mx
This directory contains build tools used only for PIC32MX platforms
bdf-convert.c
This C file is used to build the bdf-converter program. The bdf-converter
program be used to convert fonts in Bitmap Distribution Format (BDF)
into fonts that can be used in the NX graphics system.
Below are general instructions for creating and installing a new font
in the NX graphic system:
1. Locate a font in BDF format,
2. Use the bdf-converter program to convert the BDF font to the NuttX
font format. This will result in a C header file containing
defintions. That header file should be installed at, for example,
graphics/nxfonts/nxfonts_myfont.h.
Create a new NuttX configuration variable. For example, suppose
you define the following variable: CONFIG_NXFONT_MYFONT. Then
you would need to:
3. Define CONFIG_NXFONT_MYFONT=y in your NuttX configuration file.
A font ID number has to be assigned for each new font. The font ID
is defined in the file include/nuttx/nx/nxfonts.h. Those definitions
have to be extended to support your new font. Look at how the font ID
enabled by CONFIG_NXFONT_SANS23X27 is defined and add an ID for your
new font in a similar fashion:
4. include/nuttx/nx/nxfonts.h. Add you new font as a possible system
default font:
#if defined(CONFIG_NXFONT_SANS23X27)
# define NXFONT_DEFAULT FONTID_SANS23X27
#elif defined(CONFIG_NXFONT_MYFONT)
# define NXFONT_DEFAULT FONTID_MYFONT
#endif
Then define the actual font ID. Make sure that the font ID value
is unique:
enum nx_fontid_e
{
FONTID_DEFAULT = 0 /* The default font */
#ifdef CONFIG_NXFONT_SANS23X27
, FONTID_SANS23X27 = 1 /* The 23x27 sans serif font */
#endif
#ifdef CONFIG_NXFONT_MYFONT
, FONTID_MYFONT = 2 /* My shiny, new font */
#endif
...
New Add the font to the NX build system. There are several files that
you have to modify to to this. Look how the build system uses the
font CONFIG_NXFONT_SANS23X27 for examaples:
5. nuttx/graphics/Makefile. This file needs logic to auto-generate
a C source file from the header file that you generated with the
the bdf-converter program. Notice NXFONTS_FONTID=2; this must be
set to the same font ID value that you defined in the
include/nuttx/nx/nxfonts.h file.
genfontsources:
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
@$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_MYFONT),y)
@$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES)
endif
6. nuttx/graphics/nxfonts/Make.defs. Set the make variable NXFSET_CSRCS.
NXFSET_CSRCS determines the name of the font C file to build when
NXFONTS_FONTID=2:
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
NXFSET_CSRCS += nxfonts_bitmaps_sans23x27.c
endif
ifeq ($(CONFIG_NXFONT_MYFONT),y)
NXFSET_CSRCS += nxfonts_bitmaps_myfont.c
endif
7. nuttx/graphics/nxfonts/Makefile.sources. This is the Makefile used
in step 5 that will actually generate the font C file. So, given
your NXFONTS_FONTID=2, it needs to determine a prefix to use for
auto-generated variable and function names and (again) the name of
the autogenerated file to create (this must be the same name that
was used in nuttx/graphics/nxfonts/Make.defs):
ifeq ($(NXFONTS_FONTID),1)
NXFONTS_PREFIX := g_sans23x27_
GEN_CSRC = nxfonts_bitmaps_sans23x27.c
endif
ifeq ($(NXFONTS_FONTID),2)
NXFONTS_PREFIX := g_myfont_
GEN_CSRC = nxfonts_bitmaps_myfont.c
endif
8. graphics/nxfonts/nxfonts_bitmaps.c. This is the file that contains
the generic font structures. It is used as a "template" file by
nuttx/graphics/nxfonts/Makefile.sources to create your customized
font data set.
#if NXFONTS_FONTID == 1
# include "nxfonts_sans23x27.h"
#elif NXFONTS_FONTID == 2
# include "nxfonts_myfont.h"
#else
# error "No font ID specified"
#endif
Where nxfonts_myfont.h is the NuttX font file that we generated in
step 2 using the bdf-converter tool.
9. graphics/nxfonts/nxfonts_getfont.c. Finally, we need to extend the
logic that does the run-time font lookups so that can find our new
font. The lookup function is NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid).
The new font information needs to be added to data structures used by
that function:
#ifdef CONFIG_NXFONT_SANS23X27
extern const struct nx_fontpackage_s g_sans23x27_package;
#endif
#ifdef CONFIG_NXFONT_MYFONT
extern const struct nx_fontpackage_s g_myfont_package;
#endif
static FAR const struct nx_fontpackage_s *g_fontpackages[] =
{
#ifdef CONFIG_NXFONT_SANS23X27
&g_sans23x27_package,
#endif
#ifdef CONFIG_NXFONT_MYFONT
&g_myfont_package,
#endif
NULL
};
Makefile.host
This is the makefile that is used to make the mkconfig program from
the mkconfig.c C file, the cmpconfig program from cmpconfig.c C file
the mkversion program from the mkconfig.c C file, or the mksyscall
program from the mksyscall.c file. Usage:
cd tools/
make -f Makefile.host <program>
mkromfsimg.sh
This script may be used to automate the generate of a ROMFS file system
image. It accepts an rcS script "template" and generates and image that
may be mounted under /etc in the NuttX pseudo file system.
mkdeps.sh
mknulldeps.sh
NuttX uses the GCC compilers capabilities to create Makefile dependencies.
The bash script mkdeps.sh is used to run GCC in order to create the
dependencies. If a NuttX configuration uses the GCC toolchain, its Make.defs
file (see configs/README.txt) will include a line like:
MKDEP = $(TOPDIR)/tools/mkdeps.sh
If the NuttX configuration does not use a GCC compatible toolchain, then
it cannot use the dependencies and instead it uses mknulldeps.sh:
MKDEP = $(TOPDIR)/tools/mknulldeps.sh
The mknulldeps.sh is a stub script that does essentially nothing.
define.sh
Different compilers have different conventions for specifying pre-
processor definitions on the compiler command line. This bash
script allows the build system to create create command line definitions
without concern for the particular compiler in use.
incdir.sh
Different compilers have different conventions for specifying lists
of include file paths on the the compiler command line. This bash
script allows the build system to create include file paths without
concern for the particular compiler in use.
link.sh
winlink.sh
unlink.sh
Different file system have different capabilities for symbolic links.
Some windows file systems have no native support for symbolic links.
Cygwin running under windows has special links built in that work with
all cygwin tools. However, they do not work when Windows native tools
are used with cygwin. In that case something different must be done.
If you are building under Linux or under cygwin with a cygwin tool
chain, then your Make.defs file may have definitions like the
following:
DIRLINK = $(TOPDIR)/tools/link.sh
DIRUNLINK = (TOPDIR)/tools/unlink.sh
The first definition is not always present because link.sh is the
default. link.sh is a bash script that performs a normal, Linux-style
symbolic link; unlink.sh is a do-it-all unlinking script.
But if you are building under cygwin using a Windows native toolchain,
then you will need something like the following in you Make.defs file:
DIRLINK = $(TOPDIR)/tools/winlink.sh
DIRUNLINK = (TOPDIR)/tools/unlink.sh
winlink.sh will copy the whole directory instead of linking it.
NOTE: I have been told that some NuttX users have been able to build
successfully using the GnuWin32 tools and modifying the link.sh
script so that it uses the NTFS mklink command. But I have never
tried that
mkimage.sh
The creates a downloadable image as needed with the rrload bootloader.
indent.sh
This script can be used to indent .c and .h files in a manner similar
to my coding NuttX coding style. It doesn't do a really good job,
however (see the comments at the top of the indent.sh file).
zipme.sh
I use this script to create the nuttx-xx.yy.tar.gz tarballs for
release on SourceForge. It is handy because it also does the
kind of clean that you need to do to make a clean code release.
+675
View File
@@ -0,0 +1,675 @@
/****************************************************************************
* tools/bdf-converter.c
*
* Copyright (C) 2011 NX Engineering, S.A., All rights reserved.
* Author: Jose Pablo Carballo Gomez <jcarballo@nx-engineering.com>
*
* 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.
*
****************************************************************************/
/*
* Based one the "Glyph Bitmap Distribution Format (BDF) Specification",
* Version 2.2, by Adobe Systems Incorporated.
*
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/*
#define VERBOSE
#define DBG
*/
// BDF Specification Version 2.2:
// This version lifts the restriction on line length. In this version, the new
// maximum length of a value of the type string is 65535 characters, and hence
// lines may now be at least this long.
#define BDF_MAX_LINE_LENGTH 65535
/* Ranges of 7-bit and 8-bit fonts */
#define NXFONT_MIN7BIT 33
#define NXFONT_MAX7BIT 126
#define NXFONT_MIN8BIT 161
#define NXFONT_MAX8BIT 255
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure holds information about a glyph */
typedef struct glyphinfo_s
{
char *name; /* Name for they glyph */
int encoding; /* The Adobe Standard Encoding value */
int dw_x0; /* Width in x of the vector indicating
* the position of the next glyph's origin
* relative to the origin of this glyph */
int dw_y0; /* Width in y of the vector indicating
* the position of the next glyph's origin
* relative to the origin of this glyph */
int bb_w; /* The width of the black pixels in x */
int bb_h; /* The height of the black pixels in y */
int bb_x_off; /* X displacement of the lower left corner
* of the bitmap from origin 0 */
int bb_y_off; /* Y displacement of the lower left corner
* of the bitmap from origin 0 */
uint64_t *bitmap; /* Hexadecimal data for the character bitmap */
} glyphinfo_t;
/* This structures provides the metrics for one glyph */
typedef struct nx_fontmetric_s
{
uint32_t stride : 3; /* Width of one font row in bytes */
uint32_t width : 6; /* Width of the font in bits */
uint32_t height : 6; /* Height of the font in rows */
uint32_t xoffset : 6; /* Top, left-hand corner X-offset in pixels */
uint32_t yoffset : 6; /* Top, left-hand corner y-offset in pixels */
uint32_t unused : 5;
} nx_fontmetric_t;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: trimLine
*
* Description:
* Trims the line removing space characters at the front and at the end
* of the line.
*
* Input Parameters:
* line - The line to trim
*
****************************************************************************/
static void trimLine(char *line)
{
char *str;
str = line;
char *strEnd;
for (strEnd = str + strlen(str) - 1;
strEnd >= str && isspace((int)(*strEnd));
strEnd--);
*(strEnd + 1) = 0;
}
/****************************************************************************
* Name: bdf_parseIntLine
*
* Description:
* Parses a line containing a BDF property followed by integers. It will
* ignore the first token that corresponds to the property name.
*
* Input Parameters:
* line - A line with a BDF property followed by integers, i.e.:
* "FONTBOUNDINGBOX 8 13 0 -2"
* count - How many integers are specified by the BDF property. In the
* example above, count = 4.
* info - A pointer to memory provided by the caller in which to
* return the array of integers. For the example above:
* info[0] = 8
* info[1] = 13
* info[2] = 0
* info[3] = -2
*
****************************************************************************/
static void bdf_parseintline(char *line, unsigned int count, int *info)
{
char *str, *token, *saveptr1;
str = line;
/* Ignore the key */
token = (char *)strtok_r(str, " ", &saveptr1);
while ((token = (char *)strtok_r(NULL, " ", &saveptr1)) && count--)
{
*(info++) = atoi(token);
}
}
/****************************************************************************
* Name: bdf_printglyphinfo
*
* Description:
* Prints the information available for a glyph.
*
* Input Parameters:
* ginfo - A glyphinfo_t struct with the glyph's information.
*
****************************************************************************/
#ifdef DBG
static void bdf_printglyphinfo(const glyphinfo_t *ginfo)
{
printf("NAME = %s\n", ginfo->name);
printf("ENCODING = %d\n", ginfo->encoding);
printf("DW_X0 = %d\n", ginfo->dw_x0);
printf("DW_Y0 = %d\n", ginfo->dw_y0);
printf("BB_W = %d\n", ginfo->bb_w);
printf("BB_H = %d\n", ginfo->bb_h);
printf("BB_X_OFF = %d\n", ginfo->bb_x_off);
printf("BB_Y_OFF = %d\n", ginfo->bb_y_off);
int i;
for (i = 0; i < ginfo->bb_h; i++)
{
printf("BITMAP[%d] = %x\n", i, ginfo->bitmap[i]);
}
}
#endif /* DBG */
/****************************************************************************
* Name: bdf_printnxmetricinfo
*
* Description:
* Prints the information available for a glyph's metric in the NX
* graphics system.
*
* Input Parameters:
* info - A nx_fontmetric_t struct with the glyph's information.
*
****************************************************************************/
#ifdef DBG
static void bdf_printnxmetricinfo(const nx_fontmetric_t *info)
{
printf("STRIDE = %d\n", info->stride);
printf("WIDTH = %d\n", info->width);
printf("HEIGHT = %d\n", info->height);
printf("XOFFSET = %d\n", info->xoffset);
printf("YOFFSET = %d\n", info->yoffset);
}
#endif /* DBG */
/****************************************************************************
* Name: bdf_getglyphinfo
*
* Description:
* Obtains the information for an individual glyph. The BDF properties
* taken into account are:
* - ENCODING
* - DWIDTH
* - BBX
* BDF properties ignored:
* - SWIDTH
* - SWIDTH1
* - DWIDTH1
* - VVECTOR
*
* Input Parameters:
* file - The input file stream pointing to the first line of the
* glyph's information (right after STARTCHAR).
* ginfo - A glyphinfo_t struct to fill with the glyph's information.
*
****************************************************************************/
static void bdf_getglyphinfo(FILE *file, glyphinfo_t *ginfo)
{
char line[BDF_MAX_LINE_LENGTH];
char lineCopy[BDF_MAX_LINE_LENGTH];
char *str, *token, *saveptr1;
bool done;
done = false;
while(fgets(line, BDF_MAX_LINE_LENGTH, file) != NULL && !done)
{
trimLine(line);
strcpy(lineCopy, line);
str = line;
while ((token = (char *)strtok_r(str, " ", &saveptr1)))
{
/* ENCODING information */
if(strcmp(token, "ENCODING") == 0)
{
token = (char *)strtok_r(NULL, " ", &saveptr1);
ginfo->encoding = atoi(token);
}
/* DWIDTH information */
if(strcmp(token, "DWIDTH") == 0)
{
token = (char *)strtok_r(NULL, " ", &saveptr1);
ginfo->dw_x0 = atoi(token);
token = (char *)strtok_r(NULL, " ", &saveptr1);
ginfo->dw_y0 = atoi(token);
}
/* BBX information */
else if(strcmp(token, "BBX") == 0)
{
int bbxinfo[4];
bdf_parseintline(lineCopy, 4, bbxinfo);
ginfo->bb_w = bbxinfo[0];
ginfo->bb_h = bbxinfo[1];
ginfo->bb_x_off = bbxinfo[2];
ginfo->bb_y_off = bbxinfo[3];
/* This is the last BDF property of interest*/
done = true;
}
str = NULL;
}
}
}
/****************************************************************************
* Name: bdf_getglyphbitmap
*
* Description:
* Obtains the character bitmap information for an individual glyph.
*
* Input Parameters:
* file - The input file stream pointing to the first line of the
* glyph's bitmap (right after BITMAP).
* ginfo - A glyphinfo_t struct to fill with the glyph's bitmap.
*
****************************************************************************/
static void bdf_getglyphbitmap(FILE *file, glyphinfo_t *ginfo)
{
char line[BDF_MAX_LINE_LENGTH];
uint64_t *bitmap;
bool readingbitmap;
bitmap = ginfo->bitmap;
readingbitmap = true;
while (readingbitmap)
{
if (fgets(line, BDF_MAX_LINE_LENGTH, file) != NULL)
{
trimLine(line);
if(strcmp(line, "ENDCHAR") == 0)
{
readingbitmap = false;
}
else
{
char *endptr;
*bitmap = strtoul(line, &endptr, 16);
bitmap++;
}
}
else
{
/* error condition */
readingbitmap = false;
}
}
}
/****************************************************************************
* Name: bdf_getstride
*
* Description:
* Obtains the stride for an individual glyph. The stride is the width
* of one glyph's bitmap row in bytes.
*
* Input Parameters:
* ginfo - A glyphinfo_t struct with the glyph's information.
* stride - A pointer to memory provided by the caller in which to
* return the stride.
*
****************************************************************************/
static void bdf_getstride(glyphinfo_t *ginfo, uint32_t *stride)
{
*stride = (ginfo->bb_w % 8 == 0) ? ginfo->bb_w / 8 : ginfo->bb_w / 8 + 1;
}
/****************************************************************************
* Name: bdf_printoutput
*
* Description:
* Prints to the output stream the information of an individual glyph in
* the NuttX font format.
*
* Input Parameters:
* out - The output stream.
* ginfo - A glyphinfo_t struct with the glyph's information.
* nxmetric - A nx_fontmetric_t struct with the glyph's information.
*
****************************************************************************/
static void bdf_printoutput(FILE *out,
glyphinfo_t *ginfo,
nx_fontmetric_t *nxmetric)
{
/* Only interested in the 7 and 8 bit ranges */
if ((ginfo->encoding >= NXFONT_MIN7BIT &&
ginfo->encoding <= NXFONT_MAX7BIT) ||
(ginfo->encoding >= NXFONT_MIN8BIT &&
ginfo->encoding <= NXFONT_MAX8BIT))
{
/* Glyph general info */
if (ginfo->bb_x_off < 0)
{
fprintf(out,
"/* %s (%d) -- NOTE: Xoffset should be %d, not 0. */\n",
ginfo->name,
ginfo->encoding,
ginfo->bb_x_off);
}
else
{
fprintf(out, "/* %s (%d) */\n", ginfo->name, ginfo->encoding);
}
/* Glyph metrics */
fprintf(out,
"#define NXFONT_METRICS_%d {%d, %d, %d, %d, %d, 0}\n",
ginfo->encoding,
nxmetric->stride,
nxmetric->width,
nxmetric->height,
nxmetric->xoffset,
nxmetric->yoffset);
/* Glyph bitmap */
fprintf(out, "#define NXFONT_BITMAP_%d {", ginfo->encoding);
int i, j;
for (i = 0; i < ginfo->bb_h - 1; i++)
{
for (j = 1; j <= nxmetric->stride; j++)
{
int nxbyteoffset;
uint8_t nxbyte = 0;
uint64_t tempbitmap = ginfo->bitmap[i];
/* Get the next byte */
nxbyteoffset = (nxmetric->stride - j) * 8;
nxbyte = (uint8_t)(tempbitmap >> nxbyteoffset);
fprintf(out, "0x%x, ", nxbyte);
}
}
/* Different behavior for the last bitmap */
for (j = 1; j <= nxmetric->stride; j++)
{
int nxbyteoffset;
uint8_t nxbyte = 0;
uint64_t tempbitmap = ginfo->bitmap[i];
/* Get the next byte */
nxbyteoffset = (nxmetric->stride - j) * 8;
nxbyte = (uint8_t)(tempbitmap >> nxbyteoffset);
if (j == nxmetric->stride)
{
fprintf(out, "0x%x}\n", nxbyte);
}
else
{
fprintf(out, "0x%x, ", nxbyte);
}
}
fprintf(out, "\n");
}
}
/****************************************************************************
* Main
****************************************************************************/
int main(int argc, char **argv)
{
FILE *file, *out;
char line[BDF_MAX_LINE_LENGTH];
char lineCopy[BDF_MAX_LINE_LENGTH];
char *str, *token, *saveptr1;
char *input, *output;
/* FONTBOUNDINGBOX properties*/
int fbb_x = 0;
int fbb_y = 0;
int fbb_x_off = 0;
int fbb_y_off = 0;
/* Input BDF file */
input = argv[1];
if (input == NULL)
{
printf("%s: no input file\n", argv[0]);
exit(0);
}
file = fopen(input, "r");
if (file == NULL)
{
printf("%s: error opening file %s\n", argv[0], input);
exit(0);
}
else
{
#ifdef VERBOSE
printf("Opening \"%s\"\n", input);
#endif /* VERBOSE */
}
/* Output file */
if (argv[2])
{
output = argv[2];
}
else
{
output = "nxfonts_myfont.h";
}
out = fopen(output, "w");
if (out == NULL)
{
printf("%s: error opening file %s\n", argv[0], output);
fclose(file);
exit(0);
}
else
{
while (fgets(line, BDF_MAX_LINE_LENGTH, file) != NULL)
{
#ifdef DBG
printf("--\n");
#endif /* DBG */
// Save a copy of the line
strcpy(lineCopy,line);
// Clean it
trimLine(line);
str = line;
while ((token = (char *)strtok_r(str, " ", &saveptr1)))
{
/* FONTBOUNDINGBOX - Global font information */
if (strcmp(token, "FONTBOUNDINGBOX") == 0)
{
int fbbinfo[4];
bdf_parseintline(lineCopy, 4, fbbinfo);
fbb_x = fbbinfo[0];
fbb_y = fbbinfo[1];
fbb_x_off = fbbinfo[2];
fbb_y_off = fbbinfo[3];
/* Print FONTBOUNDINGBOX information */
fprintf(out, "/* Maximum height and width of any");
fprintf(out, " glyph in the set */\n\n");
fprintf(out, "#define NXFONT_MAXHEIGHT %d\n", fbb_y);
fprintf(out, "#define NXFONT_MAXWIDTH %d\n\n", fbb_x);
}
/* STARTCHAR - Individual glyph information */
if (strcmp(token, "STARTCHAR") == 0)
{
glyphinfo_t ginfo;
/* Glyph name */
ginfo.name = (char *)strtok_r(NULL, " ", &saveptr1);
#ifdef VERBOSE
printf("Processing glyph: %s\n", ginfo.name);
#endif /* VERBOSE */
/* Glyph information:
* ENCODING
* DWIDTH
* BBX
*/
ginfo.encoding = 0;
ginfo.dw_x0 = 0;
ginfo.dw_y0 = 0;
ginfo.bb_w = 0;
ginfo.bb_h = 0;
ginfo.bb_x_off = 0;
ginfo.bb_y_off = 0;
bdf_getglyphinfo(file, &ginfo);
/* Glyph bitmap */
ginfo.bitmap = malloc(sizeof(uint64_t) * ginfo.bb_h);
bdf_getglyphbitmap(file, &ginfo);
#ifdef DBG
bdf_printglyphinfo(&ginfo);
#endif /* DBG */
/* Convert to nxfonts */
nx_fontmetric_t nxmetric;
uint32_t stride;
bdf_getstride(&ginfo, &stride);
nxmetric.stride = stride;
nxmetric.width = ginfo.bb_w;
nxmetric.height = ginfo.bb_h;
/* The NuttX font format does not support
* negative X offsets. */
if (ginfo.bb_x_off < 0)
{
nxmetric.xoffset = 0;
printf("%s: ignoring negative x offset for "
"glyph '%s' (%d)\n",
argv[0],
ginfo.name,
ginfo.encoding);
}
else
{
nxmetric.xoffset = ginfo.bb_x_off;
}
nxmetric.yoffset = fbb_y + fbb_y_off -
ginfo.bb_y_off - ginfo.bb_h;
#ifdef DBG
bdf_printnxmetricinfo(&nxmetric);
#endif /* DBG */
/* The space (32) character is treated differently */
if (ginfo.encoding == 32)
{
fprintf(out, "/* The width of a space */\n\n");
fprintf(out, "#define NXFONT_SPACEWIDTH %d\n\n", ginfo.dw_x0);
}
else
{
bdf_printoutput(out, &ginfo, &nxmetric);
}
/* Free memory */
free(ginfo.bitmap);
}
str = NULL;
}
}
fclose(file);
fclose(out);
/* The End */
printf("Generated \"%s\"\n", output);
}
return EXIT_SUCCESS;
}
+311
View File
@@ -0,0 +1,311 @@
/****************************************************************************
* tools/cfgpaser.c
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <>
*
* 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 <string.h>
#include <ctype.h>
#include "cfgparser.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
char line[LINESIZE+1];
/****************************************************************************
* Private Data
****************************************************************************/
/* These are configuration variable name that are quoted by configuration tool
* but which must be unquoated when used in C code.
*/
static const char *dequote_list[] =
{
"CONFIG_USER_ENTRYPOINT",
NULL
};
/****************************************************************************
* Private Functions
****************************************************************************/
/* Skip over any spaces */
static char *skip_space(char *ptr)
{
while (*ptr && isspace((int)*ptr)) ptr++;
return ptr;
}
/* Find the end of a variable string */
static char *find_name_end(char *ptr)
{
while (*ptr && (isalnum((int)*ptr) || *ptr == '_')) ptr++;
return ptr;
}
/* Find the end of a value string */
static char *find_value_end(char *ptr)
{
while (*ptr && !isspace((int)*ptr))
{
if (*ptr == '"')
{
do ptr++; while (*ptr && *ptr != '"');
if (*ptr) ptr++;
}
else
{
do ptr++; while (*ptr && !isspace((int)*ptr) && *ptr != '"');
}
}
return ptr;
}
/* Read the next line from the configuration file */
static char *read_line(FILE *stream)
{
char *ptr;
for (;;)
{
line[LINESIZE] = '\0';
if (!fgets(line, LINESIZE, stream))
{
return NULL;
}
else
{
ptr = skip_space(line);
if (*ptr && *ptr != '#' && *ptr != '\n')
{
return ptr;
}
}
}
}
/* Parse the line from the configuration file into a variable name
* string and a value string.
*/
static void parse_line(char *ptr, char **varname, char **varval)
{
/* Skip over any leading spaces */
ptr = skip_space(ptr);
/* The first no-space is the beginning of the variable name */
*varname = skip_space(ptr);
*varval = NULL;
/* Parse to the end of the variable name */
ptr = find_name_end(ptr);
/* An equal sign is expected next, perhaps after some white space */
if (*ptr && *ptr != '=')
{
/* Some else follows the variable name. Terminate the variable
* name and skip over any spaces.
*/
*ptr = '\0';
ptr = skip_space(ptr + 1);
}
/* Verify that the equal sign is present */
if (*ptr == '=')
{
/* Make sure that the variable name is terminated (this was already
* done if the name was followed by white space.
*/
*ptr = '\0';
/* The variable value should follow =, perhaps separated by some
* white space.
*/
ptr = skip_space(ptr + 1);
if (*ptr)
{
/* Yes.. a variable follows. Save the pointer to the start
* of the variable string.
*/
*varval = ptr;
/* Find the end of the variable string and make sure that it
* is terminated.
*/
ptr = find_value_end(ptr);
*ptr = '\0';
}
}
}
static char *dequote_value(const char *varname, char *varval)
{
const char **dqnam;
char *dqval = varval;
int len;
if (dqval)
{
/* Check if the variable name is in the list of strings to be dequoated */
for (dqnam = dequote_list; *dqnam; dqnam++)
{
if (strcmp(*dqnam, varname) == 0)
{
break;
}
}
/* Did we find the variable name in the list of configuration variables
* to be dequoated?
*/
if (*dqnam)
{
/* Yes... Check if there is a traiing quote */
len = strlen(dqval);
if (dqval[len-1] == '"')
{
/* Yes... replace it with a terminator */
dqval[len-1] = '\0';
len--;
}
/* Is there a leading quote? */
if (dqval[0] == '"')
{
/* Yes.. skip over the leading quote */
dqval++;
len--;
}
/* Handle the case where nothing is left after dequoting */
if (len < 0)
{
dqval = NULL;
}
}
}
return dqval;
}
/****************************************************************************
* Public Functions
****************************************************************************/
void parse_file(FILE *stream)
{
char *varname;
char *varval;
char *ptr;
/* Loop until the entire file has been parsed. */
do
{
/* Read the next line from the file */
ptr = read_line(stream);
if (ptr)
{
/* Parse the line into a variable and a value field */
parse_line(ptr, &varname, &varval);
/* Was a variable name found? */
if (varname)
{
/* Yes.. dequote the value if necessary */
varval = dequote_value(varname, varval);
/* If no value was provided or if the special value 'n' was provided,
* then undefine the configuration variable.
*/
if (!varval || strcmp(varval, "n") == 0)
{
printf("#undef %s\n", varname);
}
/* Simply define the configuration variable if it has the special
* value "y"
*/
else if (strcmp(varval, "y") == 0)
{
printf("#define %s 1\n", varname);
}
/* Otherwise, use the value as provided */
else
{
printf("#define %s %s\n", varname, varval);
}
}
}
}
while (ptr);
}
+64
View File
@@ -0,0 +1,64 @@
/****************************************************************************
* tools/cfgpaser.h
*
* Copyright (C) 2007-2011 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.
*
****************************************************************************/
#ifndef __TOOLS_CFGPARSER_H
#define __TOOLS_CFGPARSER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <limits.h>
/****************************************************************************
* Definitions
****************************************************************************/
#define LINESIZE ( PATH_MAX > 256 ? PATH_MAX : 256 )
/****************************************************************************
* Public Data
****************************************************************************/
extern char line[LINESIZE+1];
/****************************************************************************
* Public Functions
****************************************************************************/
extern void parse_file(FILE *stream);
#endif /* __TOOLS_CFGPARSER_H */
+328
View File
@@ -0,0 +1,328 @@
/****************************************************************************
* tools/cmpconfig.c
*
* Copyright (C) 2012 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
struct variable_s
{
struct variable_s *flink;
char *var;
char *val;
char storage[1];
};
/****************************************************************************
* Private Functions
****************************************************************************/
static void show_usage(const char *progname)
{
fprintf(stderr, "USAGE: %s <config1> <config2>\n", progname);
exit(EXIT_FAILURE);
}
static char *skip_space(char *ptr)
{
while (*ptr && isspace((int)*ptr)) ptr++;
return ptr;
}
static char *read_line(FILE *stream, char *line, int len)
{
char *ptr;
for (;;)
{
line[len-1] = '\0';
if (!fgets(line, len, stream))
{
return NULL;
}
else
{
ptr = skip_space(line);
if (*ptr && *ptr != '#' && *ptr != '\n')
{
return ptr;
}
}
}
}
static char *find_name_end(char *ptr)
{
while (*ptr && (isalnum((int)*ptr) || *ptr == '_')) ptr++;
return ptr;
}
static char *find_value_end(char *ptr)
{
while (*ptr && !isspace((int)*ptr))
{
if (*ptr == '"')
{
do ptr++; while (*ptr && *ptr != '"');
if (*ptr) ptr++;
}
else
{
do ptr++; while (*ptr && !isspace((int)*ptr) && *ptr != '"');
}
}
return ptr;
}
static void parse_line(char *ptr, char **varname, char **varval)
{
*varname = ptr;
*varval = NULL;
ptr = find_name_end(ptr);
if (*ptr && *ptr != '=')
{
*ptr = '\0';
ptr = skip_space(ptr + 1);
}
if (*ptr == '=')
{
*ptr = '\0';
ptr = skip_space(ptr + 1);
if (*ptr)
{
*varval = ptr;
ptr = find_value_end(ptr);
*ptr = '\0';
}
}
}
static void parse_file(FILE *stream, struct variable_s **list)
{
char line[10242];
struct variable_s *curr;
struct variable_s *prev;
struct variable_s *next;
char *varname;
char *varval;
char *ptr;
do
{
ptr = read_line(stream, line, 1024);
if (ptr)
{
parse_line(ptr, &varname, &varval);
if (!varval || strcmp(varval, "n") == 0)
{
continue;
}
if (varname)
{
int varlen = strlen(varname) + 1;
int vallen = 0;
if (varval)
{
vallen = strlen(varval) + 1;
}
curr = (struct variable_s *)malloc(sizeof(struct variable_s) + varlen + vallen - 1);
if (curr)
{
curr->var = &curr->storage[0];
strcpy(curr->var, varname);
curr->val = NULL;
if (varval)
{
curr->val = &curr->storage[varlen];
strcpy(curr->val, varval);
}
}
prev = 0;
next = *list;
while (next && strcmp(next->var, curr->var) <= 0)
{
prev = next;
next = next->flink;
}
if (prev)
{
prev->flink = curr;
}
else
{
*list = curr;
}
curr->flink = next;
}
}
}
while (ptr);
}
static void compare_variables(struct variable_s *list1, struct variable_s *list2)
{
char *varval1;
char *varval2;
while (list1 || list2)
{
if (list1 && list1->val)
{
varval1 = list1->val;
}
else
{
varval1 = "<NULL>";
}
if (list2 && list2->val)
{
varval2 = list2->val;
}
else
{
varval2 = "<NULL>";
}
if (!list1)
{
printf("file1:\n");
printf("file2: %s=%s\n\n", list2->var, varval2);
list2 = list2->flink;
}
else if (!list2)
{
printf("file1: %s=%s\n", list1->var, varval1);
printf("file2:\n\n");
list1 = list1->flink;
}
else
{
int result = strcmp(list1->var, list2->var);
if (result < 0)
{
printf("file1: %s=%s\n", list1->var, varval1);
printf("file2:\n\n");
list1 = list1->flink;
}
else if (result > 0)
{
printf("file1:\n");
printf("file2: %s=%s\n\n", list2->var, varval2);
list2 = list2->flink;
}
else
{
int result = strcmp(varval1, varval2);
if (result != 0)
{
printf("file1: %s=%s\n", list1->var, varval1);
printf("file2: %s=%s\n\n", list2->var, varval2);
}
list1 = list1->flink;
list2 = list2->flink;
}
}
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
struct variable_s *list1 = 0;
struct variable_s *list2 = 0;
FILE *stream1;
FILE *stream2;
if (argc != 3)
{
fprintf(stderr, "Unexpected number of arguments: %d\n\n", argc);
show_usage(argv[0]);
}
stream1 = fopen(argv[1], "r");
if (!stream1)
{
fprintf(stderr, "Failed to open %s for reading: %s\n\n",
argv[1], strerror(errno));
show_usage(argv[0]);
}
stream2 = fopen(argv[2], "r");
if (!stream2)
{
fprintf(stderr, "Failed to open %s for reading: %s\n\n",
argv[2], strerror(errno));
show_usage(argv[0]);
}
parse_file(stream1, &list1);
parse_file(stream2, &list2);
fclose(stream1);
fclose(stream2);
printf("Comparing:\n\n");
printf(" file1 = %s\n", argv[1]);
printf(" file2 = %s\n\n", argv[2]);
compare_variables(list1, list2);
return EXIT_SUCCESS;
}
+208
View File
@@ -0,0 +1,208 @@
#!/bin/bash
# configure.sh
#
# Copyright (C) 2007, 2008, 2011 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.
#
WD=`pwd`
TOPDIR="${WD}/.."
USAGE="
USAGE: ${0} [-d] [-a <app-dir>] <board-name>/<config-name>
Where:
<board-name> is the name of the board in the configs directory
<config-name> is the name of the board configuration sub-directory
<add-dir> is the path to the apps/ directory, relative to the nuttx directory
"
# Parse command arguments
unset boardconfig
unset appdir
while [ ! -z "$1" ]; do
case "$1" in
-d )
set -x
;;
-h )
echo "$USAGE"
exit 0
;;
-a )
shift
appdir=$1
;;
*)
if [ ! -z "${boardconfig}" ]; then
echo ""
echo "<board/config> defined twice"
echo "$USAGE"
exit 1
fi
boardconfig=$1
;;
esac
shift
done
# Sanity checking
if [ -z "${boardconfig}" ]; then
echo ""
echo "Missing <board/config> argument"
echo "$USAGE"
exit 2
fi
configpath=${TOPDIR}/configs/${boardconfig}
if [ ! -d "${configpath}" ]; then
echo "Directory ${configpath} does not exist. Options are:"
echo ""
echo "Select one of the following options for <board-name>:"
configlist=`find ${TOPDIR}/configs -name defconfig`
for defconfig in $configlist; do
config=`dirname $defconfig | sed -e "s,${TOPDIR}/configs/,,g"`
echo " $config"
done
echo ""
echo "$USAGE"
exit 3
fi
if [ ! -r "${configpath}/Make.defs" ]; then
echo "File \"${configpath}/Make.defs\" does not exist"
exit 4
fi
if [ ! -r "${configpath}/setenv.sh" ]; then
echo "File \"${configpath}/setenv.sh\" does not exist"
exit 5
fi
if [ ! -r "${configpath}/defconfig" ]; then
echo "File \"${configpath}/defconfig\" does not exist"
exit 6
fi
# Extract values needed from the defconfig file. We need:
# (1) The CONFIG_NUTTX_NEWCONFIG setting to know if this is a "new" style
# configuration, and
# (2) The CONFIG_APPS_DIR to see if there is a configured location for the
# application directory.
newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${configpath}/defconfig" | cut -d'=' -f2`
defappdir=y
if [ -z "${appdir}" ]; then
quoted=`grep "^CONFIG_APPS_DIR=" "${configpath}/defconfig" | cut -d'=' -f2`
if [ ! -z "${appdir}" ]; then
appdir=`echo ${quoted} | sed -e "s/\"//g"`
defappdir=n
fi
fi
# Check for the apps/ directory in the usual place if appdir was not provided
if [ -z "${appdir}" ]; then
# Check for a version file
unset CONFIG_VERSION_STRING
if [ -x "${TOPDIR}/.version" ]; then
. "${TOPDIR}/.version"
fi
# Check for an unversioned apps/ directory
if [ -d "${TOPDIR}/../apps" ]; then
appdir="../apps"
else
# Check for a versioned apps/ directory
if [ -d "${TOPDIR}/../apps-${CONFIG_VERSION_STRING}" ]; then
appdir="../apps-${CONFIG_VERSION_STRING}"
fi
fi
fi
# If appsdir was provided (or discovered) then make sure that the apps/
# directory exists
if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${appdir}" ]; then
echo "Directory \"${TOPDIR}/${appdir}\" does not exist"
exit 7
fi
# Okay... Everything looks good. Setup the configuration
install -C "${configpath}/Make.defs" "${TOPDIR}/." || \
{ echo "Failed to copy ${configpath}/Make.defs" ; exit 7 ; }
install -C "${configpath}/setenv.sh" "${TOPDIR}/." || \
{ echo "Failed to copy ${configpath}/setenv.sh" ; exit 8 ; }
chmod 755 "${TOPDIR}/setenv.sh"
install -C "${configpath}/defconfig" "${TOPDIR}/.configX" || \
{ echo "Failed to copy ${configpath}/defconfig" ; exit 9 ; }
# If we did not use the CONFIG_APPS_DIR that was in the defconfig config file,
# then append the correct application information to the tail of the .config
# file
if [ "X${defappdir}" = "Xy" ]; then
sed -i -e "/^CONFIG_APPS_DIR/d" "${TOPDIR}/.configX"
echo "" >> "${TOPDIR}/.configX"
echo "# Application configuration" >> "${TOPDIR}/.configX"
echo "" >> "${TOPDIR}/.configX"
echo "CONFIG_APPS_DIR=\"$appdir\"" >> "${TOPDIR}/.configX"
fi
# Copy appconfig file. The appconfig file will be copied to ${appdir}/.config
# if both (1) ${appdir} is defined and (2) we are not using the new configuration
# (which does not require a .config file in the appsdir.
if [ ! -z "${appdir}" -a "X${newconfig}" != "Xy" ]; then
if [ ! -r "${configpath}/appconfig" ]; then
echo "NOTE: No readable appconfig file found in ${configpath}"
else
install -C "${configpath}/appconfig" "${TOPDIR}/${appdir}/.config" || \
{ echo "Failed to copy ${configpath}/appconfig" ; exit 10 ; }
fi
fi
# install the final .configX only if it differs from any existing
# .config file.
install -C "${TOPDIR}/.configX" "${TOPDIR}/.config"
rm -f "${TOPDIR}/.configX"
+234
View File
@@ -0,0 +1,234 @@
/****************************************************************************
* tools/csvparser.c
*
* Copyright (C) 2011-2012 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "csvparser.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
bool g_debug;
char g_line[LINESIZE+1];
char g_parm[MAX_FIELDS][MAX_PARMSIZE];
int g_lineno;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: skip_space
****************************************************************************/
static char *skip_space(char *ptr)
{
while (*ptr && isspace((int)*ptr)) ptr++;
return ptr;
}
/****************************************************************************
* Name: copy_parm
****************************************************************************/
static char *copy_parm(char *src, char *dest)
{
char *start = src;
int i;
/* De-quote the parameter and copy it into the parameter array */
for (i = 0; i < MAX_PARMSIZE; i++)
{
if (*src == '"')
{
*dest = '\0';
return src;
}
else if (*src == '\n' || *src == '\0')
{
fprintf(stderr, "%d: Unexpected end of line: \"%s\"\n", g_lineno, start);
exit(4);
}
else
{
*dest++ = *src++;
}
}
fprintf(stderr, "%d: Parameter too long: \"%s\"\n", g_lineno, start);
exit(3);
}
/****************************************************************************
* Name: find_parm
****************************************************************************/
static char *find_parm(char *ptr)
{
char *start = ptr;
if (*ptr != '"')
{
fprintf(stderr, "%d: I'm confused: \"%s\"\n", g_lineno, start);
exit(5);
}
ptr++;
ptr = skip_space(ptr);
if (*ptr == '\n' || *ptr == '\0')
{
return NULL;
}
else if (*ptr != ',')
{
fprintf(stderr, "%d: Expected ',': \"%s\"\n", g_lineno, start);
exit(6);
}
ptr++;
ptr = skip_space(ptr);
if (*ptr != '"')
{
fprintf(stderr, "%d: Expected \": \"%s\"\n", g_lineno, start);
exit(7);
}
ptr++;
return ptr;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: read_line
****************************************************************************/
char *read_line(FILE *stream)
{
char *ptr;
for (;;)
{
g_line[LINESIZE] = '\0';
if (!fgets(g_line, LINESIZE, stream))
{
return NULL;
}
else
{
g_lineno++;
if (g_debug)
{
printf("Line: %s\n", g_line);
}
ptr = skip_space(g_line);
if (*ptr && *ptr != '#' && *ptr != '\n')
{
return ptr;
}
}
}
}
/****************************************************************************
* Name: parse_csvline
****************************************************************************/
int parse_csvline(char *ptr)
{
int nparms;
int i;
/* Format "arg1","arg2","arg3",... Spaces will be tolerated outside of the
* quotes. Any initial spaces have already been skipped so the first thing
* should be '"'.
*/
if (*ptr != '"')
{
fprintf(stderr, "%d: Bad line: \"%s\"\n", g_lineno, g_line);
exit(2);
}
ptr++;
nparms = 0;
/* Copy each comma-separated value in an array (stripping quotes from each
* of the values).
*/
do
{
ptr = copy_parm(ptr, &g_parm[nparms][0]);
nparms++;
ptr = find_parm(ptr);
}
while (ptr);
/* If debug is enabled, show what we got */
if (g_debug)
{
printf("Parameters: %d\n", nparms);
for (i = 0; i < nparms; i++)
{
printf(" Parm%d: \"%s\"\n", i+1, g_parm[i]);
}
}
return nparms;
}
+76
View File
@@ -0,0 +1,76 @@
/****************************************************************************
* tools/csvparser.h
*
* Copyright (C) 2011-2012 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.
*
****************************************************************************/
#ifndef __TOOLS_CSVPARSER_H
#define __TOOLS_CSVPARSER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
#include <limits.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define LINESIZE (PATH_MAX > 256 ? PATH_MAX : 256)
#define MAX_FIELDS 16
#define MAX_PARMSIZE 128
#define NAME_INDEX 0
#define HEADER_INDEX 1
#define COND_INDEX 2
#define RETTYPE_INDEX 3
#define PARM1_INDEX 4
/****************************************************************************
* Public Data
****************************************************************************/
extern bool g_debug;
extern char g_line[LINESIZE+1];
extern char g_parm[MAX_FIELDS][MAX_PARMSIZE];
extern int g_lineno;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
char *read_line(FILE *stream);
int parse_csvline(char *ptr);
#endif /* __TOOLS_CSVPARSER_H */
+224
View File
@@ -0,0 +1,224 @@
#!/bin/bash
# tools/define.sh
#
# Copyright (C) 2011 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.
#
#
# Handle command line options
#
progname=$0
wintool=n
usage="USAGE: $progname [-w] [-d] [-l] [-h] <compiler-path> <def1>[=val1] [<def2>[=val2] [<def3>[=val3] ...]]"
advice="Try '$progname -h' for more information"
while [ ! -z "$1" ]; do
case $1 in
-d )
set -x
;;
-w )
wintool=y
;;
-h )
echo "$progname is a tool for flexible generation of command line pre-processor"
echo "definitions arguments for a variety of diffent compilers in a variety of"
echo "compilation environments"
echo ""
echo $usage
echo ""
echo "Where:"
echo " <compiler-path>"
echo " The full path to your compiler"
echo " <def1> <def2> [<def3> ..."
echo " A list of pre-preprocesser variable names to be defind."
echo " [=val1] [=val2] [=val3]"
echo " optional values to be assigned to each pre-processor variable."
echo " If not supplied, the variable will be defined with no explicit value."
echo " -w"
echo " The compiler is a Windows native tool and requires Windows"
echo " style pathnames like C:\\Program Files"
echo " -d"
echo " Enable script debug"
;;
* )
break;
;;
esac
shift
done
ccpath=$1
shift
varlist=$@
if [ -z "$ccpath" ]; then
echo "Missing compiler path"
echo $usage
echo $advice
exit 1
fi
if [ -z "$varlist" ]; then
echo "Missing definition list"
echo $usage
echo $advice
exit 1
fi
#
# Most compilers support CFLAG options like '-D<defn>' to add pre-processor
# variable defintions. Some (like the Zilog tools), do not. This script
# makes the selection of pre-processor definitions compiler independent.
#
# Below are all known compiler names (as found in the config/*/*/Make.defs
# files). If a new compiler is used that has some unusual syntax, then
# additional logic needs to be added to this file.
#
# NAME Syntax
# $(CROSSDEV)gcc -D<def1> -D<def2> -D<def3> ...
# sdcc -D<def2> -D<def2> -D<def3> ...
# $(ZDSBINDIR)/ez8cc.exe -define:<def1> -define:<def2> -define:<def3> ...
# $(ZDSBINDIR)/zneocc.exe -define:<def1> -define:<def2> -define:<def3> ...
# $(ZDSBINDIR)/ez80cc.exe -define:<def1> -define:<def2> -define:<def3> ...
#
os=`uname -o 2>/dev/null || echo "Other"`
#
# Let's assume that all GCC compiler paths contain the string gcc and
# no non-GCC compiler pathes include this substring
#
gcc=`echo $ccpath | grep gcc`
sdcc=`echo $ccpath | grep sdcc`
if [ "X$os" = "XCygwin" ]; then
#
# We can treat Cygwin native toolchains just like Linux native
# toolchains in the Linux. Let's assume:
# 1. GCC or SDCC are the only possible Cygwin native compilers
# 2. If this is a Window native GCC version, then -w provided
# on the command line (wintool=y)
if [ -z "$gcc" -a -z "$sdcc" ]; then
#
# Not GCC or SDCC, must be Windows native
#
compiler=`cygpath -u "$ccpath"`
else
if [ "X$wintool" == "Xy" ]; then
#
# It is a native GCC or SDCC compiler
#
compiler=`cygpath -u "$ccpath"`
else
#
# GCC or SDCC and not for Windows
#
compiler="$ccpath"
fi
fi
else
#
# Otherwise, we must be in a Linux environment where there are
# only Linux native toolchains
#
compiler="$ccpath"
fi
exefile=`basename "$compiler"`
# Check for some well known, non-GCC Windows native tools that require
# a special output format as well as special paths
if [ "X$exefile" = "Xez8cc.exe" -o "X$exefile" = "Xzneocc.exe" -o "X$exefile" = "Xez80cc.exe" ]; then
fmt=define
else
fmt=std
fi
# Now process each directory in the directory list
unset response
for vardef in $varlist; do
varname=`echo $vardef | cut -d'=' -f1`
varvalue=`echo $vardef | cut -d'=' -f2`
# Handle the output depending on if there is a value for the variable or not
if [ -z "$varvalue" ]; then
# Handle the output using the selected format
if [ "X$fmt" = "Xdefine" ]; then
# Treat the first definition differently
if [ -z "$response" ]; then
response="-define:"$varname
else
response=$response" -define:$varname"
fi
else
# Treat the first definition differently
if [ -z "$response" ]; then
response=-D$varname
else
response=$response" -D$varname"
fi
fi
else
# Handle the output using the selected format
if [ "X$fmt" = "Xdefine" ]; then
# Treat the first definition differently
if [ -z "$response" ]; then
response="-define:"$varname=$varvalue
else
response=$response" -define:$varname=$varvalue"
fi
else
# Treat the first definition differently
if [ -z "$response" ]; then
response=-D$varname=$varvalue
else
response=$response" -D$varname=$varvalue"
fi
fi
fi
done
echo $response
+98
View File
@@ -0,0 +1,98 @@
#!/usr/bin/env python
############################################################################
# tools/discover.py
#
# Copyright (C) 2012 Max Holtzberg. All rights reserved.
# Author: Max Holtzberg <mh@uvc.de>
#
# 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.
#
############################################################################
import array
import time
from socket import *
PORT = 96
DISCOVER_PROTO_ID = 0x99
DISCOVER_ALL = 0xff # 0xff means all devices
DISCOVER_REQUEST = 0x01
DISCOVER_RESPONSE = 0x02
DISCOVER_REQUEST_SIZE = 4
DISCOVER_RESPONSE_SIZE = 35
def check_sum(data):
chksum = 0
for c in data[:-1]:
chksum -= c
return (chksum & 0xff) == data[-1]
def send_discover(socket):
cmd = array.array('B', [0] * DISCOVER_REQUEST_SIZE)
cmd[0] = DISCOVER_PROTO_ID # Tag for identification of the protocol
cmd[1] = DISCOVER_REQUEST # Request command
cmd[2] = DISCOVER_ALL
chksum = 0
for c in cmd[:3]:
chksum -= c;
cmd[3] = chksum & 0xff
socket.sendto(cmd, ('<broadcast>', PORT))
def read_responses(socket):
res = []
response = array.array('B', [0] * DISCOVER_RESPONSE_SIZE)
try:
while 1:
size, src = socket.recvfrom_into(response)
if (size == DISCOVER_RESPONSE_SIZE
and response[0] == DISCOVER_PROTO_ID
and response[1] == DISCOVER_RESPONSE
and check_sum(response)):
dev = {}
dev['addr'] = src[0]
dev['descr'] = response[2:-1].tostring().rstrip('\0')
res.append(dev)
except timeout:
return res
if __name__ == '__main__':
print 'Sending discover...'
s = socket(AF_INET, SOCK_DGRAM)
s.bind(('0.0.0.0', PORT))
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.settimeout(1.0);
send_discover(s)
devices = read_responses(s)
socket.close(s)
print devices
+211
View File
@@ -0,0 +1,211 @@
#!/bin/bash
# tools/incdir.sh
#
# Copyright (C) 2008-2009, 2011 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.
#
# Handle command line options
progname=$0
wintool=n
usage="USAGE: $progname [-w] [-d] [-h] <compiler-path> <dir1> [<dir2> [<dir3> ...]]"
advice="Try '$progname -h' for more information"
while [ ! -z "$1" ]; do
case $1 in
-d )
set -x
;;
-w )
wintool=y
;;
-h )
echo "$progname is a tool for flexible generation of include path arguments for a"
echo "variety of different compilers in a variety of compilation environments"
echo ""
echo $usage
echo ""
echo "Where:"
echo " <compiler-path>"
echo " The full path to your compiler"
echo " <dir1> [<dir2> [<dir3> ...]]"
echo " A list of include directories"
echo " -w"
echo " The compiler is a Windows native tool and requires Windows"
echo " style pathnames like C:\\Program Files"
echo " -d"
echo " Enable script debug"
;;
* )
break;
;;
esac
shift
done
ccpath=$1
shift
dirlist=$@
if [ -z "$ccpath" ]; then
echo "Missing compiler path"
echo $usage
echo $advice
exit 1
fi
if [ -z "$dirlist" ]; then
echo "Missing include directory list"
echo $usage
echo $advice
exit 1
fi
#
# Most compilers support CFLAG options like '-I<dir>' to add include
# file header paths. Some (like the Zilog tools), do not. This script
# makes the selection of header file paths compiler independent.
#
# Below are all known compiler names (as found in the config/*/*/Make.defs
# files). If a new compiler is used that has some unusual syntax, then
# additional logic needs to be added to this file.
#
# NAME Syntax
# $(CROSSDEV)gcc -I<dir1> -I<dir2> -I<dir3> ...
# sdcc -I<dir2> -I<dir2> -I<dir3> ...
# $(ZDSBINDIR)/ez8cc.exe -usrinc:'<dir1>:<dir2>:<dir3>:...`
# $(ZDSBINDIR)/zneocc.exe -usrinc:'<dir1>:<dir2>:<dir3>:...`
# $(ZDSBINDIR)/ez80cc.exe -usrinc:'<dir1>:<dir2>:<dir3>:...`
#
# Furthermore, just to make matters more difficult, with Windows based
# toolchains, we have to use the full windows-style paths to the header
# files.
os=`uname -o 2>/dev/null || echo "Other"`
# Let's assume that all GCC compiler paths contain the string gcc or
# g++ and no non-GCC compiler pathes include these substrings
gcc=`echo $ccpath | grep gcc`
if [ -z "${gcc}" ]; then
gcc=`echo $ccpath | grep g++`
fi
sdcc=`echo $ccpath | grep sdcc`
if [ "X$os" = "XCygwin" ]; then
# We can treat Cygwin native toolchains just like Linux native
# toolchains in the Linux. Let's assume:
# 1. GCC or SDCC are the only possible Cygwin native compilers
# 2. If this is a Window native GCC version, then -w must be
# provided on the command line (wintool=y)
if [ -z "$gcc" -a -z "$sdcc" ]; then
# Not GCC or SDCC, must be Windows native
windows=yes
compiler=`cygpath -u "$ccpath"`
else
if [ "X$wintool" == "Xy" ]; then
# It is a native GCC or SDCC compiler
windows=yes
compiler=`cygpath -u "$ccpath"`
else
# GCC or SDCC and not for Windows
windows=no
compiler="$ccpath"
fi
fi
else
# Otherwise, we must be in a Linux environment where there are
# only Linux native toolchains
windows=no
compiler="$ccpath"
fi
exefile=`basename "$compiler"`
# Check for some well known, non-GCC Windows native tools that require
# a special output format as well as special paths
if [ "X$exefile" = "Xez8cc.exe" -o "X$exefile" = "Xzneocc.exe" -o "X$exefile" = "Xez80cc.exe" ]; then
fmt=userinc
else
fmt=std
fi
# Now process each directory in the directory list
unset response
for dir in $dirlist; do
# Verify that the include directory exists
if [ ! -d $dir ]; then
echo "Include path '$dir' does not exist"
echo $showusage
exit 1
fi
# Check if the path needs to be extended for Windows-based tools under Cygwin
if [ "X$windows" = "Xyes" ]; then
path=`cygpath -w $dir`
else
path=$dir
fi
# Handle the output using the selected format
if [ "X$fmt" = "Xuserinc" ]; then
# Treat the first directory differently
if [ -z "$response" ]; then
response="-usrinc:'"$path
else
response=$response":$path"
fi
else
# Treat the first directory differently
if [ -z "$response" ]; then
response=-I\"$path\"
else
response=$response" -I\"$path\""
fi
fi
done
if [ "X$fmt" = "Xuserinc" ]; then
response=$response"'"
fi
echo $response
+85
View File
@@ -0,0 +1,85 @@
#!/bin/sh
############################################################################
# tools/indent.sh
#
# Copyright (C) 2008, 2010 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.
#
############################################################################
#
# This script uses the Linux 'indent' utility to re-format C source files
# to match the coding style that I use. It differs from my coding style in that
#
# - I normally put the trailing */ of a multi-line comment on a separate line,
# - I usually align things vertically (like '=' in assignments),
# - indent puts a bogus blank line at the top of the file,
# - I don't like the way it handles nested conditional compilation intermixed with code.
#
# Constants
options="-nbad -bap -bbb -nbbo -nbc -bl -bl2 -bls -nbs -cbi2 -ncdw -nce -ci2 -cli0 -cp40 -ncs -nbfda -nbfde -di1 -nfc1 -fca -i2 -l80 -lp -ppi2 -lps -npcs -pmt -nprs -npsl -saf -sai -sbi2 -saw -sc -sob -nss -nut"
usage="USAGE: $0 <in-file> <out-file>"
# Inputs
infile=$1
outfile=$2
# Verify inputs
if [ -z "$infile" ]; then
echo "Missing <in-file>"
echo $usage
exit 1
fi
if [ ! -r $infile ]; then
echo "Readable $infile does not exist"
exit 1
fi
if [ -z "$outfile" ]; then
echo "Missing <out-file>"
echo $usage
exit 1
fi
if [ -f $outfile ]; then
echo "Removing old $outfile"
rm $outfile || { echo "Failed to remove $outfile" ; exit 1 ; }
fi
# Perform the indentation
indent $options $infile -o $outfile
+87
View File
@@ -0,0 +1,87 @@
#!/bin/bash
############################################################################
# tools/link.sh
#
# Copyright (C) 2008 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.
#
############################################################################
#set -x
src=$1
dest=$2
# Verify that arguments were provided
if [ -z "${src}" -o -z "${dest}" ]; then
echo "Missing src and/or dest arguments"
exit 1
fi
# Check if something already exists at the destination path replace it with
# the new link (which might be different). Note that we check for the
# the link (-h) before we check for existence (-e) because a bad link will
# report that it does not exist.
if [ -h "${dest}" ]; then
rm -f "${dest}"
else
# If the path exists and is a directory that contains the "fake link"
# mark, then treat it like a soft link (i.e., remove the directory)
if [ -d "${dest}" -a -f "${dest}/.fakelnk" ]; then
rm -rf "${dest}"
else
# Does anything exist at the destination path?
if [ -e "${dest}" ]; then
# It is something else (like a file) or directory that does
# not contain the "fake link" mark
echo "${dest} already exists but is not a symbolic link"
exit 1
fi
fi
fi
# Verify that a directory exists at the source path
if [ ! -d "${src}" ]; then
echo "No directory at ${src}"
exit 1
fi
# Create the soft link
ln -s "${src}" "${dest}" || \
{ echo "Failed to create link: $dest" ; exit 1 ; }
+277
View File
@@ -0,0 +1,277 @@
/****************************************************************************
* tools/mkconfig.c
*
* Copyright (C) 2007-2012 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "cfgparser.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DEFCONFIG ".config"
/****************************************************************************
* Private Functions
****************************************************************************/
static inline char *getfilepath(const char *name)
{
snprintf(line, PATH_MAX, "%s/" DEFCONFIG, name);
line[PATH_MAX] = '\0';
return strdup(line);
}
static void show_usage(const char *progname)
{
fprintf(stderr, "USAGE: %s <abs path to .config>\n", progname);
exit(1);
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
char *filepath;
FILE *stream;
if (argc != 2)
{
fprintf(stderr, "Unexpected number of arguments\n");
show_usage(argv[0]);
}
filepath = getfilepath(argv[1]);
if (!filepath)
{
fprintf(stderr, "getfilepath failed\n");
exit(2);
}
stream = fopen(filepath, "r");
if (!stream)
{
fprintf(stderr, "open %s failed: %s\n", filepath, strerror(errno));
exit(3);
}
printf("/* config.h -- Autogenerated! Do not edit. */\n\n");
printf("#ifndef __INCLUDE_NUTTX_CONFIG_H\n");
printf("#define __INCLUDE_NUTTX_CONFIG_H\n\n");
printf("/* Architecture-specific options *************************/\n\n");
parse_file(stream);
printf("\n/* Sanity Checks *****************************************/\n\n");
printf("/* If this is an NXFLAT, external build, then make sure that\n");
printf(" * NXFLAT support is enabled in the base code.\n");
printf(" */\n\n");
printf("#if defined(__NXFLAT__) && !defined(CONFIG_NXFLAT)\n");
printf("# error \"NXFLAT support not enabled in this configuration\"\n");
printf("#endif\n\n");
printf("/* NXFLAT requires PIC support in the TCBs. */\n\n");
printf("#if defined(CONFIG_NXFLAT)\n");
printf("# undef CONFIG_PIC\n");
printf("# define CONFIG_PIC 1\n");
printf("#endif\n\n");
printf("/* Binary format support is disabled if no binary formats are\n");
printf(" * configured (at present, NXFLAT is the only supported binary.\n");
printf(" * format).\n");
printf(" */\n\n");
printf("#if !defined(CONFIG_NXFLAT)\n");
printf("# undef CONFIG_BINFMT_DISABLE\n");
printf("# define CONFIG_BINFMT_DISABLE 1\n");
printf("#endif\n\n");
printf("/* The correct way to disable RR scheduling is to set the\n");
printf(" * timeslice to zero.\n");
printf(" */\n\n");
printf("#ifndef CONFIG_RR_INTERVAL\n");
printf("# define CONFIG_RR_INTERVAL 0\n");
printf("#endif\n\n");
printf("/* The correct way to disable filesystem supuport is to set the\n");
printf(" * number of file descriptors to zero.\n");
printf(" */\n\n");
printf("#ifndef CONFIG_NFILE_DESCRIPTORS\n");
printf("# define CONFIG_NFILE_DESCRIPTORS 0\n");
printf("#endif\n\n");
printf("/* If a console is selected, then make sure that there are\n");
printf(" * resources for 3 file descriptors and, if any streams are\n");
printf(" * selected, also for 3 file streams.\n");
printf(" */\n\n");
printf("#ifdef CONFIG_DEV_CONSOLE\n");
printf("# if CONFIG_NFILE_DESCRIPTORS < 3\n");
printf("# undef CONFIG_NFILE_DESCRIPTORS\n");
printf("# define CONFIG_NFILE_DESCRIPTORS 3\n");
printf("# endif\n\n");
printf("# if CONFIG_NFILE_STREAMS > 0 && CONFIG_NFILE_STREAMS < 3\n");
printf("# undef CONFIG_NFILE_STREAMS\n");
printf("# define CONFIG_NFILE_STREAMS 3\n");
printf("# endif\n\n");
printf("/* If no console is selected, then disable all console devices */\n\n");
printf("#else\n");
printf("# undef CONFIG_DEV_LOWCONSOLE\n");
printf("# undef CONFIG_RAMLOG_CONSOLE\n");
printf("# undef CONFIG_CDCACM_CONSOLE\n");
printf("# undef CONFIG_PL2303_CONSOLE\n");
printf("#endif\n\n");
printf("/* If priority inheritance is disabled, then do not allocate any\n");
printf(" * associated resources.\n");
printf(" */\n\n");
printf("#if !defined(CONFIG_PRIORITY_INHERITANCE) || !defined(CONFIG_SEM_PREALLOCHOLDERS)\n");
printf("# undef CONFIG_SEM_PREALLOCHOLDERS\n");
printf("# define CONFIG_SEM_PREALLOCHOLDERS 0\n");
printf("#endif\n\n");
printf("#if !defined(CONFIG_PRIORITY_INHERITANCE) || !defined(CONFIG_SEM_NNESTPRIO)\n");
printf("# undef CONFIG_SEM_NNESTPRIO\n");
printf("# define CONFIG_SEM_NNESTPRIO 0\n");
printf("#endif\n\n");
printf("/* If no file descriptors are configured, then make certain no\n");
printf(" * streams are configured either.\n");
printf(" */\n\n");
printf("#if CONFIG_NFILE_DESCRIPTORS == 0\n");
printf("# undef CONFIG_NFILE_STREAMS\n");
printf("# define CONFIG_NFILE_STREAMS 0\n");
printf("#endif\n\n");
printf("/* There must be at least one memory region. */\n\n");
printf("#ifndef CONFIG_MM_REGIONS\n");
printf("# define CONFIG_MM_REGIONS 1\n");
printf("#endif\n\n");
printf("/* If the end of RAM is not specified then it is assumed to be the beginning\n");
printf(" * of RAM plus the RAM size.\n");
printf(" */\n\n");
printf("#ifndef CONFIG_DRAM_END\n");
printf("# define CONFIG_DRAM_END (CONFIG_DRAM_START+CONFIG_DRAM_SIZE)\n");
printf("#endif\n\n");
printf("/* If no file streams are configured, then make certain that buffered I/O\n");
printf(" * support is disabled\n");
printf(" */\n\n");
printf("#if CONFIG_NFILE_STREAMS == 0\n");
printf("# undef CONFIG_STDIO_BUFFER_SIZE\n");
printf("# define CONFIG_STDIO_BUFFER_SIZE 0\n");
printf("#endif\n\n");
printf("/* We are building a kernel version of the C library, then some user-space features\n");
printf(" * need to be disabled\n");
printf(" */\n\n");
printf("#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__)\n");
printf("# undef CONFIG_STDIO_BUFFER_SIZE\n");
printf("# define CONFIG_STDIO_BUFFER_SIZE 0\n");
printf("# undef CONFIG_NUNGET_CHARS\n");
printf("# define CONFIG_NUNGET_CHARS 0\n");
printf("#endif\n\n");
printf("/* If no standard C buffered I/O is not supported, then line-oriented buffering\n");
printf(" * cannot be supported.\n");
printf(" */\n\n");
printf("#if CONFIG_STDIO_BUFFER_SIZE == 0\n");
printf("# undef CONFIG_STDIO_LINEBUFFER\n");
printf("#endif\n\n");
printf("/* If the maximum message size is zero, then we assume that message queues\n");
printf(" * support should be disabled\n");
printf(" */\n\n");
printf("#if CONFIG_MQ_MAXMSGSIZE <= 0 && !defined(CONFIG_DISABLE_MQUEUE)\n");
printf("# define CONFIG_DISABLE_MQUEUE 1\n");
printf("#endif\n\n");
printf("/* If mountpoint support in not included, then no filesystem can be supported */\n\n");
printf("#ifdef CONFIG_DISABLE_MOUNTPOINT\n");
printf("# undef CONFIG_FS_FAT\n");
printf("# undef CONFIG_FS_ROMFS\n");
printf("# undef CONFIG_FS_NXFFS\n");
printf("# undef CONFIG_APPS_BINDIR\n");
printf("# undef CONFIG_NFS\n");
printf("#endif\n\n");
printf("/* Check if any readable and writable filesystem (OR USB storage) is supported */\n\n");
printf("#undef CONFIG_FS_READABLE\n");
printf("#undef CONFIG_FS_WRITABLE\n");
printf("#if defined(CONFIG_FS_FAT) || defined(CONFIG_FS_ROMFS) || defined(CONFIG_USBMSC) || \\\n");
printf(" defined(CONFIG_FS_NXFFS) || defined(CONFIG_APPS_BINDIR) || defined(CONFIG_NFS)\n");
printf("# define CONFIG_FS_READABLE 1\n");
printf("#endif\n\n");
printf("#if defined(CONFIG_FS_FAT) || defined(CONFIG_USBMSC) || defined(CONFIG_FS_NXFFS) || \\\n");
printf(" defined(CONFIG_NFS)\n");
printf("# define CONFIG_FS_WRITABLE 1\n");
printf("#endif\n\n");
printf("/* There can be no network support with no socket descriptors */\n\n");
printf("#if CONFIG_NSOCKET_DESCRIPTORS <= 0\n");
printf("# undef CONFIG_NET\n");
printf("#endif\n\n");
printf("/* Conversely, if there is no network support, there is no need for\n");
printf(" * socket descriptors\n");
printf(" */\n\n");
printf("#ifndef CONFIG_NET\n");
printf("# undef CONFIG_NSOCKET_DESCRIPTORS\n");
printf("# define CONFIG_NSOCKET_DESCRIPTORS 0\n");
printf("#endif\n\n");
printf("/* Protocol support can only be provided on top of basic network support */\n\n");
printf("#ifndef CONFIG_NET\n");
printf("# undef CONFIG_NET_TCP\n");
printf("# undef CONFIG_NET_UDP\n");
printf("# undef CONFIG_NET_ICMP\n");
printf("#endif\n\n");
printf("/* NFS client can only be provided on top of UDP network support */\n\n");
printf("#if !defined(CONFIG_NET) || !defined(CONFIG_NET_UDP)\n");
printf("# undef CONFIG_NFS\n");
printf("#endif\n\n");
printf("/* Verbose debug and sub-system debug only make sense if debug is enabled */\n\n");
printf("#ifndef CONFIG_DEBUG\n");
printf("# undef CONFIG_DEBUG_VERBOSE\n");
printf("# undef CONFIG_DEBUG_SCHED\n");
printf("# undef CONFIG_DEBUG_MM\n");
printf("# undef CONFIG_DEBUG_PAGING\n");
printf("# undef CONFIG_DEBUG_DMA\n");
printf("# undef CONFIG_DEBUG_FS\n");
printf("# undef CONFIG_DEBUG_LIB\n");
printf("# undef CONFIG_DEBUG_BINFMT\n");
printf("# undef CONFIG_DEBUG_NET\n");
printf("# undef CONFIG_DEBUG_USB\n");
printf("# undef CONFIG_DEBUG_GRAPHICS\n");
printf("# undef CONFIG_DEBUG_GPIO\n");
printf("# undef CONFIG_DEBUG_SPI\n");
printf("# undef CONFIG_DEBUG_STACK\n");
printf("#endif\n\n");
printf("/* User entry point. This is provided as a fall-back to keep compatibility\n");
printf(" * with existing code, for builds which do not define CONFIG_USER_ENTRYPOINT.\n");
printf(" */\n\n");
printf("#ifndef CONFIG_USER_ENTRYPOINT\n");
printf("# define CONFIG_USER_ENTRYPOINT user_start\n");
printf("#endif\n\n");
printf("#endif /* __INCLUDE_NUTTX_CONFIG_H */\n");
fclose(stream);
return 0;
}
+196
View File
@@ -0,0 +1,196 @@
#!/bin/bash
############################################################################
# tools/mkdeps.sh
#
# Copyright (C) 2007-2009, 2011 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.
#
############################################################################
#
# Usage:
show_usage ()
{
echo ""
echo "$progname [OPTIONS] CC -- CFLAGS -- file [file [file...]]"
echo ""
echo "Where:"
echo " CC"
echo " A variable number of arguments that define how to execute the compiler"
echo " CFLAGS"
echo " The compiler compilation flags"
echo " file"
echo " One or more C files whose dependencies will be checked. Each file is expected"
echo " to reside in the current directory unless --dep-path is provided on the command line"
echo ""
echo "And [OPTIONS] include:"
echo " --dep-debug"
echo " Enable script debug"
echo " --dep-path <path>"
echo " Do not look in the current directory for the file. Instead, look in <path> to see"
echo " if the file resides there. --dep-path may be used multiple times to specify"
echo " multiple alternative location"
echo " --winpaths <TOPDIR>"
echo " CC generates dependency lists using Windows paths (e.g., C:\blablah\blabla). This"
echo " switch instructs the script to use 'cygpath' to convert the Windows paths to Cygwin"
echo " paths"
echo " --help"
echo " Shows this message and exits"
exit 1
}
dodep ()
{
unset fullpath
if [ -z "$altpath" ]; then
if [ -r $1 ]; then
fullpath=$1
else
echo "# ERROR: No readable file at $1"
show_usage
fi
else
for path in $altpath; do
tmppath=$path/$1
if [ -r $tmppath ]; then
fullpath=$tmppath
break;
fi
done
if [ -z "$fullpath" ]; then
echo "# ERROR: No readable file for $1 found at any location"
show_usage
fi
fi
$cc -M $cflags $fullpath || \
( echo "# ERROR: $cc -M $cflags $fullpath FAILED"; exit 4; )
}
unset cc
unset cflags
unset files
unset args
unset altpath
winpaths=n
unset topdir
# Accumulate CFLAGS up to "--"
progname=$0
while [ ! -z "$1" ]; do
case $1 in
-- )
cc=$cflags
cflags=$args
args=
;;
--dep-debug )
if [ -z "$args" ]; then
set -x
else
args="$args $1"
fi
;;
--dep-path )
if [ -z "$args" ]; then
shift
altpath="$altpath $1"
else
args="$args $1"
fi
;;
--winpaths )
if [ -z "$args" ]; then
shift
winpaths=y
topdir=$1
else
args="$args $1"
fi
;;
--help )
show_usage
;;
*)
args="$args $1"
;;
esac
shift
done
files=$args
if [ -z "$cc" ]; then
echo "ERROR: No compiler specified"
show_usage
exit 1
fi
if [ -z "$files" ]; then
# Don't report an error -- this happens normally in some configurations
echo "# No files specified for dependency generataion"
exit 0
fi
# Check if this compiler generates Cygwin/Linux paths or Windows paths
if [ "X${winpaths}" = "Xy" ]; then
# We will have to parse and modify each dependency (yech)
# Make sure a valid TOPDIR argument was provided
if [ -z "$topdir" -o ! -d $topdir ]; then
echo "<TOPDIR> not specified or does not exist: $topdir"
show_usage
exit 1
fi
# Get the top dir expressed like the Windows GCC would use it, except
# with forward slashs
wtopdir=`cygpath -w ${topdir} | sed -e "s,\\\\\\,/,g"`
# Then get the dependency and perform conversions on it to make it
# palatable to the Cygwin make. This is probably not sufficiently
# general to work on all platforms (like if your disk is not C:).
for file in $files ; do
dodep $file | sed -e "s,\\\,/,g" -e "s,${wtopdir},${topdir},g" \
-e "s,/ ,\\\ ,g" -e "s,c:/,/cygdrive/c/,g" \
-e "s,/$,\\\,g"
done
else
# For normal Cygwin/Linux GCC, the dependency paths are in the
# correct form and can simply be echoed on stdout
for file in $files ; do
dodep $file
done
fi
+327
View File
@@ -0,0 +1,327 @@
#!/bin/bash
# tools/mkexport.sh
#
# Copyright (C) 2011-2012 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.
#
# TODO:
# 1. This script assumes the host archiver ar may not be appropriate for
# non-GCC toolchains
# 2. For the kernel build, the user libriars should be built into some
# libuser.a. The list of user libraries would have to accepted with
# some new argument, perhaps -u.
# Get the input parameter list
USAGE="USAGE: $0 [-d] [-z] [-w|wy|wn] -t <top-dir> [-x <lib-ext>] -l \"lib1 [lib2 [lib3 ...]]\""
unset TOPDIR
unset LIBLIST
unset TGZ
WINTOOL=n
LIBEXT=.a
while [ ! -z "$1" ]; do
case $1 in
-d )
set -x
;;
-l )
shift
LIBLIST=$1
;;
-wy )
WINTOOL=y
;;
-w | -wn )
WINTOOL=n
;;
-t )
shift
TOPDIR=$1
;;
-x )
shift
LIBEXT=$1
;;
-z )
TGZ=y
;;
-h )
echo $USAGE
exit 0
;;
* )
echo "Unrecognized argument: $1"
echo $USAGE
exit 1
;;
esac
shift
done
# Check arguments
if [ -z "${TOPDIR}" -o -z "${LIBLIST}" ]; then
echo "MK: Missing required arguments"
echo $USAGE
exit 1
fi
if [ ! -d "${TOPDIR}" ]; then
echo "MK: Directory ${TOPDIR} does not exist"
exit 1
fi
# Get the version string
if [ ! -f "${TOPDIR}/.version" ]; then
echo "MK: File ${TOPDIR}/.version does not exist"
exit 1
fi
source "${TOPDIR}/.version"
if [ ! -z "${CONFIG_VERSION_STRING}" -a "${CONFIG_VERSION_STRING}" != "0.0" ]; then
VERSION="-${CONFIG_VERSION_STRING}"
fi
# Create the export directory
EXPORTSUBDIR="nuttx-export${VERSION}"
EXPORTDIR="${TOPDIR}/${EXPORTSUBDIR}"
# If the export directory already exists, then remove it and create a new one
if [ -d "${EXPORTDIR}" ]; then
echo "MK: Removing old export directory"
rm -rf "${EXPORTDIR}"
fi
# Remove any possible previous results
rm -f "${EXPORTDIR}.tar"
rm -f "${EXPORTDIR}.zip"
rm -f "${EXPORTDIR}.tar.gz"
# Create the export directory and some of its subdirectories
mkdir "${EXPORTDIR}" || { echo "MK: 'mkdir ${EXPORTDIR}' failed"; exit 1; }
mkdir "${EXPORTDIR}/startup" || { echo "MK: 'mkdir ${EXPORTDIR}/startup' failed"; exit 1; }
mkdir "${EXPORTDIR}/libs" || { echo "MK: 'mkdir ${EXPORTDIR}/libs' failed"; exit 1; }
mkdir "${EXPORTDIR}/build" || { echo "MK: 'mkdir ${EXPORTDIR}/build' failed"; exit 1; }
mkdir "${EXPORTDIR}/arch" || { echo "MK: 'mkdir ${EXPORTDIR}/arch' failed"; exit 1; }
# Verify that we have a Make.defs file.
if [ ! -f "${TOPDIR}/Make.defs" ]; then
echo "MK: Directory ${TOPDIR}/Make.defs does not exist"
exit 1
fi
# Copy the Make.defs files, but disable windows path conversions
grep -v "WINTOOL[ \t]*=[ \t]y" "${TOPDIR}/Make.defs" > "${EXPORTDIR}/Make.defs"
# Extract information from the Make.defs file. A Makefile can do this best
make -C "${TOPDIR}/tools" -f Makefile.export TOPDIR="${TOPDIR}" EXPORTDIR="${EXPORTDIR}"
source "${EXPORTDIR}/makeinfo.sh"
rm -f "${EXPORTDIR}/makeinfo.sh"
rm -f "${EXPORTDIR}/Make.defs"
# Verify the build info that we got from makeinfo.sh
if [ ! -d "${ARCHDIR}" ]; then
echo "MK: Directory ${ARCHDIR} does not exist"
exit 1
fi
# Is there a linker script in this configuration?
if [ ! -z "${LDPATH}" ]; then
# Apparently so. Verify that the script exists
if [ ! -f "${LDPATH}" ]; then
echo "MK: File ${LDPATH} does not exist"
exit 1
fi
# Copy the linker script
cp -p "${LDPATH}" "${EXPORTDIR}/build/." || \
{ echo "MK: cp ${LDPATH} failed"; exit 1; }
fi
# Save the compilation options
echo "ARCHCFLAGS = ${ARCHCFLAGS}" >"${EXPORTDIR}/build/Make.defs"
echo "ARCHCXXFLAGS = ${ARCHCXXFLAGS}" >>"${EXPORTDIR}/build/Make.defs"
# Copy the NuttX include directory (retaining attributes and following symbolic links)
cp -LR -p "${TOPDIR}/include" "${EXPORTDIR}/." || \
{ echo "MK: 'cp ${TOPDIR}/include' failed"; exit 1; }
find "${EXPORTDIR}/include" -name .svn | xargs rm -rf
# Copy the startup object file(s)
make -C ${ARCHDIR} export_head TOPDIR=${TOPDIR} EXPORT_DIR="${EXPORTDIR}"
# Copy architecture-specific header files into the arch export sub-directory.
# This is tricky because each architecture does things in a little different
# way.
#
# First copy any header files in the architecture src/ sub-directory (some
# architectures keep all of the header files there, some a few, and others
# none
cp -f "${ARCHDIR}"/*.h "${EXPORTDIR}"/arch/. 2>/dev/null
# Then look a list of possible places where other architecture-specific
# header files might be found. If those places exist (as directories or
# as symbolic links to directories, then copy the header files from
# those directories into the EXPORTDIR
ARCH_HDRDIRS="arm armv7-m avr avr32 board common chip mips32"
for hdir in $ARCH_HDRDIRS; do
# Does the directory (or symbolic link) exist?
if [ -d "${ARCHDIR}/${hdir}" -o -h "${ARCHDIR}/${hdir}" ]; then
# Yes.. create a export sub-directory of the same name
mkdir "${EXPORTDIR}/arch/${hdir}" || \
{ echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}' failed"; exit 1; }
# Then copy the header files (only) into the new directory
cp -f "${ARCHDIR}"/${hdir}/*.h "${EXPORTDIR}"/arch/${hdir}/. 2>/dev/null
# One architecture has low directory called "chip" that holds the
# header files
if [ -d "${ARCHDIR}/${hdir}/chip" ]; then
# Yes.. create a export sub-directory of the same name
mkdir "${EXPORTDIR}/arch/${hdir}/chip" || \
{ echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}/chip' failed"; exit 1; }
# Then copy the header files (only) into the new directory
cp -f "${ARCHDIR}"/${hdir}/chip/*.h "${EXPORTDIR}"/arch/${hdir}/chip/. 2>/dev/null
fi
fi
done
# Copy OS internal header files as well. They are used by some architecture-
# specific header files.
mkdir "${EXPORTDIR}/arch/os" || \
{ echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}/chip' failed"; exit 1; }
cp -f "${TOPDIR}"/sched/*.h "${EXPORTDIR}"/arch/os/. 2>/dev/null
# Add the board library to the list of libraries
if [ -f "${ARCHDIR}/board/libboard${LIBEXT}" ]; then
LIBLIST="${LIBLIST} ${ARCHSUBDIR}/board/libboard${LIBEXT}"
fi
# Then process each library
AR=${CROSSDEV}ar
for lib in ${LIBLIST}; do
if [ ! -f "${TOPDIR}/${lib}" ]; then
echo "MK: Library ${TOPDIR}/${lib} does not exist"
exit 1
fi
# Get some shorter names for the library
libname=`basename ${lib} ${LIBEXT}`
shortname=`echo ${libname} | sed -e "s/^lib//g"`
# Copy the application library unmodified
if [ "X${libname}" = "Xlibapps" ]; then
cp -p "${TOPDIR}/${lib}" "${EXPORTDIR}/libs/." || \
{ echo "MK: cp ${TOPDIR}/${lib} failed"; exit 1; }
else
# Create a temporary directory and extract all of the objects there
# Hmmm.. this probably won't work if the archiver is not 'ar'
mkdir "${EXPORTDIR}/tmp" || \
{ echo "MK: 'mkdir ${EXPORTDIR}/tmp' failed"; exit 1; }
cd "${EXPORTDIR}/tmp" || \
{ echo "MK: 'cd ${EXPORTDIR}/tmp' failed"; exit 1; }
if [ "X${WINTOOL}" = "Xy" ]; then
WLIB=`cygpath -w "${TOPDIR}/${lib}"`
${AR} x "${WLIB}"
else
${AR} x "${TOPDIR}/${lib}"
fi
# Rename each object file (to avoid collision when they are combined)
# and add the file to libnuttx
for file in `ls`; do
mv "${file}" "${shortname}-${file}"
if [ "X${WINTOOL}" = "Xy" ]; then
WLIB=`cygpath -w "${EXPORTDIR}/libs/libnuttx${LIBEXT}"`
${AR} rcs "${WLIB}" "${shortname}-${file}"
else
${AR} rcs "${EXPORTDIR}/libs/libnuttx${LIBEXT}" "${shortname}-${file}"
fi
done
cd "${TOPDIR}" || \
{ echo "MK: 'cd ${TOPDIR}' failed"; exit 1; }
rm -rf "${EXPORTDIR}/tmp"
fi
done
# Now tar up the whole export directory
cd "${TOPDIR}" || \
{ echo "MK: 'cd ${TOPDIR}' failed"; exit 1; }
if [ "X${TGZ}" = "Xy" ]; then
tar cvf "${EXPORTSUBDIR}.tar" "${EXPORTSUBDIR}" 1>/dev/null 2>&1
gzip -f "${EXPORTSUBDIR}.tar"
else
zip -r "${EXPORTSUBDIR}.zip" "${EXPORTSUBDIR}" 1>/dev/null 2>&1
fi
# Clean up after ourselves
rm -rf "${EXPORTSUBDIR}"
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/perl
# tools/mkfsdata.pl
#
# Extracted from uIP which has a license that is compatible with NuttX.
# There is no authorship, copyright, or licensing information in the
# original file. Possibly written by Adam Dunkels.
#
# 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.
#
open(OUTPUT, "> httpd_fsdata.c");
chdir("httpd-fs");
opendir(DIR, ".");
@files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
closedir(DIR);
print(OUTPUT "#include <apps/netutils/httpd.h>\n\n");
print(OUTPUT "#ifndef NULL\n#define NULL 0\n#endif\n\n");
foreach $file (@files) {
if(-d $file && $file !~ /^\./) {
print "Processing directory $file\n";
opendir(DIR, $file);
@newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
closedir(DIR);
printf "Adding files @newfiles\n";
@files = (@files, map { $_ = "$file/$_" } @newfiles);
next;
}
}
foreach $file (@files) {
if(-f $file) {
print "Adding file $file\n";
open(FILE, $file) || die "Could not open file $file\n";
$file =~ s-^-/-;
$fvar = $file;
$fvar =~ s-/-_-g;
$fvar =~ s-\.-_-g;
# for AVR, add PROGMEM here
print(OUTPUT "static const unsigned char data".$fvar."[] =\n");
print(OUTPUT "{\n /* $file */\n\n ");
for($j = 0; $j < length($file); $j++) {
printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
}
printf(OUTPUT "0x00,\n ");
$i = 0;
while(read(FILE, $data, 1)) {
printf(OUTPUT "%#02x, ", unpack("C", $data));
$i++;
if($i == 10) {
print(OUTPUT "\n");
$i = 0;
print(OUTPUT " ");
}
}
print(OUTPUT "0x00\n};\n\n");
close(FILE);
push(@fvars, $fvar);
push(@pfiles, $file);
}
}
for($i = 0; $i < @fvars; $i++) {
$file = $pfiles[$i];
$fvar = $fvars[$i];
if($i == 0) {
$prevfile = "NULL";
} else {
$prevfile = "file" . $fvars[$i - 1];
}
if($i == @fvars-1) {
print(OUTPUT "const struct httpd_fsdata_file g_httpdfs_root[] =\n {{$prevfile, data$fvar, ");
} else {
print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] =\n {{$prevfile, data$fvar, ");
}
print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");
print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");
}
# print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
print(OUTPUT "const int g_httpd_numfiles = $i;\n");
+289
View File
@@ -0,0 +1,289 @@
#!/bin/bash
#
# File: mkimage.sh
#
# Copyright (C) 2002 RidgeRun, Inc.
# Author: RidgeRun, Inc <skranz@@ridgerun.com>
# - Adapted for the Cadenux environment, 9-6-02, Gregory Nutt
# - Added --EAddr option, 6-18-03, Gregory Nutt
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
#
########################################################
# Description:
# -----------
# Scenario #1
# -----------
# This utility was developed by RidgeRun for the
# purpose of converting a standard binary executable
# image (such as ELF) into a special format (RR
# format) suitable for quick downloads to the target
# TI925 RidgeRun Bootloader (rrload). The image is
# produced by constructing a special header which is
# then tacked onto the front of the supplied binary
# image. The resulting binary image is smaller than
# what would normally be encountered with traditional
# download formats (such as SREC or uuencoded; both
# ascii based). The special header at the front of the
# image is used to guide the target's rrload (a
# booloader developed by RidgeRun Inc). The header
# data contains a field representing the total byte
# count of the binary data following the header as
# well as a field that indicates the load address of
# run image. Additionally, a field exists in the
# header which indicates the image's entry point which
# could be called by the bootloader to invoked the
# just downloaded program.
# -----------
# Scenario #2
# -----------
# If the supplied image is not a standard binary
# executagle image then that is ok too, a header is
# constructed and tacked onto the front of the supplied
# binary data forming the new binary image (in rr format).
# In this case the EntryAddr is set to 0xFFFFFFFF by
# default and the LoadAddr is set to 0x00000000 by
# default unless otherwise indicated by command line
# arguments -LEntry and -LAddr which if used are assumed
# to be in hexidecimal units.
#
# -----------
# Scenario #3
# -----------
#
# Read/Write file system (like JFFS) that will not
# work if rrload stores a 20 byte header at the beginning
# of the flashed component image
#
# mkimage [--NoHeader ] <input-bin> <out-RR>
#
# Usage:
# mkimage [--LAddr h] [--EAddr h] [--NoHeader] <input-bin> <out-RR>
#
# Examples:
# $ mkimage linux linux.rr
# ..or..
# $ mkimage -LAddr 10008000 -EAddr 10008000 vmlinux vmlinux.rr
# ..or..
# $ mkimage --NoHeader fileSys.gz fileSys.gz.rr
# ..or..
# $ mkimage --LAddr A00 fileSys.gz fileSys.gz.rr
# ..or..
# $ mkimage --LAddr A00 fileSys.gz fileSys.gz.rr
# ^
# |
# Assumed hex units.
# Please omit the
# leading "0x".
########################################################
if [ $# -lt 2 ] ; then
echo "Error: missing argument"
echo "Usage: mkimage [--Prefix prefix] [--LAddr n] [--EAddr n] [--NoHeader] <input-Bin> <out-RR>"
exit 1
fi
# Pleae Note the following formatting inconsistency.
# (Sorry, for now this is necessary)
LoadAddr="00000000" # Note: hex val *without* proceeding "0x"
EntryAddr="0xFFFFFFFF" # Note: hex val *with* procedding "0x"
unset prefix
Header="y"
LAddrSupplied="n"
EAddrSupplied="n"
compress="n"
while [ $# -gt 0 ] ; do
case "$1" in
--Prefix)
shift;
prefix="$1"
shift
;;
--LAddr )
shift
LoadAddr="$1"
# Next, make the supplied LAddr exactly 8 hex chars long.
LoadAddr="0000000${LoadAddr}"
LoadAddr=$(echo $LoadAddr | sed -e "s/^.*\(........\)$/\1/g")
LAddrSupplied="y"
shift
;;
--EAddr )
shift
EntryAddr="$1"
# Next, make the supplied LEntry exactly 8 hex chars long.
EntryAddr="0000000${EntryAddr}"
EntryAddr=$(echo $EntryAddr | sed -e "s/^.*\(........\)$/\1/g")
EntryAddr=0x$EntryAddr
EAddrSupplied="y"
shift
;;
--NoHeader )
Header="n"
shift
;;
--compress )
compress="y"
shift
;;
*)
break
;;
esac
done
if [ ! $# -eq 2 ] ; then
echo "Error: invalid argument set."
echo "Usage: mkimage [--LAddr h] <input-Bin> <out-RR>"
exit 1
fi
binary=$1.stripped
outbin=$2
cp $1 $binary
FileTypeExec=$(${prefix}objdump -f $binary 2>/dev/null | egrep "EXEC_P")
if [ ! -z "$FileTypeExec" ] ; then
# -----------
# Scenario #1
# -----------
# We have an executable style binary (like ELF, etc).
# So...
# ---------------------------------
# Next | Create the binary image data.
# ---------------------------------
${prefix}strip ${binary}
${prefix}objcopy -S -O binary $binary ${binary}.binary
# ---------------------------------
# Next | Create compress image if requested
# ---------------------------------
image_file=${binary}.binary
if [ "$compress" = "y" ] ; then
gzip -f -9 -c ${binary}.binary > ${binary}.binary.gz
image_file=${binary}.binary.gz
fi
# ---------------------------------
# Next | Create the header information (ascii) needed
# | by the TI925 bootloader. This includes the
# | load address, entry address and byte count of
# | the binary executable data which will follow it.
# ---------------------------------
if [ "$LAddrSupplied" = "n" ] ; then
# Next, Since LoadAddr not already supplied by user we'll
# derive it by consulting the binary executable file.
LoadAddr=$(${prefix}objdump -h ${binary} | grep " 0 \.")
LoadAddr=$(echo $LoadAddr | cut -d' ' -f4) # eight hex chars
fi
if [ "$EAddrSupplied" = "n" ] ; then
# Next, Since EntryAddr not already supplied by user we'll
# derive it by consulting the binary executable file.
EntryAddr=$(${prefix}objdump -f ${binary} | grep -i "start")
EntryAddr=$(echo $EntryAddr | cut -d' ' -f3) # eight hex chars
fi
# Next, Compute byte length of binary portion.
numBytes=$(wc --bytes $image_file)
numBytes=$(echo $numBytes | cut -d' ' -f1)
numBytes=$(echo 16o $numBytes p | dc) # converts to hex.
# Next, make the numBytes string exactly 8 hex chars long.
numBytes="0000000${numBytes}"
numBytes=$(echo $numBytes | sed -e "s/^.*\(........\)$/\1/g")
# ---------------------------------
# Next | Combine the ascii header information
# | with the binary image to make the
# | final downloadable *mostly* binary
# | image.
# ---------------------------------
rm -f ${outbin}
echo ">LoadAddr :0x${LoadAddr}" >> ${outbin}
if [ "${Header}" = "y" ]; then
echo ">EntryAddr:${EntryAddr}" >> ${outbin}
else
echo ">NoHeader" >> ${outbin}
fi
echo ">NumBytes :0x${numBytes}" >> ${outbin}
cat $image_file >> ${outbin}
# ---------------------------------
# Cleanup and exit
# ---------------------------------
rm -f ${binary}.binary $image_file
exit 0
else
# -----------
# Scenario #2
# -----------
# Just a binary image but not a standard executable
# style binary (like ELF, etc). Might be a compressed
# filesystem image, etc.
# So...
# ---------------------------------
# Next | Create the header information (ascii) needed
# | by the TI925 bootloader. This includes the
# | load address, entry address and byte count of
# | the binary file which will follow it.
# ---------------------------------
# | Create compress image if requested
# ---------------------------------
#
image_file=${binary}
if [ "$compress" = "y" ] ; then
gzip -f -9 -c ${image_file} > ${image_file}.gz
image_file=${image_file}.gz
fi
#
# Note: The LoadAddr and EntryAddr are already established
# for us at this point, but we will need to compute the
# byte length of binary portion next.
#
numBytes=$(wc --bytes ${image_file})
numBytes=$(echo $numBytes | cut -d' ' -f1)
numBytes=$(echo 16o $numBytes p | dc) # converts to hex.
# Next, make the numBytes string exactly 8 hex chars long.
numBytes="0000000${numBytes}"
numBytes=$(echo $numBytes | sed -e "s/^.*\(........\)$/\1/g")
#
# ---------------------------------
# Next | Combine the ascii header information
# | with the binary image to make the
# | final downloadable *mostly* binary
# | image.
# ---------------------------------
#
rm -f ${outbin}
echo ">LoadAddr :0x${LoadAddr}" >> ${outbin}
if [ ${Header} = "y" ]; then
echo ">EntryAddr:${EntryAddr}" >> ${outbin}
else
echo ">NoHeader" >> ${outbin}
fi
echo ">NumBytes :0x${numBytes}" >> ${outbin}
cat ${image_file} >> ${outbin}
# ---------------------------------
# Cleanup and exit
# ---------------------------------
rm -f ${image_file}.gz
exit 0
fi
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
# tools/mknulldeps.sh
#
# Copyright (C) 2008 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.
#
echo "# The selected toolchain does not support dependency generation"
+261
View File
@@ -0,0 +1,261 @@
#!/bin/bash
############################################################################
# tools/mkromfsimg.sh
#
# Copyright (C) 2008, 2011 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.
#
############################################################################
# Environmental stuff
wd=`pwd`
workingdir=$wd/img
rcsfile=rcS
rcstemplate=$rcsfile.template
romfsimg=romfs.img
headerfile=nsh_romfsimg.h
# Get the input parameters
topdir=$1
usage="USAGE: $0 <topdir>"
if [ -z "$topdir" -o ! -d "$topdir" ]; then
echo "The full path to the NuttX base directory must be provided on the command line"
echo $usage
exit 1
fi
# Extract all values from the .config in the $topdir that contains all of the NuttX
# configuration settings. The .config file was intended to be include-able by makefiles
# and source-able by scripts. Unfortunately,there are too many syntactic differents
# to make that practical
if [ ! -r $topdir/.config ]; then
echo "No readable file at $topdir/.config"
echo "Has NuttX been configured?"
exit 1
fi
romfsetc=`grep CONFIG_NSH_ROMFSETC= $topdir/.config | cut -d'=' -f2`
disablempt=`grep CONFIG_DISABLE_MOUNTPOINT= $topdir/.config | cut -d'=' -f2`
disablescript=`grep CONFIG_NSH_DISABLESCRIPT= $topdir/.config | cut -d'=' -f2`
ndescriptors=`grep CONFIG_NFILE_DESCRIPTORS= $topdir/.config | cut -d'=' -f2`
devconsole=`grep CONFIG_DEV_CONSOLE= $topdir/.config | cut -d'=' -f2`
romfs=`grep CONFIG_FS_ROMFS= $topdir/.config | cut -d'=' -f2`
romfsmpt=`grep CONFIG_NSH_ROMFSMOUNTPT= $topdir/.config | cut -d'=' -f2`
initscript=`grep CONFIG_NSH_INITSCRIPT= $topdir/.config | cut -d'=' -f2`
romfsdevno=`grep CONFIG_NSH_ROMFSDEVNO= $topdir/.config | cut -d'=' -f2`
romfssectsize=`grep CONFIG_NSH_ROMFSSECTSIZE= $topdir/.config | cut -d'=' -f2`
fatfs=`grep CONFIG_FS_FAT= $topdir/.config | cut -d'=' -f2`
fatdevno=`grep CONFIG_NSH_FATDEVNO= $topdir/.config | cut -d'=' -f2`
fatsectsize=`grep CONFIG_NSH_FATSECTSIZE= $topdir/.config | cut -d'=' -f2`
fatnsectors=`grep CONFIG_NSH_FATNSECTORS= $topdir/.config | cut -d'=' -f2`
fatmpt=`grep CONFIG_NSH_FATMOUNTPT= $topdir/.config | cut -d'=' -f2`
# The following settings are required for general ROMFS support
#
# Mountpoint support must be enabled
if [ "X$disablempt" = "Xy" ]; then
echo "Mountpoint support is required for this feature"
echo "Set CONFIG_DISABLE_MOUNTPOINT=n to continue"
exit 1
fi
# Scripting support must be enabled
if [ "X$disablescript" = "Xy" ]; then
echo "NSH scripting support is required for this feature"
echo "Set CONFIG_NSH_DISABLESCRIPT=n to continue"
exit 1
fi
# We need at least 2 file descriptors 1 for the ROMFS mount and one for
# FAT mount performed in rcS. That still wouldn't be enough to to do much
# with NSH
if [ -z "$ndescriptors" -o "$ndescriptors" -lt 2 ]; then
echo "No file descriptors have been allocated"
if [ "X$devconsole" = "Xy" ]; then
echo "Set CONFIG_NFILE_DESCRIPTORS to value greater than 4"
else
echo "Set CONFIG_NFILE_DESCRIPTORS to value greater than 1"
fi
exit 1
fi
# If a console is enabled, then three more file descriptors are required
# for stdin, stdout, and stderr
if [ "X$devconsole" = "Xy" -a "$ndescriptors" -lt 5 ]; then
echo "Insufficient file descriptors have been allocated"
echo "Set CONFIG_NFILE_DESCRIPTORS to value greater than 4"
fi
# ROMFS support is required, of course
if [ "X$romfs" != "Xy" ]; then
echo "ROMFS support is disabled in the NuttX configuration"
echo "Set CONFIG_FS_ROMFS=y to continue"
exit 0
fi
# The options in the default rcS.template also require FAT FS support
if [ "X$fatfs" != "Xy" ]; then
echo "FAT FS support is disabled in the NuttX configuration"
echo "Set CONFIG_FS_FAT=y to continue"
exit 0
fi
# Verify that genromfs has been installed
genromfs -h 1>/dev/null 2>&1 || { \
echo "Host executable genromfs not available in PATH"; \
echo "You may need to download in from http://romfs.sourceforge.net/"; \
exit 1; \
}
# Supply defaults for all un-defined ROMFS settings
if [ -z "$romfsmpt" ]; then
romfsmpt="/etc"
fi
if [ -z "$initscript" ]; then
initscript="init.d/rcS"
fi
if [ -z "$romfsdevno" ]; then
romfsdevno=0
fi
if [ -z "$romfssectsize" ]; then
romfssectsize=64
fi
# Supply defaults for all un-defined FAT FS settings
if [ -z "$fatdevno" ]; then
fatdevno=1
fi
if [ -z "$fatsectsize" ]; then
fatsectsize=512
fi
if [ -z "$fatnsectors" ]; then
fatnsectors=1024
fi
if [ -z "$fatmpt" ]; then
fatmpt="/tmp"
fi
# Verify the mountpoint. Verify that it is an absolute path but not /, /dev,
# /., /./*, /.., or /../*
if [ ${romfsmpt:0:1} != "\"" ]; then
echo "CONFIG_NSH_ROMFSMOUNTPT must be a string"
echo "Change it so that it is enclosed in quotes."
exit 1
fi
uromfsmpt=`echo $romfsmpt | sed -e "s/\"//g"`
if [ ${uromfsmpt:0:1} != "/" ]; then
echo "CONFIG_NSH_ROMFSMOUNTPT must be an absolute path in the target FS"
echo "Change it so that it begins with the character '/'. Eg. /etc"
exit 1
fi
tmpdir=$uromfsmpt
while [ ${tmpdir:0:1} == "/" ]; do
tmpdir=${tmpdir:1}
done
if [ -z "$tmpdir" -o "X$tmpdir" = "Xdev" -o "X$tmpdir" = "." -o \
${tmpdir:0:2} = "./" -o "X$tmpdir" = ".." -o ${tmpdir:0:3} = "../" ]; then
echo "Invalid CONFIG_NSH_ROMFSMOUNTPT selection."
exit 1
fi
# Verify that the path to the init file is a relative path and not ., ./*, .., or ../*
if [ ${initscript:0:1} != "\"" ]; then
echo "CONFIG_NSH_INITSCRIPT must be a string"
echo "Change it so that it is enclosed in quotes."
exit 1
fi
uinitscript=`echo $initscript | sed -e "s/\"//g"`
if [ ${uinitscript:0:1} == "/" ]; then
echo "CONFIG_NSH_INITSCRIPT must be an relative path in under $romfsmpt"
echo "Change it so that it begins with the character '/'. Eg. init.d/rcS. "
exit 1
fi
if [ "X$uinitscript" = "." -o ${uinitscript:0:2} = "./" -o \
"X$uinitscript" = ".." -o ${uinitscript:0:3} = "../" ]; then
echo "Invalid CONFIG_NSH_INITSCRIPT selection. Must not begin with . or .."
exit 1
fi
# Create a working directory
rm -rf $workingdir || { echo "Failed to remove the old $workingdir"; exit 1; }
mkdir -p $workingdir || { echo "Failed to created the new $workingdir"; exit 1; }
# Create the rcS file from the rcS.template
if [ ! -r $rcstemplate ]; then
echo "$rcstemplete does not exist"
rmdir $workingdir
exit 1
fi
cat $rcstemplate | \
sed -e "s,XXXMKRDMINORXXX,$fatdevno,g" | \
sed -e "s,XXMKRDSECTORSIZEXXX,$fatsectsize,g" | \
sed -e "s,XXMKRDBLOCKSXXX,$fatnsectors,g" | \
sed -e "s,XXXRDMOUNTPOUNTXXX,$fatmpt,g" >$rcsfile
# And install it at the specified relative location
install -D --mode=0755 $rcsfile $workingdir/$uinitscript || \
{ echo "Failed to install $rcsfile at $workingdir/$uinitscript"; rm -f $rcsfile; exit 1; }
rm -f $rcsfile
# Now we are ready to make the ROMFS image
genromfs -f $romfsimg -d $workingdir -V "NSHInitVol" || { echo "genromfs failed" ; exit 1 ; }
rm -rf $workingdir || { echo "Failed to remove the old $workingdir"; exit 1; }
# And, finally, create the header file
xxd -i $romfsimg >$headerfile || { echo "xxd of $< failed" ; rm -f $romfsimg; exit 1 ; }
rm -f $romfsimg
+289
View File
@@ -0,0 +1,289 @@
/****************************************************************************
* tools/mksymtab.c
*
* Copyright (C) 2012 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "csvparser.h"
/****************************************************************************
* Definitions
****************************************************************************/
#define MAX_HEADER_FILES 500
#define SYMTAB_NAME "g_symtab"
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static const char *g_hdrfiles[MAX_HEADER_FILES];
static int nhdrfiles;
/****************************************************************************
* Private Functions
****************************************************************************/
static void show_usage(const char *progname)
{
fprintf(stderr, "USAGE: %s <cvs-file> <symtab-file>\n\n", progname);
fprintf(stderr, "Where:\n\n");
fprintf(stderr, " <cvs-file> : The path to the input CSV file\n");
fprintf(stderr, " <symtab-file>: The path to the output symbol table file\n");
fprintf(stderr, " -d : Enable debug output\n");
exit(EXIT_FAILURE);
}
static bool check_hdrfile(const char *hdrfile)
{
int i;
for (i = 0; i < nhdrfiles; i++)
{
if (strcmp(g_hdrfiles[i], hdrfile) == 0)
{
return true;
}
}
return false;
}
static void add_hdrfile(const char *hdrfile)
{
if (hdrfile && strlen(hdrfile) > 0)
{
if (!check_hdrfile(hdrfile))
{
if (nhdrfiles > MAX_HEADER_FILES)
{
fprintf(stderr, "ERROR: Too man header files. Increase MAX_HEADER_FILES\n");
exit(EXIT_FAILURE);
}
g_hdrfiles[nhdrfiles] = strdup(hdrfile);
nhdrfiles++;
}
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
char *csvpath;
char *symtab;
char *nextterm;
char *finalterm;
char *ptr;
bool cond;
FILE *instream;
FILE *outstream;
int ch;
int i;
/* Parse command line options */
g_debug = false;
while ((ch = getopt(argc, argv, ":d")) > 0)
{
switch (ch)
{
case 'd' :
g_debug = true;
break;
case '?' :
fprintf(stderr, "Unrecognized option: %c\n", optopt);
show_usage(argv[0]);
case ':' :
fprintf(stderr, "Missing option argument, option: %c\n", optopt);
show_usage(argv[0]);
break;
fprintf(stderr, "Unexpected option: %c\n", ch);
show_usage(argv[0]);
}
}
if (optind >= argc)
{
fprintf(stderr, "Missing <cvs-file> and <symtab-file>\n");
show_usage(argv[0]);
}
csvpath = argv[optind];
optind++;
if (optind >= argc)
{
fprintf(stderr, "Missing <symtab-file>\n");
show_usage(argv[0]);
}
symtab = argv[optind];
optind++;
if (optind < argc)
{
fprintf(stderr, "Unexpected garbage at the end of the line\n");
show_usage(argv[0]);
}
/* Open the CSV file for reading */
instream = fopen(csvpath, "r");
if (!instream)
{
fprintf(stderr, "open %s failed: %s\n", csvpath, strerror(errno));
exit(EXIT_FAILURE);
}
/* Open the Symbol table file for writing */
outstream = fopen(symtab, "w");
if (!outstream)
{
fprintf(stderr, "open %s failed: %s\n", csvpath, strerror(errno));
exit(EXIT_FAILURE);
}
/* Get all of the header files that we need to include */
while ((ptr = read_line(instream)) != NULL)
{
/* Parse the line from the CVS file */
int nargs = parse_csvline(ptr);
if (nargs < PARM1_INDEX)
{
fprintf(stderr, "Only %d arguments found: %s\n", nargs, g_line);
exit(EXIT_FAILURE);
}
/* Add the header file to the list of header files we need to include */
add_hdrfile(g_parm[HEADER_INDEX]);
}
/* Back to the beginning */
rewind(instream);
/* Output up-front file boilerplate */
fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", symtab);
fprintf(outstream, "#include <nuttx/config.h>\n");
fprintf(outstream, "#include <nuttx/symtab.h>\n\n");
/* Output all of the require header files */
for (i = 0; i < nhdrfiles; i++)
{
fprintf(outstream, "#include <%s>\n", g_hdrfiles[i]);
}
/* Now the symbol table itself */
fprintf(outstream, "\nstruct symtab_s %s[] =\n", SYMTAB_NAME);
fprintf(outstream, "{\n");
/* Parse each line in the CVS file */
nextterm = "";
finalterm = "";
while ((ptr = read_line(instream)) != NULL)
{
/* Parse the line from the CVS file */
int nargs = parse_csvline(ptr);
if (nargs < PARM1_INDEX)
{
fprintf(stderr, "Only %d arguments found: %s\n", nargs, g_line);
exit(EXIT_FAILURE);
}
/* Output any conditional compilation */
cond = (g_parm[COND_INDEX] && strlen(g_parm[COND_INDEX]) > 0);
if (cond)
{
fprintf(outstream, "%s#if %s\n", nextterm, g_parm[COND_INDEX]);
nextterm = "";
}
/* Output the symbol table entry */
fprintf(outstream, "%s { \"%s\", (FAR const void *)%s }",
nextterm, g_parm[NAME_INDEX], g_parm[NAME_INDEX]);
if (cond)
{
nextterm = ",\n#endif\n";
finalterm = "\n#endif\n";
}
else
{
nextterm = ",\n";
finalterm = "\n";
}
}
fprintf(outstream, "%s};\n\n", finalterm);
fprintf(outstream, "#define NSYMBOLS (sizeof(%s) / sizeof (struct symtab_s))\n", SYMTAB_NAME);
/* Close the CSV and symbol table files and exit */
fclose(instream);
fclose(outstream);
return EXIT_SUCCESS;
}
+684
View File
@@ -0,0 +1,684 @@
/****************************************************************************
* tools/mksyscall.c
*
* Copyright (C) 2011-2012 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "csvparser.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static bool g_inline;
static FILE *g_stubstream;
/****************************************************************************
* Private Functions
****************************************************************************/
static bool is_vararg(const char *type, int index, int nparms)
{
if (strcmp(type,"...") == 0)
{
if (index != (nparms-1))
{
fprintf(stderr, "%d: ... is not the last in the argument list\n", g_lineno);
exit(11);
}
else if (nparms < 2)
{
fprintf(stderr, "%d: Need one parameter before ...\n", g_lineno);
exit(14);
}
return true;
}
return false;
}
static bool is_union(const char *type)
{
return (strncmp(type,"union", 5) == 0);
}
static const char *check_funcptr(const char *type)
{
const char *str = strstr(type,"(*)");
if (str)
{
return str + 2;
}
return NULL;
}
static const char *check_array(const char *type)
{
const char *str = strchr(type, '[');
if (str)
{
return str;
}
return NULL;
}
static void print_formalparm(FILE *stream, const char *argtype, int parmno)
{
const char *part2;
int len;
/* Function pointers and array formal parameter types are a little more work */
if ((part2 = check_funcptr(argtype)) != NULL || (part2 = check_array(argtype)) != NULL)
{
len = part2 - argtype;
(void)fwrite(argtype, 1, len, stream);
fprintf(stream, "parm%d%s", parmno, part2);
}
else
{
fprintf(stream, "%s parm%d", argtype, parmno);
}
}
static void get_formalparmtype(const char *arg, char *formal)
{
/* The formal parm type is a pointer to everything up to the first'|' (or
* the end of the string if there is no '|' in the type description).
*/
while (*arg != '|' && *arg != '\0')
{
*formal++ = *arg++;
}
*formal = '\0';
}
static void get_actualparmtype(const char *arg, char *actual)
{
const char *pstart = strchr(arg,'|');
if (pstart)
{
/* The actual parameter type starts after the '|' */
pstart++;
}
else
{
/* The actual parameter is the same as the formal parameter
* at starts at the beginning of the type string.
*/
pstart = arg;
}
/* The actual parm type is a pointer to everything up to the next '|' (or
* the end of the string if there is no '|' in the type description).
*/
while (*pstart != '|' && *pstart != '\0')
{
*actual++ = *pstart++;
}
*actual = '\0';
}
static void get_fieldname(const char *arg, char *fieldname)
{
char *pactual = strchr(arg,'|');
char *pstart;
if (pactual)
{
/* The actual parameter type starts after the '|' */
pactual++;
pstart = strchr(pactual,'|');
if (pstart)
{
/* The fieldname is everything past the second '|' to the end of the string */
pstart++;
strncpy(fieldname, pstart, MAX_PARMSIZE);
return;
}
}
fprintf(stderr, "%d: Missing union fieldname: %s\n", g_lineno, arg);
exit(15);
}
static FILE *open_proxy(void)
{
char filename[MAX_PARMSIZE+10];
FILE *stream;
snprintf(filename, MAX_PARMSIZE+9, "PROXY_%s.c", g_parm[NAME_INDEX]);
filename[MAX_PARMSIZE+9] = '\0';
stream = fopen(filename, "w");
if (stream == NULL)
{
fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno));
exit(10);
}
return stream;
}
static void generate_proxy(int nparms)
{
FILE *stream = open_proxy();
char formal[MAX_PARMSIZE];
char fieldname[MAX_PARMSIZE];
bool bvarargs = false;
int nformal;
int nactual;
int i;
/* Generate "up-front" information, include correct header files */
fprintf(stream, "/* Auto-generated %s proxy file -- do not edit */\n\n", g_parm[NAME_INDEX]);
fprintf(stream, "#include <nuttx/config.h>\n");
/* Does this function have a variable number of parameters? If so then the
* final parameter type will be encoded as "..."
*/
if (is_vararg(g_parm[PARM1_INDEX+nparms-1], nparms-1, nparms))
{
nformal = nparms-1;
bvarargs = true;
fprintf(stream, "#include <stdarg.h>\n");
}
else
{
nformal = nparms;
}
fprintf(stream, "#include <%s>\n", g_parm[HEADER_INDEX]);
fprintf(stream, "#include <syscall.h>\n\n");
if (g_parm[COND_INDEX][0] != '\0')
{
fprintf(stream, "#if %s\n\n", g_parm[COND_INDEX]);
}
/* Generate the function definition that matches standard function prototype */
fprintf(stream, "%s %s(", g_parm[RETTYPE_INDEX], g_parm[NAME_INDEX]);
/* Generate the formal parameter list */
if (nformal <= 0)
{
fprintf(stream, "void");
}
else
{
for (i = 0; i < nformal; i++)
{
/* The formal and actual parameter types may be encoded.. extra the
* formal parameter type.
*/
get_formalparmtype(g_parm[PARM1_INDEX+i], formal);
/* Arguments after the first must be separated from the preceding
* parameter with a comma.
*/
if (i > 0)
{
fprintf(stream, ", ");
}
print_formalparm(stream, formal, i+1);
}
}
/* Handle the end of the formal parameter list */
if (bvarargs)
{
fprintf(stream, ", ...)\n{\n");
/* Get parm variables .. some from the parameter list and others from
* the varargs.
*/
if (nparms < 7)
{
fprintf(stream, " va_list ap;\n");
for (i = nparms; i < 7; i++)
{
fprintf(stream, " uintptr_t parm%d;\n", i);
}
fprintf(stream, "\n va_start(ap, parm%d);\n", nparms-1);
for (i = nparms; i < 7; i++)
{
fprintf(stream, " parm%d = va_arg(ap, uintptr_t);\n", i);
}
fprintf(stream, " va_end(ap);\n\n");
}
}
else
{
fprintf(stream, ")\n{\n");
}
/* Generate the system call. Functions that do not return or return void
* are special cases.
*/
nactual = bvarargs ? 6 : nparms;
if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0)
{
fprintf(stream, " (void)sys_call%d(", nactual);
}
else
{
fprintf(stream, " return (%s)sys_call%d(", g_parm[RETTYPE_INDEX], nactual);
}
/* Create the parameter list with the matching types. The first parameter
* is always the syscall number.
*/
fprintf(stream, "(unsigned int)SYS_%s", g_parm[NAME_INDEX]);
for (i = 0; i < nactual; i++)
{
/* Is the parameter a union member */
if (i < nparms && is_union(g_parm[PARM1_INDEX+i]))
{
/* Then we will have to pick a field name that can be cast to a
* uintptr_t. There probably should be some error handling here
* to catch the case where the fieldname was not supplied.
*/
get_fieldname(g_parm[PARM1_INDEX+i], fieldname);
fprintf(stream, ", (uintptr_t)parm%d.%s", i+1, fieldname);
}
else
{
fprintf(stream, ", (uintptr_t)parm%d", i+1);
}
}
/* Handle the tail end of the function. */
fprintf(stream, ");\n}\n\n");
if (g_parm[COND_INDEX][0] != '\0')
{
fprintf(stream, "#endif /* %s */\n", g_parm[COND_INDEX]);
}
fclose(stream);
}
static FILE *open_stub(void)
{
if (g_inline)
{
if (!g_stubstream)
{
g_stubstream = fopen("STUB.h", "w");
if (g_stubstream == NULL)
{
fprintf(stderr, "Failed to open STUB.h: %s\n", strerror(errno));
exit(9);
}
fprintf(g_stubstream, "/* Autogenerated STUB header file */\n\n");
fprintf(g_stubstream, "#ifndef __STUB_H\n");
fprintf(g_stubstream, "#define __STUB_H\n\n");
}
return g_stubstream;
}
else
{
char filename[MAX_PARMSIZE+8];
FILE *stream;
snprintf(filename, MAX_PARMSIZE+7, "STUB_%s.c", g_parm[NAME_INDEX]);
filename[MAX_PARMSIZE+7] = '\0';
stream = fopen(filename, "w");
if (stream == NULL)
{
fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno));
exit(9);
}
return stream;
}
}
static void stub_close(FILE *stream)
{
if (!g_inline)
{
fclose(stream);
}
}
static void generate_stub(int nparms)
{
FILE *stream = open_stub();
char formal[MAX_PARMSIZE];
char actual[MAX_PARMSIZE];
int i;
int j;
/* Generate "up-front" information, include correct header files */
fprintf(stream, "/* Auto-generated %s stub file -- do not edit */\n\n", g_parm[0]);
fprintf(stream, "#include <nuttx/config.h>\n");
fprintf(stream, "#include <stdint.h>\n");
fprintf(stream, "#include <%s>\n\n", g_parm[HEADER_INDEX]);
if (g_parm[COND_INDEX][0] != '\0')
{
fprintf(stream, "#if %s\n\n", g_parm[COND_INDEX]);
}
/* Generate the function definition that matches standard function prototype */
if (g_inline)
{
fprintf(stream, "static inline ");
}
fprintf(stream, "uintptr_t STUB_%s(", g_parm[NAME_INDEX]);
/* Generate the formal parameter list. A function received no parameters is a special case. */
if (nparms <= 0)
{
fprintf(stream, "void");
}
else
{
for (i = 0; i < nparms; i++)
{
/* Treat the first argument in the list differently from the others..
* It does not need a comma before it.
*/
if (i > 0)
{
/* Check for a variable number of arguments */
if (is_vararg(g_parm[PARM1_INDEX+i], i, nparms))
{
/* Always receive six arguments in this case */
for (j = i+1; j <= 6; j++)
{
fprintf(stream, ", uintptr_t parm%d", j);
}
}
else
{
fprintf(stream, ", uintptr_t parm%d", i+1);
}
}
else
{
fprintf(stream, "uintptr_t parm%d", i+1);
}
}
}
fprintf(stream, ")\n{\n");
/* Then call the proxied function. Functions that have no return value are
* a special case.
*/
if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0)
{
fprintf(stream, " %s(", g_parm[NAME_INDEX]);
}
else
{
fprintf(stream, " return (uintptr_t)%s(", g_parm[NAME_INDEX]);
}
/* The pass all of the system call parameters, casting to the correct type
* as necessary.
*/
for (i = 0; i < nparms; i++)
{
/* Get the formal type of the parameter, and get the type that we
* actually have to cast to. For example for a formal type like 'int parm[]'
* we have to cast the actual parameter to 'int*'. The worst is a union
* type like 'union sigval' where we have to cast to (union sigval)((FAR void *)parm)
* -- Yech.
*/
get_formalparmtype(g_parm[PARM1_INDEX+i], formal);
get_actualparmtype(g_parm[PARM1_INDEX+i], actual);
/* Treat the first argument in the list differently from the others..
* It does not need a comma before it.
*/
if (i > 0)
{
/* Check for a variable number of arguments */
if (is_vararg(actual, i, nparms))
{
/* Always pass six arguments */
for (j = i+1; j <=6; j++)
{
fprintf(stream, ", parm%d", j);
}
}
else
{
if (is_union(formal))
{
fprintf(stream, ", (%s)((%s)parm%d)", formal, actual, i+1);
}
else
{
fprintf(stream, ", (%s)parm%d", actual, i+1);
}
}
}
else
{
if (is_union(formal))
{
fprintf(stream, "(%s)((%s)parm%d)", formal, actual, i+1);
}
else
{
fprintf(stream, "(%s)parm%d",actual, i+1);
}
}
}
/* Tail end of the function. If the proxied function has no return
* value, just return zero (OK).
*/
if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0)
{
fprintf(stream, ");\n return 0;\n}\n\n");
}
else
{
fprintf(stream, ");\n}\n\n");
}
if (g_parm[COND_INDEX][0] != '\0')
{
fprintf(stream, "#endif /* %s */\n", g_parm[COND_INDEX]);
}
stub_close(stream);
}
static void show_usage(const char *progname)
{
fprintf(stderr, "USAGE: %s [-p|s|i] <CSV file>\n\n", progname);
fprintf(stderr, "Where:\n\n");
fprintf(stderr, "\t-p : Generate proxies\n");
fprintf(stderr, "\t-s : Generate stubs\n");
fprintf(stderr, "\t-i : Generate proxies as static inline functions\n");
fprintf(stderr, "\t-d : Enable debug output\n");
exit(1);
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
char *csvpath;
bool proxies = false;
FILE *stream;
char *ptr;
int ch;
/* Parse command line options */
g_debug = false;
g_inline = false;
while ((ch = getopt(argc, argv, ":dps")) > 0)
{
switch (ch)
{
case 'd' :
g_debug = true;
break;
case 'p' :
proxies = true;
break;
case 's' :
proxies = false;
break;
case 'i' :
g_inline = true;
break;
case '?' :
fprintf(stderr, "Unrecognized option: %c\n", optopt);
show_usage(argv[0]);
case ':' :
fprintf(stderr, "Missing option argument, option: %c\n", optopt);
show_usage(argv[0]);
break;
fprintf(stderr, "Unexpected option: %c\n", ch);
show_usage(argv[0]);
}
}
if (optind >= argc)
{
fprintf(stderr, "Missing <CSV file>\n");
show_usage(argv[0]);
}
csvpath = argv[optind];
if (++optind < argc)
{
fprintf(stderr, "Unexpected garbage at the end of the line\n");
show_usage(argv[0]);
}
/* Open the CSV file */
stream= fopen(csvpath, "r");
if (!stream)
{
fprintf(stderr, "open %s failed: %s\n", csvpath, strerror(errno));
exit(3);
}
/* Process each line in the CVS file */
while ((ptr = read_line(stream)) != NULL)
{
/* Parse the line from the CVS file */
int nargs = parse_csvline(ptr);
if (nargs < PARM1_INDEX)
{
fprintf(stderr, "Only %d arguments found: %s\n", nargs, g_line);
exit(8);
}
if (proxies)
{
generate_proxy(nargs - PARM1_INDEX);
}
else
{
g_stubstream = NULL;
generate_stub(nargs - PARM1_INDEX);
if (g_stubstream != NULL)
{
fprintf(g_stubstream, "\n#endif /* __STUB_H */\n");
fclose(g_stubstream);
}
}
}
/* Close the CSV file */
fclose(stream);
return 0;
}
+106
View File
@@ -0,0 +1,106 @@
/****************************************************************************
* tools/mkversion.c
*
* Copyright (C) 2011 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "cfgparser.h"
/****************************************************************************
* Definitions
****************************************************************************/
#define DEFCONFIG ".version"
/****************************************************************************
* Private Functions
****************************************************************************/
static inline char *getfilepath(const char *name)
{
snprintf(line, PATH_MAX, "%s/" DEFCONFIG, name);
line[PATH_MAX] = '\0';
return strdup(line);
}
static void show_usage(const char *progname)
{
fprintf(stderr, "USAGE: %s <abs path to .version>\n", progname);
exit(1);
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
char *filepath;
FILE *stream;
if (argc != 2)
{
fprintf(stderr, "Unexpected number of arguments\n");
show_usage(argv[0]);
}
filepath = getfilepath(argv[1]);
if (!filepath)
{
fprintf(stderr, "getfilepath failed\n");
exit(2);
}
stream= fopen(filepath, "r");
if (!stream)
{
fprintf(stderr, "open %s failed: %s\n", filepath, strerror(errno));
exit(3);
}
printf("/* version.h -- Autogenerated! Do not edit. */\n\n");
printf("#ifndef __INCLUDE_NUTTX_VERSION_H\n");
printf("#define __INCLUDE_NUTTX_VERSION_H\n\n");
parse_file(stream);
printf("\n#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 8) | (CONFIG_VERSION_MINOR))\n\n");
printf("#endif /* __INCLUDE_NUTTX_VERSION_H */\n");
fclose(stream);
return 0;
}
+51
View File
@@ -0,0 +1,51 @@
############################################################################
# tools/pic32mx//Makefile
#
# Copyright (C) 2011-2012 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.
#
############################################################################
all: mkpichex
default: mkpichex
.PHONY: clean
# Add CFLAGS=-g on the make command line to build debug versions
CFLAGS = -O2 -Wall -I.
# mkpichex - Convert virtual addresses in nuttx.hex to physical addresses
mkconfig: mkpichex.c mkpichex.c
@gcc $(CFLAGS) -o mkpichex mkpichex.c
clean:
@rm -f *.o *.a *~ .*.swp
@rm -f mkpichex mkpichex.exe
+315
View File
@@ -0,0 +1,315 @@
/****************************************************************************
* tools/pic32mx//mkpichex.c
*
* Copyright (C) 2011-2012 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MAX_LINE 1024
/* Line offsets */
#define START_OFFSET 0
#define LEN_OFFSET 1
#define ADDR_OFFSET (LEN_OFFSET + 2)
#define TYPE_OFFSET (ADDR_OFFSET + 4)
#define PAYLOAD_OFFSET (TYPE_OFFSET + 2)
#define CHKSUM_OFFSET(n) (PAYLOAD_OFFSET+2*(n))
/* Record types:
*
* 00, data record, contains data and 16-bit address. The format described
* above.
* 01, End Of File record, a file termination record. No data. Has to be
* the last line of the file, only one per file permitted. Usually
* ':00000001FF'. Originally the End Of File record could contain a
* start address for the program being loaded, e.g. :00AB2F0125
* would make a jump to address AB2F. This was convenient when programs
* were loaded from punched paper tape.
* 02, Extended Segment Address Record, segment-base address. Used when 16
* bits are not enough, identical to 80x86 real mode addressing. The
* address specified by the 02 record is multiplied by 16 (shifted 4
* bits left) and added to the subsequent 00 record addresses. This
* allows addressing of up to a megabyte of address space. The address
* field of this record has to be 0000, the byte count is 02 (the segment
* is 16-bit). The least significant hex digit of the segment address is
* always 0.
* 03, Start Segment Address Record. For 80x86 processors, it specifies the
* initial content of the CS:IP registers. The address field is 0000, the
* byte count is 04, the first two bytes are the CS value, the latter two
* are the IP value.
* 04, Extended Linear Address Record, allowing for fully 32 bit addressing.
* The address field is 0000, the byte count is 02. The two data bytes
* represent the upper 16 bits of the 32 bit address, when combined with
* the address of the 00 type record.
* 05, Start Linear Address Record. The address field is 0000, the byte
* count is 04. The 4 data bytes represent the 32-bit value loaded into
* the EIP register of the 80386 and higher CPU.
*/
#define TYPE_DATA 0
#define TYPE_EOF 1
#define TYPE_EXTSEG 2
#define TYPE_STARTSEG 3
#define TYPE_EXTLIN 4
#define TYPE_STARTLIN 5
/****************************************************************************
* Private Types
****************************************************************************/
struct hex_s
{
unsigned char len; /* Length of the data payload */
unsigned char type; /* Record type */
unsigned short addr; /* Lower 16-bit address */
};
/****************************************************************************
* Private Data
****************************************************************************/
static char line[MAX_LINE+1];
/****************************************************************************
* Private Functions
****************************************************************************/
static inline char *getfilepath(const char *path, const char *name, const char *extension)
{
snprintf(line, MAX_LINE, "%s/%s.%s", path, name, extension);
line[MAX_LINE] = '\0';
return strdup(line);
}
static void show_usage(const char *progname)
{
fprintf(stderr, "USAGE: %s <abs path to nuttx.hex>\n", progname);
exit(1);
}
static unsigned char get4(char hex)
{
if (hex >= '0' && hex <= '9')
{
return hex - '0';
}
else if (hex >= 'a' && hex <= 'f')
{
return hex - 'a' + 10;
}
else if (hex >= 'A' && hex <= 'F')
{
return hex - 'A' + 10;
}
fprintf(stderr, "Bad hex character code: %s\n", line);
exit(2);
}
static unsigned char get8(const char *ptr)
{
return get4(ptr[0]) << 4 | get4(ptr[1]);
}
static unsigned short get16(const char *ptr)
{
return (unsigned short)get8(&ptr[0]) << 8 | (unsigned short)get8(&ptr[2]);
}
static int parse_line(struct hex_s *hexline)
{
/* :LLAAAATT... */
if (line[START_OFFSET] != ':')
{
fprintf(stderr, "Bad start code: %s\n", line);
return 1;
}
hexline->len = get8(&line[LEN_OFFSET]);
hexline->addr = get16(&line[ADDR_OFFSET]);
hexline->type = get8(&line[TYPE_OFFSET]);
return 0;
}
#if 0
static unsigned char checksum(chksum_ndx)
{
int chksum = 0;
int ndx;
for (ndx = 1; ndx < chksum_ndx; ndx += 2)
{
chksum += (int)get8(&line[ndx]);
}
return (unsigned char)((-chksum) & 0xff);
}
#endif
static void adjust_extlin(struct hex_s *hexline)
{
unsigned short segment;
int chksum;
/* Make sure that the payload is exactly 2 bytes */
if (hexline->len != 2)
{
fprintf(stderr, "Bad length on extended segment address record\n");
fprintf(stderr, " %s", line);
}
/* And the address field is supposed to be zero */
if (hexline->addr != 0)
{
fprintf(stderr, "Bad address on extended segment address record\n");
fprintf(stderr, " %s", line);
}
/* Decode the 2 byte payload */
segment = get16(&line[PAYLOAD_OFFSET]);
/* Convert the address to a 29-bit physical address */
segment &= 0x1fff;
/* Recalculate the checksum and make sure that there is a null terminator
* Since len=2, addr=0, type=4, the is a trivial calculation.
*/
chksum = (-(segment + (segment >> 8) + 6)) & 0xff;
/* Then create the new output record */
snprintf(line, MAX_LINE-PAYLOAD_OFFSET, ":02000004%04X%02X\n", segment, chksum);
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
struct hex_s hexline;
char *srcfile;
char *destfile;
FILE *src;
FILE *dest;
if (argc != 2)
{
fprintf(stderr, "Unexpected number of arguments\n");
show_usage(argv[0]);
}
srcfile = getfilepath(argv[1], "nuttx", "hex");
if (!srcfile)
{
fprintf(stderr, "getfilepath failed\n");
exit(2);
}
destfile = getfilepath(argv[1], "nuttx", "tmp");
if (!destfile)
{
fprintf(stderr, "getfilepath failed\n");
exit(2);
}
src = fopen(srcfile, "r");
if (!src)
{
fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno));
exit(3);
}
dest = fopen(destfile, "w");
if (!dest)
{
fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno));
exit(3);
}
/* Read each line from the source file */
while (fgets(line, MAX_LINE, src) != NULL)
{
if (parse_line(&hexline))
{
fprintf(stderr, "Failed to parse line\n");
exit(1);
}
/* Adjust 'Extended Segment Address Records'. */
if (hexline.type == TYPE_EXTLIN)
{
adjust_extlin(&hexline);
}
fputs(line, dest);
}
fclose(src);
fclose(dest);
/* Remove the original nuttx.hex file */
if (remove(srcfile) != 0)
{
fprintf(stderr, "Failed to remove the old '%s'\n", srcfile);
}
/* Rename the new nuttx.tmp file to nuttx.hex */
if (rename(destfile, srcfile) != 0)
{
fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile);
}
return 0;
}
+70
View File
@@ -0,0 +1,70 @@
#!/bin/bash
############################################################################
# tools/unlink.sh
#
# Copyright (C) 2008 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.
#
############################################################################
link=$1
# Verify that arguments were provided
if [ -z "${link}" ]; then
echo "Missing link argument"
exit 1
fi
# Check if something already exists at the link path
if [ -e "${link}" ]; then
# Yes, is it a symbolic link? If so, then remove it
if [ -h "${link}" ]; then
rm -f "${link}"
else
# If the path is a directory and contains the "fake link" mark, then
# treat it like a soft link (i.e., remove the directory)
if [ -d "${link}" -a -f "${link}/.fakelnk" ]; then
rm -rf "${link}"
else
# It is something else (like a file) or directory that does
# not contain the "fake link" mark
echo "${link} already exists but is not a symbolic link"
exit 1
fi
fi
fi
+135
View File
@@ -0,0 +1,135 @@
#!/bin/bash
# version.sh
#
# Copyright (C) 2011 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.
#
WD=`pwd`
# Get command line parameters
USAGE="USAGE: $0 [-d|-h] [-b build] -v <major.minor> <outfile-path>"
ADVICE="Try '$0 -h' for more information"
unset VERSION
unset BUILD
unset OUTFILE
while [ ! -z "$1" ]; do
case $1 in
-b )
shift
BUILD=$1
;;
-d )
set -x
;;
-v )
shift
VERSION=$1
;;
-h )
echo "$0 is a tool for generation of proper version files for the NuttX build"
echo ""
echo $USAGE
echo ""
echo "Where:"
echo " -d"
echo " Enable script debug"
echo " -h"
echo " show this help message and exit"
echo " -v <major.minor>"
echo " The NuttX version number expressed a major and minor number separated"
echo " by a period"
echo " <outfile-path>"
echo " The full path to the version file to be created"
exit 0
;;
* )
break;
;;
esac
shift
done
OUTFILE=$1
# Make sure we know what is going on
if [ -z ${VERSION} ] ; then
echo "Missing versioning information"
echo $USAGE
echo $ADVICE
exit 1
fi
if [ -z ${OUTFILE} ] ; then
echo "Missing path to the output file"
echo $USAGE
echo $ADVICE
exit 1
fi
# Get the major and minor version numbers
MAJOR=`echo ${VERSION} | cut -d'.' -f1`
if [ "X${MAJOR}" = "X${VERSION}" ]; then
echo "Missing minor version number"
echo $USAGE
echo $ADVICE
exit 2
fi
MINOR=`echo ${VERSION} | cut -d'.' -f2`
# Get SVN information (if not provided on the command line)
if [ -z "${BUILD}" ]; then
SVNINFO=`svn info 2>/dev/null | fgrep 'Revision:'`
if [ -z "${SVNINFO}" ]; then
echo "SVN version information is not available"
exit 3
fi
BUILD=`echo ${SVNINFO} | cut -d' ' -f2`
if [ -z "${BUILD}" ]; then
echo "SVN build information not found"
exit 4
fi
fi
# Write a version file into the NuttX directoy. The syntax of file is such that it
# may be sourced by a bash script or included by a Makefile.
echo "#!/bin/bash" >${OUTFILE}
echo "" >>${OUTFILE}
echo "CONFIG_VERSION_STRING=\"${VERSION}\"" >>${OUTFILE}
echo "CONFIG_VERSION_MAJOR=${MAJOR}" >>${OUTFILE}
echo "CONFIG_VERSION_MINOR=${MINOR}" >>${OUTFILE}
echo "CONFIG_VERSION_BUILD=${BUILD}" >>${OUTFILE}
+102
View File
@@ -0,0 +1,102 @@
#!/bin/bash
############################################################################
# tools/winlink.sh
#
# Copyright (C) 2008 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.
#
############################################################################
#
# NuttX uses symbolic links to configure platform-specific directories into
# the build system. This works great except for when a Windows native
# toolchain is used in a Cygwin environment. In that case, symbolic
# links do not work correctly when accessed from the Windows native toolchain;
# rather, just look link files with the extension .lnk
#
# In this environment, the build system will work around this using this script
# as a replacement for the 'ln' command. This scrpt will simply copy the
# directory into the expected positiion.
#
#set -x
src=$1
dest=$2
# Verify that arguments were provided
if [ -z "${src}" -o -z "${dest}" ]; then
echo "Missing src and/or dest arguments"
exit 1
fi
# Check if something already exists at the destination path replace it with
# the new link (which might be different). Note that we check for the
# the link (-h) before we check for existence (-e) because a bad link will
# report that it does not exist.
if [ -h "${dest}" ]; then
rm -f "${dest}"
else
# If the path exists and is a directory that contains the "fake link"
# mark, then treat it like a soft link (i.e., remove the directory)
if [ -d "${dest}" -a -f "${dest}/.fakelnk" ]; then
rm -rf "${dest}"
else
# Does anything exist at the destination path?
if [ -e "${dest}" ]; then
# It is something else (like a file) or directory that does
# not contain the "fake link" mark
echo "${dest} already exists but is not a symbolic link"
exit 1
fi
fi
fi
# Verify that a directory exists at the source path
if [ ! -d "${src}" ]; then
echo "No directory at ${src}"
exit 1
fi
# Copy the directory
cp -a "${src}" "${dest}" || \
{ echo "Failed to create link: $dest" ; rm -rf ${dest} ; exit 1 ; }
touch "${dest}/.fakelnk" || \
{ echo "Failed to touch ${dest}/.fakelnk" ; rm -rf ${dest} ; exit 1 ; }
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env python
############################################################################
# tools/xmlrpc_test.py
#
# Copyright (C) 2012 Max Holtzberg. All rights reserved.
# Author: Max Holtzberg <mh@uvc.de>
#
# 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.
#
############################################################################
import sys
import xmlrpclib
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Usage: %s <ip address>' % sys.argv[0]
quit(1)
server_url = 'http://%s/device' % sys.argv[1]
server = xmlrpclib.ServerProxy(server_url)
result = server.get_device_stats("username", "password", 0)
print result
+178
View File
@@ -0,0 +1,178 @@
#!/bin/bash
# zipme.sh
#
# Copyright (C) 2007-2011 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.
#
#set -x
WD=`pwd`
VERSION=$1
TAR="tar cvf"
ZIP=gzip
# Make sure we know what is going on
if [ -z ${VERSION} ] ; then
echo "You must supply a version like xx.yy as a parameter"
exit 1;
fi
# Find the directory we were executed from and were we expect to
# see the directories to tar up
MYNAME=`basename $0`
if [ -x ${WD}/${MYNAME} ] ; then
TRUNKDIR="${WD}/../.."
else
if [ -x ${WD}/tools/${MYNAME} ] ; then
TRUNKDIR="${WD}/.."
else
if [ -x ${WD}/nuttx-${VERSION}/tools/${MYNAME} ] ; then
TRUNKDIR="${WD}"
else
echo "You must cd into the NUTTX directory to execute this script."
exit 1
fi
fi
fi
# Get the NuttX directory names and the path to the parent directory
NUTTX=${TRUNKDIR}/nuttx-${VERSION}
APPDIR=${TRUNKDIR}/apps-${VERSION}
# Make sure that the versioned directory exists
if [ ! -d ${TRUNKDIR} ]; then
echo "Directory ${TRUNKDIR} does not exist"
exit 1
fi
cd ${TRUNKDIR} || \
{ echo "Failed to cd to ${TRUNKDIR}" ; exit 1 ; }
if [ ! -d nuttx-${VERSION} ] ; then
echo "Directory ${TRUNKDIR}/nuttx-${VERSION} does not exist!"
exit 1
fi
if [ ! -d apps-${VERSION} ] ; then
echo "Directory ${TRUNKDIR}/apps-${VERSION} does not exist!"
exit 1
fi
# Create the versioned tarball names
NUTTX_TARNAME=nuttx-${VERSION}.tar
APPS_TARNAME=apps-${VERSION}.tar
NUTTX_ZIPNAME=${NUTTX_TARNAME}.gz
APPS_ZIPNAME=${APPS_TARNAME}.gz
# Prepare the nuttx directory -- Remove editor garbage
find ${TRUNKDIR} -name '*~' -exec rm -f '{}' ';' || \
{ echo "Removal of emacs garbage failed!" ; exit 1 ; }
find ${TRUNKDIR} -name '*.swp' -exec rm -f '{}' ';' || \
{ echo "Removal of VI garbage failed!" ; exit 1 ; }
# Make sure that versioned copies of the certain files are in place
cd ${NUTTX}/Documentation || \
{ echo "Failed to cd to ${NUTTX}/Documentation" ; exit 1 ; }
cp -f ../TODO TODO.txt
cp -f ../ChangeLog ChangeLog.txt
# Write a version file into the NuttX directoy. The syntax of file is such that it
# may be sourced by a bash script or included by a Makefile.
VERSIONSH=${NUTTX}/tools/version.sh
if [ ! -x "${VERSIONSH}" ]; then
echo "No executable script was found at: ${VERSIONSH}"
exit 1
fi
${VERSIONSH} -v ${VERSION} ${NUTTX}/.version || \
{ echo "${VERSIONSH} failed"; cat ${NUTTX}/.version; exit 1; }
chmod 755 ${NUTTX}/.version
# Perform a full clean for the distribution
cd ${TRUNKDIR} || \
{ echo "Failed to cd to ${TRUNKDIR}" ; exit 1 ; }
make -C ${NUTTX} distclean
# Remove any previous tarballs
if [ -f ${NUTTX_TARNAME} ] ; then
echo "Removing ${TRUNKDIR}/${NUTTX_TARNAME}"
rm -f ${NUTTX_TARNAME} || \
{ echo "rm ${NUTTX_TARNAME} failed!" ; exit 1 ; }
fi
if [ -f ${NUTTX_ZIPNAME} ] ; then
echo "Removing ${TRUNKDIR}/${NUTTX_ZIPNAME}"
rm -f ${NUTTX_ZIPNAME} || \
{ echo "rm ${NUTTX_ZIPNAME} failed!" ; exit 1 ; }
fi
if [ -f ${APPS_TARNAME} ] ; then
echo "Removing ${TRUNKDIR}/${APPS_TARNAME}"
rm -f ${APPS_TARNAME} || \
{ echo "rm ${APPS_TARNAME} failed!" ; exit 1 ; }
fi
if [ -f ${APPS_ZIPNAME} ] ; then
echo "Removing ${TRUNKDIR}/${APPS_ZIPNAME}"
rm -f ${APPS_ZIPNAME} || \
{ echo "rm ${APPS_ZIPNAME} failed!" ; exit 1 ; }
fi
# Then tar and zip-up the directories
cd ${TRUNKDIR} || \
{ echo "Failed to cd to ${TRUNKDIR}" ; exit 1 ; }
${TAR} ${NUTTX_TARNAME} nuttx-${VERSION} || \
{ echo "tar of ${NUTTX_TARNAME} failed!" ; exit 1 ; }
${ZIP} ${NUTTX_TARNAME} || \
{ echo "zip of ${NUTTX_TARNAME} failed!" ; exit 1 ; }
${TAR} ${APPS_TARNAME} apps-${VERSION} || \
{ echo "tar of ${APPS_TARNAME} failed!" ; exit 1 ; }
${ZIP} ${APPS_TARNAME} || \
{ echo "zip of ${APPS_TARNAME} failed!" ; exit 1 ; }
cd ${NUTTX}