4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * See file CREDITS for list of people who contributed to this
9 * Licensed under the GPL-2 or later.
16 #include <asm/blackfin.h>
17 #include <asm/mach-common/bits/bootrom.h>
19 /* Simple sanity check on the specified address to make sure it contains
20 * an LDR image of some sort.
22 static bool ldr_valid_signature(uint8_t *data)
24 #if defined(__ADSPBF561__)
26 /* BF56x has a 4 byte global header */
30 #elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
31 defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
32 defined(__ADSPBF538__) || defined(__ADSPBF539__)
34 /* all the BF53x should start at this address mask */
36 memmove(&addr, data, sizeof(addr));
37 if ((addr & 0xFF0FFF0F) == 0xFF000000)
41 /* everything newer has a magic byte */
43 memmove(&count, data + 8, sizeof(count));
44 if (data[3] == 0xAD && count == 0)
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.
56 #define ZEROFILL 0x0001
57 #define RESVECT 0x0002
61 static void ldr_load(uint8_t *base_addr)
63 #if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
64 /*defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) ||*/\
65 defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
71 /* the bf56x has a 4 byte global header ... but it is useless to
72 * us when booting an LDR from a memory address, so skip it
78 memmove(&flags, base_addr + 8, sizeof(flags));
79 bfin_write_EVT1(flags & RESVECT ? 0xFFA00000 : 0xFFA08000);
82 /* block header may not be aligned */
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);
88 printf("loading to 0x%08x (0x%x bytes) flags: 0x%04x\n",
91 if (!(flags & IGNORE)) {
93 memset((void *)addr, 0x00, count);
95 memcpy((void *)addr, base_addr, count);
98 void (*init)(void) = (void *)addr;
103 if (!(flags & ZEROFILL))
105 } while (!(flags & FINAL));
110 /* For BF537, we use the _BOOTROM_BOOT_DXE_FLASH funky ROM function.
111 * For all other BF53x/BF56x, we just call the entry point.
112 * For everything else (newer), we use _BOOTROM_MEMBOOT ROM function.
114 static void ldr_exec(void *addr)
116 #if defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__)
118 /* restore EVT1 to reset value as this is what the bootrom uses as
119 * the default entry point when booting the final block of LDRs
121 bfin_write_EVT1(L1_INST_SRAM);
122 __asm__("call (%0);" : : "a"(_BOOTROM_MEMBOOT), "q7"(addr) : "RETS", "memory");
124 #elif defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
125 defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
127 void (*ldr_entry)(void) = (void *)bfin_read_EVT1();
132 int32_t (*BOOTROM_MEM)(void *, int32_t, int32_t, void *) = (void *)_BOOTROM_MEMBOOT;
133 BOOTROM_MEM(addr, 0, 0, NULL);
139 * the bootldr command loads an address, checks to see if there
140 * is a Boot stream that the on-chip BOOTROM can understand,
141 * and loads it via the BOOTROM Callback. It is possible
142 * to also add booting from SPI, or TWI, but this function does
143 * not currently support that.
145 int do_bootldr(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
149 /* Get the address */
151 addr = (void *)load_addr;
153 addr = (void *)simple_strtoul(argv[1], NULL, 16);
155 /* Check if it is a LDR file */
156 if (ldr_valid_signature(addr)) {
157 printf("## Booting ldr image at 0x%p ...\n", addr);
165 printf("## No ldr image at address 0x%p\n", addr);
170 U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
171 "boot ldr image from memory",