freemyipod r89 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r88‎ | r89 | r90 >
Date:04:37, 11 August 2010
Author:theseven
Status:new
Tags:
Comment:
Fix Nano2G flash bug and add boot-time application loader
Modified paths:
  • /embios/trunk/SOURCES (modified) (history)
  • /embios/trunk/global.h (modified) (history)
  • /embios/trunk/init.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/ls.x (modified) (history)
  • /embios/trunk/target/ipodnano2g/s5l8701.h (modified) (history)
  • /embios/trunk/target/ipodnano4g/ls.x (modified) (history)
  • /embios/trunk/ucl.S (modified) (history)

Diff [purge]

Index: embios/trunk/init.c
@@ -26,6 +26,9 @@
2727 #include "console.h"
2828 #include "power.h"
2929 #include "interrupt.h"
 30+#include "ucl.h"
 31+#include "util.h"
 32+#include "execimage.h"
3033 #ifdef HAVE_LCD
3134 #include "lcd.h"
3235 #include "lcdconsole.h"
@@ -39,14 +42,115 @@
4043 #ifdef HAVE_STORAGE
4144 #include "storage.h"
4245 #include "disk.h"
 46+#include "file.h"
4347 #endif
4448
4549
 50+struct bootinfo_t
 51+{
 52+ char signature[8];
 53+ int version;
 54+ bool trydataflash;
 55+ char dataflashpath[256];
 56+ bool dataflashflags;
 57+ bool trybootflash;
 58+ char bootimagename[8];
 59+ bool bootflashflags;
 60+ bool trymemmapped;
 61+ void* memmappedaddr;
 62+ uint32_t memmappedsize;
 63+ bool memmappedflags;
 64+};
 65+
 66+
4667 static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION " r" VERSION_SVN "\n\n";
4768 static const char initthreadname[] INITCONST_ATTR = "Initialisation thread";
48 -static uint32_t initstack[0x400] INITBSS_ATTR;
 69+static uint32_t initstack[0x400] INITSTACK_ATTR;
 70+extern int _loadspaceend;
 71+extern int _initstart;
 72+const struct bootinfo_t bootinfo_src INITCONST_ATTR =
 73+{
 74+ .signature = "emBIboot",
 75+ .version = 0,
 76+ .trydataflash = false,
 77+ .trybootflash = false,
 78+ .trymemmapped = false
 79+};
4980
5081
 82+void boot()
 83+{
 84+ struct bootinfo_t bootinfo = bootinfo_src;
 85+#ifdef HAVE_STORAGE
 86+ if (bootinfo.trydataflash)
 87+ {
 88+ int fd = file_open(bootinfo.dataflashpath, O_RDONLY);
 89+ if (fd < 0) goto dataflashfailed;
 90+ uint32_t size = filesize(fd);
 91+ if (bootinfo.dataflashflags & 1)
 92+ {
 93+ void* addr = (void*)((((uint32_t)&_loadspaceend) - size) & ~(CACHEALIGN_SIZE - 1));
 94+ if (read(fd, addr, size) != size) goto dataflashfailed;
 95+ if (ucl_decompress(addr, size, &_initstart, &size)) goto dataflashfailed;
 96+ }
 97+ else if (read(fd, &_initstart, size) != size) goto dataflashfailed;
 98+ if (execimage(&_initstart) < 0) return;
 99+ }
 100+dataflashfailed:
 101+#endif
 102+#ifdef HAVE_BOOTFLASH
 103+ if (bootinfo.trybootflash)
 104+ {
 105+ uint32_t size = bootflash_filesize(bootinfo.bootimagename);
 106+ if (size < 0) goto bootflashfailed;
 107+#ifdef BOOTFLASH_IS_MEMMAPPED
 108+ void* addr = bootflash_getaddr(bootinfo.bootimagename);
 109+ if (bootinfo.bootflashflags & 1)
 110+ {
 111+ if (ucl_decompress(addr, size, &_initstart, &size)) goto bootflashfailed;
 112+ if (execimage(&_initstart) < 0) return;
 113+ }
 114+ else if (bootinfo.bootflashflags & 2)
 115+ {
 116+ memcpy(&_initstart, addr, size);
 117+ if (execimage(&_initstart) < 0) return;
 118+ }
 119+ else execimage(addr);
 120+#else
 121+ if (bootinfo.bootflashflags & 1)
 122+ {
 123+ void* addr = (void*)((((uint32_t)&_loadspaceend) - size) & ~(CACHEALIGN_SIZE - 1));
 124+ bootflash_read(bootinfo.bootimagename, addr, 0, size);
 125+ if (ucl_decompress(addr, size, &_initstart, &size)) goto bootflashfailed;
 126+ }
 127+ else bootflash_read(bootinfo.bootimagename, &_initstart, 0, size);
 128+ if (execimage(&_initstart) < 0) return;
 129+#endif
 130+ }
 131+bootflashfailed:
 132+#endif
 133+ if (bootinfo.trymemmapped)
 134+ {
 135+ uint32_t size = bootinfo.memmappedsize;
 136+ if (bootinfo.bootflashflags & 1)
 137+ {
 138+ if (ucl_decompress(bootinfo.memmappedaddr, size, &_initstart, &size))
 139+ goto memmappedfailed;
 140+ if (execimage(&_initstart) < 0) return;
 141+ }
 142+ else if (bootinfo.bootflashflags & 2)
 143+ {
 144+ memcpy(&_initstart, bootinfo.memmappedaddr, size);
 145+ if (execimage(&_initstart) < 0) return;
 146+ }
 147+ else if (execimage(bootinfo.memmappedaddr) < 0) return;
 148+ }
 149+memmappedfailed:
 150+ if (bootinfo.trydataflash || bootinfo.trybootflash || bootinfo.trymemmapped)
 151+ cputs(CONSOLE_BOOT, "Could not find a usable boot image!\n");
 152+ cputs(CONSOLE_BOOT, "Waiting for USB commands\n\n");
 153+}
 154+
