Index: tools/Makefile =================================================================== --- tools/Makefile (revision 23367) +++ tools/Makefile (working copy) @@ -13,10 +13,10 @@ CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \ generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat \ - lngdump telechips gigabeats creative hmac-sha1 mktccboot mknkboot rbspeexenc \ - mkzenboot mk500boot + lngdump telechips gigabeats creative hmac-sha1 mknkboot rbspeexenc mkzenboot \ + mk500boot -all: scramble descramble sh2d rdf2binary mkboot mktccboot mknkboot mkzenboot \ +all: scramble descramble sh2d rdf2binary mkboot mknkboot mkzenboot \ convbdf codepages uclpack rbspeexenc voicefont mk500boot scramble: scramble.o iriver.o mi4.o gigabeat.o gigabeats.o telechips.o iaudio_bl_flash.o creative.o hmac-sha1.o @@ -46,9 +46,6 @@ mkboot: mkboot.c $(SILENT)$(CC) $(CFLAGS) $+ -o $@ -mktccboot: mktccboot.c telechips.o - $(SILENT)$(CC) $(CFLAGS) $+ -o $@ - mk500boot: mk500boot.c mr500.c $(SILENT)$(CC) $(CFLAGS) $+ -o $@ Index: tools/configure =================================================================== --- tools/configure (revision 23367) +++ tools/configure (working copy) @@ -909,7 +909,7 @@ iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb" ipodbitmaptools="$toolset scramble bmp2rb" gigabeatbitmaptools="$toolset scramble descramble bmp2rb" - tccbitmaptools="$toolset scramble mktccboot bmp2rb" + tccbitmaptools="$toolset scramble bmp2rb" # generic is used by IFP, Meizu and Onda genericbitmaptools="$toolset bmp2rb" # scramble is used by all other targets Index: tools/root.make =================================================================== --- tools/root.make (revision 23367) +++ tools/root.make (working copy) @@ -20,7 +20,7 @@ TOOLS = $(TOOLSDIR)/rdf2binary $(TOOLSDIR)/convbdf \ $(TOOLSDIR)/codepages $(TOOLSDIR)/scramble $(TOOLSDIR)/bmp2rb \ - $(TOOLSDIR)/uclpack $(TOOLSDIR)/mktccboot $(TOOLSDIR)/mkboot + $(TOOLSDIR)/uclpack $(TOOLSDIR)/mkboot ifeq (,$(PREFIX)) Index: tools/mktccboot.c =================================================================== --- tools/mktccboot.c (revision 23367) +++ tools/mktccboot.c (working copy) @@ -1,206 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * 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 -#include -#include -#include -#include -#include -#include -#include -#include "telechips.h" - -/* - -Append a Rockbox bootloader to a Telechips original firmware file. - -The first instruction in a TCC firmware file is always of the form: - - ldr pc, [pc, #xxx] - -where [pc, #xxx] is the entry point of the firmware - e.g. 0x20000020 - -mktccboot appends the Rockbox bootloader to the end of the original -firmware image and replaces the contents of [pc, #xxx] with the entry -point of our bootloader - i.e. the length of the original firmware plus -0x20000000. - -It then stores the original entry point from [pc, #xxx] in a fixed -offset in the Rockbox boootloader, which is used by the bootloader to -dual-boot. - -Finally, mktccboot corrects the length and CRCs in the main firmware -header, creating a new legal firmware file which can be installed on -the device. - -*/ - -/* win32 compatibility */ - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -static void put_uint32le(uint32_t x, unsigned char* p) -{ - p[0] = x & 0xff; - p[1] = (x >> 8) & 0xff; - p[2] = (x >> 16) & 0xff; - p[3] = (x >> 24) & 0xff; -} - -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 \n"); - - exit(1); -} - -off_t filesize(int fd) { - struct stat buf; - - if (fstat(fd,&buf) < 0) { - perror("[ERR] Checking filesize of input file"); - return -1; - } else { - return(buf.st_size); - } -} - - -int main(int argc, char *argv[]) -{ - char *infile, *bootfile, *outfile; - int fdin = -1, fdboot = -1, fdout = -1; - int n; - int inlength,bootlength; - uint32_t ldr; - unsigned char* image; - int origoffset; - int ret = 0; - - if(argc < 3) { - usage(); - } - - infile = argv[1]; - bootfile = argv[2]; - outfile = argv[3]; - - fdin = open(infile, O_RDONLY|O_BINARY); - if (fdin < 0) - { - perror(infile); - ret = 1; - goto error_exit; - } - - fdboot = open(bootfile, O_RDONLY|O_BINARY); - if (fdboot < 0) - { - perror(bootfile); - ret = 2; - goto error_exit; - } - - inlength = filesize(fdin); - bootlength = filesize(fdboot); - - image = malloc(inlength + bootlength); - - if (image==NULL) - { - printf("[ERR] Could not allocate memory, aborting\n"); - ret = 3; - goto error_exit; - } - - n = read(fdin, image, inlength); - if (n != inlength) - { - printf("[ERR] Could not read from %s\n",infile); - ret = 4; - goto error_exit; - } - - n = read(fdboot, image + inlength, bootlength); - if (n != bootlength) - { - printf("[ERR] Could not read from %s\n",bootfile); - ret = 5; - goto error_exit; - } - - ldr = get_uint32le(image); - - /* TODO: Verify it's a LDR instruction */ - origoffset = (ldr&0xfff) + 8; - - printf("original firmware entry point: 0x%08x\n", - (unsigned int) get_uint32le(image + origoffset)); - printf("New entry point: 0x%08x\n",0x20000000 + inlength + 8); - - /* Save the original firmware entry point at the start of the bootloader image */ - put_uint32le(get_uint32le(image + origoffset),image+inlength); - put_uint32le(0x20000000 + inlength,image + inlength + 4); - - /* Change the original firmware entry point to the third word in our bootloader */ - put_uint32le(0x20000000 + inlength + 8,image+origoffset); - - - telechips_encode_crc(image, inlength + bootlength); - - fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); - if (fdout < 0) - { - perror(bootfile); - ret = 6; - goto error_exit; - } - - n = write(fdout, image, inlength + bootlength); - if (n != inlength + bootlength) - { - printf("[ERR] Could not write output file %s\n",outfile); - ret = 7; - goto error_exit; - } - -error_exit: - - if (fdin >= 0) - close(fdin); - - if (fdboot >= 0) - close(fdboot); - - if (fdout >= 0) - close(fdout); - - return ret; -} Index: tools/tools.make =================================================================== --- tools/tools.make (revision 23367) +++ tools/tools.make (working copy) @@ -18,7 +18,6 @@ $(TOOLSDIR)/convbdf: $(TOOLSDIR)/convbdf.c $(TOOLSDIR)/codepages: $(TOOLSDIR)/codepages.c $(TOOLSDIR)/codepage_tables.c $(TOOLSDIR)/mkboot: $(TOOLSDIR)/mkboot.c -$(TOOLSDIR)/mktccboot: $(TOOLSDIR)/mktccboot.c $(TOOLSDIR)/telechips.c $(TOOLSDIR)/wavtrim: $(TOOLSDIR)/wavtrim.c $(TOOLSDIR)/voicefont: $(TOOLSDIR)/voicefont.c Index: rbutil/ipodpatcher/ipodpatcher.c =================================================================== --- rbutil/ipodpatcher/ipodpatcher.c (revision 23367) +++ rbutil/ipodpatcher/ipodpatcher.c (working copy) @@ -96,17 +96,6 @@ return unknown; } -off_t filesize(int fd) { - struct stat buf; - - if (fstat(fd,&buf) < 0) { - perror("[ERR] Checking filesize of input file"); - return -1; - } else { - return(buf.st_size); - } -} - /* Partition table parsing code taken from Rockbox */ #define MAX_SECTOR_SIZE 2048 Index: rbutil/ipodpatcher/ipodpatcher.h =================================================================== --- rbutil/ipodpatcher/ipodpatcher.h (revision 23367) +++ rbutil/ipodpatcher/ipodpatcher.h (working copy) @@ -58,7 +58,7 @@ void ipod_get_ramsize(struct ipod_t* ipod); int read_aupd(struct ipod_t* ipod, char* filename); int write_aupd(struct ipod_t* ipod, char* filename); -off_t filesize(int fd); +extern off_t filesize(int fd); #ifdef __cplusplus } Index: rbutil/mkboot_common/mkboot_common.c =================================================================== --- rbutil/mkboot_common/mkboot_common.c (revision 0) +++ rbutil/mkboot_common/mkboot_common.c (revision 0) @@ -0,0 +1,51 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * mkboot_common.h - a common code used for merging bootloader code into + * firmware + * + * Copyright (C) 2009 Tomer Shalev + + * 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 +#include +#include "mkboot_common.h" + +off_t filesize(int fd) +{ + struct stat buf; + + if (fstat(fd, &buf) < 0) { + perror("[ERR] Checking filesize of input file"); + return -1; + } else { + return(buf.st_size); + } +} + +void put_uint32le(uint32_t x, unsigned char *p) +{ + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; + p[2] = (x >> 16) & 0xff; + p[3] = (x >> 24) & 0xff; +} + +uint32_t get_uint32le(unsigned char *p) +{ + return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); +} Index: rbutil/mkboot_common/mkboot_common.h =================================================================== --- rbutil/mkboot_common/mkboot_common.h (revision 0) +++ rbutil/mkboot_common/mkboot_common.h (revision 0) @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * mkboot_common.h - a common code used for merging bootloader code into + * firmware + * + * Copyright (C) 2009 Tomer Shalev + * + * 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. + * + ****************************************************************************/ + +#ifndef _MKBOOT_COMMON_H_ +#define _MKBOOT_COMMON_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +off_t filesize(int fd); + +void put_uint32le(uint32_t x, unsigned char *p); + +uint32_t get_uint32le(unsigned char *p); + +#ifdef __cplusplus +}; +#endif + +#endif Index: rbutil/mkboot_common/Makefile =================================================================== --- rbutil/mkboot_common/Makefile (revision 0) +++ rbutil/mkboot_common/Makefile (revision 0) @@ -0,0 +1,30 @@ +# We use the UCL code available in the Rockbox tools/ directory +CFLAGS=-Wall +CC = gcc + +#change for releases +ifndef APPVERSION +APPVERSION=`../../tools/version.sh` +endif + +ifndef V +SILENT = @ +endif + +ifdef RBARCH +CFLAGS += -arch $(RBARCH) +endif + +OUT = $(TARGET_DIR)$(RBARCH) + +$(OUT)mkboot_common.o: mkboot_common.c + @echo CC $< + $(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/mkboot_common.o -W -Wall mkboot_common.c -DVERSION=\"$(APPVERSION)\" + +clean: + rm -rf build* mkboot_common-* + +$(OUT): + @echo MKDIR $(OUT) + $(SILENT)mkdir $(OUT) + Index: rbutil/mktccboot/mktccboot.c =================================================================== --- rbutil/mktccboot/mktccboot.c (revision 0) +++ rbutil/mktccboot/mktccboot.c (revision 0) @@ -0,0 +1,246 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * Based on mkamsboot, Copyright (C) 2008 by Dave Chapman + * + * 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 +#include +#include +#include +#include +#include "telechips.h" +#include "mkboot_common.h" + +/* + +Append a Rockbox bootloader to a Telechips original firmware file. + +The first instruction in a TCC firmware file is always of the form: + + ldr pc, [pc, #xxx] + +where [pc, #xxx] is the entry point of the firmware - e.g. 0x20000020 + +mktccboot appends the Rockbox bootloader to the end of the original +firmware image and replaces the contents of [pc, #xxx] with the entry +point of our bootloader - i.e. the length of the original firmware plus +0x20000000. + +It then stores the original entry point from [pc, #xxx] in a fixed +offset in the Rockbox boootloader, which is used by the bootloader to +dual-boot. + +Finally, mktccboot corrects the length and CRCs in the main firmware +header, creating a new legal firmware file which can be installed on +the device. + +*/ + +/* win32 compatibility */ + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +void usage(void) +{ + printf("Usage: mktccboot \n"); + + exit(1); +} + +#define DRAMORIG 0x20000000 +/* Injects a bootloader into a Telechips 77X/78X firmware file */ +unsigned char *patch_firmware_tcc(unsigned char *of_buf, int of_size, + unsigned char *boot_buf, int boot_size, int *patched_size) +{ + unsigned char *patched_buf; + uint32_t ldr, old_ep_offset, new_ep_offset; + int of_offset; + + patched_buf = malloc(of_size + boot_size); + if (!patched_buf) + return NULL; + + memcpy(patched_buf, of_buf, of_size); + memcpy(patched_buf + of_size, boot_buf, boot_size); + + ldr = get_uint32le(patched_buf); + + /* TODO: Verify it's a LDR instruction */ + of_offset = (ldr & 0xfff) + 8; + old_ep_offset = get_uint32le(patched_buf + of_offset); + new_ep_offset = DRAMORIG + of_size; + + printf("OF entry point: 0x%08x\n", old_ep_offset); + printf("New entry point: 0x%08x\n", new_ep_offset + 8); + + /* Save the OF entry point at the start of the bootloader image */ + put_uint32le(old_ep_offset, patched_buf + of_size); + put_uint32le(new_ep_offset, patched_buf + of_size + 4); + + /* Change the OF entry point to the third word in our bootloader */ + put_uint32le(new_ep_offset + 8, patched_buf + of_offset); + + telechips_encode_crc(patched_buf, of_size + boot_size); + *patched_size = of_size + boot_size; + + return patched_buf; +} + +unsigned char *file_read(char *filename, int *size) +{ + unsigned char *buf = NULL; + int n, fd = -1; + + /* Open file for reading */ + fd = open(filename, O_RDONLY|O_BINARY); + if (fd < 0) + { + printf("[ERR] Could open file for reading, aborting\n"); + perror(filename); + goto error; + } + + /* Get file size, and allocate a buffer of that size */ + *size = filesize(fd); + buf = malloc(*size); + if (buf == NULL) + { + printf("[ERR] Could not allocate memory, aborting\n"); + goto error; + } + + /* Read the file's content to the buffer */ + n = read(fd, buf, *size); + if (n != *size) + { + printf("[ERR] Could not read from %s\n", filename); + goto error; + } + + return buf; + +error: + if (fd >= 0) + close(fd); + + if (buf) + free(buf); + + return NULL; +} + +#ifndef LIB +int main(int argc, char *argv[]) +{ + char *of_file, *boot_file, *patched_file; + int fd = -1; + int n, of_size, boot_size, patched_size; + unsigned char *of_buf; + unsigned char *boot_buf = NULL; + unsigned char *patched_buf = NULL; + int ret = 0; + + /* Read parameters */ + if (argc < 3) + usage(); + + of_file = argv[1]; + boot_file = argv[2]; + patched_file = argv[3]; + + /* Read OF and boot files */ + of_buf = file_read(of_file, &of_size); + if (!of_buf) + { + ret = 1; + goto error_exit; + } + +#if 0 /* TODO: Not implemented yet */ + /* A CRC test in order to reject non OF file */ + if (telechips_test_crc(of_buf, of_size)) + { + printf("[ERR] Unknown OF file used, aborting\n"); + ret = 2; + goto error_exit; + } +#endif + + boot_buf = file_read(boot_file, &boot_size); + if (!boot_buf) + { + ret = 3; + goto error_exit; + } + + /* Allocate buffer for patched firmware */ + patched_buf = malloc(of_size + boot_size); + if (patched_buf == NULL) + { + printf("[ERR] Could not allocate memory, aborting\n"); + ret = 4; + goto error_exit; + } + + /* Create the patched firmware */ + patched_buf = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size, + &patched_size); + if (!patched_buf) + { + printf("[ERR] Error creating patched firmware, aborting\n"); + ret = 5; + goto error_exit; + } + + fd = open(patched_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); + if (fd < 0) + { + perror(patched_file); + ret = 6; + goto error_exit; + } + + n = write(fd, patched_buf, patched_size); + if (n != patched_size) + { + printf("[ERR] Could not write output file %s\n", patched_file); + ret = 7; + goto error_exit; + } + +error_exit: + + if (fd >= 0) + close(fd); + + if (of_buf) + free(of_buf); + + if (boot_buf) + free(boot_buf); + + if (patched_buf) + free(patched_buf); + + return ret; +} +#endif Index: rbutil/mktccboot/mktccboot.h =================================================================== --- rbutil/mktccboot/mktccboot.h (revision 0) +++ rbutil/mktccboot/mktccboot.h (revision 0) @@ -0,0 +1,42 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * mktccboot.h - a tool to inject a bootloader into a Telechips 77X/78X firmware + * file. + * + * Copyright (C) 2009 Tomer Shalev + * + * 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. + * + ****************************************************************************/ + +#ifndef _MKTCCBOOT_H_ +#define _MKTCCBOOT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Injects a bootloader into a Telechips 77X/78X firmware file */ +unsigned char *patch_firmware_tcc(unsigned char *of_buf, int of_size, + unsigned char *boot_buf, int boot_size, int *patched_size); + +unsigned char *file_read(char *filename, int *size); + +#ifdef __cplusplus +}; +#endif + +#endif Index: rbutil/mktccboot/Makefile =================================================================== --- rbutil/mktccboot/Makefile (revision 0) +++ rbutil/mktccboot/Makefile (revision 0) @@ -0,0 +1,112 @@ +# We use the Telechips code available in the Rockbox tools/ directory +CFLAGS=-I../../tools -I../mkboot_common -Wall +PLAT=tcc + +MKBOOT_COMMON=../mkboot_common/mkboot_common +MKBOOT_COMMON_OBJ=$(MKBOOT_COMMON).o +CC = gcc +MKPLATBOOT=mk$(PLAT)boot +LIB_MKPLATBOOT=lib$(MKPLATBOOT) + +#change for releases +ifndef APPVERSION +APPVERSION=`../../tools/version.sh` +endif + +ifndef V +SILENT = @ +endif + +ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) +OUTPUT=$(MKPLATBOOT).exe +CFLAGS+=-mno-cygwin +else +ifeq ($(findstring MINGW,$(shell uname)),MINGW) +OUTPUT=$(MKPLATBOOT).exe +else +ifeq ($(findstring mingw,$(CC)),mingw) +OUTPUT=$(MKPLATBOOT).exe +else +OUTPUT=$(MKPLATBOOT) +endif +endif +endif + +ifdef RBARCH +CFLAGS += -arch $(RBARCH) +endif + +OUT = $(TARGET_DIR)build$(RBARCH) + +MKPLATBOOT_OBJ=$(OUT)/$(MKPLATBOOT).o +LIBMKPLATBOOT_OBJ=$(OUT)/$(LIB_MKPLATBOOT).o + +all: $(OUTPUT) + +# Dependant modules +TELECHIPS=../../tools/telechips +TELECHIPS_OBJ=$(TELECHIPS).o + +$(TELECHIPS_OBJ): $(TELECHIPS).[ch] + make -C ../../tools $(TARGET_DIR)telechips.o + +DEPENDANT_OBJS=$(TELECHIPS_OBJ) + +$(MKBOOT_COMMON_OBJ): $(MKBOOT_COMMON).[ch] + make -C ../mkboot_common $(TARGET_DIR)mkboot_common.o + +$(MKPLATBOOT_OBJ): $(MKPLATBOOT).[ch] $(MKBOOT_COMMON_OBJ) $(DEPENDANT_OBJS) + @echo CC $< + $(SILENT)$(CC) $(CFLAGS) -c -o $(MKPLATBOOT_OBJ) -W -Wall $(MKPLATBOOT).c -DVERSION=\"$(APPVERSION)\" + +$(OUTPUT): $(OUT) $(MKPLATBOOT_OBJ) + @echo CC $< + $(SILENT)$(CC) $(CFLAGS) -o $(OUTPUT) $(MKPLATBOOT_OBJ) $(MKBOOT_COMMON_OBJ) $(DEPENDANT_OBJS) + +$(LIBMKPLATBOOT_OBJ): $(MKPLATBOOT_OBJ) + @echo CC $< + $(SILENT)$(CC) $(CFLAGS) -DLIB -c -o $(LIBMKPLATBOOT_OBJ) -W -Wall $(MKPLATBOOT).c + +$(LIB_MKPLATBOOT)$(RBARCH).a: $(OUT) $(LIBMKPLATBOOT_OBJ) + @echo AR $@ + $(SILENT)$(AR) ruc $(TARGET_DIR)$(LIB_MKPLATBOOT)$(RBARCH).a $(LIBMKPLATBOOT_OBJ) + +# some trickery to build ppc and i386 from a single call +ifeq ($(RBARCH),) +$(LIB_MKPLATBOOT)i386.a: + make RBARCH=i386 TARGET_DIR=$(TARGET_DIR) $(LIB_MKPLATBOOT)i386.a + +$(LIB_MKPLATBOOT)ppc.a: + make RBARCH=ppc TARGET_DIR=$(TARGET_DIR) $(LIB_MKPLATBOOT)ppc.a +endif + +$(LIB_MKPLATBOOT)-universal: $(LIB_MKPLATBOOT)i386.a $(LIB_MKPLATBOOT)ppc.a + @echo lipo $(TARGET_DIR)$(LIB_MKPLATBOOT).a + $(SILENT) rm -f $(TARGET_DIR)$(LIB_MKPLATBOOT).a + lipo -create $(TARGET_DIR)$(LIB_MKPLATBOOT)ppc.a $(TARGET_DIR)$(LIB_MKPLATBOOT)i386.a -output $(TARGET_DIR)$(LIB_MKPLATBOOT).a + +clean: + rm -f $(OUTPUT) $(LIB_MKPLATBOOT).o $(TARGET_DIR)$(LIB_MKPLATBOOT)*.a $(MKPLATBOOT).dmg + rm -f $(MKBOOT_COMMON_OBJ) $(DEPENDANT_OBJS) + rm -rf build* $(MKPLATBOOT)-* + +$(MKPLATBOOT)-i386: + $(MAKE) RBARCH=i386 + mv $(MKPLATBOOT) $(MKPLATBOOT)-i386 + +$(MKPLATBOOT)-ppc: + make RBARCH=ppc + mv $(MKPLATBOOT) $(MKPLATBOOT)-ppc + +$(MKPLATBOOT)-mac: $(MKPLATBOOT)-i386 $(MKPLATBOOT)-ppc + lipo -create $(MKPLATBOOT)-ppc $(MKPLATBOOT)-i386 -output $(MKPLATBOOT)-mac + +$(MKPLATBOOT).dmg: $(MKPLATBOOT)-mac + mkdir -p $(MKPLATBOOT)-dmg + cp -p $(MKPLATBOOT)-mac $(MKPLATBOOT)-dmg + hdiutil create -srcfolder $(MKPLATBOOT)-dmg $(MKPLATBOOT).dmg + +$(OUT): + @echo MKDIR $(OUT) + $(SILENT)mkdir $(OUT) + Index: rbutil/mktccboot/README =================================================================== --- rbutil/mktccboot/README (revision 0) +++ rbutil/mktccboot/README (revision 0) @@ -0,0 +1,35 @@ +mktccboot +--------- + +A tool to inject a bootloader into a Telechips 77X/78X firmware file. + +Usage +----- + +mktccboot + + is an original Telechips firmware file. + + is the code you want to execute (a rockbox bootloader), previously + scrambled with tools/scramble utility. + + is the resulting firmware file which you'll have to copy on your + player. See "Firmware filenames". + +Dual-Boot +--------- + +The purpose of this program is to provide dual-boot between the original +firmware and the new (rockbox) firmware. + +By default the player will boot into the new firmware. + +To boot into the Original Firmware, you need to press the key. + +The player will boot into the Original Firmware as well if it is powered up by +inserting an usb cable. + +Hacking +------- + +See comments in mktccboot.c for more information. Index: rbutil/rbutilqt/rbutil.ini =================================================================== --- rbutil/rbutilqt/rbutil.ini (revision 23367) +++ rbutil/rbutilqt/rbutil.ini (working copy) @@ -58,8 +58,8 @@ platform70=smsgyh820 platform71=smsgyh920 platform72=smsgyh925 +platform73=cowond2 - [player] name="Jukebox Player 6000 / Jukebox Studio 5 / 10 / 20" buildserver_modelname=player @@ -537,6 +537,19 @@ configure_modelname=yh925 encoder=rbspeex +[cowond2] +name="D2 (Unstable)" +buildserver_modelname=cowond2 +bootloadermethod=tcc +bootloadername=/cowon/d2.bin +bootloaderfile=d2n.bin +manualname= +brand=Cowon +usbid=0x0e210800, 0x0e210860, 0x0e210870, 0x0e210880, 0x0e210890 +usberror=0x0e210801, 0x0e210861, 0x0e210871, 0x0e210881, 0x0e210891 +configure_modelname=cowond2 +encoder=rbspeex + [05ac1240] name="Apple Ipod Nano (Second Generation, DFU Mode)" Index: rbutil/rbutilqt/rbutilqt.cpp =================================================================== --- rbutil/rbutilqt/rbutilqt.cpp (revision 23367) +++ rbutil/rbutilqt/rbutilqt.cpp (working copy) @@ -47,6 +47,7 @@ #include "bootloaderinstallfile.h" #include "bootloaderinstallchinachip.h" #include "bootloaderinstallams.h" +#include "bootloaderinstalltcc.h" #if defined(Q_OS_LINUX) @@ -669,6 +670,9 @@ else if(type == "ams") { bl = new BootloaderInstallAms(this); } + else if(type == "tcc") { + bl = new BootloaderInstallTcc(this); + } else { logger->addItem(tr("No install method known."), LOGERROR); logger->setFinished(); Index: rbutil/rbutilqt/rbutilqt.pro =================================================================== --- rbutil/rbutilqt/rbutilqt.pro (revision 23367) +++ rbutil/rbutilqt/rbutilqt.pro (working copy) @@ -42,14 +42,16 @@ rbspeex.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/tools/rbspeex librbspeex.a libucl.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/tools/ucl/src libucl.a libmkamsboot.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/rbutil/mkamsboot libmkamsboot.a +libmktccboot.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/rbutil/mktccboot libmktccboot.a } mac { rbspeex.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/tools/rbspeex librbspeex-universal libucl.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/tools/ucl/src libucl-universal libmkamsboot.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/rbutil/mkamsboot libmkamsboot-universal +libmktccboot.commands = @$(MAKE) TARGET_DIR=$$MYBUILDDIR -C $$RBBASE_DIR/rbutil/mktccboot libmktccboot-universal } -QMAKE_EXTRA_TARGETS += rbspeex libucl libmkamsboot -PRE_TARGETDEPS += rbspeex libucl libmkamsboot +QMAKE_EXTRA_TARGETS += rbspeex libucl libmkamsboot libmktccboot +PRE_TARGETDEPS += rbspeex libucl libmkamsboot libmktccboot # rule for creating ctags file tags.commands = ctags -R --c++-kinds=+p --fields=+iaS --extra=+q $(SOURCES) @@ -110,8 +112,11 @@ base/bootloaderinstallfile.cpp \ base/bootloaderinstallchinachip.cpp \ base/bootloaderinstallams.cpp \ + base/bootloaderinstalltcc.cpp \ ../../tools/mkboot.c \ - ../../tools/iriver.c + ../../tools/iriver.c \ + ../../tools/telechips.c \ + ../mkboot_common/mkboot_common.c HEADERS += rbutilqt.h \ install.h \ @@ -170,8 +175,11 @@ base/bootloaderinstallfile.h \ base/bootloaderinstallchinachip.h \ base/bootloaderinstallams.h \ + base/bootloaderinstalltcc.h \ ../../tools/mkboot.h \ - ../../tools/iriver.h + ../../tools/iriver.h \ + ../../tools/telechips.h \ + ../mkboot_common/mkboot_common.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 @@ -179,7 +187,7 @@ DEPENDPATH = $$INCLUDEPATH -LIBS += -L$$OUT_PWD -L$$MYBUILDDIR -lrbspeex -lmkamsboot -lucl +LIBS += -L$$OUT_PWD -L$$MYBUILDDIR -lrbspeex -lmkamsboot -lmktccboot -lucl TEMPLATE = app dbg { Index: rbutil/rbutilqt/base/bootloaderinstalltcc.h =================================================================== --- rbutil/rbutilqt/base/bootloaderinstalltcc.h (revision 0) +++ rbutil/rbutilqt/base/bootloaderinstalltcc.h (revision 0) @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2009 by Tomer Shalev + * $Id$ + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * This file is a modified version of the AMS installer by Dominik Wenger + * + ****************************************************************************/ +#ifndef BOOTLOADERINSTALLTCC_H +#define BOOTLOADERINSTALLTCC_H + +#include +#include "bootloaderinstallbase.h" + +//! bootloader installation derivate based on mktccboot +class BootloaderInstallTcc : public BootloaderInstallBase +{ + Q_OBJECT + public: + BootloaderInstallTcc(QObject *parent); + bool install(void); + bool uninstall(void); + BootloaderInstallBase::BootloaderType installed(void); + Capabilities capabilities(void); + QString ofHint(); + + private: + + private slots: + void installStage2(void); +}; + +#endif Index: rbutil/rbutilqt/base/bootloaderinstalltcc.cpp =================================================================== --- rbutil/rbutilqt/base/bootloaderinstalltcc.cpp (revision 0) +++ rbutil/rbutilqt/base/bootloaderinstalltcc.cpp (revision 0) @@ -0,0 +1,165 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2009 by Tomer Shalev + * $Id$ + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * This file is a modified version of the AMS installer by Dominik Wenger + * + ****************************************************************************/ + +#include +#include "bootloaderinstallbase.h" +#include "bootloaderinstalltcc.h" + +#include "../../mktccboot/mktccboot.h" + +BootloaderInstallTcc::BootloaderInstallTcc(QObject *parent) + : BootloaderInstallBase(parent) +{ +} + +QString BootloaderInstallTcc::ofHint() +{ + return tr("Bootloader installation requires you to provide " + "a firmware file of the original firmware (bin file). " + "You need to download this file yourself due to legal " + "reasons." + "Press Ok to continue and browse your computer for the firmware " + "file."); +} + +bool BootloaderInstallTcc::install(void) +{ + if(m_offile.isEmpty()) + return false; + + // Download firmware from server + emit logItem(tr("Downloading bootloader file"), LOGINFO); + + connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2())); + downloadBlStart(m_blurl); + + return true; +} + +void BootloaderInstallTcc::installStage2(void) +{ + unsigned char *of_buf, *boot_buf = NULL, *patched_buf = NULL; + int n, of_size, boot_size, patched_size; + char errstr[200]; + bool ret = false; + + m_tempfile.open(); + QString bootfile = m_tempfile.fileName(); + m_tempfile.close(); + + /* Construct path for write out. + * Combine path of m_blfile with filename from OF */ + QString outfilename = QFileInfo(m_blfile).absolutePath() + "/" + + QFileInfo(m_offile).fileName(); + + /* Write out file */ + QFile out(outfilename); + + /* Load original firmware file */ + of_buf = file_read(m_offile.toLocal8Bit().data(), &of_size); + if (of_buf == NULL) + { + emit logItem(errstr, LOGERROR); + emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR); + goto exit; + } + +#if 0 /* TODO: Not implemented yet */ + /* A CRC test in order to reject non OF file */ + if (telechips_test_crc(of_buf, of_size)) + { + emit logItem(errstr, LOGERROR); + emit logItem(tr("Unknown OF file used: %1").arg(m_offile), LOGERROR); + goto exit; + } +#endif + + /* Load bootloader file */ + boot_buf = file_read(bootfile.toLocal8Bit().data(), &boot_size); + if (boot_buf == NULL) + { + emit logItem(errstr, LOGERROR); + emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR); + goto exit; + } + + /* Patch the firmware */ + emit logItem(tr("Patching Firmware..."), LOGINFO); + + patched_buf = patch_firmware_tcc(of_buf, of_size, boot_buf, boot_size, + &patched_size); + if (patched_buf == NULL) + { + emit logItem(errstr, LOGERROR); + emit logItem(tr("Could patch firmware"), LOGERROR); + goto exit; + } + + if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + emit logItem(tr("Could not open %1 for writing").arg(m_blfile), + LOGERROR); + goto exit; + } + + n = out.write((char*)patched_buf, patched_size); + out.close(); + if (n != patched_size) + { + emit logItem(tr("Could not write firmware file"), LOGERROR); + goto exit; + } + + /* End of install */ + emit logItem(tr("Success: modified firmware file created"), LOGINFO); + logInstall(LogAdd); + + ret = true; + +exit: + if (of_buf) + free(of_buf); + + if (boot_buf) + free(boot_buf); + + if (patched_buf) + free(patched_buf); + + emit done(ret); +} + +bool BootloaderInstallTcc::uninstall(void) +{ + emit logItem("To uninstall, perform a normal upgrade with an unmodified original firmware", LOGINFO); + logInstall(LogRemove); + return false; +} + +BootloaderInstallBase::BootloaderType BootloaderInstallTcc::installed(void) +{ + return BootloaderUnknown; +} + +BootloaderInstallBase::Capabilities BootloaderInstallTcc::capabilities(void) +{ + return (Install | NeedsOf); +}