diff options
Diffstat (limited to 'bootloader')
-rw-r--r-- | bootloader/x1000/utils.c | 76 | ||||
-rw-r--r-- | bootloader/x1000/x1000bootloader.h | 7 |
2 files changed, 83 insertions, 0 deletions
diff --git a/bootloader/x1000/utils.c b/bootloader/x1000/utils.c index 6cb9bb379a..faeab40739 100644 --- a/bootloader/x1000/utils.c +++ b/bootloader/x1000/utils.c | |||
@@ -25,8 +25,11 @@ | |||
25 | #include "button.h" | 25 | #include "button.h" |
26 | #include "kernel.h" | 26 | #include "kernel.h" |
27 | #include "usb.h" | 27 | #include "usb.h" |
28 | #include "file.h" | ||
28 | #include "rb-loader.h" | 29 | #include "rb-loader.h" |
29 | #include "loader_strerror.h" | 30 | #include "loader_strerror.h" |
31 | #include "linuxboot.h" | ||
32 | #include "nand-x1000.h" | ||
30 | 33 | ||
31 | /* Set to true if a SYS_USB_CONNECTED event is seen | 34 | /* Set to true if a SYS_USB_CONNECTED event is seen |
32 | * Set to false if a SYS_USB_DISCONNECTED event is seen | 35 | * Set to false if a SYS_USB_DISCONNECTED event is seen |
@@ -96,3 +99,76 @@ int load_rockbox(const char* filename, size_t* sizep) | |||
96 | 99 | ||
97 | return handle; | 100 | return handle; |
98 | } | 101 | } |
102 | |||
103 | int load_uimage_file(const char* filename, | ||
104 | struct uimage_header* uh, size_t* sizep) | ||
105 | { | ||
106 | if(check_disk(true) != DISK_PRESENT) | ||
107 | return -1; | ||
108 | |||
109 | int fd = open(filename, O_RDONLY); | ||
110 | if(fd < 0) { | ||
111 | splash2(5*HZ, "Can't open file", filename); | ||
112 | return -2; | ||
113 | } | ||
114 | |||
115 | int handle = uimage_load(uh, sizep, uimage_fd_reader, (void*)(intptr_t)fd); | ||
116 | if(handle <= 0) { | ||
117 | splash2(5*HZ, "Cannot load uImage", filename); | ||
118 | return -3; | ||
119 | } | ||
120 | |||
121 | return handle; | ||
122 | } | ||
123 | |||
124 | struct nand_reader_data | ||
125 | { | ||
126 | nand_drv* ndrv; | ||
127 | uint32_t addr; | ||
128 | uint32_t end_addr; | ||
129 | }; | ||
130 | |||
131 | static ssize_t uimage_nand_reader(void* buf, size_t count, void* rctx) | ||
132 | { | ||
133 | struct nand_reader_data* d = rctx; | ||
134 | |||
135 | if(d->addr + count > d->end_addr) | ||
136 | count = d->end_addr - d->addr; | ||
137 | |||
138 | int ret = nand_read_bytes(d->ndrv, d->addr, count, buf); | ||
139 | if(ret != NAND_SUCCESS) | ||
140 | return -1; | ||
141 | |||
142 | d->addr += count; | ||
143 | return count; | ||
144 | } | ||
145 | |||
146 | int load_uimage_flash(uint32_t addr, uint32_t length, | ||
147 | struct uimage_header* uh, size_t* sizep) | ||
148 | { | ||
149 | int handle = -1; | ||
150 | |||
151 | struct nand_reader_data n; | ||
152 | n.ndrv = nand_init(); | ||
153 | n.addr = addr; | ||
154 | n.end_addr = addr + length; | ||
155 | |||
156 | nand_lock(n.ndrv); | ||
157 | if(nand_open(n.ndrv) != NAND_SUCCESS) { | ||
158 | splash(5*HZ, "NAND open failed"); | ||
159 | nand_unlock(n.ndrv); | ||
160 | return -1; | ||
161 | } | ||
162 | |||
163 | handle = uimage_load(uh, sizep, uimage_nand_reader, &n); | ||
164 | |||
165 | nand_close(n.ndrv); | ||
166 | nand_unlock(n.ndrv); | ||
167 | |||
168 | if(handle <= 0) { | ||
169 | splash(5*HZ, "uImage load failed"); | ||
170 | return -2; | ||
171 | } | ||
172 | |||
173 | return handle; | ||
174 | } | ||
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index 84feded9b3..c5984c9a91 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h | |||
@@ -24,8 +24,11 @@ | |||
24 | 24 | ||
25 | #include "config.h" | 25 | #include "config.h" |
26 | #include <stddef.h> | 26 | #include <stddef.h> |
27 | #include <stdint.h> | ||
27 | #include <stdbool.h> | 28 | #include <stdbool.h> |
28 | 29 | ||
30 | struct uimage_header; | ||
31 | |||
29 | #if defined(FIIO_M3K) | 32 | #if defined(FIIO_M3K) |
30 | # define BL_RECOVERY BUTTON_VOL_UP | 33 | # define BL_RECOVERY BUTTON_VOL_UP |
31 | # define BL_UP BUTTON_VOL_UP | 34 | # define BL_UP BUTTON_VOL_UP |
@@ -108,6 +111,10 @@ int check_disk(bool wait); | |||
108 | void usb_mode(void); | 111 | void usb_mode(void); |
109 | 112 | ||
110 | int load_rockbox(const char* filename, size_t* sizep); | 113 | int load_rockbox(const char* filename, size_t* sizep); |
114 | int load_uimage_file(const char* filename, | ||
115 | struct uimage_header* uh, size_t* sizep); | ||
116 | int load_uimage_flash(uint32_t addr, uint32_t length, | ||
117 | struct uimage_header* uh, size_t* sizep); | ||
111 | 118 | ||
112 | void recovery_menu(void) __attribute__((noreturn)); | 119 | void recovery_menu(void) __attribute__((noreturn)); |
113 | 120 | ||