51155 void initthread() INITCODE_ATTR;
52156 void initthread()
53157 {
@@ -69,6 +173,7 @@
70174 disk_mount_all();
71175 #endif
72176 DEBUGF("Finished initialisation sequence");
 177+ boot();
73178 }
74179
75180 void init() INITCODE_ATTR;
Index: embios/trunk/SOURCES
@@ -61,6 +61,7 @@
6262 strcasecmp.c
6363 strlcpy.c
6464 strlcat.c
 65+execimage.c
6566
6667 libc/strstr.c
6768 libc/strtok.c
Index: embios/trunk/ucl.S
@@ -49,8 +49,8 @@
5050
5151 .section .icode.ucl_decompress, "ax", %progbits
5252 .align 2
53 -ucl_decompress: .globl ucl_nrv2e_decompress_8 @ ARM mode
54 - .type ucl_nrv2e_decompress_8, %function
 53+ucl_decompress: .globl ucl_decompress @ ARM mode
 54+ .type ucl_decompress, %function
5555 /* error = (*)(char const *src, int len_src, char *dst, int *plen_dst)
5656 Actual decompressed length is stored through plen_dst.
5757 */
Index: embios/trunk/target/ipodnano2g/ls.x
@@ -5,7 +5,8 @@
66
77 MEMORY
88 {
9 - INIT : ORIGIN = 0x08000000, LENGTH = 0x01f00000
 9+ INIT : ORIGIN = 0x08000000, LENGTH = 0x01eff000
 10+ INITSTACK : ORIGIN = 0x09eff000, LENGTH = 0x00001000
1011 SRAM : ORIGIN = 0x22000000, LENGTH = 0x0002bdf0
1112 SDRAM : ORIGIN = 0x09f00000, LENGTH = 0x00100000
1213 }
@@ -85,6 +86,14 @@
8687 _bssend = .;
8788 } > SDRAM
8889
 90+ .initstack (NOLOAD) :
 91+ {
 92+ _loadspaceend = .;
 93+ *(.initstack*)
 94+ *(COMMON)
 95+ . = ALIGN(0x4);
 96+ } > INITSTACK
 97+
8998 /DISCARD/ :
9099 {
91100 *(.eh_frame)
Index: embios/trunk/target/ipodnano2g/s5l8701.h
@@ -42,7 +42,7 @@
4343 #define RSTSR (*((volatile uint32_t*)(0x3C500034)))
4444 #define DSPCLKMD (*((volatile uint32_t*)(0x3C500038)))
4545 #define CLKCON2 (*((volatile uint32_t*)(0x3C50003C)))
46 -#define PWRCON(i) (*((volatile uint32_t*)(0x3C500000 + ((i) == 1 ? 0x28 : 0x40))))
 46+#define PWRCON(i) (*((volatile uint32_t*)(0x3C500000 + ((i) == 1 ? 0x40 : 0x28))))
4747
4848
4949 /////ICU/////
Index: embios/trunk/target/ipodnano4g/ls.x
@@ -5,7 +5,8 @@
66
77 MEMORY
88 {
9 - INIT : ORIGIN = 0x08000000, LENGTH = 0x01f00000
 9+ INIT : ORIGIN = 0x08000000, LENGTH = 0x01eff000
 10+ INITSTACK : ORIGIN = 0x09eff000, LENGTH = 0x00001000
1011 SRAM : ORIGIN = 0x22000000, LENGTH = 0x00030000
1112 SDRAM : ORIGIN = 0x09f00000, LENGTH = 0x00100000
1213 }
@@ -85,6 +86,14 @@
8687 _bssend = .;
8788 } > SDRAM
8889
 90+ .initstack (NOLOAD) :
 91+ {
 92+ _loadspaceend = .;
 93+ *(.initstack*)
 94+ *(COMMON)
 95+ . = ALIGN(0x4);
 96+ } > INITSTACK
 97+
8998 /DISCARD/ :
9099 {
91100 *(.eh_frame)
Index: embios/trunk/global.h
@@ -33,6 +33,7 @@
3434 #define INITCONST_ATTR __attribute__((section(".initrodata")))
3535 #define INITDATA_ATTR __attribute__((section(".initdata")))
3636 #define INITBSS_ATTR __attribute__((section(".initbss")))
 37+#define INITSTACK_ATTR __attribute__((section(".initstack")))
3738 #define STACK_ATTR __attribute__((section(".stack")))
3839
3940 #ifndef ASM_FILE