summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/.gitignore1
-rw-r--r--tools/Makefile121
-rw-r--r--tools/easylogo/Makefile9
-rw-r--r--tools/fit_image.c34
-rw-r--r--tools/gdb/Makefile15
-rw-r--r--tools/img2srec.c164
-rw-r--r--tools/imls/Makefile29
-rw-r--r--tools/mingw_support.c157
-rw-r--r--tools/mingw_support.h2
-rw-r--r--tools/mkimage.c56
10 files changed, 310 insertions, 278 deletions
diff --git a/tools/.gitignore b/tools/.gitignore
index 03f54ef..cb067a4 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -8,3 +8,4 @@
/ncp
/ubsha1
/inca-swap-bytes
+/*.exe
diff --git a/tools/Makefile b/tools/Makefile
index b04e3f3..5b8c3c3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -24,33 +24,6 @@
TOOLSUBDIRS =
#
-# Mac OS X / Darwin's C preprocessor is Apple specific. It
-# generates numerous errors and warnings. We want to bypass it
-# and use GNU C's cpp. To do this we pass the -traditional-cpp
-# option to the compiler. Note that the -traditional-cpp flag
-# DOES NOT have the same semantics as GNU C's flag, all it does
-# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
-#
-# Apple's linker is similar, thanks to the new 2 stage linking
-# multiple symbol definitions are treated as errors, hence the
-# -multiply_defined suppress option to turn off this error.
-#
-
-HOSTCFLAGS = -Wall
-HOST_LDFLAGS =
-
-ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
-HOSTCFLAGS += -traditional-cpp
-HOST_LDFLAGS += -multiply_defined suppress
-else
-HOSTCFLAGS += -pedantic
-endif
-
-ifeq ($(HOSTOS),cygwin)
-HOSTCFLAGS += -ansi
-endif
-
-#
# toolchains targeting win32 generate .exe files
#
ifneq (,$(findstring WIN32 ,$(shell $(HOSTCC) -E -dM -xc /dev/null)))
@@ -93,16 +66,16 @@ EXT_OBJ_FILES-y += lib_generic/sha1.o
# Source files located in the tools directory
OBJ_FILES-$(CONFIG_LCD_LOGO) += bmp_logo.o
OBJ_FILES-$(CONFIG_VIDEO_LOGO) += bmp_logo.o
-OBJ_FILES-y += default_image.o
-OBJ_FILES-$(CONFIG_ENV_IS_EMBEDDED) += envcrc.o
-OBJ_FILES-y += fit_image.o
+NOPED_OBJ_FILES-y += default_image.o
+OBJ_FILES-y += envcrc.o
+NOPED_OBJ_FILES-y += fit_image.o
OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
OBJ_FILES-$(CONFIG_INCA_IP) += inca-swap-bytes.o
-OBJ_FILES-y += kwbimage.o
-OBJ_FILES-y += mkimage.o
+NOPED_OBJ_FILES-y += kwbimage.o
+NOPED_OBJ_FILES-y += mkimage.o
OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
-OBJ_FILES-y += os_support.o
+NOPED_OBJ_FILES-y += os_support.o
OBJ_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1.o
# Don't build by default
@@ -134,57 +107,52 @@ LOGO_BMP= logos/ronetix.bmp
endif
# now $(obj) is defined
-SRCS += $(addprefix $(SRCTREE)/,$(EXT_OBJ_FILES-y:.o=.c))
-SRCS += $(addprefix $(SRCTREE)/tools/,$(OBJ_FILES-y:.o=.c))
-SRCS += $(addprefix $(SRCTREE)/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c))
+HOSTSRCS += $(addprefix $(SRCTREE)/,$(EXT_OBJ_FILES-y:.o=.c))
+HOSTSRCS += $(addprefix $(SRCTREE)/tools/,$(OBJ_FILES-y:.o=.c))
+HOSTSRCS += $(addprefix $(SRCTREE)/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c))
BINS := $(addprefix $(obj),$(sort $(BIN_FILES-y)))
LIBFDT_OBJS := $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y))
+HOSTOBJS := $(addprefix $(obj),$(OBJ_FILES-y))
+NOPEDOBJS := $(addprefix $(obj),$(NOPED_OBJ_FILES-y))
+
#
# Use native tools and options
# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
#
-CPPFLAGS = -idirafter $(SRCTREE)/include \
+HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \
-idirafter $(OBJTREE)/include2 \
-idirafter $(OBJTREE)/include \
-I $(SRCTREE)/libfdt \
-I $(SRCTREE)/tools \
-DTEXT_BASE=$(TEXT_BASE) -DUSE_HOSTCC \
-D__KERNEL_STRICT_NAMES
-CFLAGS = $(HOSTCFLAGS) $(CPPFLAGS) -O
-
-# No -pedantic switch to avoid libfdt compilation warnings
-FIT_CFLAGS = -Wall $(CPPFLAGS) -O
-AFLAGS = -D__ASSEMBLY__ $(CPPFLAGS)
-CC = $(HOSTCC)
-STRIP = $(HOSTSTRIP)
-MAKEDEPEND = makedepend
all: $(obj).depend $(BINS) $(LOGO-y) subdirs
$(obj)bin2header$(SFX): $(obj)bin2header.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)bmp_logo$(SFX): $(obj)bmp_logo.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)envcrc$(SFX): $(obj)crc32.o $(obj)env_embedded.o $(obj)envcrc.o $(obj)sha1.o
- $(CC) $(CFLAGS) -o $@ $^
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
$(obj)gen_eth_addr$(SFX): $(obj)gen_eth_addr.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)img2srec$(SFX): $(obj)img2srec.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)inca-swap-bytes$(SFX): $(obj)inca-swap-bytes.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)mkimage$(SFX): $(obj)crc32.o \
$(obj)default_image.o \
@@ -196,48 +164,29 @@ $(obj)mkimage$(SFX): $(obj)crc32.o \
$(obj)os_support.o \
$(obj)sha1.o \
$(LIBFDT_OBJS)
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)mpc86x_clk$(SFX): $(obj)mpc86x_clk.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)ncb$(SFX): $(obj)ncb.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
- $(STRIP) $@
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
+ $(HOSTSTRIP) $@
$(obj)ubsha1$(SFX): $(obj)os_support.o $(obj)sha1.o $(obj)ubsha1.o
- $(CC) $(CFLAGS) -o $@ $^
-
-# Some files complain if compiled with -pedantic, use FIT_CFLAGS
-$(obj)default_image.o: $(SRCTREE)/tools/default_image.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
-
-$(obj)fit_image.o: $(SRCTREE)/tools/fit_image.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
-
-$(obj)image.o: $(SRCTREE)/common/image.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
-
-$(obj)kwbimage.o: $(SRCTREE)/tools/kwbimage.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
-
-$(obj)mkimage.o: $(SRCTREE)/tools/mkimage.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
-
-$(obj)os_support.o: $(SRCTREE)/tools/os_support.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
# Some of the tool objects need to be accessed from outside the tools directory
$(obj)%.o: $(SRCTREE)/common/%.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+ $(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
$(obj)%.o: $(SRCTREE)/lib_generic/%.c
- $(CC) -g $(CFLAGS) -c -o $@ $<
+ $(HOSTCC) -g $(HOSTCFLAGS) -c -o $@ $<
$(LIBFDT_OBJS):
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+ $(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
subdirs:
ifeq ($(TOOLSUBDIRS),)
@@ -247,8 +196,6 @@ else
$(MAKE) \
HOSTOS=$(HOSTOS) \
HOSTARCH=$(HOSTARCH) \
- HOSTCFLAGS="$(HOSTCFLAGS)" \
- HOST_LDFLAGS="$(HOST_LDFLAGS)" \
-C $$dir || exit 1 ; \
done
endif
diff --git a/tools/easylogo/Makefile b/tools/easylogo/Makefile
index 566b125..d8e28b0 100644
--- a/tools/easylogo/Makefile
+++ b/tools/easylogo/Makefile
@@ -1,8 +1,11 @@
-CFLAGS += -Wall
+include $(TOPDIR)/config.mk
-all: easylogo
+all: $(obj)easylogo
+
+$(obj)easylogo: $(SRCTREE)/tools/easylogo/easylogo.c
+ $(HOSTCC) $(HOSTCFLAGS_NOPED) $(HOSTLDFLAGS) -o $@ $^
clean:
- rm -f easylogo *.o
+ rm -f $(obj)easylogo
.PHONY: all clean
diff --git a/tools/fit_image.c b/tools/fit_image.c
index d1e612f..ef9ffee 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -155,38 +155,6 @@ static int fit_handle_file (struct mkimage_params *params)
return (EXIT_SUCCESS);
}
-static void fit_set_header (void *ptr, struct stat *sbuf, int ifd,
- struct mkimage_params *params)
-{
- uint32_t checksum;
-
- image_header_t * hdr = (image_header_t *)ptr;
-
- checksum = crc32 (0,
- (const unsigned char *)(ptr +
- sizeof(image_header_t)),
- sbuf->st_size - sizeof(image_header_t));
-
- /* Build new header */
- image_set_magic (hdr, IH_MAGIC);
- image_set_time (hdr, sbuf->st_mtime);
- image_set_size (hdr, sbuf->st_size - sizeof(image_header_t));
- image_set_load (hdr, params->addr);
- image_set_ep (hdr, params->ep);
- image_set_dcrc (hdr, checksum);
- image_set_os (hdr, params->os);
- image_set_arch (hdr, params->arch);
- image_set_type (hdr, params->type);
- image_set_comp (hdr, params->comp);
-
- image_set_name (hdr, params->imagename);
-
- checksum = crc32 (0, (const unsigned char *)hdr,
- sizeof(image_header_t));
-
- image_set_hcrc (hdr, checksum);
-}
-
static int fit_check_params (struct mkimage_params *params)
{
return ((params->dflag && (params->fflag || params->lflag)) ||
@@ -202,7 +170,7 @@ static struct image_type_params fitimage_params = {
.print_header = fit_print_contents,
.check_image_type = fit_check_image_types,
.fflag_handle = fit_handle_file,
- .set_header = fit_set_header,
+ .set_header = NULL, /* FIT images use DTB header */
.check_params = fit_check_params,
};
diff --git a/tools/gdb/Makefile b/tools/gdb/Makefile
index 0a5687d..90037c7 100644
--- a/tools/gdb/Makefile
+++ b/tools/gdb/Makefile
@@ -30,17 +30,14 @@ BINS = gdbsend gdbcont
COBJS = gdbsend.o gdbcont.o error.o remote.o serial.o
-OBJS := $(addprefix $(obj),$(COBJS))
-SRCS := $(COBJS:.o=.c)
+HOSTOBJS := $(addprefix $(obj),$(COBJS))
+HOSTSRCS := $(COBJS:.o=.c)
BINS := $(addprefix $(obj),$(BINS))
#
# Use native tools and options
#
-CPPFLAGS = -I$(BFD_ROOT_DIR)/include
-CFLAGS = $(HOSTCFLAGS) -O $(CPPFLAGS)
-CC = $(HOSTCC)
-MAKEDEPEND = makedepend
+HOSTCPPFLAGS = -I$(BFD_ROOT_DIR)/include
HOSTOS := $(shell uname -s | sed -e 's/\([Cc][Yy][Gg][Ww][Ii][Nn]\).*/cygwin/')
@@ -54,13 +51,13 @@ else # ! CYGWIN
all: $(obj).depend $(BINS)
$(obj)gdbsend: $(obj)gdbsend.o $(obj)error.o $(obj)remote.o $(obj)serial.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
$(obj)gdbcont: $(obj)gdbcont.o $(obj)error.o $(obj)remote.o $(obj)serial.o
- $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
+ $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
clean:
- rm -f $(OBJS)
+ rm -f $(HOSTOBJS)
distclean: clean
rm -f $(BINS) $(obj)core $(obj)*.bak $(obj).depend
diff --git a/tools/img2srec.c b/tools/img2srec.c
index f10379f..ec76964 100644
--- a/tools/img2srec.c
+++ b/tools/img2srec.c
@@ -53,6 +53,7 @@
|*************************************************************************/
#include "os_support.h"
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -63,63 +64,22 @@
#include <errno.h>
/*************************************************************************
-| DEFINES
-|*************************************************************************/
-
-#define FALSE 0
-#define TRUE 1
-
-/*************************************************************************
-| MACROS
-|*************************************************************************/
-
-/*************************************************************************
-| TYPEDEFS
-|*************************************************************************/
-
-typedef uint8_t CHAR;
-typedef uint8_t BYTE;
-typedef uint16_t WORD;
-typedef uint32_t DWORD;
-typedef int BOOL;
-
-/*************************************************************************
-| LOCALS
-|*************************************************************************/
-
-/*************************************************************************
-| PROTOTYPES
-|*************************************************************************/
-
-static char *ExtractHex(DWORD *value, char *getPtr);
-static char *ExtractDecimal(DWORD *value, char *getPtr);
-static void ExtractNumber(DWORD *value, char *getPtr);
-static BYTE *ExtractWord(WORD *value, BYTE *buffer);
-static BYTE *ExtractLong(DWORD *value, BYTE *buffer);
-static BYTE *ExtractBlock(WORD count, BYTE *data, BYTE *buffer);
-static char *WriteHex(char *pa, BYTE value, WORD *pCheckSum);
-static char *BuildSRecord(char *pa, WORD sType, DWORD addr,
- const BYTE *data, int nCount);
-static void ConvertELF(char *fileName, DWORD loadOffset);
-int main(int argc, char *argv[]);
-
-/*************************************************************************
| FUNCTIONS
|*************************************************************************/
-static char* ExtractHex (DWORD* value, char* getPtr)
+static char* ExtractHex (uint32_t* value, char* getPtr)
{
- DWORD num;
- DWORD digit;
- BYTE c;
+ uint32_t num;
+ uint32_t digit;
+ uint8_t c;
while (*getPtr == ' ') getPtr++;
num = 0;
for (;;) {
c = *getPtr;
- if ((c >= '0') && (c <= '9')) digit = (DWORD)(c - '0');
- else if ((c >= 'A') && (c <= 'F')) digit = (DWORD)(c - 'A' + 10);
- else if ((c >= 'a') && (c <= 'f')) digit = (DWORD)(c - 'a' + 10);
+ if ((c >= '0') && (c <= '9')) digit = (uint32_t)(c - '0');
+ else if ((c >= 'A') && (c <= 'F')) digit = (uint32_t)(c - 'A' + 10);
+ else if ((c >= 'a') && (c <= 'f')) digit = (uint32_t)(c - 'a' + 10);
else break;
num <<= 4;
num += digit;
@@ -129,17 +89,17 @@ static char* ExtractHex (DWORD* value, char* getPtr)
return getPtr;
} /* ExtractHex */
-static char* ExtractDecimal (DWORD* value, char* getPtr)
+static char* ExtractDecimal (uint32_t* value, char* getPtr)
{
- DWORD num;
- DWORD digit;
- BYTE c;
+ uint32_t num;
+ uint32_t digit;
+ uint8_t c;
while (*getPtr == ' ') getPtr++;
num = 0;
for (;;) {
c = *getPtr;
- if ((c >= '0') && (c <= '9')) digit = (DWORD)(c - '0');
+ if ((c >= '0') && (c <= '9')) digit = (uint32_t)(c - '0');
else break;
num *= 10;
num += digit;
@@ -150,13 +110,13 @@ static char* ExtractDecimal (DWORD* value, char* getPtr)
} /* ExtractDecimal */
-static void ExtractNumber (DWORD* value, char* getPtr)
+static void ExtractNumber (uint32_t* value, char* getPtr)
{
- BOOL neg = FALSE;;
+ bool neg = false;;
while (*getPtr == ' ') getPtr++;
if (*getPtr == '-') {
- neg = TRUE;
+ neg = true;
getPtr++;
} /* if */
if ((*getPtr == '0') && ((*(getPtr+1) == 'x') || (*(getPtr+1) == 'X'))) {
@@ -170,38 +130,38 @@ static void ExtractNumber (DWORD* value, char* getPtr)
} /* ExtractNumber */
-static BYTE* ExtractWord(WORD* value, BYTE* buffer)
+static uint8_t* ExtractWord(uint16_t* value, uint8_t* buffer)
{
- WORD x;
- x = (WORD)*buffer++;
- x = (x<<8) + (WORD)*buffer++;
+ uint16_t x;
+ x = (uint16_t)*buffer++;
+ x = (x<<8) + (uint16_t)*buffer++;
*value = x;
return buffer;
} /* ExtractWord */
-static BYTE* ExtractLong(DWORD* value, BYTE* buffer)
+static uint8_t* ExtractLong(uint32_t* value, uint8_t* buffer)
{
- DWORD x;
- x = (DWORD)*buffer++;
- x = (x<<8) + (DWORD)*buffer++;
- x = (x<<8) + (DWORD)*buffer++;
- x = (x<<8) + (DWORD)*buffer++;
+ uint32_t x;
+ x = (uint32_t)*buffer++;
+ x = (x<<8) + (uint32_t)*buffer++;
+ x = (x<<8) + (uint32_t)*buffer++;
+ x = (x<<8) + (uint32_t)*buffer++;
*value = x;
return buffer;
} /* ExtractLong */
-static BYTE* ExtractBlock(WORD count, BYTE* data, BYTE* buffer)
+static uint8_t* ExtractBlock(uint16_t count, uint8_t* data, uint8_t* buffer)
{
while (count--) *data++ = *buffer++;
return buffer;
} /* ExtractBlock */
-static char* WriteHex(char* pa, BYTE value, WORD* pCheckSum)
+static char* WriteHex(char* pa, uint8_t value, uint16_t* pCheckSum)
{
- WORD temp;
+ uint16_t temp;
static char ByteToHex[] = "0123456789ABCDEF";
@@ -214,13 +174,13 @@ static char* WriteHex(char* pa, BYTE value, WORD* pCheckSum)
}
-static char* BuildSRecord(char* pa, WORD sType, DWORD addr,
- const BYTE* data, int nCount)
+static char* BuildSRecord(char* pa, uint16_t sType, uint32_t addr,
+ const uint8_t* data, int nCount)
{
- WORD addrLen;
- WORD sRLen;
- WORD checkSum;
- WORD i;
+ uint16_t addrLen;
+ uint16_t sRLen;
+ uint16_t checkSum;
+ uint16_t i;
switch (sType) {
case 0:
@@ -244,11 +204,11 @@ static char* BuildSRecord(char* pa, WORD sType, DWORD addr,
*pa++ = (char)(sType + '0');
sRLen = addrLen + nCount + 1;
checkSum = 0;
- pa = WriteHex(pa, (BYTE)sRLen, &checkSum);
+ pa = WriteHex(pa, (uint8_t)sRLen, &checkSum);
/* Write address field */
for (i = 1; i <= addrLen; i++) {
- pa = WriteHex(pa, (BYTE)(addr >> (8 * (addrLen - i))), &checkSum);
+ pa = WriteHex(pa, (uint8_t)(addr >> (8 * (addrLen - i))), &checkSum);
} /* for */
/* Write code/data fields */
@@ -258,25 +218,25 @@ static char* BuildSRecord(char* pa, WORD sType, DWORD addr,
/* Write checksum field */
checkSum = ~checkSum;
- pa = WriteHex(pa, (BYTE)checkSum, &checkSum);
+ pa = WriteHex(pa, (uint8_t)checkSum, &checkSum);
*pa++ = '\0';
return pa;
}
-static void ConvertELF(char* fileName, DWORD loadOffset)
+static void ConvertELF(char* fileName, uint32_t loadOffset)
{
FILE* file;
int i;
int rxCount;
- BYTE rxBlock[1024];
- DWORD loadSize;
- DWORD firstAddr;
- DWORD loadAddr;
- DWORD loadDiff = 0;
+ uint8_t rxBlock[1024];
+ uint32_t loadSize;
+ uint32_t firstAddr;
+ uint32_t loadAddr;
+ uint32_t loadDiff = 0;
Elf32_Ehdr elfHeader;
Elf32_Shdr sectHeader[32];
- BYTE* getPtr;
+ uint8_t* getPtr;
char srecLine[128];
char *hdr_name;
@@ -292,11 +252,11 @@ static void ConvertELF(char* fileName, DWORD loadOffset)
getPtr = ExtractBlock(sizeof elfHeader.e_ident, elfHeader.e_ident, rxBlock);
getPtr = ExtractWord(&elfHeader.e_type, getPtr);
getPtr = ExtractWord(&elfHeader.e_machine, getPtr);
- getPtr = ExtractLong((DWORD *)&elfHeader.e_version, getPtr);
- getPtr = ExtractLong((DWORD *)&elfHeader.e_entry, getPtr);
- getPtr = ExtractLong((DWORD *)&elfHeader.e_phoff, getPtr);
- getPtr = ExtractLong((DWORD *)&elfHeader.e_shoff, getPtr);
- getPtr = ExtractLong((DWORD *)&elfHeader.e_flags, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_version, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_entry, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_phoff, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_shoff, getPtr);
+ getPtr = ExtractLong((uint32_t *)&elfHeader.e_flags, getPtr);
getPtr = ExtractWord(&elfHeader.e_ehsize, getPtr);
getPtr = ExtractWord(&elfHeader.e_phentsize, getPtr);
getPtr = ExtractWord(&elfHeader.e_phnum, getPtr);
@@ -319,16 +279,16 @@ static void ConvertELF(char* fileName, DWORD loadOffset)
fseek(file, elfHeader.e_shoff, SEEK_SET);
for (i = 0; i < elfHeader.e_shnum; i++) {
rxCount = fread(rxBlock, 1, sizeof sectHeader[0], file);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_name, rxBlock);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_type, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_flags, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_addr, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_offset, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_size, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_link, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_info, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_addralign, getPtr);
- getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_entsize, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_name, rxBlock);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_type, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_flags, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_addr, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_offset, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_size, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_link, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_info, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_addralign, getPtr);
+ getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_entsize, getPtr);
if (rxCount != sizeof sectHeader[0]) {
fclose(file);
fprintf (stderr, "*** illegal file format\n");
@@ -342,7 +302,7 @@ static void ConvertELF(char* fileName, DWORD loadOffset)
++hdr_name;
}
/* write start record */
- (void)BuildSRecord(srecLine, 0, 0, (BYTE *)hdr_name, strlen(hdr_name));
+ (void)BuildSRecord(srecLine, 0, 0, (uint8_t *)hdr_name, strlen(hdr_name));
printf("%s\r\n",srecLine);
/* write data records */
@@ -395,7 +355,7 @@ static void ConvertELF(char* fileName, DWORD loadOffset)
int main( int argc, char *argv[ ])
{
- DWORD offset;
+ uint32_t offset;
if (argc == 2) {
ConvertELF(argv[1], 0);
diff --git a/tools/imls/Makefile b/tools/imls/Makefile
index 59b928c..9b2afb0 100644
--- a/tools/imls/Makefile
+++ b/tools/imls/Makefile
@@ -19,8 +19,6 @@
include $(TOPDIR)/config.mk
-HOSTCFLAGS = -Wall -pedantic
-
# Generated executable files
BIN_FILES-y += imls
@@ -48,50 +46,43 @@ BINS := $(addprefix $(obj),$(sort $(BIN_FILES-y)))
LIBFDT_OBJS := $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y))
#
-# Use native tools and options
+# Compile for a hosted environment on the target
# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
#
-CPPFLAGS = -idirafter $(SRCTREE)/include \
+HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \
-idirafter $(OBJTREE)/include2 \
-idirafter $(OBJTREE)/include \
-I $(SRCTREE)/libfdt \
-I $(SRCTREE)/tools \
-DUSE_HOSTCC -D__KERNEL_STRICT_NAMES
-CFLAGS = $(HOSTCFLAGS) $(CPPFLAGS) -O
-
-# No -pedantic switch to avoid libfdt compilation warnings
-FIT_CFLAGS = -Wall $(CPPFLAGS) -O
-
-CC = $(CROSS_COMPILER)gcc
-STRIP = $(CROSS_COMPILER)strip
ifeq ($(MTD_VERSION),old)
-CPPFLAGS += -DMTD_OLD
+HOSTCPPFLAGS += -DMTD_OLD
endif
all: $(BINS)
$(obj)imls: $(obj)imls.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
$(obj)sha1.o $(LIBFDT_OBJS)
- $(CC) $(CFLAGS) -o $@ $^
+ $(CC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
$(STRIP) $@
# Some files complain if compiled with -pedantic, use FIT_CFLAGS
$(obj)image.o: $(SRCTREE)/common/image.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+ $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
-$(obj)imls.o: imls.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+$(obj)imls.o: $(SRCTREE)/tools/imls/imls.c
+ $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
# Some of the tool objects need to be accessed from outside the tools/imls directory
$(obj)%.o: $(SRCTREE)/common/%.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+ $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
$(obj)%.o: $(SRCTREE)/lib_generic/%.c
- $(CC) -g $(CFLAGS) -c -o $@ $<
+ $(CC) -g $(HOSTCFLAGS) -c -o $@ $<
$(obj)%.o: $(SRCTREE)/libfdt/%.c
- $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+ $(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
clean:
rm -rf *.o imls
diff --git a/tools/mingw_support.c b/tools/mingw_support.c
index 67cd6e1..6379710 100644
--- a/tools/mingw_support.c
+++ b/tools/mingw_support.c
@@ -24,7 +24,9 @@
#include "mingw_support.h"
#include <stdio.h>
#include <stdint.h>
+#include <string.h>
#include <errno.h>
+#include <assert.h>
#include <io.h>
int fsync(int fd)
@@ -77,3 +79,158 @@ int munmap(void *addr, size_t len)
return 0;
}
+
+/* Reentrant string tokenizer. Generic version.
+ Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Parse S into tokens separated by characters in DELIM.
+ If S is NULL, the saved pointer in SAVE_PTR is used as
+ the next starting point. For example:
+ char s[] = "-abc-=-def";
+ char *sp;
+ x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
+ x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
+ x = strtok_r(NULL, "=", &sp); // x = NULL
+ // s = "abc\0-def\0"
+*/
+char *strtok_r(char *s, const char *delim, char **save_ptr)
+{
+ char *token;
+
+ if (s == NULL)
+ s = *save_ptr;
+
+ /* Scan leading delimiters. */
+ s += strspn(s, delim);
+ if (*s == '\0') {
+ *save_ptr = s;
+ return NULL;
+ }
+
+ /* Find the end of the token. */
+ token = s;
+ s = strpbrk (token, delim);
+ if (s == NULL) {
+ /* This token finishes the string. */
+ *save_ptr = memchr(token, '\0', strlen(token));
+ } else {
+ /* Terminate the token and make *SAVE_PTR point past it. */
+ *s = '\0';
+ *save_ptr = s + 1;
+ }
+ return token;
+}
+
+/* getline.c -- Replacement for GNU C library function getline
+
+Copyright (C) 1993, 1996, 2001, 2002 Free Software Foundation, Inc.
+
+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 program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */
+
+/* Always add at least this many bytes when extending the buffer. */
+#define MIN_CHUNK 64
+
+/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
+ + OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
+ malloc (or NULL), pointing to *N characters of space. It is realloc'd
+ as necessary. Return the number of characters read (not including the
+ null terminator), or -1 on error or EOF.
+ NOTE: There is another getstr() function declared in <curses.h>. */
+static int getstr(char **lineptr, size_t *n, FILE *stream,
+ char terminator, size_t offset)
+{
+ int nchars_avail; /* Allocated but unused chars in *LINEPTR. */
+ char *read_pos; /* Where we're reading into *LINEPTR. */
+ int ret;
+
+ if (!lineptr || !n || !stream)
+ return -1;
+
+ if (!*lineptr) {
+ *n = MIN_CHUNK;
+ *lineptr = malloc(*n);
+ if (!*lineptr)
+ return -1;
+ }
+
+ nchars_avail = *n - offset;
+ read_pos = *lineptr + offset;
+
+ for (;;) {
+ register int c = getc(stream);
+
+ /* We always want at least one char left in the buffer, since we
+ always (unless we get an error while reading the first char)
+ NUL-terminate the line buffer. */
+
+ assert(*n - nchars_avail == read_pos - *lineptr);
+ if (nchars_avail < 2) {
+ if (*n > MIN_CHUNK)
+ *n *= 2;
+ else
+ *n += MIN_CHUNK;
+
+ nchars_avail = *n + *lineptr - read_pos;
+ *lineptr = realloc(*lineptr, *n);
+ if (!*lineptr)
+ return -1;
+ read_pos = *n - nchars_avail + *lineptr;
+ assert(*n - nchars_avail == read_pos - *lineptr);
+ }
+
+ if (c == EOF || ferror (stream)) {
+ /* Return partial line, if any. */
+ if (read_pos == *lineptr)
+ return -1;
+ else
+ break;
+ }
+
+ *read_pos++ = c;
+ nchars_avail--;
+
+ if (c == terminator)
+ /* Return the line. */
+ break;
+ }
+
+ /* Done - NUL terminate and return the number of chars read. */
+ *read_pos = '\0';
+
+ ret = read_pos - (*lineptr + offset);
+ return ret;
+}
+
+int getline (char **lineptr, size_t *n, FILE *stream)
+{
+ return getstr(lineptr, n, stream, '\n', 0);
+}
diff --git a/tools/mingw_support.h b/tools/mingw_support.h
index 9e45e64..2793674 100644
--- a/tools/mingw_support.h
+++ b/tools/mingw_support.h
@@ -44,5 +44,7 @@ typedef ULONG ulong;
int fsync(int fd);
void *mmap(void *, size_t, int, int, int, int);
int munmap(void *, size_t);
+char *strtok_r(char *s, const char *delim, char **save_ptr);
+int getline(char **lineptr, size_t *n, FILE *stream);
#endif /* __MINGW_SUPPORT_H_ */
diff --git a/tools/mkimage.c b/tools/mkimage.c
index ab6ea32..1bed933 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -229,6 +229,11 @@ main (int argc, char **argv)
case 'f':
if (--argc <= 0)
usage ();
+ /*
+ * The flattened image tree (FIT) format
+ * requires a flattened device tree image type
+ */
+ params.type = IH_TYPE_FLATDT;
params.datafile = *++argv;
params.fflag = 1;
goto NXTARG;
@@ -292,23 +297,35 @@ NXTARG: ;
params.imagefile = *argv;
- if (!params.fflag){
- if (params.lflag) {
- ifd = open (params.imagefile, O_RDONLY|O_BINARY);
- } else {
- ifd = open (params.imagefile,
- O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666);
- }
+ if (params.fflag){
+ if (tparams->fflag_handle)
+ /*
+ * in some cases, some additional processing needs
+ * to be done if fflag is defined
+ *
+ * For ex. fit_handle_file for Fit file support
+ */
+ retval = tparams->fflag_handle(&params);
- if (ifd < 0) {
- fprintf (stderr, "%s: Can't open %s: %s\n",
- params.cmdname, params.imagefile,
- strerror(errno));
- exit (EXIT_FAILURE);
- }
+ if (retval != EXIT_SUCCESS)
+ exit (retval);
+ }
+
+ if (params.lflag || params.fflag) {
+ ifd = open (params.imagefile, O_RDONLY|O_BINARY);
+ } else {
+ ifd = open (params.imagefile,
+ O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666);
+ }
+
+ if (ifd < 0) {
+ fprintf (stderr, "%s: Can't open %s: %s\n",
+ params.cmdname, params.imagefile,
+ strerror(errno));
+ exit (EXIT_FAILURE);
}
- if (params.lflag) {
+ if (params.lflag || params.fflag) {
/*
* list header information of existing image
*/
@@ -346,17 +363,6 @@ NXTARG: ;
(void) close (ifd);
exit (retval);
- } else if (params.fflag) {
- if (tparams->fflag_handle)
- /*
- * in some cases, some additional processing needs
- * to be done if fflag is defined
- *
- * For ex. fit_handle_file for Fit file support
- */
- retval = tparams->fflag_handle(&params);
-
- exit (retval);
}
/*