]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_bootldr.c
Blackfin: convert old boards to use COBJS-y Makefile style
[people/ms/u-boot.git] / common / cmd_bootldr.c
CommitLineData
86a20fb9
MF
1/*
2 * U-boot - bootldr.c
3 *
4 * Copyright (c) 2005-2008 Analog Devices Inc.
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * Licensed under the GPL-2 or later.
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
29d4ea0a
MF
19/* Simple sanity check on the specified address to make sure it contains
20 * an LDR image of some sort.
21 */
22static bool ldr_valid_signature(uint8_t *data)
23{
24#if defined(__ADSPBF561__)
25
26 /* BF56x has a 4 byte global header */
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 /* all the BF53x should start at this address mask */
35 uint32_t addr;
36 memmove(&addr, data, sizeof(addr));
37 if ((addr & 0xFF0FFF0F) == 0xFF000000)
38 return true;
39#else
40
41 /* everything newer has a magic byte */
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/* If the Blackfin is new enough, the Blackfin on-chip ROM supports loading
53 * LDRs from random memory addresses. So whenever possible, use that. In
54 * the older cases (BF53x/BF561), parse the LDR format ourselves.
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 /*defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) ||*/\
65 defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
66
67 void *ret;
68
69 uint32_t addr;
70 uint32_t count;
71 uint16_t flags;
72
73 /* the bf56x has a 4 byte global header ... but it is useless to
74 * us when booting an LDR from a memory address, so skip it
75 */
76# ifdef __ADSPBF561__
77 base_addr += 4;
78# endif
79
80 memmove(&flags, base_addr + 8, sizeof(flags));
81 bfin_write_EVT1(flags & RESVECT ? 0xFFA00000 : 0xFFA08000);
82
83 do {
84 /* block header may not be aligned */
85 memmove(&addr, base_addr, sizeof(addr));
86 memmove(&count, base_addr+4, sizeof(count));
87 memmove(&flags, base_addr+8, sizeof(flags));
88 base_addr += sizeof(addr) + sizeof(count) + sizeof(flags);
89
90 printf("loading to 0x%08x (0x%x bytes) flags: 0x%04x\n",
91 addr, count, flags);
92
93 if (!(flags & IGNORE)) {
94 if (flags & ZEROFILL)
95 memset((void *)addr, 0x00, count);
96 else
97 memcpy((void *)addr, base_addr, count);
98
99 if (flags & INIT) {
100 void (*init)(void) = (void *)addr;
101 init();
102 }
103 }
104
105 if (!(flags & ZEROFILL))
106 base_addr += count;
107 } while (!(flags & FINAL));
108
109#endif
110}
111
112/* For BF537, we use the _BOOTROM_BOOT_DXE_FLASH funky ROM function.
113 * For all other BF53x/BF56x, we just call the entry point.
114 * For everything else (newer), we use _BOOTROM_MEMBOOT ROM function.
115 */
116static void ldr_exec(void *addr)
117{
118#if defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__)
119
120 /* restore EVT1 to reset value as this is what the bootrom uses as
121 * the default entry point when booting the final block of LDRs
122 */
123 bfin_write_EVT1(L1_INST_SRAM);
124 __asm__("call (%0);" : : "a"(_BOOTROM_MEMBOOT), "q7"(addr) : "RETS", "memory");
125
126#elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
127 defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
128
129 void (*ldr_entry)(void) = bfin_read_EVT1();
130 ldr_entry();
131
132#else
133
134 int32_t (*BOOTROM_MEM)(void *, int32_t, int32_t, void *) = (void *)_BOOTROM_MEMBOOT;
135 BOOTROM_MEM(addr, 0, 0, NULL);
136
137#endif
138}
139
86a20fb9
MF
140/*
141 * the bootldr command loads an address, checks to see if there
142 * is a Boot stream that the on-chip BOOTROM can understand,
143 * and loads it via the BOOTROM Callback. It is possible
144 * to also add booting from SPI, or TWI, but this function does
145 * not currently support that.
146 */
86a20fb9
MF
147int do_bootldr(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
148{
149 void *addr;
86a20fb9
MF
150
151 /* Get the address */
152 if (argc < 2)
153 addr = (void *)load_addr;
154 else
155 addr = (void *)simple_strtoul(argv[1], NULL, 16);
156
157 /* Check if it is a LDR file */
29d4ea0a 158 if (ldr_valid_signature(addr)) {
86a20fb9 159 printf("## Booting ldr image at 0x%p ...\n", addr);
29d4ea0a 160 ldr_load(addr);
86a20fb9
MF
161
162 icache_disable();
163 dcache_disable();
164
29d4ea0a 165 ldr_exec(addr);
86a20fb9
MF
166 } else
167 printf("## No ldr image at address 0x%p\n", addr);
168
169 return 0;
170}
171
172U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
2fb2604d 173 "boot ldr image from memory",
86a20fb9
MF
174 "[addr]\n"
175 " - boot ldr image stored in memory\n");