summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile5
-rwxr-xr-xtools/configure66
-rw-r--r--tools/mktccboot.c184
3 files changed, 251 insertions, 4 deletions
diff --git a/tools/Makefile b/tools/Makefile
index 347b113287..f45c5df036 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -11,7 +11,7 @@ LDFLAGS := -g
11 11
12CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \ 12CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \
13 generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat database \ 13 generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat database \
14 lngdump telechips gigabeats 14 lngdump telechips gigabeats mktccboot
15 15
16all: 16all:
17 @echo "Run make in your build directory!" 17 @echo "Run make in your build directory!"
@@ -38,6 +38,9 @@ rdf2binary: rdf2binary.c
38mkboot: mkboot.c 38mkboot: mkboot.c
39 $(SILENT)$(CC) -g $+ -o $@ 39 $(SILENT)$(CC) -g $+ -o $@
40 40
41mktccboot: mktccboot.c telechips.o
42 $(SILENT)$(CC) -g $+ -o $@
43
41lngdump: lngdump.c 44lngdump: lngdump.c
42 $(SILENT)$(CC) -g $+ -o $@ 45 $(SILENT)$(CC) -g $+ -o $@
43 46
diff --git a/tools/configure b/tools/configure
index 1cc7e6220e..3971bcb2e4 100755
--- a/tools/configure
+++ b/tools/configure
@@ -212,6 +212,13 @@ arm9tdmicc () {
212 endian="little" 212 endian="little"
213} 213}
214 214
215arm946cc () {
216 prefixtools arm-elf-
217 GCCOPTS="$CCOPTS -mcpu=arm9e -mlong-calls"
218 GCCOPTIMIZE="-fomit-frame-pointer"
219 endian="little"
220}
221
215whichadvanced () { 222whichadvanced () {
216 ################################################################## 223 ##################################################################
217 # Prompt for specific developer options 224 # Prompt for specific developer options
@@ -619,10 +626,10 @@ cat <<EOF
619 ==iAudio== ==Toshiba== ==SanDisk== 626 ==iAudio== ==Toshiba== ==SanDisk==
620 30) X5/X5V/X5L 40) Gigabeat F 50) Sansa e200 627 30) X5/X5V/X5L 40) Gigabeat F 50) Sansa e200
621 31) M5/M5L 41) Gigabeat S 51) Sansa e200R 628 31) M5/M5L 41) Gigabeat S 51) Sansa e200R
622 52) Sansa c200 629 32) 7 52) Sansa c200
623 630
624 ==Tatung== ==Olympus== 631 ==Tatung== ==Olympus== ==Logik==
625 60) Elio TPJ-1022 70) M:Robe 500 632 60) Elio TPJ-1022 70) M:Robe 500 80) DAX 1GB MP3/DAB
626EOF 633EOF
627 634
628 buildfor=`input`; 635 buildfor=`input`;
@@ -636,6 +643,7 @@ EOF
636 iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb" 643 iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb"
637 ipodbitmaptools="$toolset scramble ipod_fw bmp2rb" 644 ipodbitmaptools="$toolset scramble ipod_fw bmp2rb"
638 gigabeatbitmaptools="$toolset scramble descramble bmp2rb" 645 gigabeatbitmaptools="$toolset scramble descramble bmp2rb"
646 tccbitmaptools="$toolset scramble mktccboot bmp2rb"
639 # generic is used by IFP, H10, Sansa-e200 647 # generic is used by IFP, H10, Sansa-e200
640 genericbitmaptools="$toolset bmp2rb" 648 genericbitmaptools="$toolset bmp2rb"
641 649
@@ -1310,6 +1318,32 @@ EOF
1310 t_model="mrobe-500" 1318 t_model="mrobe-500"
1311 ;; 1319 ;;
1312 1320
1321 80|logikdax)
1322 target_id=31
1323 archos="logikdax"
1324 target="-DLOGIK_DAX"
1325 memory=2 # always
1326 arm946cc
1327 tool="$rootdir/tools/scramble -add=ldax"
1328 boottool="$rootdir/tools/scramble -tcc=crc"
1329 bootoutput="player.rom"
1330 bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
1331 bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
1332 output="rockbox.logik"
1333 appextra="recorder:gui"
1334 archosrom=""
1335 flash=""
1336 plugins="no"
1337 swcodec="yes"
1338 # toolset is the tools within the tools directory that we build for
1339 # this particular target.
1340 toolset=$tccbitmaptools
1341 # architecture, manufacturer and model for the target-tree build
1342 t_cpu="arm"
1343 t_manufacturer="tcc77x"
1344 t_model="logikdax"
1345 ;;
1346
1313 50|e200) 1347 50|e200)
1314 target_id=23 1348 target_id=23
1315 archos="e200" 1349 archos="e200"
@@ -1416,6 +1450,32 @@ EOF
1416 t_manufacturer="tatung" 1450 t_manufacturer="tatung"
1417 t_model="tpj1022" 1451 t_model="tpj1022"
1418 ;; 1452 ;;
1453
1454 32|iaudio7)
1455 target_id=32
1456 archos="iaudio7"
1457 target="-DIAUDIO_7"
1458 memory=16 # always
1459 arm946cc
1460 tool="$rootdir/tools/scramble -add i7"
1461 boottool="$rootdir/tools/scramble -tcc=crc"
1462 bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
1463 bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
1464 output="rockbox.iaudio"
1465 appextra="recorder:gui"
1466 archosrom=""
1467 flash=""
1468 plugins="yes"
1469 swcodec="yes"
1470 bootoutput="I7_FW.BIN"
1471 # toolset is the tools within the tools directory that we build for
1472 # this particular target.
1473 toolset="$tccbitmaptools"
1474 # architecture, manufacturer and model for the target-tree build
1475 t_cpu="arm"
1476 t_manufacturer="tcc77x"
1477 t_model="iaudio7"
1478 ;;
1419 1479
1420 *) 1480 *)
1421 echo "Please select a supported target platform!" 1481 echo "Please select a supported target platform!"
diff --git a/tools/mktccboot.c b/tools/mktccboot.c
new file mode 100644
index 0000000000..90b85e8335
--- /dev/null
+++ b/tools/mktccboot.c
@@ -0,0 +1,184 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Dave Chapman
11 *
12 * Based on mkboot, Copyright (C) 2005 by Linus Nielsen Feltzing
13 *
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27#include <inttypes.h>
28#include "telechips.h"
29
30/*
31
32Append a Rockbox bootloader to a Telechips original firmware file.
33
34The first instruction in a TCC firmware file is always of the form:
35
36 ldr pc, [pc, #xxx]
37
38where [pc, #xxx] is the entry point of the firmware - e.g. 0x20000020
39
40mktccboot appends the Rockbox bootloader to the end of the original
41firmware image and replaces the contents of [pc, #xxx] with the entry
42point of our bootloader - i.e. the length of the original firmware plus
430x20000000.
44
45It then stores the original entry point from [pc, #xxx] in a fixed
46offset in the Rockbox boootloader, which is used by the bootloader to
47dual-boot.
48
49Finally, mktccboot corrects the length and CRCs in the main firmware
50header, creating a new legal firmware file which can be installed on
51the device.
52
53*/
54
55/* win32 compatibility */
56
57#ifndef O_BINARY
58#define O_BINARY 0
59#endif
60
61static void put_uint32le(uint32_t x, unsigned char* p)
62{
63 p[0] = x & 0xff;
64 p[1] = (x >> 8) & 0xff;
65 p[2] = (x >> 16) & 0xff;
66 p[3] = (x >> 24) & 0xff;
67}
68
69static uint32_t get_uint32le(unsigned char* p)
70{
71 return (p[3] << 24) | (p[2] << 16) | (p[1]<<8) | p[0];
72}
73
74void usage(void)
75{
76 printf("Usage: mktccboot <firmware file> <boot file> <output file>\n");
77
78 exit(1);
79}
80
81off_t filesize(int fd) {
82 struct stat buf;
83
84 if (fstat(fd,&buf) < 0) {
85 perror("[ERR] Checking filesize of input file");
86 return -1;
87 } else {
88 return(buf.st_size);
89 }
90}
91
92
93int main(int argc, char *argv[])
94{
95 char *infile, *bootfile, *outfile;
96 int fdin, fdboot,fdout;
97 int i,n;
98 int inlength,bootlength;
99 uint32_t ldr;
100 unsigned char* image;
101 int origoffset;
102
103 if(argc < 3) {
104 usage();
105 }
106
107 infile = argv[1];
108 bootfile = argv[2];
109 outfile = argv[3];
110
111 fdin = open(infile, O_RDONLY|O_BINARY);
112 if (fdin < 0)
113 {
114 perror(infile);
115 }
116
117 fdboot = open(bootfile, O_RDONLY|O_BINARY);
118 if (fdboot < 0)
119 {
120 perror(bootfile);
121 }
122
123 inlength = filesize(fdin);
124 bootlength = filesize(fdboot);
125
126 image = malloc(inlength + bootlength);
127
128 if (image==NULL)
129 {
130 printf("[ERR] Could not allocate memory, aborting\n");
131 return 1;
132 }
133
134 n = read(fdin, image, inlength);
135 if (n != inlength)
136 {
137 printf("[ERR] Could not read from %s\n",infile);
138 return 2;
139 }
140
141 n = read(fdboot, image + inlength, bootlength);
142 if (n != bootlength)
143 {
144 printf("[ERR] Could not read from %s\n",bootfile);
145 return 3;
146 }
147
148 ldr = get_uint32le(image);
149
150 /* TODO: Verify it's a LDR instruction */
151 origoffset = (ldr&0xfff) + 8;
152
153 printf("original firmware entry point: 0x%08x\n",get_uint32le(image + origoffset));
154 printf("New entry point: 0x%08x\n",0x20000000 + inlength + 8);
155
156 /* Save the original firmware entry point at the start of the bootloader image */
157 put_uint32le(get_uint32le(image + origoffset),image+inlength);
158 put_uint32le(0x20000000 + inlength,image + inlength + 4);
159
160 /* Change the original firmware entry point to the third word in our bootloader */
161 put_uint32le(0x20000000 + inlength + 8,image+origoffset);
162
163
164 telechips_encode_crc(image, inlength + bootlength);
165
166 fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
167 if (fdout < 0)
168 {
169 perror(bootfile);
170 }
171
172 n = write(fdout, image, inlength + bootlength);
173 if (n != inlength + bootlength)
174 {
175 printf("[ERR] Could not write output file %s\n",outfile);
176 return 3;
177 }
178
179 close(fdin);
180 close(fdboot);
181 close(fdout);
182
183 return 0;
184}