summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2009-10-11 01:37:12 +0000
committerDave Chapman <dave@dchapman.com>2009-10-11 01:37:12 +0000
commitb04a7a86e1d903a37091486764d0dfe09372d663 (patch)
tree35c74cc921eb641858269c30c2add4e436d97ec8
parenta27f2b8683204e337b142124979592ee1cd0d6f9 (diff)
downloadrockbox-b04a7a86e1d903a37091486764d0dfe09372d663.tar.gz
rockbox-b04a7a86e1d903a37091486764d0dfe09372d663.zip
Make the Nano2G bootloader actually function as a bootloader. The resulting bootloader-ipodnano2g.ipod file needs to be encrypted on a target using the crypt_firmware plugin to create bootloader-ipodnano2g.ipodx, which can then be written to the firmware partition using the ipodpatcher patch at FS#10609. Dual-booting doesn't work yet - only Rockbox can be run.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23084 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/SOURCES7
-rw-r--r--bootloader/ipodnano2g.c137
-rw-r--r--firmware/target/arm/s5l8700/boot.lds12
-rw-r--r--firmware/target/arm/s5l8700/crt0.S21
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/ftl-target.h5
-rwxr-xr-xtools/configure3
6 files changed, 141 insertions, 44 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES
index f297f18fba..a512064ffd 100644
--- a/bootloader/SOURCES
+++ b/bootloader/SOURCES
@@ -1,6 +1,8 @@
1common.c 1common.c
2 2
3#if defined(IPOD_ARCH) 3#if defined(IPOD_NANO2G)
4ipodnano2g.c
5#elif defined(IPOD_ARCH)
4ipod.c 6ipod.c
5#elif defined(GIGABEAT_F) 7#elif defined(GIGABEAT_F)
6gigabeat.c 8gigabeat.c
@@ -55,7 +57,4 @@ show_logo.c
55#elif defined(LYRE_PROTO1) 57#elif defined(LYRE_PROTO1)
56lyre_proto1.c 58lyre_proto1.c
57show_logo.c 59show_logo.c
58#elif defined(IPOD_NANO2G)
59ipodnano2g.c
60show_logo.c
61#endif 60#endif
diff --git a/bootloader/ipodnano2g.c b/bootloader/ipodnano2g.c
index f6bfe148ac..f05829eb6d 100644
--- a/bootloader/ipodnano2g.c
+++ b/bootloader/ipodnano2g.c
@@ -45,56 +45,127 @@
45#include "file.h" 45#include "file.h"
46#include "common.h" 46#include "common.h"
47 47
48char version[] = APPSVERSION; 48/* Safety measure - maximum allowed firmware image size.
49 The largest known current (October 2009) firmware is about 6.2MB so
50 we set this to 8MB.
51*/
52#define MAX_LOADSIZE (8*1024*1024)
53
54/* The buffer to load the firmware into */
55unsigned char *loadbuffer = (unsigned char *)0x08000000;
49 56
50/* Show the Rockbox logo - in show_logo.c */ 57/* Bootloader version */
51extern int show_logo(void); 58char version[] = APPSVERSION;
52 59
53extern int line; 60extern int line;
54 61
62void fatal_error(void)
63{
64 extern int line;
65 bool holdstatus=false;
66
67 /* System font is 6 pixels wide */
68 printf("Hold MENU+SELECT to");
69 printf("reboot then SELECT+PLAY");
70 printf("for disk mode");
71 lcd_update();
72
73 while (1) {
74 if (button_hold() != holdstatus) {
75 if (button_hold()) {
76 holdstatus=true;
77 lcd_puts(0, line, "Hold switch on!");
78 } else {
79 holdstatus=false;
80 lcd_puts(0, line, " ");
81 }
82 lcd_update();
83 }
84 }
85}
86
55void main(void) 87void main(void)
56{ 88{
57 int i; 89 int i;
90 int btn;
91 int rc;
92 bool button_was_held;
93
94 /* Check the button hold status as soon as possible - to
95 give the user maximum chance to turn it on in order to
96 reset the settings in rockbox. */
97 button_was_held = button_hold();
58 98
59 system_init(); 99 system_init();
60 i2c_init();
61 kernel_init(); 100 kernel_init();
62 101
102 i2c_init();
103
63 enable_irq(); 104 enable_irq();
64 105
106 backlight_init(); /* Turns on the backlight */
107
65 lcd_init(); 108 lcd_init();
109 font_init();
110
111 lcd_set_foreground(LCD_WHITE);
112 lcd_set_background(LCD_BLACK);
113 lcd_clear_display();
114
115// button_init();
116
117 btn=0; /* TODO */
66 118
67 _backlight_init(); 119 /* Enable bootloader messages */
68 120 if (btn==BUTTON_RIGHT)
69 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---"); 121 verbose = true;
70 verbose = 0; 122
71 i = 0; 123 lcd_setfont(FONT_SYSFIXED);
72 while (!button_hold()) { 124
73 line = 1; 125 printf("Rockbox boot loader");
74 126 printf("Version: %s", version);
75 printf("i=%d",i++); 127
76 printf("TBCNT: %08x",TBCNT); 128 i = storage_init();
77 printf("GPIO 0: %08x",PDAT0); 129
78 printf("GPIO 1: %08x",PDAT1); 130 if (i != 0) {
79 printf("GPIO 2: %08x",PDAT2); 131 printf("ATA error: %d", i);
80 printf("GPIO 3: %08x",PDAT3); 132 fatal_error();
81 printf("GPIO 4: %08x",PDAT4);
82 printf("GPIO 5: %08x",PDAT5);
83 printf("GPIO 6: %08x",PDAT6);
84 printf("GPIO 7: %08x",PDAT7);
85 printf("GPIO 10: %08x",PDAT10);
86 printf("GPIO 11: %08x",PDAT11);
87 printf("GPIO 13: %08x",PDAT13);
88 printf("GPIO 14: %08x",PDAT14);
89
90 lcd_update();
91 } 133 }
92 134
93 disable_irq(); 135 disk_init();
136 rc = disk_mount_all();
137 if (rc<=0)
138 {
139 printf("No partition found");
140 fatal_error();
141 }
142
143 if (button_was_held || (btn==BUTTON_MENU)) {
144 /* If either the hold switch was on, or the Menu button was held, then
145 try the Apple firmware */
94 146
95 /* Branch back to iBugger entry point */ 147 printf("Loading original firmware...");
96 asm volatile("ldr pc, =0x08640568"); 148
149 /* TODO */
150 fatal_error();
151 } else {
152 printf("Loading Rockbox...");
153 rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE);
154
155 if (rc != EOK) {
156 printf("Error!");
157 printf("Can't load " BOOTFILE ": ");
158 printf(strerror(rc));
159 fatal_error();
160 }
161
162 printf("Rockbox loaded.");
163 }
164
165 /* If we get here, we have a new firmware image at 0x08000000, run it */
166
167 disable_irq();
97 168
98 /* We never reach here */ 169 /* Branch to start of DRAM */
99 while(1); 170 asm volatile("ldr pc, =0x08000000");
100} 171}
diff --git a/firmware/target/arm/s5l8700/boot.lds b/firmware/target/arm/s5l8700/boot.lds
index 2dea0ee4ea..637a3a29c1 100644
--- a/firmware/target/arm/s5l8700/boot.lds
+++ b/firmware/target/arm/s5l8700/boot.lds
@@ -9,14 +9,14 @@ OUTPUT_FORMAT(elf32-bigarm)
9OUTPUT_ARCH(arm) 9OUTPUT_ARCH(arm)
10STARTUP(target/arm/s5l8700/crt0.o) 10STARTUP(target/arm/s5l8700/crt0.o)
11 11
12/* DRAMORIG is in fact 0x08000000 but remapped to 0x0 */
13#define DRAMORIG 0x08000000 12#define DRAMORIG 0x08000000
14#define DRAMSIZE (MEMORYSIZE * 0x100000) 13#define DRAMSIZE (MEMORYSIZE * 0x100000)
15 14
16#define IRAMORIG 0x22000000
17#if CONFIG_CPU==S5L8701 15#if CONFIG_CPU==S5L8701
16#define IRAMORIG 0x0
18#define IRAMSIZE 176K 17#define IRAMSIZE 176K
19#else 18#else
19#define IRAMORIG 0x22000000
20#define IRAMSIZE 256K 20#define IRAMSIZE 256K
21#endif 21#endif
22 22
@@ -91,7 +91,11 @@ SECTIONS
91 _fiqstackend = .; 91 _fiqstackend = .;
92 } > IRAM 92 } > IRAM
93 93
94 .bss : { 94 /* The bss section is too large for IRAM - we just move it 12MB into the
95 DRAM */
96
97 . = DRAMORIG;
98 .bss . + (12*1024*1024): {
95 _edata = .; 99 _edata = .;
96 *(.bss*); 100 *(.bss*);
97 *(.ibss); 101 *(.ibss);
@@ -99,5 +103,5 @@ SECTIONS
99 *(COMMON); 103 *(COMMON);
100 . = ALIGN(0x4); 104 . = ALIGN(0x4);
101 _end = .; 105 _end = .;
102 } > IRAM 106 } > DRAM
103} 107}
diff --git a/firmware/target/arm/s5l8700/crt0.S b/firmware/target/arm/s5l8700/crt0.S
index 4a89f3da39..aa2923cb29 100644
--- a/firmware/target/arm/s5l8700/crt0.S
+++ b/firmware/target/arm/s5l8700/crt0.S
@@ -27,7 +27,11 @@
27 .global _newstart 27 .global _newstart
28 /* Exception vectors */ 28 /* Exception vectors */
29start: 29start:
30#if CONFIG_CPU==S5L8701 && defined(BOOTLOADER)
31 b newstart2
32#else
30 b _newstart 33 b _newstart
34#endif
31 ldr pc, =undef_instr_handler 35 ldr pc, =undef_instr_handler
32 ldr pc, =software_int_handler 36 ldr pc, =software_int_handler
33 ldr pc, =prefetch_abort_handler 37 ldr pc, =prefetch_abort_handler
@@ -88,7 +92,22 @@ newstart2:
88 orr r2, r2, #1 92 orr r2, r2, #1
89 bic r2, r2, #0x10000 93 bic r2, r2, #0x10000
90 str r2, [r1] // remap iram to address 0x0 94 str r2, [r1] // remap iram to address 0x0
91#endif 95
96#ifdef BOOTLOADER
97 /* Relocate ourself to IRAM - we have been loaded to DRAM */
98 mov r0, #0x08000000 /* source (DRAM) */
99 mov r1, #0x00000000 /* dest (IRAM) */
100 ldr r2, =_dataend
1011:
102 cmp r2, r1
103 ldrhi r3, [r0], #4
104 strhi r3, [r1], #4
105 bhi 1b
106
107 ldr pc, =start_loc /* jump to the relocated start_loc: */
108start_loc:
109#endif /* BOOTLOADER */
110#endif /* CONFIG_CPU==S5L8701 */
92 111
93 ldr r1, =0x3c500000 // CLKCON 112 ldr r1, =0x3c500000 // CLKCON
94 ldr r0, =0x00800080 113 ldr r0, =0x00800080
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/ftl-target.h b/firmware/target/arm/s5l8700/ipodnano2g/ftl-target.h
index f214964551..0c36db9799 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/ftl-target.h
+++ b/firmware/target/arm/s5l8700/ipodnano2g/ftl-target.h
@@ -25,6 +25,11 @@
25#include "config.h" 25#include "config.h"
26#include "inttypes.h" 26#include "inttypes.h"
27 27
28#ifdef BOOTLOADER
29/* Bootloaders don't need write access */
30#define FTL_READONLY
31#endif
32
28uint32_t ftl_init(void); 33uint32_t ftl_init(void);
29uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer); 34uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer);
30uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer); 35uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer);
diff --git a/tools/configure b/tools/configure
index acbfba42e0..790be27cc5 100755
--- a/tools/configure
+++ b/tools/configure
@@ -1441,8 +1441,7 @@ fi
1441 appextra="recorder:gui" 1441 appextra="recorder:gui"
1442 plugins="yes" 1442 plugins="yes"
1443 swcodec="yes" 1443 swcodec="yes"
1444 boottool="cp" 1444 bootoutput="bootloader-$modelname.ipod"
1445 bootoutput="bootloader-$modelname.bin"
1446 # toolset is the tools within the tools directory that we build for 1445 # toolset is the tools within the tools directory that we build for
1447 # this particular target. 1446 # this particular target.
1448 toolset=$ipodbitmaptools 1447 toolset=$ipodbitmaptools