]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx25/3stack/v2_0/src/redboot_cmds.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx25 / 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 char HAL_PLATFORM_EXTRA[55] = " 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_MMU_OFF();
77     asm volatile (
78                  "mov r0, #0;"
79                  "mov r1, r12;"
80                  "mov r11, #0;"
81                  "mov r12, #0;"
82                  "mrs r10, cpsr;"
83                  "bic r10, r10, #0xF0000000;"
84                  "msr cpsr_f, r10;"
85                  "mov pc, r1"
86                  );
87 }
88
89 extern unsigned long entry_address;
90
91 static void runImg(int argc,char *argv[])
92 {
93     unsigned int virt_addr, phys_addr;
94
95     // Default physical entry point for Symbian
96     if (entry_address == 0xFFFFFFFF)
97         virt_addr = 0x800000;
98     else
99     virt_addr = entry_address;
100
101     if (!scan_opts(argc,argv,1,0,0,(void*)&virt_addr,
102                    OPTION_ARG_TYPE_NUM, "virtual address"))
103         return;
104
105     if (entry_address != 0xFFFFFFFF)
106         diag_printf("load entry_address=0x%lx\n", entry_address);
107     HAL_VIRT_TO_PHYS_ADDRESS(virt_addr, phys_addr);
108
109     diag_printf("virt_addr=0x%x\n",virt_addr);
110     diag_printf("phys_addr=0x%x\n",phys_addr);
111
112     launchRunImg(phys_addr);
113 }
114
115 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
116
117 RedBoot_cmd("romupdate",
118             "Update Redboot with currently running image",
119             "",
120             romupdate
121            );
122
123 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
124 extern int flash_erase(void *addr, int len, void **err_addr);
125 extern char *flash_errmsg(int err);
126 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
127
128 #ifdef CYGPKG_IO_FLASH
129 void romupdate(int argc, char *argv[])
130 {
131     void *err_addr, *base_addr;
132     int stat;
133
134     if (IS_FIS_FROM_MMC()) {
135         diag_printf("Updating ROM in MMC/SD flash\n");
136         base_addr = (void*)0;
137         /* Read the first 1K from the card */
138         mmc_data_read((cyg_uint32*)ram_end, 0x400, base_addr);
139         diag_printf("Programming Redboot to MMC/SD flash\n");
140         mmc_data_write((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
141         return;
142     } else if (IS_FIS_FROM_NAND()) {
143         base_addr = (void*)MXC_NAND_BASE_DUMMY;
144         diag_printf("Updating ROM in NAND flash\n");
145     } else if (IS_FIS_FROM_NOR()) {
146         base_addr = (void*)BOARD_FLASH_START;
147         diag_printf("Updating ROM in NOR flash\n");
148     } else {
149         diag_printf("romupdate not supported\n");
150         diag_printf("Use \"factive [NOR|NAND|MMC]\" to select either NOR, NAND or MMC flash\n");
151         return;
152     }
153
154     // Erase area to be programmed
155     if ((stat = flash_erase((void *)base_addr,
156                             CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
157                             (void **)&err_addr)) != 0) {
158         diag_printf("Can't erase region at %p: %s\n",
159                     err_addr, flash_errmsg(stat));
160         return;
161     }
162     // Now program it
163     if ((stat = flash_program((void *)base_addr, (void *)ram_end,
164                               CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
165                               (void **)&err_addr)) != 0) {
166         diag_printf("Can't program region at %p: %s\n",
167                     err_addr, flash_errmsg(stat));
168     }
169 }
170
171 RedBoot_cmd("factive",
172             "Enable one flash media for Redboot",
173             "[NOR | NAND | MMC]",
174             factive
175            );
176
177 void factive(int argc, char *argv[])
178 {
179     unsigned long phys_addr;
180
181     if (argc != 2) {
182         diag_printf("Invalid factive cmd\n");
183         return;
184     }
185
186     if (strcasecmp(argv[1], "NOR") == 0) {
187 #ifndef MXCFLASH_SELECT_NOR
188         diag_printf("Not supported\n");
189         return;
190 #else
191         MXC_ASSERT_NOR_BOOT();
192 #endif
193     } else if (strcasecmp(argv[1], "NAND") == 0) {
194 #ifndef MXCFLASH_SELECT_NAND
195         diag_printf("Not supported\n");
196         return;
197 #else
198         MXC_ASSERT_NAND_BOOT();
199 #endif
200     } else if (strcasecmp(argv[1], "MMC") == 0) {
201 #ifndef MXCFLASH_SELECT_MMC
202         diag_printf("Not supported\n");
203         return;
204 #else
205         MXC_ASSERT_MMC_BOOT();
206 #endif
207     } else {
208         diag_printf("Invalid command: %s\n", argv[1]);
209         return;
210     }
211     HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
212
213     launchRunImg(phys_addr);
214 }
215 #endif //CYGPKG_IO_FLASH
216 #endif /* CYG_HAL_STARTUP_ROMRAM */
217
218 static void setcorevol(int argc, char *argv[]);
219
220 RedBoot_cmd("setcorevol",
221             "Set the core voltage. Setting is not checked against current core frequency.",
222             "[1.16 | 1.2 | 1.23 | 1.27 | 1.3 | 1.34 | 1.38 | 1.41 | 1.45 | 1.49 | 1.52 | 1.56 | 1.59 | 1.63 | 1.67 | 1.7]",
223             setcorevol
224            );
225
226 static void setcorevol(int argc, char *argv[])
227 {
228     unsigned int coreVol;
229
230     /* check if the number of args is OK. 1 arg expected. argc = 2 */
231     if(argc != 2) {
232         diag_printf("Invalid argument. Need to specify a voltage\n");
233         return;
234     }
235
236     /* check if the argument is valid. */
237     if (strcasecmp(argv[1], "1.16") == 0) {     /* -20% */
238         coreVol = 0x8;
239     } else if (strcasecmp(argv[1], "1.2") == 0) {
240         coreVol = 0x9;
241     } else if (strcasecmp(argv[1], "1.23") == 0) {
242         coreVol = 0xA;
243     } else if (strcasecmp(argv[1], "1.27") == 0) {
244         coreVol = 0xB;
245     } else if (strcasecmp(argv[1], "1.3") == 0) {
246         coreVol = 0xC;
247     } else if (strcasecmp(argv[1], "1.34") == 0) {
248         coreVol = 0xD;
249     } else if (strcasecmp(argv[1], "1.38") == 0) {
250         coreVol = 0xE;
251     } else if (strcasecmp(argv[1], "1.41") == 0) {
252         coreVol = 0xF;
253     } else if (strcasecmp(argv[1], "1.45") == 0) {      /* 0% */
254         coreVol = 0x0;
255     } else if (strcasecmp(argv[1], "1.49") == 0) {
256         coreVol = 0x1;
257     } else if (strcasecmp(argv[1], "1.52") == 0) {
258         coreVol = 0x2;
259     } else if (strcasecmp(argv[1], "1.56") == 0) {
260         coreVol = 0x3;
261     } else if (strcasecmp(argv[1], "1.59") == 0) {
262         coreVol = 0x4;
263     } else if (strcasecmp(argv[1], "1.63") == 0) {
264         coreVol = 0x5;
265     } else if (strcasecmp(argv[1], "1.67") == 0) {
266         coreVol = 0x6;
267     } else if (strcasecmp(argv[1], "1.7") == 0) {       /* +17.5% */
268         coreVol = 0x7;
269     } else {
270         diag_printf("Invalid argument. Type \"help setcorevol\" for valid settings\n");
271         return;
272     }
273
274     pmic_reg(0x08, coreVol << 1, 1);
275
276     return;
277 }