]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx21/ads/v2_0/src/redboot_cmds.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx21 / ads / v2_0 / src / redboot_cmds.c
1 //==========================================================================
2 //
3 //      redboot_cmds.c
4 //
5 //      Board [platform] specific RedBoot commands
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 #include <redboot.h>
42 #include <cyg/hal/hal_intr.h>
43 #include <cyg/hal/hal_cache.h>
44 #include <cyg/hal/plf_mmap.h>
45 #include <cyg/hal/fsl_board.h>          // Platform specific hardware definitions
46
47 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
48 #include <flash_config.h>
49
50 #if (REDBOOT_IMAGE_SIZE != CYGBLD_REDBOOT_MIN_IMAGE_SIZE)
51 #error REDBOOT_IMAGE_SIZE != CYGBLD_REDBOOT_MIN_IMAGE_SIZE
52 #endif 
53
54 RedBoot_config_option("Board specifics",
55                       brd_specs,
56                       ALWAYS_ENABLED, 
57                       true,
58                       CONFIG_INT,
59                       0
60                      );
61 #endif  //CYGSEM_REDBOOT_FLASH_CONFIG
62
63 static void runImg(int argc, char *argv[]);
64
65 RedBoot_cmd("run",
66             "Run an image at a location with MMU off",
67             "[<virtual addr>]",
68             runImg
69            );
70
71 void launchRunImg(unsigned long addr)
72 {
73     asm volatile ("mov r1, r0;");
74     HAL_MMU_OFF();
75     asm volatile (
76                  "mov r11, #0;"
77                  "mov r12, #0;"
78                  "mrs r10, cpsr;"
79                  "bic r10, r10, #0xF0000000;"
80                  "msr cpsr_f, r10;"
81                  "mov pc, r1"
82                  );
83 }
84
85 extern unsigned long entry_address;
86
87 static void runImg(int argc,char *argv[])
88 {
89     unsigned int virt_addr, phys_addr;
90
91     // Default physical entry point for Symbian
92     if (entry_address == 0xFFFFFFFF)
93         virt_addr = 0x800000;
94     else
95     virt_addr = entry_address;
96
97     if (!scan_opts(argc,argv,1,0,0,(void*)&virt_addr,
98                    OPTION_ARG_TYPE_NUM, "virtual address"))
99         return;
100
101     if (entry_address != 0xFFFFFFFF)
102         diag_printf("load entry_address=0x%lx\n", entry_address);
103     HAL_VIRT_TO_PHYS_ADDRESS(virt_addr, phys_addr);
104
105     diag_printf("virt_addr=0x%x\n",virt_addr);
106     diag_printf("phys_addr=0x%x\n",phys_addr);
107
108     launchRunImg(phys_addr);
109 }
110
111 #if CYGPKG_REDBOOT_NETWORKING
112 #define LAN_BASE        BOARD_CS_LAN_BASE
113
114 #define PP_EE_ADDR_W0   0x001C
115 #define PP_EE_ADDR_W1   0x001D
116 #define PP_EE_ADDR_W2   0x001E
117
118 extern cyg_uint16 read_eeprom(cyg_addrword_t base, cyg_uint16 offset);
119 extern void write_eeprom(cyg_addrword_t base, cyg_uint16 offset, cyg_uint16 data);
120
121 // Exported CLI function(s)
122 static void setMac(int argc, char *argv[]);
123 RedBoot_cmd("setmac",
124             "Set Ethernet MAC address in EEPROM",
125             "[0x##:0x##:0x##:0x##:0x##:0x##]",
126             setMac
127            );
128
129 const static unsigned short RESET_CONFIG_BLOCK[] = {
130     0xA002,
131     0x5E00,
132 };
133
134 #define DRIVER_CONFIG_BASE        0x1C   //Cirrus driver config base
135
136 static unsigned short g_drv_cfg_blk[] = {
137     0xFFFF, //1C - MAC 4,5
138     0xFFFF, //1D - MAC 2,3
139     0xFFFF, //1E - MAC 0,1
140     0x0000, //1F - ISA config
141     0x0000, //20 - PP mem base
142     0x0000, //21 - Boot PROM base
143     0x0000, //22 - Boot PROM mask
144     0x8040, //23 - Tx ctrl: Full duplex, media not required
145     0x0021, //24 - Adapter config: 10Base-T, 10Base-T circuitry
146     0x0001, //25 - EEPROM rev: 1.0
147     0x0000, //26 - resvd
148     0x0A2D, //27 - Mfg date
149     0xFFFF, //28 - copy of 1C
150     0xFFFF, //29 - copy of 1D
151     0xFFFF, //2A - copy of 1E
152     0x0000, //2B - resvd
153     0x0000, //2C - resvd
154     0x0000, //2D - resvd
155     0x0000, //2E - resvd
156     0x0000, //2F - Checksum
157 };
158
159 static void setMac(int argc,char *argv[])
160 {
161     int i, ret, wsize = sizeof(g_drv_cfg_blk) / 2;  // word size
162     unsigned char data[6];
163     unsigned long temp;
164     unsigned short ee_word[3];
165
166     if (argc == 1) {
167         ee_word[0] = read_eeprom(LAN_BASE, PP_EE_ADDR_W0 + 0);
168         ee_word[1] = read_eeprom(LAN_BASE, PP_EE_ADDR_W0 + 1);
169         ee_word[2] = read_eeprom(LAN_BASE, PP_EE_ADDR_W0 + 2);
170         if (ee_word[0] == 0 && ee_word[1] == 0 && ee_word[2] == 0) {
171             diag_printf("Can't read MAC address\n\n");
172             return;
173         }
174
175         diag_printf("MAC address: ");
176         diag_printf("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n\n",
177                     (ee_word[0] & 0x00FF), (ee_word[0] >> 8),
178                     (ee_word[1] & 0x00FF), (ee_word[1] >> 8),
179                     (ee_word[2] & 0x00FF), (ee_word[2] >> 8));
180         return;
181     }
182
183     if (argc != 2) {
184         ret = -1; goto error;
185     }
186
187     for (i = 0;  i < 6;  i++) {
188         if (!parse_num(*(&argv[1]), &temp, &argv[1], ":")) {
189             ret = -2; goto error;
190         }
191         if (temp > 0xFF) {
192             ret = -3; goto error;
193         }
194         data[i] = temp & 0xFF;
195     }
196
197     g_drv_cfg_blk[0] = g_drv_cfg_blk[12] = *(unsigned short*)(&data[0]);
198     g_drv_cfg_blk[1] = g_drv_cfg_blk[13] = *(unsigned short*)(&data[2]);
199     g_drv_cfg_blk[2] = g_drv_cfg_blk[14] = *(unsigned short*)(&data[4]);
200
201     // Calculate checksum
202     temp = 0;
203     for (i = 0; i < wsize-1; i++) {
204         temp += g_drv_cfg_blk[i];
205     }
206     temp = (~temp + 1) & 0xFFFF;
207     g_drv_cfg_blk[wsize-1] = temp;
208
209     // Program the EEPROM
210     // Reset config block first
211     for (i = 0; i < sizeof(RESET_CONFIG_BLOCK)/2; i++) {
212         write_eeprom(LAN_BASE, i, RESET_CONFIG_BLOCK[i]);
213     }
214     // Driver config block 2nd
215     for (i = 0; i < wsize; i++) {
216         write_eeprom(LAN_BASE, DRIVER_CONFIG_BASE+i,
217                      g_drv_cfg_blk[i]);
218     }
219     return;
220     error:
221     diag_printf("Wrong value for setMac. Error=%d\n\n", ret);
222 }
223
224 //#define EEPROM_DEBUG
225 #ifdef EEPROM_DEBUG
226 RedBoot_cmd("eefun",
227             "read/write a word into EEPROM",
228             "[0-based IO Base offset:value]",
229             eefun
230            );
231
232 static void eefun(int argc,char *argv[])
233 {
234     int i, ret;
235     unsigned short data[2];
236     unsigned int temp;
237
238     if (argc != 2) {
239         ret=-1; goto error;
240     }
241
242     for (i = 0;  i < 2;  i++) {
243         if (!parse_num(*(&argv[1]), &temp, &argv[1], ":")) {
244             ret=-2; goto error;
245         }
246         if (temp > 0xFFFF) {
247             ret=-3; goto error;
248         }
249         data[i] = (unsigned short)temp;
250     }
251
252     if (data[0] >= 0x30 && data[0] != 0xFFFF) {
253         ret=-4; goto error;
254     }
255
256     if (data[0] == 0xFFFF) {
257         for (i = 0; i < 0x30; i++) {
258             if (i % 8 == 0) diag_printf("0x%02x: ", i);
259             diag_printf("%04x ", read_eeprom(LAN_BASE, i));
260             if (i % 8 == 7) diag_printf("\n");
261         }
262         return;
263     }
264
265     diag_printf("writeEE() Offset: 0x%x, value=0x%x\n", data[0], data[1]);
266     write_eeprom(LAN_BASE, data[0], data[1]);
267     diag_printf("Reading back: 0x%x\n\n", read_eeprom(LAN_BASE, data[0]));
268     return;
269     error:
270     diag_printf("Wrong value %d for writeEE\n\n", ret);
271 }
272 #endif //EEPROM_DEBUG
273
274 #endif //CYGPKG_REDBOOT_NETWORKING
275
276 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
277
278 RedBoot_cmd("romupdate", 
279             "Update Redboot with currently running image", 
280             "",
281             romupdate 
282            );
283
284 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
285 extern int flash_erase(void *addr, int len, void **err_addr);
286 extern char *flash_errmsg(int err);
287 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
288
289 #ifdef CYGPKG_IO_FLASH
290 void romupdate(int argc, char *argv[])
291 {
292     void *err_addr, *base_addr;
293     int stat;
294
295     if (IS_FIS_FROM_NAND()) {
296         base_addr = (void*)MXC_NAND_BASE_DUMMY;
297         diag_printf("Updating ROM in NAND flash\n");
298     } else if (IS_FIS_FROM_NOR()) {
299         base_addr = (void*)BOARD_FLASH_START;
300         diag_printf("Updating ROM in NOR flash\n");
301     } else {
302         diag_printf("romupdate not supported\n");
303         diag_printf("Use \"factive [NOR|NAND]\" to select either NOR or NAND flash\n");
304         return;
305     }
306     // Erase area to be programmed
307     if ((stat = flash_erase((void *)base_addr,
308                             CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
309                             (void **)&err_addr)) != 0) {
310         diag_printf("Can't erase region at %p: %s\n", 
311                     err_addr, flash_errmsg(stat));
312         return;
313     }
314     // Now program it
315     if ((stat = flash_program((void *)base_addr, (void *)ram_end,
316                               CYGBLD_REDBOOT_MIN_IMAGE_SIZE, 
317                               (void **)&err_addr)) != 0) {
318         diag_printf("Can't program region at %p: %s\n", 
319                     err_addr, flash_errmsg(stat));
320     }
321 }
322 RedBoot_cmd("factive", 
323             "Enable one flash media for Redboot", 
324             "[NOR | NAND]",
325             factive 
326            );
327
328 void factive(int argc, char *argv[])
329 {
330     unsigned long phys_addr;
331
332     if (argc != 2) {
333         diag_printf("Invalid factive cmd\n");
334         return;
335     }
336
337     if (strcasecmp(argv[1], "NOR") == 0) {
338 #ifndef MXCFLASH_SELECT_NOR
339         diag_printf("Not supported\n");
340         return;
341 #else
342         MXC_ASSERT_NOR_BOOT();
343 #endif
344     } else if (strcasecmp(argv[1], "NAND") == 0) {
345 #ifndef MXCFLASH_SELECT_NAND
346         diag_printf("Not supported\n");
347         return;
348 #else
349         MXC_ASSERT_NAND_BOOT();
350 #endif
351     } else {
352         diag_printf("Invalid command: %s\n", argv[1]);
353         return;
354     }
355     HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
356
357     launchRunImg(phys_addr);
358 }
359 #endif //CYGPKG_IO_FLASH
360 #endif /* CYG_HAL_STARTUP_ROMRAM */