1
2
3
4
5
6
7
8
9
10
11
12#include <config.h>
13#include <common.h>
14#include <command.h>
15
16#include <asm/blackfin.h>
17#include <asm/mach-common/bits/bootrom.h>
18
19
20
21
22static bool ldr_valid_signature(uint8_t *data)
23{
24#if defined(__ADSPBF561__)
25
26
27 if (data[3] == 0xA0)
28 return true;
29
30#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
31 defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
32 defined(__ADSPBF538__) || defined(__ADSPBF539__)
33
34
35 uint32_t addr;
36 memmove(&addr, data, sizeof(addr));
37 if ((addr & 0xFF0FFF0F) == 0xFF000000)
38 return true;
39#else
40
41
42 uint32_t count;
43 memmove(&count, data + 8, sizeof(count));
44 if (data[3] == 0xAD && count == 0)
45 return true;
46
47#endif
48
49 return false;
50}
51
52
53
54
55
56#define ZEROFILL 0x0001
57#define RESVECT 0x0002
58#define INIT 0x0008
59#define IGNORE 0x0010
60#define FINAL 0x8000
61static void ldr_load(uint8_t *base_addr)
62{
63#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
64 \
65 defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
66
67 uint32_t addr;
68 uint32_t count;
69 uint16_t flags;
70
71
72
73
74# ifdef __ADSPBF561__
75 base_addr += 4;
76# endif
77
78 memmove(&flags, base_addr + 8, sizeof(flags));
79 bfin_write_EVT1(flags & RESVECT ? 0xFFA00000 : 0xFFA08000);
80
81 do {
82
83 memmove(&addr, base_addr, sizeof(addr));
84 memmove(&count, base_addr+4, sizeof(count));
85 memmove(&flags, base_addr+8, sizeof(flags));
86 base_addr += sizeof(addr) + sizeof(count) + sizeof(flags);
87
88 printf("loading to 0x%08x (0x%x bytes) flags: 0x%04x\n",
89 addr, count, flags);
90
91 if (!(flags & IGNORE)) {
92 if (flags & ZEROFILL)
93 memset((void *)addr, 0x00, count);
94 else
95 memcpy((void *)addr, base_addr, count);
96
97 if (flags & INIT) {
98 void (*init)(void) = (void *)addr;
99 init();
100 }
101 }
102
103 if (!(flags & ZEROFILL))
104 base_addr += count;
105 } while (!(flags & FINAL));
106
107#endif
108}
109
110
111
112
113
114static void ldr_exec(void *addr)
115{
116#if defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__)
117
118
119
120
121 bfin_write_EVT1(L1_INST_SRAM);
122 __asm__("call (%0);" : : "a"(_BOOTROM_MEMBOOT), "q7"(addr) : "RETS", "memory");
123
124#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
125 defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
126
127 void (*ldr_entry)(void) = (void *)bfin_read_EVT1();
128 ldr_entry();
129
130#else
131
132 int32_t (*BOOTROM_MEM)(void *, int32_t, int32_t, void *) = (void *)_BOOTROM_MEMBOOT;
133 BOOTROM_MEM(addr, 0, 0, NULL);
134
135#endif
136}
137
138
139
140
141
142
143
144
145int do_bootldr(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
146{
147 void *addr;
148
149
150 if (argc < 2)
151 addr = (void *)load_addr;
152 else
153 addr = (void *)simple_strtoul(argv[1], NULL, 16);
154
155
156 if (ldr_valid_signature(addr)) {
157 printf("## Booting ldr image at 0x%p ...\n", addr);
158 ldr_load(addr);
159
160 icache_disable();
161 dcache_disable();
162
163 ldr_exec(addr);
164 } else
165 printf("## No ldr image at address 0x%p\n", addr);
166
167 return 0;
168}
169
170U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
171 "boot ldr image from memory",
172 "[addr]\n"
173 ""
174);
175