summaryrefslogtreecommitdiff
path: root/bootloader/x1000/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/x1000/utils.c')
-rw-r--r--bootloader/x1000/utils.c76
1 files changed, 76 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
103int 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
124struct nand_reader_data
125{
126 nand_drv* ndrv;
127 uint32_t addr;
128 uint32_t end_addr;
129};
130
131static 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
146int 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}