1 //==========================================================================
5 // Board [platform] specific RedBoot commands
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.
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.
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
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.
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.
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.
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 //==========================================================================
42 #include <cyg/hal/hal_intr.h>
43 #include <cyg/hal/hal_cache.h>
44 #include <cyg/hal/plf_mmap.h>
45 #include CYGBLD_HAL_PLF_DEFS_H // Platform specific hardware definitions
47 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
48 #include <flash_config.h>
50 #if (REDBOOT_IMAGE_SIZE != CYGBLD_REDBOOT_MIN_IMAGE_SIZE)
51 #error REDBOOT_IMAGE_SIZE != CYGBLD_REDBOOT_MIN_IMAGE_SIZE
54 #endif //CYGSEM_REDBOOT_FLASH_CONFIG
56 #ifdef CYGPKG_IO_FLASH
57 #include <cyg/io/flash.h>
59 char HAL_PLATFORM_EXTRA[55] = "PASS x.x [x16 SDRAM]";
61 static void runImg(int argc, char *argv[]);
62 static void do_mem(int argc, char *argv[]);
65 "Set a memory location",
66 "[-h|-b] [-n] [-a <address>] <data>",
71 "Run an image at a location with MMU off",
76 static void do_mem(int argc, char *argv[])
78 struct option_info opts[4];
79 bool mem_half_word, mem_byte;
82 unsigned long address;
85 init_opts(&opts[0], 'b', false, OPTION_ARG_TYPE_FLG,
86 &mem_byte, NULL, "write a byte");
87 init_opts(&opts[1], 'h', false, OPTION_ARG_TYPE_FLG,
88 &mem_half_word, NULL, "write a half-word");
89 init_opts(&opts[2], 'a', true, OPTION_ARG_TYPE_NUM,
90 &address, &addr_set, "address to write to");
91 init_opts(&opts[3], 'n', false, OPTION_ARG_TYPE_FLG,
92 &no_verify, NULL, "noverify");
94 ret = scan_opts(argc, argv, 1, opts, sizeof(opts) / sizeof(opts[0]),
95 &value, OPTION_ARG_TYPE_NUM, "value to be written");
100 diag_printf("** Error: '-a <address>' must be specified\n");
103 if (ret == argc + 1) {
104 diag_printf("** Error: non-option argument '<value>' must be specified\n");
107 if (mem_byte && mem_half_word) {
108 diag_printf("** Error: Should not specify both byte and half-word access\n");
109 } else if (mem_byte) {
111 *(volatile cyg_uint8*)address = (cyg_uint8)value;
113 diag_printf(" Set 0x%08lX to 0x%02X\n", address, value);
115 diag_printf(" Set 0x%08lX to 0x%02X (result 0x%02X)\n",
116 address, value, (int)*(cyg_uint8*)address );
118 } else if (mem_half_word) {
120 diag_printf("** Error: address for half-word access must be half-word aligned\n");
123 *(volatile cyg_uint16*)address = (cyg_uint16)value;
125 diag_printf(" Set 0x%08lX to 0x%04X\n", address, value);
127 diag_printf(" Set 0x%08lX to 0x%04X (result 0x%04X)\n",
128 address, value, (int)*(cyg_uint16*)address);
133 diag_printf("** Error: address for word access must be word aligned\n");
135 *(volatile cyg_uint32*)address = (cyg_uint32)value;
137 diag_printf(" Set 0x%08lX to 0x%08X\n", address, value);
139 diag_printf(" Set 0x%08lX to 0x%08X (result 0x%08X)\n",
140 address, value, (int)*(cyg_uint32*)address);
146 void launchRunImg(unsigned long addr)
148 asm volatile ("mov r12, r0;");
156 "bic r10, r10, #0xF0000000;"
162 static void runImg(int argc,char *argv[])
164 unsigned int virt_addr, phys_addr;
166 // Default physical entry point for Symbian
167 if (entry_address == 0xFFFFFFFF)
168 virt_addr = 0x800000;
170 virt_addr = entry_address;
172 if (!scan_opts(argc, argv, 1, 0, 0, &virt_addr,
173 OPTION_ARG_TYPE_NUM, "virtual address"))
176 if (entry_address != 0xFFFFFFFF)
177 diag_printf("load entry_address=0x%lx\n", entry_address);
178 HAL_VIRT_TO_PHYS_ADDRESS(virt_addr, phys_addr);
180 diag_printf("virt_addr=0x%x\n",virt_addr);
181 diag_printf("phys_addr=0x%x\n",phys_addr);
183 launchRunImg(phys_addr);
186 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
188 RedBoot_cmd("romupdate",
189 "Update Redboot with currently running image",
194 #ifdef CYGPKG_IO_FLASH
195 void romupdate(int argc, char *argv[])
197 void *err_addr, *base_addr;
200 base_addr = (void*)(MXC_NAND_BASE_DUMMY + CYGBLD_REDBOOT_FLASH_BOOT_OFFSET);
201 diag_printf("Updating RedBoot in NAND flash\n");
203 // Erase area to be programmed
204 if ((stat = flash_erase(base_addr, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, &err_addr)) != 0) {
205 diag_printf("Can't erase region at %p: %s\n",
206 err_addr, flash_errmsg(stat));
210 if ((stat = flash_program(base_addr, ram_end,
211 CYGBLD_REDBOOT_MIN_IMAGE_SIZE, &err_addr)) != 0) {
212 diag_printf("Can't program region at %p: %s\n",
213 err_addr, flash_errmsg(stat));
216 #endif //CYGPKG_IO_FLASH
217 #endif /* CYG_HAL_STARTUP_ROMRAM */