]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx27/karo/v1_0/src/redboot_cmds.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx27 / karo / v1_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/karo_tx27.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 #endif  //CYGSEM_REDBOOT_FLASH_CONFIG
55
56 static void runImg(int argc, char *argv[]);
57 static void do_mem(int argc, char *argv[]);
58
59 RedBoot_cmd("mem",
60             "Set a memory location",
61             "[-h|-b] [-n] [-a <address>] <data>",
62             do_mem
63     );
64
65 RedBoot_cmd("run",
66             "Run an image at a location with MMU off",
67             "[<virtual addr>]",
68             runImg
69            );
70
71 static void do_mem(int argc, char *argv[])
72 {
73         struct option_info opts[4];
74         bool mem_half_word, mem_byte;
75         bool no_verify;
76         bool addr_set;
77         unsigned long address;
78         unsigned int value;
79         int ret;
80         init_opts(&opts[0], 'b', false, OPTION_ARG_TYPE_FLG,
81                   &mem_byte, NULL, "write a byte");
82         init_opts(&opts[1], 'h', false, OPTION_ARG_TYPE_FLG,
83                   &mem_half_word, NULL, "write a half-word");
84         init_opts(&opts[2], 'a', true, OPTION_ARG_TYPE_NUM,
85                   &address, &addr_set, "address to write to");
86         init_opts(&opts[3], 'n', false, OPTION_ARG_TYPE_FLG,
87                   &no_verify, NULL, "noverify");
88
89         ret = scan_opts(argc, argv, 1, opts, sizeof(opts) / sizeof(opts[0]),
90                         &value, OPTION_ARG_TYPE_NUM, "value to be written");
91         if (ret == 0) {
92                 return;
93         }
94         if (!addr_set) {
95                 diag_printf("** Error: '-a <address>' must be specified\n");
96                 return;
97         }
98         if (ret == argc + 1) {
99                 diag_printf("** Error: non-option argument '<value>' must be specified\n");
100                 return;
101         }
102         if (mem_byte && mem_half_word) {
103                 diag_printf("** Error: Should not specify both byte and half-word access\n");
104         } else if (mem_byte) {
105                 value &= 0xff;
106                 *(volatile cyg_uint8*)address = (cyg_uint8)value;
107                 if (no_verify) {
108                         diag_printf("  Set 0x%08lX to 0x%02X\n", address, value);
109                 } else {
110                         diag_printf("  Set 0x%08lX to 0x%02X (result 0x%02X)\n",
111                                     address, value, (int)*(cyg_uint8*)address );
112                 }
113         } else if (mem_half_word) {
114                 if (address & 1) {
115                         diag_printf("** Error: address for half-word access must be half-word aligned\n");
116                 } else {
117                         value &= 0xffff;
118                         *(volatile cyg_uint16*)address = (cyg_uint16)value;
119                         if (no_verify) {
120                                 diag_printf("  Set 0x%08lX to 0x%04X\n", address, value);
121                         } else {
122                                 diag_printf("  Set 0x%08lX to 0x%04X (result 0x%04X)\n",
123                                             address, value, (int)*(cyg_uint16*)address);
124                         }
125                 }
126         } else {
127                 if (address & 3) {
128                         diag_printf("** Error: address for word access must be word aligned\n");
129                 } else {
130                         *(volatile cyg_uint32*)address = (cyg_uint32)value;
131                         if (no_verify) {
132                                 diag_printf("  Set 0x%08lX to 0x%08X\n", address, value);
133                         } else {
134                                 diag_printf("  Set 0x%08lX to 0x%08X (result 0x%08X)\n",
135                                             address, value, (int)*(cyg_uint32*)address);
136                         }
137                 }
138         }
139 }
140
141 void launchRunImg(unsigned long addr)
142 {
143     asm volatile ("mov r1, r0;");
144     HAL_MMU_OFF();
145     asm volatile (
146                  "mov r11, #0;"
147                  "mov r12, #0;"
148                  "mrs r10, cpsr;"
149                  "bic r10, r10, #0xF0000000;"
150                  "msr cpsr_f, r10;"
151                  "mov pc, r1"
152                  );
153 }
154
155 extern unsigned long entry_address;
156
157 static void runImg(int argc,char *argv[])
158 {
159         unsigned int virt_addr, phys_addr;
160
161         // Default physical entry point for Symbian
162         if (entry_address == 0xFFFFFFFF)
163                 virt_addr = 0x800000;
164         else
165                 virt_addr = entry_address;
166
167         if (!scan_opts(argc, argv, 1, 0, 0, &virt_addr,
168                        OPTION_ARG_TYPE_NUM, "virtual address"))
169                 return;
170
171         if (entry_address != 0xFFFFFFFF)
172                 diag_printf("load entry_address=0x%lx\n", entry_address);
173         HAL_VIRT_TO_PHYS_ADDRESS(virt_addr, phys_addr);
174
175         diag_printf("virt_addr=0x%x\n",virt_addr);
176         diag_printf("phys_addr=0x%x\n",phys_addr);
177
178         launchRunImg(phys_addr);
179 }
180
181 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
182
183 RedBoot_cmd("romupdate",
184             "Update Redboot with currently running image",
185             "",
186             romupdate
187            );
188
189 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
190 extern int flash_erase(void *addr, int len, void **err_addr);
191 extern char *flash_errmsg(int err);
192
193 #ifdef CYGPKG_IO_FLASH
194 void romupdate(int argc, char *argv[])
195 {
196         void *err_addr, *base_addr;
197         int stat;
198
199         base_addr = (void*)MXC_NAND_BASE_DUMMY;
200         diag_printf("Updating RedBoot in NAND flash\n");
201
202         // Erase area to be programmed
203         if ((stat = flash_erase(base_addr, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, &err_addr)) != 0) {
204                 diag_printf("Can't erase region at %p: %s\n",
205                             err_addr, flash_errmsg(stat));
206                 return;
207         }
208         // Now program it
209         if ((stat = flash_program(base_addr, ram_end - CYGMEM_REGION_rom_SIZE,
210                                   CYGBLD_REDBOOT_MIN_IMAGE_SIZE, &err_addr)) != 0) {
211                 diag_printf("Can't program region at %p: %s\n",
212                             err_addr, flash_errmsg(stat));
213         }
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.2 | 1.25 | 1.3 | 1.35 | 1.4 | 1.45 | 1.5 | 1.55 | 1.6]",
223             setcorevol
224            );
225
226 /*
227  * This function communicates with LP3972 to set the core voltage according to
228  * the argument
229  */
230 // LW: revisit use I2C routines for LP3972
231 unsigned int setCoreVoltage(unsigned int coreVol)
232 {
233         /* Set the core voltage */
234         diag_printf("%s: Not yet implemented\n", __FUNCTION__);
235         return 0;
236 }
237
238 static void setcorevol(int argc, char *argv[])
239 {
240         unsigned int coreVol;
241
242         /* check if the number of args is OK. 1 arg expected. argc = 2 */
243         if (argc != 2) {
244                 diag_printf("Invalid argument. Need to specify a voltage\n");
245                 return;
246         }
247
248         /* check if the argument is valid. */
249         if (strcasecmp(argv[1], "1.2") == 0) {
250                 coreVol = 0xC;
251         } else if (strcasecmp(argv[1], "1.25") == 0) {
252                 coreVol = 0xE;
253         } else if (strcasecmp(argv[1], "1.3") == 0) {
254                 coreVol = 0x10;
255         } else if (strcasecmp(argv[1], "1.35") == 0) {
256                 coreVol = 0x12;
257         } else if (strcasecmp(argv[1], "1.4") == 0) {
258                 coreVol = 0x14;
259         } else if (strcasecmp(argv[1], "1.45") == 0) {
260                 coreVol = 0x16;
261         } else if (strcasecmp(argv[1], "1.5") == 0) {
262                 coreVol = 0x18;
263         } else if (strcasecmp(argv[1], "1.55") == 0) {
264                 coreVol = 0x1A;
265         } else if (strcasecmp(argv[1], "1.6") == 0) {
266                 coreVol = 0x1C;
267         } else {
268                 diag_printf("Invalid argument. Type help setcorevol for valid values\n");
269                 return ;
270         }
271
272         setCoreVoltage(coreVol);
273         return;
274 }