summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-03 19:56:26 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-03-11 11:15:56 -0500
commit428491df697e0a87eb14512151b3ce969dae8c54 (patch)
tree2b89996fbac4450001385fe54741bc361608ace5 /firmware/target/mips/ingenic_x1000
parent7fa48faeb55fb43b6a4e727d0abd104b267c89a4 (diff)
downloadrockbox-428491df697e0a87eb14512151b3ce969dae8c54.tar.gz
rockbox-428491df697e0a87eb14512151b3ce969dae8c54.zip
x1000: support new binary header in rolo
Change-Id: I192c3d69616c39534ff329174c4d8d4a357d014d
Diffstat (limited to 'firmware/target/mips/ingenic_x1000')
-rw-r--r--firmware/target/mips/ingenic_x1000/boot-x1000.c109
-rw-r--r--firmware/target/mips/ingenic_x1000/boot-x1000.h5
2 files changed, 114 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/boot-x1000.c b/firmware/target/mips/ingenic_x1000/boot-x1000.c
new file mode 100644
index 0000000000..d3e6eb35d7
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/boot-x1000.c
@@ -0,0 +1,109 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2022 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "boot-x1000.h"
23#include "system.h"
24#include <string.h>
25
26#define HDR_BEGIN 128 /* header must begin within this many bytes */
27#define HDR_LEN 256 /* header length cannot exceed this */
28
29/* search for header value, label must be a 4-character string.
30 * Returns the found value or 0 if the label wasn't found. */
31static uint32_t search_header(const unsigned char* source, size_t length,
32 const char* label)
33{
34 size_t search_len = MIN(length, HDR_BEGIN);
35 if(search_len < 8)
36 return 0;
37 search_len -= 7;
38
39 /* find the beginning marker */
40 size_t i;
41 for(i = 8; i < search_len; i += 4)
42 if(!memcmp(&source[i], "BEGINHDR", 8))
43 break;
44 if(i >= search_len)
45 return 0;
46 i += 8;
47
48 /* search within the header */
49 search_len = MIN(length, i + HDR_LEN) - 7;
50 for(; i < search_len; i += 8) {
51 if(!memcmp(&source[i], "ENDH", 4)) {
52 break;
53 } else if(!memcmp(&source[i], label, 4)) {
54 i += 4;
55 /* read little-endian value */
56 uint32_t ret = source[i];
57 ret |= source[i+1] << 8;
58 ret |= source[i+2] << 16;
59 ret |= source[i+3] << 24;
60 return ret;
61 }
62 }
63
64 return 0;
65}
66
67static void iram_memmove(void* dest, const void* source, size_t length)
68 __attribute__((section(".icode")));
69
70static void iram_memmove(void* dest, const void* source, size_t length)
71{
72 unsigned char* d = dest;
73 const unsigned char* s = source;
74
75 if(s < d && d < s + length) {
76 d += length;
77 s += length;
78 while(length--)
79 *--d = *--s;
80 } else {
81 while(length--)
82 *d++ = *s++;
83 }
84}
85
86void x1000_boot_rockbox(const void* source, size_t length)
87{
88 uint32_t load_addr = search_header(source, length, "LOAD");
89 if(!load_addr)
90 load_addr = X1000_STANDARD_DRAM_BASE;
91
92 disable_irq();
93
94 /* --- Beyond this point, do not call into DRAM --- */
95
96 iram_memmove((void*)load_addr, source, length);
97 commit_discard_idcache();
98
99 typedef void(*entry_fn)(void);
100 entry_fn fn = (entry_fn)load_addr;
101 fn();
102 while(1);
103}
104
105void rolo_restart(const unsigned char* source, unsigned char* dest, int length)
106{
107 (void)dest;
108 x1000_boot_rockbox(source, length);
109}
diff --git a/firmware/target/mips/ingenic_x1000/boot-x1000.h b/firmware/target/mips/ingenic_x1000/boot-x1000.h
index 400eb93dc1..620d7de89a 100644
--- a/firmware/target/mips/ingenic_x1000/boot-x1000.h
+++ b/firmware/target/mips/ingenic_x1000/boot-x1000.h
@@ -24,6 +24,8 @@
24 24
25#include "x1000/cpm.h" 25#include "x1000/cpm.h"
26#include <stdbool.h> 26#include <stdbool.h>
27#include <stdint.h>
28#include <stddef.h>
27 29
28enum { 30enum {
29 BOOT_OPTION_ROCKBOX = 0, 31 BOOT_OPTION_ROCKBOX = 0,
@@ -43,6 +45,9 @@ enum {
43 BOOT_FLAG_USB_BOOT = (1 << 30), 45 BOOT_FLAG_USB_BOOT = (1 << 30),
44}; 46};
45 47
48void x1000_boot_rockbox(const void* source, size_t length)
49 __attribute__((section(".icode")));
50
46/* Note: these functions are inlined to minimize SPL code size. 51/* Note: these functions are inlined to minimize SPL code size.
47 * They are private to the X1000 early boot code anyway... */ 52 * They are private to the X1000 early boot code anyway... */
48 53