Subversion Repositories freemyipod

Rev

Rev 87 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87 Rev 89
Line 24... Line 24...
24
#include "global.h"
24
#include "global.h"
25
#include "thread.h"
25
#include "thread.h"
26
#include "console.h"
26
#include "console.h"
27
#include "power.h"
27
#include "power.h"
28
#include "interrupt.h"
28
#include "interrupt.h"
-
 
29
#include "ucl.h"
-
 
30
#include "util.h"
-
 
31
#include "execimage.h"
29
#ifdef HAVE_LCD
32
#ifdef HAVE_LCD
30
#include "lcd.h"
33
#include "lcd.h"
31
#include "lcdconsole.h"
34
#include "lcdconsole.h"
32
#endif
35
#endif
33
#ifdef HAVE_I2C
36
#ifdef HAVE_I2C
Line 37... Line 40...
37
#include "usb/usb.h"
40
#include "usb/usb.h"
38
#endif
41
#endif
39
#ifdef HAVE_STORAGE
42
#ifdef HAVE_STORAGE
40
#include "storage.h"
43
#include "storage.h"
41
#include "disk.h"
44
#include "disk.h"
-
 
45
#include "file.h"
42
#endif
46
#endif
43
 
47
 
44
 
48
 
-
 
49
struct bootinfo_t
-
 
50
{
-
 
51
    char signature[8];
-
 
52
    int version;
-
 
53
    bool trydataflash;
-
 
54
    char dataflashpath[256];
-
 
55
    bool dataflashflags;
-
 
56
    bool trybootflash;
-
 
57
    char bootimagename[8];
-
 
58
    bool bootflashflags;
-
 
59
    bool trymemmapped;
-
 
60
    void* memmappedaddr;
-
 
61
    uint32_t memmappedsize;
-
 
62
    bool memmappedflags;
-
 
63
};
-
 
64
 
-
 
65
 
45
static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION " r" VERSION_SVN "\n\n";
66
static const char welcomestring[] INITCONST_ATTR = "emBIOS v" VERSION " r" VERSION_SVN "\n\n";
46
static const char initthreadname[] INITCONST_ATTR = "Initialisation thread";
67
static const char initthreadname[] INITCONST_ATTR = "Initialisation thread";
47
static uint32_t initstack[0x400] INITBSS_ATTR;
68
static uint32_t initstack[0x400] INITSTACK_ATTR;
-
 
69
extern int _loadspaceend;
-
 
70
extern int _initstart;
-
 
71
const struct bootinfo_t bootinfo_src INITCONST_ATTR =
-
 
72
{
-
 
73
    .signature = "emBIboot",
-
 
74
    .version = 0,
-
 
75
    .trydataflash = false,
-
 
76
    .trybootflash = false,
-
 
77
    .trymemmapped = false
-
 
78
};
-
 
79
 
48
 
80
 
-
 
81
void boot()
-
 
