]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx27/3stack/v2_0/src/redboot_cmds.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx27 / 3stack / 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 defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
112
113 RedBoot_cmd("romupdate", 
114             "Update Redboot with currently running image", 
115             "",
116             romupdate 
117            );
118
119 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
120 extern int flash_erase(void *addr, int len, void **err_addr);
121 extern char *flash_errmsg(int err);
122 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
123
124 #ifdef CYGPKG_IO_FLASH
125 void romupdate(int argc, char *argv[])
126 {
127     void *err_addr, *base_addr;
128     int stat;
129
130     if (IS_FIS_FROM_NAND()) {
131         base_addr = (void*)0;
132         diag_printf("Updating ROM in NAND flash\n");
133     } else if (IS_FIS_FROM_NOR()) {
134         base_addr = (void*)BOARD_FLASH_START;
135         diag_printf("Updating ROM in NOR flash\n");
136     } else {
137         diag_printf("romupdate not supported\n");
138         diag_printf("Use \"factive [NOR|NAND]\" to select either NOR or NAND flash\n");
139         return;
140     }
141     // Erase area to be programmed
142     if ((stat = flash_erase((void *)base_addr,
143                             CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
144                             (void **)&err_addr)) != 0) {
145         diag_printf("Can't erase region at %p: %s\n", 
146                     err_addr, flash_errmsg(stat));
147         return;
148     }
149     // Now program it
150     if ((stat = flash_program((void *)base_addr, (void *)ram_end,
151                               CYGBLD_REDBOOT_MIN_IMAGE_SIZE, 
152                               (void **)&err_addr)) != 0) {
153         diag_printf("Can't program region at %p: %s\n", 
154                     err_addr, flash_errmsg(stat));
155     }
156 }
157 RedBoot_cmd("factive", 
158             "Enable one flash media for Redboot", 
159             "[NOR | NAND]",
160             factive 
161            );
162
163 void factive(int argc, char *argv[])
164 {
165     unsigned long phys_addr;
166
167     if (argc != 2) {
168         diag_printf("Invalid factive cmd\n");
169         return;
170     }
171
172     if (strcasecmp(argv[1], "NOR") == 0) {
173 #ifndef MXCFLASH_SELECT_NOR
174         diag_printf("Not supported\n");
175         return;
176 #else
177         MXC_ASSERT_NOR_BOOT();
178 #endif
179     } else if (strcasecmp(argv[1], "NAND") == 0) {
180 #ifndef MXCFLASH_SELECT_NAND
181         diag_printf("Not supported\n");
182         return;
183 #else
184         MXC_ASSERT_NAND_BOOT();
185 #endif
186     } else {
187         diag_printf("Invalid command: %s\n", argv[1]);
188         return;
189     }
190     HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
191
192     launchRunImg(phys_addr);
193 }
194 #endif //CYGPKG_IO_FLASH
195 #endif /* CYG_HAL_STARTUP_ROMRAM */