Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009, Code Aurora Forum. All rights reserved. |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 6 | * |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions are met: |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * * Neither the name of Code Aurora nor |
| 15 | * the names of its contributors may be used to endorse or promote |
| 16 | * products derived from this software without specific prior written |
| 17 | * permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <app.h> |
| 34 | #include <debug.h> |
| 35 | #include <arch/arm.h> |
| 36 | #include <dev/udc.h> |
| 37 | #include <string.h> |
| 38 | #include <kernel/thread.h> |
| 39 | #include <arch/ops.h> |
| 40 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 41 | #include <dev/flash.h> |
| 42 | #include <lib/ptable.h> |
Dima Zavin | b428360 | 2009-01-26 16:36:57 -0800 | [diff] [blame] | 43 | #include <dev/keys.h> |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 44 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 45 | #include "bootimg.h" |
| 46 | #include "fastboot.h" |
| 47 | |
Chandan Uddaraju | da91983 | 2009-11-17 01:06:11 -0800 | [diff] [blame] | 48 | #define DEFAULT_CMDLINE "mem=100M console=null"; |
Brian Swetland | 2defe16 | 2009-08-18 14:35:59 -0700 | [diff] [blame] | 49 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 50 | #define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000 |
| 51 | static const char *emmc_cmdline = " androidboot.emmc=true"; |
| 52 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 53 | static struct udc_device surf_udc_device = { |
| 54 | .vendor_id = 0x18d1, |
Chandan Uddaraju | c53a1a1 | 2009-11-18 14:53:40 -0800 | [diff] [blame] | 55 | .product_id = 0xD00D, |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 56 | .version_id = 0x0100, |
| 57 | .manufacturer = "Google", |
| 58 | .product = "Android", |
| 59 | }; |
| 60 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 61 | struct atag_ptbl_entry |
| 62 | { |
| 63 | char name[16]; |
| 64 | unsigned offset; |
| 65 | unsigned size; |
| 66 | unsigned flags; |
| 67 | }; |
| 68 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 69 | void platform_uninit_timer(void); |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 70 | unsigned* target_atag_mem(unsigned* ptr); |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 71 | unsigned board_machtype(void); |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 72 | int target_is_emmc_boot(void); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 73 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 74 | static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn) |
| 75 | { |
| 76 | struct atag_ptbl_entry atag_ptn; |
| 77 | |
| 78 | memcpy(atag_ptn.name, ptn->name, 16); |
| 79 | atag_ptn.name[15] = '\0'; |
| 80 | atag_ptn.offset = ptn->start; |
| 81 | atag_ptn.size = ptn->length; |
| 82 | atag_ptn.flags = ptn->flags; |
| 83 | memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry)); |
| 84 | *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned); |
| 85 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 86 | |
| 87 | void boot_linux(void *kernel, unsigned *tags, |
| 88 | const char *cmdline, unsigned machtype, |
| 89 | void *ramdisk, unsigned ramdisk_size) |
| 90 | { |
| 91 | unsigned *ptr = tags; |
| 92 | void (*entry)(unsigned,unsigned,unsigned*) = kernel; |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 93 | struct ptable *ptable; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 94 | int cmdline_len = 0; |
| 95 | int have_cmdline = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 96 | |
| 97 | /* CORE */ |
| 98 | *ptr++ = 2; |
| 99 | *ptr++ = 0x54410001; |
| 100 | |
| 101 | if (ramdisk_size) { |
| 102 | *ptr++ = 4; |
| 103 | *ptr++ = 0x54420005; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 104 | *ptr++ = (unsigned)ramdisk; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 105 | *ptr++ = ramdisk_size; |
| 106 | } |
| 107 | |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 108 | ptr = target_atag_mem(ptr); |
| 109 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 110 | if (!target_is_emmc_boot()) { |
| 111 | /* Skip NAND partition ATAGS for eMMC boot */ |
| 112 | if ((ptable = flash_get_ptable()) && (ptable->count != 0)) { |
| 113 | int i; |
| 114 | *ptr++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) / |
| 115 | sizeof(unsigned))); |
| 116 | *ptr++ = 0x4d534d70; |
| 117 | for (i = 0; i < ptable->count; ++i) |
| 118 | ptentry_to_tag(&ptr, ptable_get(ptable, i)); |
| 119 | } |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 122 | if (cmdline && cmdline[0]) { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 123 | cmdline_len = strlen(cmdline); |
| 124 | have_cmdline = 1; |
| 125 | } |
| 126 | if (target_is_emmc_boot()) { |
| 127 | cmdline_len += strlen(emmc_cmdline); |
| 128 | } |
| 129 | if (cmdline_len > 0) { |
| 130 | const char *src; |
| 131 | char *dst; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 132 | unsigned n; |
| 133 | /* include terminating 0 and round up to a word multiple */ |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 134 | n = (cmdline_len + 4) & (~3); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 135 | *ptr++ = (n / 4) + 2; |
| 136 | *ptr++ = 0x54410009; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 137 | dst = (char *)ptr; |
| 138 | if (have_cmdline) { |
| 139 | src = cmdline; |
| 140 | while ((*dst++ = *src++)); |
| 141 | } |
| 142 | if (target_is_emmc_boot()) { |
| 143 | src = emmc_cmdline; |
| 144 | if (have_cmdline) --dst; |
| 145 | while ((*dst++ = *src++)); |
| 146 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 147 | ptr += (n / 4); |
| 148 | } |
| 149 | |
| 150 | /* END */ |
| 151 | *ptr++ = 0; |
| 152 | *ptr++ = 0; |
| 153 | |
| 154 | dprintf(INFO, "booting linux @ %p, ramdisk @ %p (%d)\n", |
| 155 | kernel, ramdisk, ramdisk_size); |
| 156 | if (cmdline) |
| 157 | dprintf(INFO, "cmdline: %s\n", cmdline); |
| 158 | |
| 159 | enter_critical_section(); |
| 160 | platform_uninit_timer(); |
| 161 | arch_disable_cache(UCACHE); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 162 | arch_disable_mmu(); |
| 163 | |
| 164 | entry(0, machtype, tags); |
| 165 | |
| 166 | } |
| 167 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 168 | unsigned page_size = 0; |
| 169 | unsigned page_mask = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 170 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 171 | #define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y))) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 172 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 173 | static unsigned char buf[4096]; //Equal to max-supported pagesize |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 174 | |
| 175 | int boot_linux_from_flash(void) |
| 176 | { |
| 177 | struct boot_img_hdr *hdr = (void*) buf; |
| 178 | unsigned n; |
| 179 | struct ptentry *ptn; |
| 180 | struct ptable *ptable; |
| 181 | unsigned offset = 0; |
| 182 | const char *cmdline; |
| 183 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 184 | if (target_is_emmc_boot()) { |
| 185 | hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 186 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 187 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
| 188 | return -1; |
| 189 | } |
| 190 | goto continue_boot; |
| 191 | } |
| 192 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 193 | ptable = flash_get_ptable(); |
| 194 | if (ptable == NULL) { |
| 195 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 196 | return -1; |
| 197 | } |
| 198 | |
| 199 | ptn = ptable_find(ptable, "boot"); |
| 200 | if (ptn == NULL) { |
| 201 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 202 | return -1; |
| 203 | } |
| 204 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 205 | if (flash_read(ptn, offset, buf, page_size)) { |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 206 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 207 | return -1; |
| 208 | } |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 209 | offset += page_size; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 210 | |
| 211 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 212 | dprintf(CRITICAL, "ERROR: Invaled boot image heador\n"); |
| 213 | return -1; |
| 214 | } |
| 215 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 216 | if (hdr->page_size != page_size) { |
| 217 | dprintf(CRITICAL, "ERROR: Invaled boot image pagesize. Device pagesize: %d, Image pagesize: %d\n",page_size,hdr->page_size); |
| 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | n = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 222 | if (flash_read(ptn, offset, (void *)hdr->kernel_addr, n)) { |
| 223 | dprintf(CRITICAL, "ERROR: Cannot read kernel image\n"); |
| 224 | return -1; |
| 225 | } |
| 226 | offset += n; |
| 227 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 228 | n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 229 | if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, n)) { |
| 230 | dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n"); |
| 231 | return -1; |
| 232 | } |
| 233 | offset += n; |
| 234 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 235 | continue_boot: |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 236 | dprintf(INFO, "\nkernel @ %x (%d bytes)\n", hdr->kernel_addr, |
| 237 | hdr->kernel_size); |
| 238 | dprintf(INFO, "ramdisk @ %x (%d bytes)\n", hdr->ramdisk_addr, |
| 239 | hdr->ramdisk_size); |
| 240 | |
| 241 | if(hdr->cmdline[0]) { |
| 242 | cmdline = (char*) hdr->cmdline; |
| 243 | } else { |
| 244 | cmdline = DEFAULT_CMDLINE; |
| 245 | } |
| 246 | dprintf(INFO, "cmdline = '%s'\n", cmdline); |
| 247 | |
| 248 | /* TODO: create/pass atags to kernel */ |
| 249 | |
| 250 | dprintf(INFO, "\nBooting Linux\n"); |
| 251 | boot_linux((void *)hdr->kernel_addr, (void *)TAGS_ADDR, |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 252 | (const char *)cmdline, board_machtype(), |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 253 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 254 | |
| 255 | return 0; |
| 256 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 257 | |
| 258 | void cmd_boot(const char *arg, void *data, unsigned sz) |
| 259 | { |
| 260 | unsigned kernel_actual; |
| 261 | unsigned ramdisk_actual; |
| 262 | static struct boot_img_hdr hdr; |
| 263 | char *ptr = ((char*) data); |
| 264 | |
| 265 | if (sz < sizeof(hdr)) { |
| 266 | fastboot_fail("invalid bootimage header"); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | memcpy(&hdr, data, sizeof(hdr)); |
| 271 | |
| 272 | /* ensure commandline is terminated */ |
| 273 | hdr.cmdline[BOOT_ARGS_SIZE-1] = 0; |
| 274 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 275 | kernel_actual = ROUND_TO_PAGE(hdr.kernel_size, page_mask); |
| 276 | ramdisk_actual = ROUND_TO_PAGE(hdr.ramdisk_size, page_mask); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 277 | |
| 278 | if (2048 + kernel_actual + ramdisk_actual < sz) { |
| 279 | fastboot_fail("incomplete bootimage"); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | memmove((void*) KERNEL_ADDR, ptr + 2048, hdr.kernel_size); |
| 284 | memmove((void*) RAMDISK_ADDR, ptr + 2048 + kernel_actual, hdr.ramdisk_size); |
| 285 | |
| 286 | fastboot_okay(""); |
| 287 | udc_stop(); |
| 288 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 289 | boot_linux((void*) KERNEL_ADDR, (void*) TAGS_ADDR, |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 290 | (const char*) hdr.cmdline, board_machtype(), |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 291 | (void*) RAMDISK_ADDR, hdr.ramdisk_size); |
| 292 | } |
| 293 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 294 | void cmd_erase(const char *arg, void *data, unsigned sz) |
| 295 | { |
| 296 | struct ptentry *ptn; |
| 297 | struct ptable *ptable; |
| 298 | |
| 299 | ptable = flash_get_ptable(); |
| 300 | if (ptable == NULL) { |
| 301 | fastboot_fail("partition table doesn't exist"); |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | ptn = ptable_find(ptable, arg); |
| 306 | if (ptn == NULL) { |
| 307 | fastboot_fail("unknown partition name"); |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | if (flash_erase(ptn)) { |
| 312 | fastboot_fail("failed to erase partition"); |
| 313 | return; |
| 314 | } |
| 315 | fastboot_okay(""); |
| 316 | } |
| 317 | |
| 318 | void cmd_flash(const char *arg, void *data, unsigned sz) |
| 319 | { |
| 320 | struct ptentry *ptn; |
| 321 | struct ptable *ptable; |
| 322 | unsigned extra = 0; |
| 323 | |
| 324 | ptable = flash_get_ptable(); |
| 325 | if (ptable == NULL) { |
| 326 | fastboot_fail("partition table doesn't exist"); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | ptn = ptable_find(ptable, arg); |
| 331 | if (ptn == NULL) { |
| 332 | fastboot_fail("unknown partition name"); |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) { |
| 337 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 338 | fastboot_fail("image is not a boot image"); |
| 339 | return; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | if (!strcmp(ptn->name, "system") || !strcmp(ptn->name, "userdata")) |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 344 | extra = ((page_size >> 9) * 16); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 345 | else |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 346 | sz = ROUND_TO_PAGE(sz, page_mask); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 347 | |
| 348 | dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name); |
| 349 | if (flash_write(ptn, extra, data, sz)) { |
| 350 | fastboot_fail("flash write failure"); |
| 351 | return; |
| 352 | } |
| 353 | dprintf(INFO, "partition '%s' updated\n", ptn->name); |
| 354 | fastboot_okay(""); |
| 355 | } |
| 356 | |
| 357 | void cmd_continue(const char *arg, void *data, unsigned sz) |
| 358 | { |
| 359 | fastboot_okay(""); |
| 360 | udc_stop(); |
| 361 | |
| 362 | boot_linux_from_flash(); |
| 363 | } |
| 364 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 365 | void aboot_init(const struct app_descriptor *app) |
| 366 | { |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 367 | page_size = flash_page_size(); |
| 368 | page_mask = page_size - 1; |
Dima Zavin | b428360 | 2009-01-26 16:36:57 -0800 | [diff] [blame] | 369 | if (keys_get_state(KEY_BACK) != 0) |
| 370 | goto fastboot; |
| 371 | |
| 372 | boot_linux_from_flash(); |
| 373 | dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting " |
| 374 | "to fastboot mode.\n"); |
| 375 | |
| 376 | fastboot: |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 377 | udc_init(&surf_udc_device); |
| 378 | |
| 379 | fastboot_register("boot", cmd_boot); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 380 | fastboot_register("erase:", cmd_erase); |
| 381 | fastboot_register("flash:", cmd_flash); |
| 382 | fastboot_register("continue", cmd_continue); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 383 | fastboot_publish("product", "swordfish"); |
| 384 | fastboot_publish("kernel", "lk"); |
| 385 | |
Brian Swetland | 2defe16 | 2009-08-18 14:35:59 -0700 | [diff] [blame] | 386 | fastboot_init((void*) SCRATCH_ADDR, 100 * 1024 * 1024); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 387 | udc_start(); |
| 388 | } |
| 389 | |
| 390 | APP_START(aboot) |
| 391 | .init = aboot_init, |
| 392 | APP_END |
| 393 | |