82
{
-
 
83
    struct bootinfo_t bootinfo = bootinfo_src;
-
 
84
#ifdef HAVE_STORAGE
-
 
85
    if (bootinfo.trydataflash)
-
 
86
    {
-
 
87
        int fd = file_open(bootinfo.dataflashpath, O_RDONLY);
-
 
88
        if (fd < 0) goto dataflashfailed;
-
 
89
        uint32_t size = filesize(fd);
-
 
90
        if (bootinfo.dataflashflags & 1)
-
 
91
        {
-
 
92
            void* addr = (void*)((((uint32_t)&_loadspaceend) - size) & ~(CACHEALIGN_SIZE - 1));
-
 
93
            if (read(fd, addr, size) != size) goto dataflashfailed;
-
 
94
            if (ucl_decompress(addr, size, &_initstart, &size)) goto dataflashfailed;
-
 
95
        }
-
 
96
        else if (read(fd, &_initstart, size) != size) goto dataflashfailed;
-
 
97
        if (execimage(&_initstart) < 0) return;
-
 
98
    }
-
 
99
dataflashfailed:
-
 
100
#endif
-
 
101
#ifdef HAVE_BOOTFLASH
-
 
102
    if (bootinfo.trybootflash)
-
 
103
    {
-
 
104
        uint32_t size = bootflash_filesize(bootinfo.bootimagename);
-
 
105
        if (size < 0) goto bootflashfailed;
-
 
106
#ifdef BOOTFLASH_IS_MEMMAPPED
-
 
107
        void* addr = bootflash_getaddr(bootinfo.bootimagename);
-
 
108
        if (bootinfo.bootflashflags & 1)
-
 
109
        {
-
 
110
            if (ucl_decompress(addr, size, &_initstart, &size)) goto bootflashfailed;
-
 
111
            if (execimage(&_initstart) < 0) return;
-
 
112
        }
-
 
113
        else if (bootinfo.bootflashflags & 2)
-
 
114
        {
-
 
115
            memcpy(&_initstart, addr, size);
-
 
116
            if (execimage(&_initstart) < 0) return;
-
 
117
        }
-
 
118
        else execimage(addr);
-
 
119
#else
-
 
120
        if (bootinfo.bootflashflags & 1)
-
 
121
        {
-
 
122
            void* addr = (void*)((((uint32_t)&_loadspaceend) - size) & ~(CACHEALIGN_SIZE - 1));
-
 
123
            bootflash_read(bootinfo.bootimagename, addr, 0, size);
-
 
124
            if (ucl_decompress(addr, size, &_initstart, &size)) goto bootflashfailed;
-
 
125
        }
-
 
126
        else bootflash_read(bootinfo.bootimagename, &_initstart, 0, size);
-
 
127
        if (execimage(&_initstart) < 0) return;
-
 
128
#endif
-
 
129
    }
-
 
130
bootflashfailed:
-
 
131
#endif
-
 
132
    if (bootinfo.trymemmapped)
-
 
133
    {
-
 
134
        uint32_t size = bootinfo.memmappedsize;
-
 
135
        if (bootinfo.bootflashflags & 1)
-
 
136
        {
-
 
137
            if (ucl_decompress(bootinfo.memmappedaddr, size, &_initstart, &size))
-
 
138
                goto memmappedfailed;
-
 
139
            if (execimage(&_initstart) < 0) return;
-
 
140
        }
-
 
141
        else if (bootinfo.bootflashflags & 2)
-
 
142
        {
-
 
143
            memcpy(&_initstart, bootinfo.memmappedaddr, size);
-
 
144
            if (execimage(&_initstart) < 0) return;
-
 
145
        }
-
 
146
        else if (execimage(bootinfo.memmappedaddr) < 0) return;
-
 
147
    }
-
 
148
memmappedfailed:
-
 
149
    if (bootinfo.trydataflash || bootinfo.trybootflash || bootinfo.trymemmapped)
-
 
150
        cputs(CONSOLE_BOOT, "Could not find a usable boot image!\n");
-
 
151
    cputs(CONSOLE_BOOT, "Waiting for USB commands\n\n");
-
 
152
}
49
 
153
 
50
void initthread() INITCODE_ATTR;
154
void initthread() INITCODE_ATTR;
51
void initthread()
155
void initthread()
52
{
156
{
53
    cputs(CONSOLE_BOOT, welcomestring);
157
    cputs(CONSOLE_BOOT, welcomestring);
Line 67... Line 171...
67
    disk_init();
171
    disk_init();
68
    DEBUGF("Mounting partitions...");
172
    DEBUGF("Mounting partitions...");
69
    disk_mount_all();
173
    disk_mount_all();
70
	#endif
174
	#endif
71
    DEBUGF("Finished initialisation sequence");
175
    DEBUGF("Finished initialisation sequence");
-
 
176
    boot();
72
}
177
}
73
 
178
 
74
void init() INITCODE_ATTR;
179
void init() INITCODE_ATTR;
75
void init()
180
void init()
76
{
181
{