summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/mktccboot/Makefile35
-rw-r--r--rbutil/mktccboot/main.c133
-rw-r--r--rbutil/mktccboot/mktccboot.c101
-rw-r--r--rbutil/mktccboot/mktccboot.h5
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro2
5 files changed, 160 insertions, 116 deletions
diff --git a/rbutil/mktccboot/Makefile b/rbutil/mktccboot/Makefile
index cd8a539648..f51c462766 100644
--- a/rbutil/mktccboot/Makefile
+++ b/rbutil/mktccboot/Makefile
@@ -45,25 +45,35 @@ OUT = $(TARGET_DIR)build$(RBARCH)
all: $(OUTPUT)
-$(OUT)/telechips.o: $(TOOLSDIR)/telechips.[ch]
+# inputs
+LIBSOURCES := mktccboot.c $(TOOLSDIR)/telechips.o
+SOURCES := $(LIBSOURCES) main.c
+OBJS := $(patsubst %.c,%.o,$(addprefix $(OUT)/,$(notdir $(SOURCES))))
+LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OUT)/,$(notdir $(LIBSOURCES))))
+EXTRADEPS :=
+
+# rule for sources from tools dir
+$(OUT)/%.o: $(TOOLSDIR)/%.c $(OUT)
@echo CC $<
- $(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/telechips.o $(TOOLSDIR)/telechips.c
+ $(SILENT)$(CC) $(CFLAGS) -c -o $@ $<
-$(OUT)/mktccboot.o: mktccboot.[ch] $(OUT)/telechips.o
+$(OUT)/%.o: %.c $(OUT)
@echo CC $<
- $(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/mktccboot.o -W -Wall mktccboot.c -DVERSION=\"$(APPVERSION)\"
-
-$(OUTPUT): $(OUT) $(OUT)/mktccboot.o
- @echo LD $@
- $(SILENT)$(CC) $(CFLAGS) -o $(OUTPUT) $(OUT)/mktccboot.o $(OUT)/telechips.o
+ $(SILENT)$(CC) $(CFLAGS) -c -o $@ $<
+# building the library archive
$(OUT)/libmktccboot.o: $(OUT)/mktccboot.o
@echo CC $<
$(SILENT)$(CC) $(CFLAGS) -DLIB -c -o $(OUT)/libmktccboot.o -W -Wall mktccboot.c
-libmktccboot$(RBARCH).a: $(OUT) $(OUT)/libmktccboot.o
+libmktccboot$(RBARCH).a: $(LIBOBJS)
@echo AR $@
- $(SILENT)$(AR) ruc $(TARGET_DIR)libmktccboot$(RBARCH).a $(OUT)/libmktccboot.o
+ $(SILENT)$(AR) ruc $(TARGET_DIR)$@ $^
+
+# building the standalone executable
+$(OUTPUT): $(OBJS) $(EXTRADEPS)
+ @echo LD $@
+ $(SILENT)$(CC) $(CFLAGS) -o$(OUTPUT) $(OBJS) $(EXTRADEPS)
# some trickery to build ppc and i386 from a single call
ifeq ($(RBARCH),)
@@ -80,9 +90,8 @@ libmktccboot-universal: libmktccbooti386.a libmktccbootppc.a
lipo -create $(TARGET_DIR)libmktccbootppc.a $(TARGET_DIR)libmktccbooti386.a -output $(TARGET_DIR)libmktccboot.a
clean:
- rm -f $(OUTPUT) libmktccboot.o $(TARGET_DIR)libmktccboot*.a mktccboot.dmg
- rm -f $(TOOLSDIR)/telechips.o
- rm -rf build* mktccboot-*
+ rm -f $(OUTPUT) $(TARGET_DIR)libmktccboot*.a mktccboot.dmg
+ rm -rf $(OUT)
mktccboot-i386:
$(MAKE) RBARCH=i386
diff --git a/rbutil/mktccboot/main.c b/rbutil/mktccboot/main.c
new file mode 100644
index 0000000000..4dd5d0c6c4
--- /dev/null
+++ b/rbutil/mktccboot/main.c
@@ -0,0 +1,133 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2007 by Dave Chapman
+ *
+ * Based on mkboot, Copyright (C) 2005 by Linus Nielsen Feltzing
+ *
+ * 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 distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include "mktccboot.h"
+#include "telechips.h"
+
+static void usage(void)
+{
+ printf("Usage: mktccboot <firmware file> <boot file> <output file>\n");
+
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ char *infile, *bootfile, *outfile;
+ int fdout = -1;
+ int n, of_size, boot_size, patched_size;
+ unsigned char *of_buf;
+ unsigned char *boot_buf = NULL;
+ unsigned char* image = NULL;
+ int ret = 0;
+
+ if(argc < 3) {
+ usage();
+ }
+
+ infile = argv[1];
+ bootfile = argv[2];
+ outfile = argv[3];
+
+ /* Read OF and boot files */
+ of_buf = file_read(infile, &of_size);
+ if (!of_buf)
+ {
+ ret = 1;
+ goto error_exit;
+ }
+
+ /* Validate input file */
+ if (test_firmware_tcc(of_buf, of_size))
+ {
+ printf("[ERR] Unknown OF file used, aborting\n");
+ ret = 2;
+ goto error_exit;
+ }
+
+ boot_buf = file_read(bootfile, &boot_size);
+ if (!boot_buf)
+ {
+ ret = 3;
+ goto error_exit;
+ }
+
+ /* Allocate buffer for patched firmware */
+ image = malloc(of_size + boot_size);
+ if (image == NULL)
+ {
+ printf("[ERR] Could not allocate memory, aborting\n");
+ ret = 4;
+ goto error_exit;
+ }
+
+ /* Create the patched firmware */
+ image = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size,
+ &patched_size);
+ if (!image)
+ {
+ printf("[ERR] Error creating patched firmware, aborting\n");
+ ret = 5;
+ goto error_exit;
+ }
+
+ fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
+ if (fdout < 0)
+ {
+ perror(outfile);
+ ret = 6;
+ goto error_exit;
+ }
+
+ n = write(fdout, image, patched_size);
+ if (n != patched_size)
+ {
+ printf("[ERR] Could not write output file %s\n",outfile);
+ ret = 7;
+ goto error_exit;
+ }
+
+error_exit:
+
+ if (fdout >= 0)
+ close(fdout);
+
+ if (of_buf)
+ free(of_buf);
+
+ if (boot_buf)
+ free(boot_buf);
+
+ if (image)
+ free(image);
+
+ return ret;
+}
+
diff --git a/rbutil/mktccboot/mktccboot.c b/rbutil/mktccboot/mktccboot.c
index 7103f23895..4f2c3258db 100644
--- a/rbutil/mktccboot/mktccboot.c
+++ b/rbutil/mktccboot/mktccboot.c
@@ -75,13 +75,6 @@ static uint32_t get_uint32le(unsigned char* p)
return (p[3] << 24) | (p[2] << 16) | (p[1]<<8) | p[0];
}
-void usage(void)
-{
- printf("Usage: mktccboot <firmware file> <boot file> <output file>\n");
-
- exit(1);
-}
-
static off_t filesize(int fd) {
struct stat buf;
@@ -181,97 +174,3 @@ int test_firmware_tcc(unsigned char* buf, int length)
return telechips_test_crc(buf, length);
}
-#ifndef LIB
-int main(int argc, char *argv[])
-{
- char *infile, *bootfile, *outfile;
- int fdout = -1;
- int n, of_size, boot_size, patched_size;
- unsigned char *of_buf;
- unsigned char *boot_buf = NULL;
- unsigned char* image = NULL;
- int ret = 0;
-
- if(argc < 3) {
- usage();
- }
-
- infile = argv[1];
- bootfile = argv[2];
- outfile = argv[3];
-
- /* Read OF and boot files */
- of_buf = file_read(infile, &of_size);
- if (!of_buf)
- {
- ret = 1;
- goto error_exit;
- }
-
- /* Validate input file */
- if (test_firmware_tcc(of_buf, of_size))
- {
- printf("[ERR] Unknown OF file used, aborting\n");
- ret = 2;
- goto error_exit;
- }
-
- boot_buf = file_read(bootfile, &boot_size);
- if (!boot_buf)
- {
- ret = 3;
- goto error_exit;
- }
-
- /* Allocate buffer for patched firmware */
- image = malloc(of_size + boot_size);
- if (image == NULL)
- {
- printf("[ERR] Could not allocate memory, aborting\n");
- ret = 4;
- goto error_exit;
- }
-
- /* Create the patched firmware */
- image = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size,
- &patched_size);
- if (!image)
- {
- printf("[ERR] Error creating patched firmware, aborting\n");
- ret = 5;
- goto error_exit;
- }
-
- fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
- if (fdout < 0)
- {
- perror(outfile);
- ret = 6;
- goto error_exit;
- }
-
- n = write(fdout, image, patched_size);
- if (n != patched_size)
- {
- printf("[ERR] Could not write output file %s\n",outfile);
- ret = 7;
- goto error_exit;
- }
-
-error_exit:
-
- if (fdout >= 0)
- close(fdout);
-
- if (of_buf)
- free(of_buf);
-
- if (boot_buf)
- free(boot_buf);
-
- if (image)
- free(image);
-
- return ret;
-}
-#endif
diff --git a/rbutil/mktccboot/mktccboot.h b/rbutil/mktccboot/mktccboot.h
index 2df2c54506..17179c11e7 100644
--- a/rbutil/mktccboot/mktccboot.h
+++ b/rbutil/mktccboot/mktccboot.h
@@ -25,6 +25,11 @@
#ifndef _MKTCCBOOT_H_
#define _MKTCCBOOT_H_
+/* win32 compatibility */
+#ifndef O_BINARY
+#define O_BINARY 0
+
+#endif
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index b04667028b..90949fcc43 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -115,7 +115,6 @@ SOURCES += rbutilqt.cpp \
base/bootloaderinstalltcc.cpp \
../../tools/mkboot.c \
../../tools/iriver.c \
- ../../tools/telechips.c \
HEADERS += rbutilqt.h \
install.h \
@@ -177,7 +176,6 @@ HEADERS += rbutilqt.h \
base/bootloaderinstalltcc.h \
../../tools/mkboot.h \
../../tools/iriver.h \
- ../../tools/telechips.h \
# Needed by QT on Win
INCLUDEPATH = $$_PRO_FILE_PWD_ $$_PRO_FILE_PWD_/irivertools $$_PRO_FILE_PWD_/zip $$_PRO_FILE_PWD_/zlib $$_PRO_FILE_PWD_/base