summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/rb-loader.c55
-rw-r--r--firmware/export/bootdata.h84
-rw-r--r--firmware/export/config/creativezen.h2
-rw-r--r--firmware/export/config/creativezenxfi2.h2
-rw-r--r--firmware/export/config/creativezenxfi3.h2
-rw-r--r--firmware/export/config/samsungypz5.h2
-rw-r--r--firmware/export/config/sansafuzeplus.h2
-rw-r--r--firmware/export/config/sonynwze360.h2
-rw-r--r--firmware/export/config/sonynwze370.h2
-rw-r--r--firmware/target/arm/imx233/crt0.S9
10 files changed, 160 insertions, 2 deletions
diff --git a/firmware/common/rb-loader.c b/firmware/common/rb-loader.c
index 10807f9c96..82b636d451 100644
--- a/firmware/common/rb-loader.c
+++ b/firmware/common/rb-loader.c
@@ -25,6 +25,54 @@
25#include "rb-loader.h" 25#include "rb-loader.h"
26#include "loader_strerror.h" 26#include "loader_strerror.h"
27 27
28#if defined(HAVE_BOOTDATA)
29#include "bootdata.h"
30#include "crc32.h"
31
32/* Write boot data into location marked by magic header
33 * buffer is already loaded with the firmware image
34 * we just need to find the location and write
35 * data into the payload along with the crc
36 * for later verification and use.
37 * Returns payload len on success,
38 * On error returns EKEY_NOT_FOUND
39 */
40static int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume)
41{
42 struct boot_data_t bl_boot_data;
43 struct boot_data_t *fw_boot_data = NULL;
44 int search_len = MIN(len, BOOT_DATA_SEARCH_SIZE) - sizeof(struct boot_data_t);
45 int payload_len = EKEY_NOT_FOUND;
46
47 /* search for boot data header prior to search_len */
48 for(int i = 0;i < search_len;i++)
49 {
50 fw_boot_data = (struct boot_data_t*) &buf[i];
51 if (fw_boot_data->magic[0] != BOOT_DATA_MAGIC0 ||
52 fw_boot_data->magic[1] != BOOT_DATA_MAGIC1)
53 continue;
54 /* 0 fill bootloader struct then add our data */
55 memset(&bl_boot_data.payload, 0, BOOT_DATA_PAYLOAD_SIZE);
56 bl_boot_data.boot_volume = boot_volume;
57 /* 0 fill payload region in firmware */
58 memset(fw_boot_data->payload, 0, fw_boot_data->length);
59 /* determine maximum bytes we can write to firmware
60 BOOT_DATA_PAYLOAD_SIZE is the size the bootloader expects */
61 payload_len = MIN(BOOT_DATA_PAYLOAD_SIZE, fw_boot_data->length);
62 /* write payload size back to firmware struct */
63 fw_boot_data->length = payload_len;
64 /* copy data to firmware bootdata struct */
65 memcpy(fw_boot_data->payload, &bl_boot_data.payload, payload_len);
66 /* calculate and write the crc for the payload */
67 fw_boot_data->crc = crc_32(fw_boot_data->payload,
68 payload_len,
69 0xffffffff);
70 break;
71
72 }
73 return payload_len;
74}
75#endif /* HAVE_BOOTDATA */
28/* Load firmware image in a format created by add method of tools/scramble 76/* Load firmware image in a format created by add method of tools/scramble
29 * on success we return size loaded image 77 * on success we return size loaded image
30 * on error we return negative value which can be deciphered by means 78 * on error we return negative value which can be deciphered by means
@@ -105,11 +153,14 @@ int load_firmware(unsigned char* buf, const char* firmware, int buffer_size)
105 ret = EBAD_CHKSUM; 153 ret = EBAD_CHKSUM;
106 goto end; 154 goto end;
107 } 155 }
108 156#ifdef HAVE_BOOTDATA
157 /* 0 is the default boot volume */
158 write_bootdata(buf, ret, 0);
159#endif
109 ret = len; 160 ret = len;
110 161
162
111end: 163end:
112 close(fd); 164 close(fd);
113 return ret; 165 return ret;
114} 166}
115
diff --git a/firmware/export/bootdata.h b/firmware/export/bootdata.h
new file mode 100644
index 0000000000..322d50c20d
--- /dev/null
+++ b/firmware/export/bootdata.h
@@ -0,0 +1,84 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 by Amaury Pouly
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#ifndef __RB_BOOTDATA__
21#define __RB_BOOTDATA__
22
23#ifndef __ASSEMBLER__
24#include <stdint.h>
25#endif
26
27/* /!\ This file can be included in assembly files /!\ */
28
29/** The boot data will be filled by the bootloader with information that might
30 * be relevant for Rockbox. The bootloader will search for the structure using
31 * the magic header within the first BOOT_DATA_SEARCH_SIZE bytes of the binary.
32 * Typically, this structure should be as close as possible to the entry point */
33
34/* Search size for the data structure after entry point */
35#define BOOT_DATA_SEARCH_SIZE 1024
36
37#define BOOT_DATA_MAGIC0 ('r' | 'b' << 8 | 'm' << 16 | 'a' << 24)
38#define BOOT_DATA_MAGIC1 ('g' | 'i' << 8 | 'c' << 16 | '!' << 24)
39
40/* maximum size of payload */
41#define BOOT_DATA_PAYLOAD_SIZE 4
42
43#ifndef __ASSEMBLER__
44/* This is the C structure */
45struct boot_data_t
46{
47 union
48 {
49 uint32_t crc; /* crc of payload data (CRC32 with 0xffffffff for initial value) */
50 uint32_t magic[2]; /* BOOT_DATA_MAGIC0/1 */
51 };
52
53 uint32_t length; /* length of the payload */
54
55 /* add fields here */
56 union
57 {
58 struct
59 {
60 uint8_t boot_volume;
61 };
62 uint8_t payload[BOOT_DATA_PAYLOAD_SIZE];
63 };
64} __attribute__((packed));
65
66#if !defined(BOOTLOADER)
67extern struct boot_data_t boot_data;
68#endif
69#else /* __ASSEMBLER__ */
70
71/* This assembler macro implements an empty boot structure with just the magic
72 * string */
73.macro put_boot_data_here
74.global boot_data
75boot_data:
76 .word BOOT_DATA_MAGIC0
77 .word BOOT_DATA_MAGIC1
78 .word BOOT_DATA_PAYLOAD_SIZE
79 .space BOOT_DATA_PAYLOAD_SIZE, 0xff /* payload, initialised with value 0xff */
80.endm
81
82#endif
83
84#endif /* __RB_BOOTDATA__ */
diff --git a/firmware/export/config/creativezen.h b/firmware/export/config/creativezen.h
index 3667142791..0033b7d4eb 100644
--- a/firmware/export/config/creativezen.h
+++ b/firmware/export/config/creativezen.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 90 9#define MODEL_NUMBER 90
10#define MODEL_NAME "Creative Zen" 10#define MODEL_NAME "Creative Zen"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/export/config/creativezenxfi2.h b/firmware/export/config/creativezenxfi2.h
index 5b275b1de8..3945311e29 100644
--- a/firmware/export/config/creativezenxfi2.h
+++ b/firmware/export/config/creativezenxfi2.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 82 9#define MODEL_NUMBER 82
10#define MODEL_NAME "Creative Zen X-Fi2" 10#define MODEL_NAME "Creative Zen X-Fi2"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/export/config/creativezenxfi3.h b/firmware/export/config/creativezenxfi3.h
index 0503035914..d72b41d608 100644
--- a/firmware/export/config/creativezenxfi3.h
+++ b/firmware/export/config/creativezenxfi3.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 83 9#define MODEL_NUMBER 83
10#define MODEL_NAME "Creative Zen X-Fi3" 10#define MODEL_NAME "Creative Zen X-Fi3"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/export/config/samsungypz5.h b/firmware/export/config/samsungypz5.h
index 08b607741c..882acc2a6c 100644
--- a/firmware/export/config/samsungypz5.h
+++ b/firmware/export/config/samsungypz5.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 84 9#define MODEL_NUMBER 84
10#define MODEL_NAME "Samsung YP-Z5" 10#define MODEL_NAME "Samsung YP-Z5"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/export/config/sansafuzeplus.h b/firmware/export/config/sansafuzeplus.h
index 03d6c00b2e..af5235a6c3 100644
--- a/firmware/export/config/sansafuzeplus.h
+++ b/firmware/export/config/sansafuzeplus.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 72 9#define MODEL_NUMBER 72
10#define MODEL_NAME "Sandisk Sansa Fuze+" 10#define MODEL_NAME "Sandisk Sansa Fuze+"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/export/config/sonynwze360.h b/firmware/export/config/sonynwze360.h
index dc466ec797..a25e95d274 100644
--- a/firmware/export/config/sonynwze360.h
+++ b/firmware/export/config/sonynwze360.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 89 9#define MODEL_NUMBER 89
10#define MODEL_NAME "Sony NWZ-E360 series" 10#define MODEL_NAME "Sony NWZ-E360 series"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/export/config/sonynwze370.h b/firmware/export/config/sonynwze370.h
index 0f88d98b58..2ed87f2f1b 100644
--- a/firmware/export/config/sonynwze370.h
+++ b/firmware/export/config/sonynwze370.h
@@ -8,6 +8,8 @@
8/* For Rolo and boot loader */ 8/* For Rolo and boot loader */
9#define MODEL_NUMBER 88 9#define MODEL_NUMBER 88
10#define MODEL_NAME "Sony NWZ-E370/E380 series" 10#define MODEL_NAME "Sony NWZ-E370/E380 series"
11/* Define if boot data from bootloader has been enabled for the target */
12#define HAVE_BOOTDATA
11 13
12#define HW_SAMPR_CAPS SAMPR_CAP_ALL 14#define HW_SAMPR_CAPS SAMPR_CAP_ALL
13 15
diff --git a/firmware/target/arm/imx233/crt0.S b/firmware/target/arm/imx233/crt0.S
index 5e1720c7c9..8db8400dbf 100644
--- a/firmware/target/arm/imx233/crt0.S
+++ b/firmware/target/arm/imx233/crt0.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 .vectors,"ax",%progbits 28.section .vectors,"ax",%progbits
25.code 32 29.code 32
26 /* most handlers are in DRAM which is too far away for a relative jump */ 30 /* most handlers are in DRAM which is too far away for a relative jump */
@@ -165,6 +169,11 @@ remap:
1651: 1691:
166 b 1b 170 b 1b
167 171
172#if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER)
173/* boot data structure */
174put_boot_data_here
175#endif
176
168/* Cache-align interrupt stacks */ 177/* Cache-align interrupt stacks */
169 .balign 32 178 .balign 32
170/* 256 words of IRQ stack */ 179/* 256 words of IRQ stack */