summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Rauh <johnbthetenth@gmail.com>2020-08-15 18:04:47 +0200
committerWilliam Wilgus <wilgus.william@gmail.com>2020-08-19 19:17:01 -0400
commitda190727e768dea9e647989b3e765f910e9d0fbc (patch)
treed7d6443c124666ac90e5baba2605a42edd10d0c1
parent8ee035b6c884142f936b03b7419d14e9102515d9 (diff)
downloadrockbox-da190727e768dea9e647989b3e765f910e9d0fbc.tar.gz
rockbox-da190727e768dea9e647989b3e765f910e9d0fbc.zip
Enable boot from SD for Sansa e200
Change-Id: I0940f2cd5fc914d6d5061b5798b1a636009649b7
-rw-r--r--bootloader/main-pp.c14
-rw-r--r--firmware/export/config/sansae200.h11
-rw-r--r--firmware/export/mi4-loader.h19
-rw-r--r--firmware/rolo.c5
-rw-r--r--firmware/target/arm/pp/crt0-pp.S9
-rw-r--r--firmware/target/arm/pp/mi4-loader.c164
6 files changed, 199 insertions, 23 deletions
diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c
index 044c3fc9c0..ef766455b6 100644
--- a/bootloader/main-pp.c
+++ b/bootloader/main-pp.c
@@ -131,7 +131,7 @@ int load_mi4_part(unsigned char* buf, struct partinfo* pinfo,
131 unsigned long sum; 131 unsigned long sum;
132 132
133 /* Read header to find out how long the mi4 file is. */ 133 /* Read header to find out how long the mi4 file is. */
134 storage_read_sectors(pinfo->start + PPMI_SECTOR_OFFSET, 134 storage_read_sectors(IF_MD(0,) pinfo->start + PPMI_SECTOR_OFFSET,
135 PPMI_SECTORS, &ppmi_header); 135 PPMI_SECTORS, &ppmi_header);
136 136
137 /* The first four characters at 0x80000 (sector 1024) should be PPMI*/ 137 /* The first four characters at 0x80000 (sector 1024) should be PPMI*/
@@ -141,7 +141,7 @@ int load_mi4_part(unsigned char* buf, struct partinfo* pinfo,
141 printf("BL mi4 size: %x", ppmi_header.length); 141 printf("BL mi4 size: %x", ppmi_header.length);
142 142
143 /* Read mi4 header of the OF */ 143 /* Read mi4 header of the OF */
144 storage_read_sectors(pinfo->start + PPMI_SECTOR_OFFSET + PPMI_SECTORS 144 storage_read_sectors(IF_MD(0,) pinfo->start + PPMI_SECTOR_OFFSET + PPMI_SECTORS
145 + (ppmi_header.length/512), MI4_HEADER_SECTORS, &mi4header); 145 + (ppmi_header.length/512), MI4_HEADER_SECTORS, &mi4header);
146 146
147 /* We don't support encrypted mi4 files yet */ 147 /* We don't support encrypted mi4 files yet */
@@ -164,7 +164,7 @@ int load_mi4_part(unsigned char* buf, struct partinfo* pinfo,
164 printf("Binary type: %.4s", mi4header.type); 164 printf("Binary type: %.4s", mi4header.type);
165 165
166 /* Load firmware */ 166 /* Load firmware */
167 storage_read_sectors(pinfo->start + PPMI_SECTOR_OFFSET + PPMI_SECTORS 167 storage_read_sectors(IF_MD(0,) pinfo->start + PPMI_SECTOR_OFFSET + PPMI_SECTORS
168 + (ppmi_header.length/512) + MI4_HEADER_SECTORS, 168 + (ppmi_header.length/512) + MI4_HEADER_SECTORS,
169 (mi4header.mi4size-MI4_HEADER_SIZE)/512, buf); 169 (mi4header.mi4size-MI4_HEADER_SIZE)/512, buf);
170 170
@@ -183,9 +183,9 @@ int load_mi4_part(unsigned char* buf, struct partinfo* pinfo,
183 183
184 printf("Disabling database rebuild"); 184 printf("Disabling database rebuild");
185 185
186 storage_read_sectors(pinfo->start + 0x3c08, 1, block); 186 storage_read_sectors(IF_MD(0,) pinfo->start + 0x3c08, 1, block);
187 block[0xe1] = 0; 187 block[0xe1] = 0;
188 storage_write_sectors(pinfo->start + 0x3c08, 1, block); 188 storage_write_sectors(IF_MD(0,) pinfo->start + 0x3c08, 1, block);
189 } 189 }
190#else 190#else
191 (void) disable_rebuild; 191 (void) disable_rebuild;
@@ -287,7 +287,6 @@ static int handle_usb(int connect_timeout)
287 287
288void* main(void) 288void* main(void)
289{ 289{
290 char filename[MAX_PATH];
291 int i; 290 int i;
292 int btn; 291 int btn;
293 int rc; 292 int rc;
@@ -400,9 +399,8 @@ void* main(void)
400 if((btn & BOOTLOADER_BOOT_OF) == 0) 399 if((btn & BOOTLOADER_BOOT_OF) == 0)
401 { 400 {
402 printf("Loading Rockbox..."); 401 printf("Loading Rockbox...");
403 snprintf(filename,sizeof(filename), BOOTDIR "/%s", BOOTFILE);
404 402
405 rc = load_mi4(loadbuffer, filename, MAX_LOADSIZE); 403 rc = load_mi4(loadbuffer, BOOTFILE, MAX_LOADSIZE);
406 if (rc <= EFILE_EMPTY) 404 if (rc <= EFILE_EMPTY)
407 { 405 {
408 bool old_verbose = verbose; 406 bool old_verbose = verbose;
diff --git a/firmware/export/config/sansae200.h b/firmware/export/config/sansae200.h
index e03784a204..59e531241f 100644
--- a/firmware/export/config/sansae200.h
+++ b/firmware/export/config/sansae200.h
@@ -8,6 +8,12 @@
8 8
9#define HW_SAMPR_CAPS (SAMPR_CAP_48 | SAMPR_CAP_44 | SAMPR_CAP_32) 9#define HW_SAMPR_CAPS (SAMPR_CAP_48 | SAMPR_CAP_44 | SAMPR_CAP_32)
10 10
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
13
14/* define boot redirect file name allows booting from external drives */
15#define BOOT_REDIR "rockbox_main.e200"
16
11/* define this if you have recording possibility */ 17/* define this if you have recording possibility */
12#define HAVE_RECORDING 18#define HAVE_RECORDING
13 19
@@ -178,11 +184,10 @@
178#define FIRMWARE_OFFSET_FILE_CRC 0x0 184#define FIRMWARE_OFFSET_FILE_CRC 0x0
179#define FIRMWARE_OFFSET_FILE_DATA 0x8 185#define FIRMWARE_OFFSET_FILE_DATA 0x8
180 186
181#ifndef BOOTLOADER
182#define HAVE_MULTIDRIVE 187#define HAVE_MULTIDRIVE
188//#define HAVE_MULTIVOLUME
183#define NUM_DRIVES 2 189#define NUM_DRIVES 2
184#define HAVE_HOTSWAP 190#define HAVE_HOTSWAP /* required to access sd from bootloader */
185#endif
186 191
187/* USB On-the-go */ 192/* USB On-the-go */
188#define CONFIG_USBOTG USBOTG_ARC 193#define CONFIG_USBOTG USBOTG_ARC
diff --git a/firmware/export/mi4-loader.h b/firmware/export/mi4-loader.h
index 1b4a4b93b2..f66164ec2c 100644
--- a/firmware/export/mi4-loader.h
+++ b/firmware/export/mi4-loader.h
@@ -49,3 +49,22 @@ struct tea_key {
49 49
50int load_mi4(unsigned char* buf, const char* firmware, unsigned int buffer_size); 50int load_mi4(unsigned char* buf, const char* firmware, unsigned int buffer_size);
51const char *mi4_strerror(int8_t errno); 51const char *mi4_strerror(int8_t errno);
52
53#ifdef HAVE_MULTIBOOT /* defined by config.h */
54/* Check in root of this <volume> for rockbox_main.<playername>
55 * if this file empty or there is a single slash '/'
56 * buf = '<volume#>/<rootdir>/<firmware(name)>\0'
57 * If instead '/<*DIRECTORY*>' is supplied
58 * addpath will be set to this DIRECTORY buf =
59 * '/<volume#>/addpath/<rootdir>/<firmware(name)>\0'
60 * On error returns Negative number or 0
61 * On success returns bytes from snprintf
62 * and generated path will be placed in buf
63 * note: if supplied buffer is too small return will be
64 * the number of bytes that would have been written
65 */
66
67/* TODO needs mapped back to debug_menu if root redirect ever becomes a reality */
68int get_redirect_dir(char* buf, int buffer_size, int volume,
69 const char* rootdir, const char* firmware);
70#endif
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 769346662b..de19c8e925 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -42,6 +42,11 @@
42#if defined(MI4_FORMAT) 42#if defined(MI4_FORMAT)
43#include "crc32-mi4.h" 43#include "crc32-mi4.h"
44#include "mi4-loader.h" 44#include "mi4-loader.h"
45#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
46#include "bootdata.h"
47#include "crc32.h"
48extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*mi4-loader.c*/
49#endif
45#define LOAD_FIRMWARE(a,b,c) load_mi4(a,b,c) 50#define LOAD_FIRMWARE(a,b,c) load_mi4(a,b,c)
46#elif defined(RKW_FORMAT) 51#elif defined(RKW_FORMAT)
47#include "rkw-loader.h" 52#include "rkw-loader.h"
diff --git a/firmware/target/arm/pp/crt0-pp.S b/firmware/target/arm/pp/crt0-pp.S
index 4e7621ecc8..3b78f57eea 100644
--- a/firmware/target/arm/pp/crt0-pp.S
+++ b/firmware/target/arm/pp/crt0-pp.S
@@ -21,6 +21,10 @@
21#include "config.h" 21#include "config.h"
22#include "cpu.h" 22#include "cpu.h"
23 23
24#if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER)
25#include "bootdata.h"
26#endif
27
24 .section .init.text,"ax",%progbits 28 .section .init.text,"ax",%progbits
25 29
26 .global start 30 .global start
@@ -402,6 +406,11 @@ prefetch_abort_handler:
402 mov r1, #1 406 mov r1, #1
403 b UIE 407 b UIE
404 408
409#if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER)
410/* boot data structure */
411put_boot_data_here
412#endif
413
405/* Align stacks to cache line boundary */ 414/* Align stacks to cache line boundary */
406 .balign 32 415 .balign 32
407 416
diff --git a/firmware/target/arm/pp/mi4-loader.c b/firmware/target/arm/pp/mi4-loader.c
index c465b898b4..31b0065888 100644
--- a/firmware/target/arm/pp/mi4-loader.c
+++ b/firmware/target/arm/pp/mi4-loader.c
@@ -7,6 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * Copyright (C) 2006 by Barry Wardell 9 * Copyright (C) 2006 by Barry Wardell
10 * Copyright (C) 2020 by William Wilgus [MULTIBOOT]
10 * 11 *
11 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing 12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
12 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach 13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
@@ -28,6 +29,97 @@
28#include "loader_strerror.h" 29#include "loader_strerror.h"
29#include "crc32-mi4.h" 30#include "crc32-mi4.h"
30#include "file.h" 31#include "file.h"
32#if defined(HAVE_BOOTDATA)
33#include "system.h"
34#include "bootdata.h"
35#include "crc32.h"
36
37/* Write bootdata into location in FIRMWARE marked by magic header
38 * Assumes buffer is already loaded with the firmware image
39 * We just need to find the location and write data into the
40 * payload region along with the crc for later verification and use.
41 * Returns payload len on success,
42 * On error returns EKEY_NOT_FOUND
43 */
44int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume)
45{
46 struct boot_data_t bl_boot_data;
47 struct boot_data_t *fw_boot_data = NULL;
48 int search_len = MIN(len, BOOT_DATA_SEARCH_SIZE) - sizeof(struct boot_data_t);
49 int payload_len = EKEY_NOT_FOUND;
50
51 /* search for boot data header prior to search_len */
52 for(int i = 0;i < search_len;i++)
53 {
54 fw_boot_data = (struct boot_data_t*) &buf[i];
55 if (fw_boot_data->magic[0] != BOOT_DATA_MAGIC0 ||
56 fw_boot_data->magic[1] != BOOT_DATA_MAGIC1)
57 continue;
58
59 memset(&bl_boot_data.payload, 0, BOOT_DATA_PAYLOAD_SIZE);
60 bl_boot_data.boot_volume = boot_volume;
61
62 memset(fw_boot_data->payload, 0, fw_boot_data->length);
63 /* determine maximum bytes we can write to firmware
64 BOOT_DATA_PAYLOAD_SIZE is the size the bootloader expects */
65 payload_len = MIN(BOOT_DATA_PAYLOAD_SIZE, fw_boot_data->length);
66 fw_boot_data->length = payload_len;
67 /* copy data to FIRMWARE bootdata struct */
68 memcpy(fw_boot_data->payload, &bl_boot_data.payload, payload_len);
69 /* crc will be used within the firmware to check validity of bootdata */
70 fw_boot_data->crc = crc_32(fw_boot_data->payload, payload_len, 0xffffffff);
71 break;
72
73 }
74 return payload_len;
75}
76#endif /* HAVE_BOOTDATA */
77
78#ifdef HAVE_MULTIBOOT /* defined by config.h */
79/* Check in root of this <volume> for rockbox_main.<playername>
80 * if this file empty or there is a single slash '/'
81 * buf = '<volume#>/<rootdir>/<firmware(name)>\0'
82 * If instead '/<*DIRECTORY*>' is supplied
83 * addpath will be set to this DIRECTORY buf =
84 * '/<volume#>/addpath/<rootdir>/<firmware(name)>\0'
85 * On error returns Negative number or 0
86 * On success returns bytes from snprintf
87 * and generated path will be placed in buf
88 * note: if supplied buffer is too small return will be
89 * the number of bytes that would have been written
90 */
91int get_redirect_dir(char* buf, int buffer_size, int volume,
92 const char* rootdir, const char* firmware)
93{
94 int fd;
95 int f_offset;
96 char add_path[MAX_PATH];
97 /* Check in root of volume for rockbox_main.<playername> redirect */
98 snprintf(add_path, sizeof(add_path), "/<%d>/"BOOT_REDIR, volume);
99 fd = open(add_path, O_RDONLY);
100 if (fd < 0)
101 return EFILE_NOT_FOUND;
102
103 /*clear add_path for re-use*/
104 memset(add_path, 0, sizeof(add_path));
105 f_offset = read(fd, add_path,sizeof(add_path));
106 close(fd);
107
108 for(int i = f_offset - 1;i > 0; i--)
109 {
110 /* strip control chars < SPACE or all if path doesn't start with '/' */
111 if (add_path[i] < 0x20 || add_path[0] != '/')
112 add_path[i] = '\0';
113 }
114 /* if '/add_path' is specified in rockbox_main.<playername>
115 path is /<vol#>/add_path/rootdir/firmwarename
116 if add_path is empty or '/' is missing from beginning
117 path is /<vol#>/rootdir/firmwarename
118 */
119 return snprintf(buf, buffer_size, "/<%d>%s/%s/%s", volume, add_path,
120 rootdir, firmware);
121}
122#endif /* HAVE_MULTIBOOT */
31 123
32static inline unsigned int le2int(unsigned char* buf) 124static inline unsigned int le2int(unsigned char* buf)
33{ 125{
@@ -169,26 +261,20 @@ static int tea_find_key(struct mi4header_t *mi4header, unsigned char* buf)
169 return key_found; 261 return key_found;
170} 262}
171 263
172/* Load mi4 format firmware image */ 264/* Load mi4 format firmware image from a FULLY QUALIFIED PATH */
173int load_mi4(unsigned char* buf, 265static int load_mi4_filename(unsigned char* buf,
174 const char* firmware, 266 const char* filename,
175 unsigned int buffer_size) 267 unsigned int buffer_size)
176{ 268{
177 int fd; 269 int fd;
178 struct mi4header_t mi4header; 270 struct mi4header_t mi4header;
179 int rc; 271 int rc;
180 unsigned long sum; 272 unsigned long sum;
181 char filename[MAX_PATH];
182 273
183 snprintf(filename,sizeof(filename), BOOTDIR "/%s",firmware);
184 fd = open(filename, O_RDONLY); 274 fd = open(filename, O_RDONLY);
275
185 if(fd < 0) 276 if(fd < 0)
186 { 277 return EFILE_NOT_FOUND;
187 snprintf(filename,sizeof(filename),"/%s",firmware);
188 fd = open(filename, O_RDONLY);
189 if(fd < 0)
190 return EFILE_NOT_FOUND;
191 }
192 278
193 read(fd, &mi4header, MI4_HEADER_SIZE); 279 read(fd, &mi4header, MI4_HEADER_SIZE);
194 280
@@ -235,3 +321,57 @@ int load_mi4(unsigned char* buf,
235 321
236 return mi4header.mi4size - MI4_HEADER_SIZE; 322 return mi4header.mi4size - MI4_HEADER_SIZE;
237} 323}
324
325/* Load mi4 format firmware image */
326int load_mi4(unsigned char* buf, const char* firmware, unsigned int buffer_size)
327{
328
329 int ret = EFILE_NOT_FOUND;
330 char filename[MAX_PATH+2];
331 /* only filename passed */
332 if (firmware[0] != '/')
333 {
334
335#ifdef HAVE_MULTIBOOT /* defined by config.h */
336 /* checks <volumes> highest index to lowest for redirect file
337 * 0 is the default boot volume, it is not checked here
338 * if found <volume>/rockbox_main.<playername> and firmware
339 * has a bootdata region this firmware will be loaded */
340 for (unsigned int i = NUM_VOLUMES - 1; i > 0 && ret < 0; i--)
341 {
342 if (get_redirect_dir(filename, sizeof(filename), i,
343 BOOTDIR, firmware) > 0)
344 {
345 ret = load_mi4_filename(buf, filename, buffer_size);
346 /* if firmware has no boot_data don't load from external drive */
347 if (write_bootdata(buf, ret, i) <= 0)
348 ret = EKEY_NOT_FOUND;
349 }
350 /* if ret is valid breaks from loop to continue loading */
351 }
352#endif
353
354 if (ret < 0) /* Check default volume, no valid firmware file loaded yet */
355 {
356 /* First check in BOOTDIR */
357 snprintf(filename, sizeof(filename), BOOTDIR "/%s",firmware);
358
359 ret = load_mi4_filename(buf, filename, buffer_size);
360
361 if (ret < 0)
362 {
363 /* Check in root dir */
364 snprintf(filename, sizeof(filename),"/%s",firmware);
365 ret = load_mi4_filename(buf, filename, buffer_size);
366 }
367#ifdef HAVE_BOOTDATA
368 /* 0 is the default boot volume */
369 write_bootdata(buf, ret, 0);
370#endif
371 }
372 }
373 else /* full path passed ROLO etc.*/
374 ret = load_mi4_filename(buf, firmware, buffer_size);
375
376 return ret;
377}