]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx31/ads/v2_0/src/redboot_cmds.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / hal / arm / mx31 / 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 char HAL_PLATFORM_EXTRA[60] = "MX31 ADS (Freescale i.MX31 based) PASS 1.0 [x32 DDR]";
64
65 static void runImg(int argc, char *argv[]);
66
67 RedBoot_cmd("run",
68             "Run an image at a location with MMU off",
69             "[<virtual addr>]",
70             runImg
71            );
72
73 void launchRunImg(unsigned long addr)
74 {
75     asm volatile ("mov r12, r0;");
76     HAL_CLEAN_INVALIDATE_L2();
77     HAL_DISABLE_L2();
78     HAL_MMU_OFF();
79     asm volatile (
80                  "mov r0, #0;"
81                  "mov r1, r12;"
82                  "mov r11, #0;"
83                  "mov r12, #0;"
84                  "mrs r10, cpsr;"
85                  "bic r10, r10, #0xF0000000;"
86                  "msr cpsr_f, r10;"
87                  "mov pc, r1"
88                  );
89 }
90
91 extern unsigned long entry_address;
92
93 static void runImg(int argc,char *argv[])
94 {
95     unsigned int virt_addr, phys_addr;
96
97     // Default physical entry point for Symbian
98     if (entry_address == 0xFFFFFFFF)
99         virt_addr = 0x800000;
100     else
101     virt_addr = entry_address;
102
103     if (!scan_opts(argc,argv,1,0,0,(void*)&virt_addr,
104                    OPTION_ARG_TYPE_NUM, "virtual address"))
105         return;
106
107     if (entry_address != 0xFFFFFFFF)
108         diag_printf("load entry_address=0x%lx\n", entry_address);
109     HAL_VIRT_TO_PHYS_ADDRESS(virt_addr, phys_addr);
110
111     diag_printf("virt_addr=0x%x\n",virt_addr);
112     diag_printf("phys_addr=0x%x\n",phys_addr);
113
114     launchRunImg(phys_addr);
115 }
116
117 #if CYGPKG_REDBOOT_NETWORKING
118 #define LAN_BASE    BOARD_CS_LAN_BASE
119
120 #define PP_EE_ADDR_W0   0x001C
121 #define PP_EE_ADDR_W1   0x001D
122 #define PP_EE_ADDR_W2   0x001E
123
124 extern cyg_uint16 read_eeprom(cyg_addrword_t base, cyg_uint16 offset);
125 extern void write_eeprom(cyg_addrword_t base, cyg_uint16 offset, cyg_uint16 data);
126
127 // Exported CLI function(s)
128 static void setMac(int argc, char *argv[]);
129 RedBoot_cmd("setmac",
130             "Set Ethernet MAC address in EEPROM",
131             "[0x##:0x##:0x##:0x##:0x##:0x##]",
132             setMac
133            );
134
135 const static unsigned short RESET_CONFIG_BLOCK[] = {
136     0xA002,
137     0x5E00,
138 };
139
140 #define DRIVER_CONFIG_BASE        0x1C   //Cirrus driver config base
141
142 static unsigned short g_drv_cfg_blk[] = {
143     0xFFFF, //1C - MAC 4,5
144     0xFFFF, //1D - MAC 2,3
145     0xFFFF, //1E - MAC 0,1
146     0x0000, //1F - ISA config
147     0x0000, //20 - PP mem base
148     0x0000, //21 - Boot PROM base
149     0x0000, //22 - Boot PROM mask
150     0x8040, //23 - Tx ctrl: Full duplex, media not required
151     0x0021, //24 - Adapter config: 10Base-T, 10Base-T circuitry
152     0x0001, //25 - EEPROM rev: 1.0
153     0x0000, //26 - resvd
154     0x0A2D, //27 - Mfg date
155     0xFFFF, //28 - copy of 1C
156     0xFFFF, //29 - copy of 1D
157     0xFFFF, //2A - copy of 1E
158     0x0000, //2B - resvd
159     0x0000, //2C - resvd
160     0x0000, //2D - resvd
161     0x0000, //2E - resvd
162     0x0000, //2F - Checksum
163 };
164
165 static void setMac(int argc,char *argv[])
166 {
167     int i, ret, wsize = sizeof(g_drv_cfg_blk) / 2;  // word size
168     unsigned char data[6];
169     unsigned long temp;
170     unsigned short ee_word[3];
171
172     if (argc == 1) {
173         ee_word[0] = read_eeprom(LAN_BASE, PP_EE_ADDR_W0 + 0);
174         ee_word[1] = read_eeprom(LAN_BASE, PP_EE_ADDR_W0 + 1);
175         ee_word[2] = read_eeprom(LAN_BASE, PP_EE_ADDR_W0 + 2);
176         if (ee_word[0] == 0 && ee_word[1] == 0 && ee_word[2] == 0) {
177             diag_printf("Can't read MAC address\n\n");
178             return;
179         }
180
181         diag_printf("MAC address: ");
182         diag_printf("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n\n",
183                     (ee_word[0] & 0x00FF), (ee_word[0] >> 8),
184                     (ee_word[1] & 0x00FF), (ee_word[1] >> 8),
185                     (ee_word[2] & 0x00FF), (ee_word[2] >> 8));
186         return;
187     }
188
189     if (argc != 2) {
190         ret = -1; goto error;
191     }
192
193     for (i = 0;  i < 6;  i++) {
194         if (!parse_num(*(&argv[1]), &temp, &argv[1], ":")) {
195             ret = -2; goto error;
196         }
197         if (temp > 0xFF) {
198             ret = -3; goto error;
199         }
200         data[i] = temp & 0xFF;
201     }
202
203     g_drv_cfg_blk[0] = g_drv_cfg_blk[12] = *(unsigned short*)(&data[0]);
204     g_drv_cfg_blk[1] = g_drv_cfg_blk[13] = *(unsigned short*)(&data[2]);
205     g_drv_cfg_blk[2] = g_drv_cfg_blk[14] = *(unsigned short*)(&data[4]);
206
207     // Calculate checksum
208     temp = 0;
209     for (i = 0; i < wsize-1; i++) {
210         temp += g_drv_cfg_blk[i];
211     }
212     temp = (~temp + 1) & 0xFFFF;
213     g_drv_cfg_blk[wsize-1] = temp;
214
215     // Program the EEPROM
216     // Reset config block first
217     for (i = 0; i < sizeof(RESET_CONFIG_BLOCK)/2; i++) {
218         write_eeprom(LAN_BASE, i, RESET_CONFIG_BLOCK[i]);
219     }
220     // Driver config block 2nd
221     for (i = 0; i < wsize; i++) {
222         write_eeprom(LAN_BASE, DRIVER_CONFIG_BASE+i,
223                      g_drv_cfg_blk[i]);
224     }
225     return;
226     error:
227     diag_printf("Wrong value for setMac. Error=%d\n\n", ret);
228 }
229
230 //#define EEPROM_DEBUG
231 #ifdef EEPROM_DEBUG
232 RedBoot_cmd("eefun",
233             "read/write a word into EEPROM",
234             "[0-based IO Base offset:value]",
235             eefun
236            );
237
238 static void eefun(int argc,char *argv[])
239 {
240     int i, ret;
241     unsigned short data[2];
242     unsigned int temp;
243
244     if (argc != 2) {
245         ret=-1; goto error;
246     }
247
248     for (i = 0;  i < 2;  i++) {
249         if (!parse_num(*(&argv[1]), &temp, &argv[1], ":")) {
250             ret=-2; goto error;
251         }
252         if (temp > 0xFFFF) {
253             ret=-3; goto error;
254         }
255         data[i] = (unsigned short)temp;
256     }
257
258     if (data[0] >= 0x30 && data[0] != 0xFFFF) {
259         ret=-4; goto error;
260     }
261
262     if (data[0] == 0xFFFF) {
263         for (i = 0; i < 0x30; i++) {
264             if (i % 8 == 0) diag_printf("0x%02x: ", i);
265             diag_printf("%04x ", read_eeprom(LAN_BASE, i));
266             if (i % 8 == 7) diag_printf("\n");
267         }
268         return;
269     }
270
271     diag_printf("writeEE() Offset: 0x%x, value=0x%x\n", data[0], data[1]);
272     write_eeprom(LAN_BASE, data[0], data[1]);
273     diag_printf("Reading back: 0x%x\n\n", read_eeprom(LAN_BASE, data[0]));
274     return;
275     error:
276     diag_printf("Wrong value %d for writeEE\n\n", ret);
277 }
278 #endif //EEPROM_DEBUG
279
280 #endif //CYGPKG_REDBOOT_NETWORKING
281
282 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
283
284 RedBoot_cmd("romupdate",
285             "Update Redboot with currently running image",
286             "",
287             romupdate
288            );
289
290 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
291 extern int flash_erase(void *addr, int len, void **err_addr);
292 extern char *flash_errmsg(int err);
293 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
294
295 #ifdef CYGPKG_IO_FLASH
296 void romupdate(int argc, char *argv[])
297 {
298     void *err_addr, *base_addr;
299     int stat;
300     if (IS_FIS_FROM_MMC()) {
301         diag_printf("Updating ROM in MMC/SD flash\n");
302         base_addr = (void*)MXC_MMC_BASE_DUMMY;
303         /* Read the MBR from the card to RAM */
304         mmc_data_read((cyg_uint32*)(ram_end + 0x4), 0x3FC, base_addr);
305         diag_printf("Programming Redboot to MMC/SD flash\n");
306         mmc_data_write((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
307         return;
308     } else if (IS_FIS_FROM_NAND()) {
309         base_addr = (void*)0;
310         diag_printf("Updating ROM in NAND flash\n");
311     } else if (IS_FIS_FROM_NOR()) {
312         base_addr = (void*)BOARD_FLASH_START;
313         diag_printf("Updating ROM in NOR flash\n");
314     } else {
315         diag_printf("romupdate not supported\n");
316         diag_printf("Use \"factive [NOR|NAND|MMC]\" to select either MMC, NOR, NAND flash\n");
317         return;
318     }
319     // Erase area to be programmed
320     if ((stat = flash_erase((void *)base_addr,
321                             CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
322                             (void **)&err_addr)) != 0) {
323         diag_printf("Can't erase region at %p: %s\n",
324                     err_addr, flash_errmsg(stat));
325         return;
326     }
327     // Now program it
328     if ((stat = flash_program((void *)base_addr, (void *)ram_end,
329                               CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
330                               (void **)&err_addr)) != 0) {
331         diag_printf("Can't program region at %p: %s\n",
332                     err_addr, flash_errmsg(stat));
333     }
334 }
335
336 RedBoot_cmd("factive",
337             "Enable one flash media for Redboot",
338             "[NOR | NAND | MMC]",
339             factive
340            );
341
342 void factive(int argc, char *argv[])
343 {
344     unsigned long phys_addr;
345
346     if (argc != 2) {
347         diag_printf("Invalid factive cmd\n");
348         return;
349     }
350
351     if (strcasecmp(argv[1], "NOR") == 0) {
352 #ifndef MXCFLASH_SELECT_NOR
353         diag_printf("Not supported\n");
354         return;
355 #else
356         MXC_ASSERT_NOR_BOOT();
357 #endif
358     } else if (strcasecmp(argv[1], "NAND") == 0) {
359 #ifndef MXCFLASH_SELECT_NAND
360         diag_printf("Not supported\n");
361         return;
362 #else
363         MXC_ASSERT_NAND_BOOT();
364 #endif
365     } else if (strcasecmp(argv[1], "MMC") == 0) {
366 #ifndef MXCFLASH_SELECT_MMC
367         diag_printf("Not supported\n");
368         return;
369 #else
370         MXC_ASSERT_MMC_BOOT();
371 #endif
372     } else {
373         diag_printf("Invalid command: %s\n", argv[1]);
374         return;
375     }
376     HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
377
378     launchRunImg(phys_addr);
379 }
380 #endif //CYGPKG_IO_FLASH
381 #endif /* CYG_HAL_STARTUP_ROMRAM */