forked from len0rd/rockbox
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
This commit is contained in:
parent
99f68ea7e8
commit
c8bdcbf8ff
6 changed files with 257 additions and 56 deletions
|
@ -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
|
||||
|
|
195
utils/jz4740_tools/IHFSsplit.c
Normal file
195
utils/jz4740_tools/IHFSsplit.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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)); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue