summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2008-08-07 10:24:11 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2008-08-07 10:24:11 +0000
commitc8bdcbf8ff7892011a084b4b6d6f35a75248e724 (patch)
tree86e94d539e1aecf40795a3406292866dab4deda5
parent99f68ea7e8d288a7c7c31bff685168b8b4632c0d (diff)
downloadrockbox-c8bdcbf8ff7892011a084b4b6d6f35a75248e724.tar.gz
rockbox-c8bdcbf8ff7892011a084b4b6d6f35a75248e724.tar.bz2
rockbox-c8bdcbf8ff7892011a084b4b6d6f35a75248e724.zip
jz4740 utilities:
* Fix TABs problem * Add IHFSsplit made by William Poetra Yoga Hadisoeseno * Fix compilation warnings git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18206 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/jz4740_tools/HXFmerge.c24
-rw-r--r--utils/jz4740_tools/HXFreplace.c8
-rw-r--r--utils/jz4740_tools/HXFsplit.c46
-rw-r--r--utils/jz4740_tools/IHFSsplit.c195
-rw-r--r--utils/jz4740_tools/Makefile28
-rw-r--r--utils/jz4740_tools/jz4740_usbtool.c12
6 files changed, 257 insertions, 56 deletions
diff --git a/utils/jz4740_tools/HXFmerge.c b/utils/jz4740_tools/HXFmerge.c
index fb5a0bf2f3..6b6c62505e 100644
--- a/utils/jz4740_tools/HXFmerge.c
+++ b/utils/jz4740_tools/HXFmerge.c
@@ -143,12 +143,12 @@ static void merge_hxf(const char* indir, FILE* outfile, const char* add)
unsigned int filesize;
strcpy(file, dir);
strcat(file, dirs->d_name);
- if((filehandle = fopen(file, "rb")) == NULL)
+ if((filehandle = fopen(file, "rb")) == NULL)
{
- fprintf(stderr, "[ERR] Cannot open %s\n", file);
+ fprintf(stderr, "[ERR] Cannot open %s\n", file);
closedir(indir_handle);
- return;
- }
+ return;
+ }
filesize = _filesize(filehandle);
if(filesize > 0)
{
@@ -179,7 +179,7 @@ static void merge_hxf(const char* indir, FILE* outfile, const char* add)
WRITE(int2le(strlen(dirs->d_name)+strlen(add)), 4);
#endif
#ifndef _WIN32
- WRITE(replace(&add), strlen(add)-1);
+ WRITE(replace((char*)add), strlen(add)-1);
#else
WRITE(add, strlen(add)-1);
#endif
@@ -276,20 +276,20 @@ int main(int argc, char *argv[])
#ifdef _WIN32
if(strcmp((char*)(argv[1]+strlen(argv[1])-1), "\\") != 0)
{
- fprintf(stderr, "[ERR] Input path must end with a \\\n");
+ fprintf(stderr, "[ERR] Input path must end with a \\\n");
#else
if(strcmp((char*)(argv[1]+strlen(argv[1])-1), "/") != 0)
{
- fprintf(stderr, "[ERR] Input path must end with a /\n");
+ fprintf(stderr, "[ERR] Input path must end with a /\n");
#endif
- return 2;
+ return 2;
}
- if((outfile = fopen(argv[2], "wb+")) == NULL)
+ if((outfile = fopen(argv[2], "wb+")) == NULL)
{
- fprintf(stderr, "[ERR] Cannot open %s\n", argv[2]);
- return 3;
- }
+ fprintf(stderr, "[ERR] Cannot open %s\n", argv[2]);
+ return 3;
+ }
fseek(outfile, 0x40, SEEK_SET);
diff --git a/utils/jz4740_tools/HXFreplace.c b/utils/jz4740_tools/HXFreplace.c
index 154bc13071..989a59dd61 100644
--- a/utils/jz4740_tools/HXFreplace.c
+++ b/utils/jz4740_tools/HXFreplace.c
@@ -119,11 +119,11 @@ int main(int argc, char *argv[])
return 1;
}
- if((infile = fopen(argv[1], "rb")) == NULL)
+ if((infile = fopen(argv[1], "rb")) == NULL)
{
- fprintf(stderr, "[ERR] Cannot open %s\n", argv[1]);
- return 2;
- }
+ fprintf(stderr, "[ERR] Cannot open %s\n", argv[1]);
+ return 2;
+ }
if(fseek(infile, 0x40, SEEK_SET) != 0)
{
diff --git a/utils/jz4740_tools/HXFsplit.c b/utils/jz4740_tools/HXFsplit.c
index d5e578625b..6e945b067a 100644
--- a/utils/jz4740_tools/HXFsplit.c
+++ b/utils/jz4740_tools/HXFsplit.c
@@ -31,11 +31,11 @@
#define VERSION "0.2"
struct header{
- char main_header[20];
- unsigned int size;
- unsigned int checksum;
- unsigned int unknown;
- char other_header[32];
+ char main_header[20];
+ unsigned int size;
+ unsigned int checksum;
+ unsigned int unknown;
+ char other_header[32];
};
static char* basepath(char* path)
@@ -197,7 +197,7 @@ static int split_hxf(const unsigned char* infile, unsigned int size, const char*
if(!file_exists(filename))
{
printf("[INFO] %s: %d bytes\n", filename, filesize);
- if((outfile = fopen(filename, "wb")) == NULL)
+ if((outfile = fopen(filename, "wb")) == NULL)
{
fprintf(stderr, "[ERR] Error opening file %s\n", filename);
return -1;
@@ -251,20 +251,20 @@ int main(int argc, char *argv[])
#ifdef _WIN32
if(strcmp((char*)(argv[2]+strlen(argv[2])-1), "\\") != 0)
{
- fprintf(stderr, "[ERR] Output path must end with a \\\n");
+ fprintf(stderr, "[ERR] Output path must end with a \\\n");
#else
if(strcmp((char*)(argv[2]+strlen(argv[2])-1), "/") != 0)
{
- fprintf(stderr, "[ERR] Output path must end with a /\n");
+ fprintf(stderr, "[ERR] Output path must end with a /\n");
#endif
- return 2;
+ return 2;
}
- if((infile = fopen(argv[1], "rb")) == NULL)
+ if((infile = fopen(argv[1], "rb")) == NULL)
{
- fprintf(stderr, "[ERR] Cannot open %s\n", argv[1]);
- return 3;
- }
+ fprintf(stderr, "[ERR] Cannot open %s\n", argv[1]);
+ return 3;
+ }
if((inbuffer = (unsigned char*)malloc(sizeof(struct header))) == NULL)
{
@@ -273,12 +273,12 @@ int main(int argc, char *argv[])
return 4;
}
- if(fread(inbuffer, sizeof(struct header), 1, infile) != 1)
+ if(fread(inbuffer, sizeof(struct header), 1, infile) != 1)
{
fclose(infile);
- fprintf(stderr, "Cannot read header of %s\n", argv[1]);
- return 5;
- }
+ fprintf(stderr, "Cannot read header of %s\n", argv[1]);
+ return 5;
+ }
memcpy(hdr.main_header, inbuffer, 20);
hdr.size = le2int(&inbuffer[20]);
@@ -290,8 +290,8 @@ int main(int argc, char *argv[])
if(strcmp(hdr.other_header, "Chinachip PMP firmware V1.0") != 0)
{
fclose(infile);
- fprintf(stderr, "[ERR] Header doesn't match\n");
- return 6;
+ fprintf(stderr, "[ERR] Header doesn't match\n");
+ return 6;
}
if((inbuffer = (unsigned char*)malloc(hdr.size)) == NULL)
@@ -303,13 +303,13 @@ int main(int argc, char *argv[])
fseek(infile, sizeof(struct header), SEEK_SET);
- if(fread(inbuffer, hdr.size-sizeof(struct header), 1, infile) != 1)
+ if(fread(inbuffer, hdr.size-sizeof(struct header), 1, infile) != 1)
{
fclose(infile);
free(inbuffer);
- fprintf(stderr, "[ERR] Cannot read file in buffer\n");
- return 8;
- }
+ fprintf(stderr, "[ERR] Cannot read file in buffer\n");
+ return 8;
+ }
fclose(infile);
diff --git a/utils/jz4740_tools/IHFSsplit.c b/utils/jz4740_tools/IHFSsplit.c
new file mode 100644
index 0000000000..1f90a50007
--- /dev/null
+++ b/utils/jz4740_tools/IHFSsplit.c
@@ -0,0 +1,195 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2008 by William Poetra Yoga Hadisoeseno
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <libgen.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+void usage()
+{
+ fprintf(stderr, "usage: IHFSsplit <ihfs_img> <output_dir>\n");
+ exit(1);
+}
+
+typedef struct {
+ uint32_t signature;
+ uint32_t fslen;
+ uint32_t unknown1;
+ uint32_t unknown2;
+ char timestamp[12];
+ uint32_t numfiles;
+ char zeros[476];
+ uint32_t marker;
+} ihfs_header_t;
+
+#define MAX_FILES 2048
+#define MAX_IHFS_PATH 56
+
+typedef struct {
+ struct {
+ char fullpath[MAX_IHFS_PATH];
+ uint32_t sector;
+ uint32_t length;
+ } files[MAX_FILES];
+} ihfs_file_table_t;
+
+#define SECTOR_SIZE 512
+
+int ihfs_sanity(const int ihfs_img)
+{
+ struct stat statbuf;
+ ihfs_header_t ihfs_hdr;
+
+ printf("starting sanity check for IHFS image...\n");
+
+ lseek(ihfs_img, 0, SEEK_SET);
+ read(ihfs_img, &ihfs_hdr, sizeof (ihfs_hdr));
+
+ printf(" checking for IHFS signature...\n");
+ if (ihfs_hdr.signature != 0x49484653)
+ return 1;
+
+ printf(" checking for FS length...\n");
+ fstat(ihfs_img, &statbuf);
+ if (ihfs_hdr.fslen * SECTOR_SIZE != statbuf.st_size)
+ return 1;
+
+ printf(" checking for unknown value 1...\n");
+ if (ihfs_hdr.unknown1 != 0x00000004)
+ return 1;
+
+ printf(" checking for unknown value 2...\n");
+ if (ihfs_hdr.unknown2 != 0xfffff000)
+ return 1;
+
+ printf(" checking for number of files...\n");
+ if (ihfs_hdr.numfiles > MAX_FILES)
+ return 1;
+
+ printf(" checking for marker...\n");
+ if (ihfs_hdr.marker != 0x55aa55aa)
+ return 1;
+
+ return 0;
+}
+
+void mkdir_p(const char *path)
+{
+ char *dir;
+
+ dir = dirname(strdup(path));
+ if (strchr(dir, '/'))
+ mkdir_p(dir);
+
+ mkdir(dir, 0755);
+}
+
+#define BUF_SIZE 4096
+
+void outputfile(const char *outpath, const int ihfs_img, const int offset, const int length)
+{
+ int outfd;
+ int i, rem;
+ char buf[BUF_SIZE];
+
+ lseek(ihfs_img, offset, SEEK_SET);
+
+ outfd = creat(outpath, 0644);
+
+ for (i = 0; i < length / BUF_SIZE; ++i) {
+ read(ihfs_img, buf, BUF_SIZE);
+ write(outfd, buf, BUF_SIZE);
+ }
+ rem = length - i * BUF_SIZE;
+ if (rem > 0) {
+ read(ihfs_img, buf, rem);
+ write(outfd, buf, rem);
+ }
+
+ close(outfd);
+}
+
+int main(int argc, char **argv)
+{
+ struct stat statbuf;
+ int ihfs_img;
+ ihfs_header_t ihfs_hdr;
+ ihfs_file_table_t ihfs_ftbl;
+ int i, j;
+ char *outpath, *base_path, ihfs_path[MAX_IHFS_PATH+1];
+
+ /* check the arguments */
+
+ if (argc != 3)
+ usage();
+
+ stat(argv[1], &statbuf);
+ if (!S_ISREG(statbuf.st_mode))
+ usage();
+
+ stat(argv[2], &statbuf);
+ if (!S_ISDIR(statbuf.st_mode))
+ usage();
+
+ /* check the file, then split */
+
+ ihfs_img = open(argv[1], O_RDONLY);
+
+ if (ihfs_sanity(ihfs_img)) {
+ printf("Non-IHFS format!\n");
+ return 1;
+ } else
+ printf("sanity check OK\n");
+
+ lseek(ihfs_img, 0, SEEK_SET);
+ read(ihfs_img, &ihfs_hdr, sizeof (ihfs_hdr));
+ lseek(ihfs_img, 4 * SECTOR_SIZE, SEEK_SET);
+ read(ihfs_img, &ihfs_ftbl, sizeof (ihfs_ftbl));
+
+ base_path = strdup(argv[2]);
+ outpath = malloc(strlen(base_path) + 1 + MAX_IHFS_PATH + 1);
+ for (i = 0; i < ihfs_hdr.numfiles; ++i) {
+ printf("\n");
+ printf("pathname: %s\n", ihfs_ftbl.files[i].fullpath);
+ printf("starts at sector %d, length is %d bytes\n", ihfs_ftbl.files[i].sector, ihfs_ftbl.files[i].length);
+
+ strncpy(ihfs_path, ihfs_ftbl.files[i].fullpath, MAX_IHFS_PATH);
+ ihfs_path[MAX_IHFS_PATH] = '\0';
+ for (j = 0; j < strlen(ihfs_path); ++j)
+ if (ihfs_path[j] == '\\')
+ ihfs_path[j] = '/';
+
+ sprintf(outpath, "%s/%s", base_path, ihfs_path);
+ mkdir_p(outpath);
+ outputfile(outpath, ihfs_img, ihfs_ftbl.files[i].sector * SECTOR_SIZE, ihfs_ftbl.files[i].length);
+ }
+ free(outpath);
+
+ close(ihfs_img);
+
+ return 0;
+} \ No newline at end of file
diff --git a/utils/jz4740_tools/Makefile b/utils/jz4740_tools/Makefile
index 6ebf0c8fb3..7ed79eb22c 100644
--- a/utils/jz4740_tools/Makefile
+++ b/utils/jz4740_tools/Makefile
@@ -1,28 +1,34 @@
WIN_DRIVERS_LIBUSB_DIR = C:\Program Files\LibUSB-Win32
WIN_LIBUSB_INCLUDE_DIR = "$(WIN_DRIVERS_LIBUSB_DIR)\include"
-WIN_LIBUSB_LIB_DIR = "$(WIN_DRIVERS_LIBUSB_DIR)\lib\gcc"
+WIN_LIBUSB_LIB_DIR = "$(WIN_DRIVERS_LIBUSB_DIR)\lib\$(CC)"
-linux: usbtool HXFmerge HXFreplace HXFsplit
-win: usbtool_win HXFmerge_win HXFsplit_win HXFreplace_win
+CFLAGS=-Wall
+
+linux: usbtool HXFmerge HXFreplace HXFsplit IHFSsplit
+win: usbtool_win HXFmerge_win HXFsplit_win HXFreplace_win IHFSsplit_win
usbtool:
- gcc -Wall -o usbtool jz4740_usbtool.c -lusb
+ $(CC) $(CFLAGS) -o usbtool jz4740_usbtool.c -lusb
usbtool_win:
- gcc -Wall -o usbtool.exe jz4740_usbtool.c -lusb -I $(WIN_LIBUSB_INCLUDE_DIR) -L $(WIN_LIBUSB_LIB_DIR)
+ $(CC) $(CFLAGS) -o usbtool.exe jz4740_usbtool.c -lusb -I $(WIN_LIBUSB_INCLUDE_DIR) -L $(WIN_LIBUSB_LIB_DIR)
HXFmerge:
- gcc -Wall -o HXFmerge HXFmerge.c
+ $(CC) $(CFLAGS) -o HXFmerge HXFmerge.c
HXFreplace:
- gcc -Wall -o HXFreplace HXFreplace.c
+ $(CC) $(CFLAGS) -o HXFreplace HXFreplace.c
HXFsplit:
- gcc -Wall -o HXFsplit HXFsplit.c
+ $(CC) $(CFLAGS) -o HXFsplit HXFsplit.c
+IHFSsplit:
+ $(CC) $(CFLAGS) -o IHFSsplit IHFSsplit.c
HXFmerge_win:
- gcc -Wall -o HXFmerge.exe HXFmerge.c
+ $(CC) $(CFLAGS) -o HXFmerge.exe HXFmerge.c
HXFreplace_win:
- gcc -Wall -o HXFreplace.exe HXFreplace.c
+ $(CC) $(CFLAGS) -o HXFreplace.exe HXFreplace.c
HXFsplit_win:
- gcc -Wall -o HXFsplit.exe HXFsplit.c
+ $(CC) $(CFLAGS) -o HXFsplit.exe HXFsplit.c
+IHFSsplit_win:
+ $(CC) $(CFLAGS) -o IHFSsplit.exe IHFSsplit.c
clean-linux:
rm HXFmerge HXFreplace HXFsplit usbtool
diff --git a/utils/jz4740_tools/jz4740_usbtool.c b/utils/jz4740_tools/jz4740_usbtool.c
index fe8771ae12..bc26804bdd 100644
--- a/utils/jz4740_tools/jz4740_usbtool.c
+++ b/utils/jz4740_tools/jz4740_usbtool.c
@@ -127,30 +127,30 @@ int filesize(FILE* fd)
return tmp;
}
-#define SEND_COMMAND(cmd, arg) err = usb_control_msg(dh, USB_ENDPOINT_OUT | USB_TYPE_VENDOR, cmd, arg>>16, arg&0xFFFF, NULL, 0, TOUT);\
+#define SEND_COMMAND(cmd, arg) err = usb_control_msg(dh, USB_ENDPOINT_OUT | USB_TYPE_VENDOR, (cmd), (arg)>>16, (arg)&0xFFFF, NULL, 0, TOUT);\
if (err < 0) \
{ \
fprintf(stderr,"\n[ERR] Error sending control message (%d, %s)\n", err, usb_strerror()); \
return -1; \
}
-#define GET_CPU_INFO(s) err = usb_control_msg(dh, USB_ENDPOINT_IN | USB_TYPE_VENDOR, VR_GET_CPU_INFO, 0, 0, s, 8, TOUT); \
+#define GET_CPU_INFO(s) err = usb_control_msg(dh, USB_ENDPOINT_IN | USB_TYPE_VENDOR, VR_GET_CPU_INFO, 0, 0, (s), 8, TOUT); \
if (err < 0) \
{ \
fprintf(stderr,"\n[ERR] Error sending control message (%d, %s)\n", err, usb_strerror()); \
return -1; \
}
-#define SEND_DATA(ptr, size) err = usb_bulk_write(dh, USB_ENDPOINT_OUT | EP_BULK_TO, ptr, size, TOUT); \
- if (err != size) \
+#define SEND_DATA(ptr, size) err = usb_bulk_write(dh, USB_ENDPOINT_OUT | EP_BULK_TO, ((char*)(ptr)), (size), TOUT); \
+ if (err != (size)) \
{ \
fprintf(stderr,"\n[ERR] Error writing data\n"); \
fprintf(stderr,"[ERR] Bulk write error (%d, %s)\n", err, strerror(-err)); \
return -1; \
}
-#define GET_DATA(ptr, size) err = usb_bulk_read(dh, USB_ENDPOINT_IN | EP_BULK_TO, ptr, size, TOUT); \
- if (err != size) \
+#define GET_DATA(ptr, size) err = usb_bulk_read(dh, USB_ENDPOINT_IN | EP_BULK_TO, ((char*)(ptr)), (size), TOUT); \
+ if (err != (size)) \
{ \
fprintf(stderr,"\n[ERR] Error writing data\n"); \
fprintf(stderr,"[ERR] Bulk write error (%d, %s)\n", err, strerror(-err)); \