1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Greg White
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
36 #include "backlight.h"
37 #include "backlight-target.h"
43 #include "rbunicode.h"
45 #include "mmu-imx31.h"
46 #include "lcd-target.h"
47 #include "avic-imx31.h"
51 #define TAR_HEADER_SIZE 157
53 char version
[] = APPSVERSION
;
54 char basedir
[] = "/Content/0b00/00/"; /* Where files sent via MTP are stored */
55 int (*kernel_entry
)(void);
56 extern void reference_system_c(void);
58 /* Dummy stub that creates C references for C functions only used by
59 assembly - never called */
60 void reference_files(void)
65 void untar(int tar_fd
)
67 char header
[TAR_HEADER_SIZE
];
68 char copybuf
[TAR_CHUNK
];
70 int fd
, i
, size
= 0, pos
= 0;
74 read(tar_fd
, header
, TAR_HEADER_SIZE
);
76 if (*header
== '\0') /* Check for EOF */
79 /* Parse the size field */
81 for (i
= 124 ; i
< 124 + 11 ; i
++) {
82 size
= (8 * size
) + header
[i
] - '0';
85 /* Skip rest of header */
86 pos
= lseek(tar_fd
, TAR_CHUNK
- TAR_HEADER_SIZE
, SEEK_CUR
);
88 /* Make the path absolute */
92 if (header
[156] == '0') /* file */
94 int rc
, wc
, total
= 0;
99 printf("failed to create file (%d)", fd
);
101 lseek(tar_fd
, (size
+ 511) & (~511), SEEK_CUR
);
105 /* Copy the file over 512 bytes at a time */
108 rc
= read(tar_fd
, copybuf
, TAR_CHUNK
);
111 wc
= write(fd
, copybuf
, MIN(rc
, size
- total
));
114 printf("write failed (%d)", wc
);
122 else if (header
[156] == '5') /* directory */
126 /* Remove the trailing slash */
127 if (path
[strlen(path
) - 1] == '/')
128 path
[strlen(path
) - 1] = '\0';
132 if (ret
< 0 && ret
!= -4)
134 printf("failed to create dir (%d)", ret
);
146 printf("Hello world!");
147 printf("Gigabeat S Rockbox Bootloader v.00000004");
150 printf("kernel init done");
153 set_interrupt_status(IRQ_FIQ_ENABLED
, IRQ_FIQ_STATUS
);
161 printf("ata init done");
164 printf("disk init done");
166 rc
= disk_mount_all();
172 /* Look for a tar file */
173 struct dirent_uncached
* entry
;
176 dir
= opendir_uncached(basedir
);
177 while ((entry
= readdir_uncached(dir
)))
179 if (*entry
->d_name
!= '.')
181 snprintf(buf
, sizeof(buf
), "%s%s", basedir
, entry
->d_name
);
182 fd
= open(buf
, O_RDONLY
);
185 lseek(fd
, 257, SEEK_SET
);
186 rc
= read(fd
, tarstring
, 5);
190 if (strcmp(tarstring
, "ustar") == 0)
192 printf("Found tar file. Unarchiving...");
193 lseek(fd
, 0, SEEK_SET
);
196 printf("Removing tar file");
206 unsigned char *loadbuffer
= (unsigned char *)0x0;
207 int buffer_size
= 31*1024*1024;
209 rc
= load_firmware(loadbuffer
, "/.rockbox/rockbox.gigabeat", buffer_size
);
213 system_prepare_fw_start();
217 kernel_entry
= (void*) loadbuffer
;