| Index: embios/trunk/init.c |
| — | — | @@ -26,6 +26,9 @@ |
| 27 | 27 | #include "console.h"
|
| 28 | 28 | #include "power.h"
|
| 29 | 29 | #include "interrupt.h"
|
| | 30 | +#include "ucl.h"
|
| | 31 | +#include "util.h"
|
| | 32 | +#include "execimage.h"
|
| 30 | 33 | #ifdef HAVE_LCD
|
| 31 | 34 | #include "lcd.h"
|
| 32 | 35 | #include "lcdconsole.h"
|
| — | — | @@ -39,14 +42,115 @@ |
| 40 | 43 | #ifdef HAVE_STORAGE
|
| 41 | 44 | #include "storage.h"
|
| 42 | 45 | #include "disk.h"
|
| | 46 | +#include "file.h"
|
| 43 | 47 | #endif
|
| 44 | 48 |
|
| 45 | 49 |
|
| | 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 | +
|
| 46 | 67 | static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION " r" VERSION_SVN "\n\n";
|
| 47 | 68 | 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 | +};
|
| 49 | 80 |
|
| 50 | 81 |
|
| | 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 | +
|
| 51 | 155 | void initthread() INITCODE_ATTR;
|
| 52 | 156 | void initthread()
|
| 53 | 157 | {
|
| — | — | @@ -69,6 +173,7 @@ |
| 70 | 174 | disk_mount_all();
|
| 71 | 175 | #endif
|
| 72 | 176 | DEBUGF("Finished initialisation sequence");
|
| | 177 | + boot();
|
| 73 | 178 | }
|
| 74 | 179 |
|
| 75 | 180 | void init() INITCODE_ATTR;
|
| Index: embios/trunk/SOURCES |
| — | — | @@ -61,6 +61,7 @@ |
| 62 | 62 | strcasecmp.c
|
| 63 | 63 | strlcpy.c
|
| 64 | 64 | strlcat.c
|
| | 65 | +execimage.c
|
| 65 | 66 |
|
| 66 | 67 | libc/strstr.c
|
| 67 | 68 | libc/strtok.c
|
| Index: embios/trunk/ucl.S |
| — | — | @@ -49,8 +49,8 @@ |
| 50 | 50 |
|
| 51 | 51 | .section .icode.ucl_decompress, "ax", %progbits
|
| 52 | 52 | .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
|
| 55 | 55 | /* error = (*)(char const *src, int len_src, char *dst, int *plen_dst)
|
| 56 | 56 | Actual decompressed length is stored through plen_dst.
|
| 57 | 57 | */
|
| Index: embios/trunk/target/ipodnano2g/ls.x |
| — | — | @@ -5,7 +5,8 @@ |
| 6 | 6 |
|
| 7 | 7 | MEMORY
|
| 8 | 8 | {
|
| 9 | | - INIT : ORIGIN = 0x08000000, LENGTH = 0x01f00000
|
| | 9 | + INIT : ORIGIN = 0x08000000, LENGTH = 0x01eff000
|
| | 10 | + INITSTACK : ORIGIN = 0x09eff000, LENGTH = 0x00001000
|
| 10 | 11 | SRAM : ORIGIN = 0x22000000, LENGTH = 0x0002bdf0
|
| 11 | 12 | SDRAM : ORIGIN = 0x09f00000, LENGTH = 0x00100000
|
| 12 | 13 | }
|
| — | — | @@ -85,6 +86,14 @@ |
| 86 | 87 | _bssend = .;
|
| 87 | 88 | } > SDRAM
|
| 88 | 89 |
|
| | 90 | + .initstack (NOLOAD) :
|
| | 91 | + {
|
| | 92 | + _loadspaceend = .;
|
| | 93 | + *(.initstack*)
|
| | 94 | + *(COMMON)
|
| | 95 | + . = ALIGN(0x4);
|
| | 96 | + } > INITSTACK
|
| | 97 | +
|
| 89 | 98 | /DISCARD/ :
|
| 90 | 99 | {
|
| 91 | 100 | *(.eh_frame)
|
| Index: embios/trunk/target/ipodnano2g/s5l8701.h |
| — | — | @@ -42,7 +42,7 @@ |
| 43 | 43 | #define RSTSR (*((volatile uint32_t*)(0x3C500034)))
|
| 44 | 44 | #define DSPCLKMD (*((volatile uint32_t*)(0x3C500038)))
|
| 45 | 45 | #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))))
|
| 47 | 47 |
|
| 48 | 48 |
|
| 49 | 49 | /////ICU/////
|
| Index: embios/trunk/target/ipodnano4g/ls.x |
| — | — | @@ -5,7 +5,8 @@ |
| 6 | 6 |
|
| 7 | 7 | MEMORY
|
| 8 | 8 | {
|
| 9 | | - INIT : ORIGIN = 0x08000000, LENGTH = 0x01f00000
|
| | 9 | + INIT : ORIGIN = 0x08000000, LENGTH = 0x01eff000
|
| | 10 | + INITSTACK : ORIGIN = 0x09eff000, LENGTH = 0x00001000
|
| 10 | 11 | SRAM : ORIGIN = 0x22000000, LENGTH = 0x00030000
|
| 11 | 12 | SDRAM : ORIGIN = 0x09f00000, LENGTH = 0x00100000
|
| 12 | 13 | }
|
| — | — | @@ -85,6 +86,14 @@ |
| 86 | 87 | _bssend = .;
|
| 87 | 88 | } > SDRAM
|
| 88 | 89 |
|
| | 90 | + .initstack (NOLOAD) :
|
| | 91 | + {
|
| | 92 | + _loadspaceend = .;
|
| | 93 | + *(.initstack*)
|
| | 94 | + *(COMMON)
|
| | 95 | + . = ALIGN(0x4);
|
| | 96 | + } > INITSTACK
|
| | 97 | +
|
| 89 | 98 | /DISCARD/ :
|
| 90 | 99 | {
|
| 91 | 100 | *(.eh_frame)
|
| Index: embios/trunk/global.h |
| — | — | @@ -33,6 +33,7 @@ |
| 34 | 34 | #define INITCONST_ATTR __attribute__((section(".initrodata")))
|
| 35 | 35 | #define INITDATA_ATTR __attribute__((section(".initdata")))
|
| 36 | 36 | #define INITBSS_ATTR __attribute__((section(".initbss")))
|
| | 37 | +#define INITSTACK_ATTR __attribute__((section(".initstack")))
|
| 37 | 38 | #define STACK_ATTR __attribute__((section(".stack")))
|
| 38 | 39 |
|
| 39 | 40 | #ifndef ASM_FILE
|