recovery: update is modified to support various image
[kernel/u-boot.git] / recovery / recovery.c
1 /*
2  * Copyright (C) 2010 Samsung Electronics
3  * Minkyu Kang <mk7.kang@samsung.com>
4  */
5
6 #include <common.h>
7 #include <malloc.h>
8 #include "recovery.h"
9 #include "usbd.h"
10 #include "onenand.h"
11
12 #ifdef RECOVERY_DEBUG
13 #define PUTS(s) serial_puts(DEBUG_MARK""s)
14 #else
15 #define PUTS(s)
16 #endif
17
18 typedef int (init_fnc_t)(void);
19
20 static void normal_boot(void)
21 {
22         uchar *buf;
23         int ret;
24
25         buf = (uchar *)CONFIG_SYS_BOOT_ADDR;
26
27         ret = board_load_bootloader(buf);
28         if (ret)
29                 hang();
30
31 #if 0
32         /* this will be applied */
33         ret = board_lock_recoveryblock();
34         if (ret)
35                 PUTS("fail: lock-tight");
36 #endif
37         ((init_fnc_t *)CONFIG_SYS_BOOT_ADDR)();
38 }
39
40 static void recovery_boot(void)
41 {
42         PUTS("Recovery Mode\n");
43
44         board_update_init();
45
46         /* usb download and write image */
47         do_usbd_down();
48
49         /* reboot */
50         /* reset_cpu(0); */
51 }
52
53 void start_recovery_boot(void)
54 {
55         /* armboot_start is defined in the board-specific linker script */
56         mem_malloc_init(_armboot_start - CONFIG_SYS_MALLOC_LEN,
57                         CONFIG_SYS_MALLOC_LEN);
58
59         board_recovery_init();
60
61         onenand_init();
62
63         serial_init();
64         serial_puts("\n");
65
66         if (board_check_condition())
67                 recovery_boot();
68         else
69                 normal_boot();
70
71         /* NOTREACHED - no way out of command loop except booting */
72 }
73
74 void hang(void)
75 {
76         PUTS("### ERROR ### Please RESET the board ###\n");
77         for (;;);
78 }
79
80 /*
81  * origin at lib_arm/eabi_compat.c to support EABI
82  */
83 int raise(int signum)
84 {
85         return 0;
86 }