]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx51/babbage/v2_0/src/redboot_cmds.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx51 / babbage / 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[20] = "PASS x.x [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_CACHE_FLUSH_ALL();
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 defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
118
119 RedBoot_cmd("romupdate",
120             "Update Redboot with currently running image",
121             "",
122             romupdate
123            );
124
125 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
126 extern int flash_erase(void *addr, int len, void **err_addr);
127 extern char *flash_errmsg(int err);
128 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
129 extern cyg_uint32 mmc_data_read (cyg_uint32 *,cyg_uint32 ,cyg_uint32);
130 extern int spi_nor_erase_block(void* block_addr, unsigned int block_size);
131 extern int spi_nor_program_buf(void *addr, void *data, int len);
132
133 #ifdef CYGPKG_IO_FLASH
134 void romupdate(int argc, char *argv[])
135 {
136     void *err_addr, *base_addr;
137     int stat;
138     unsigned int nfc_config3_reg, temp;
139
140     if (IS_FIS_FROM_MMC() || IS_BOOTING_FROM_MMC()) {
141         diag_printf("Updating ROM in MMC/SD flash\n");
142         base_addr = (void*)0;
143         /* Read the first 1K from the card */
144         mmc_data_read((cyg_uint32*)(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000),
145                       0x400, base_addr);
146         diag_printf("Programming Redboot to MMC/SD flash\n");
147         mmc_data_write((cyg_uint32*)(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000),
148                        CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
149         return;
150     } else if (IS_BOOTING_FROM_SPI_NOR() || IS_FIS_FROM_SPI_NOR()) {
151         diag_printf("Updating ROM in SPI-NOR flash\n");
152         base_addr = (void*)0;
153     } else {
154         diag_printf("romupdate not supported\n");
155         diag_printf("Use \"factive [SPI|MMC]\" to select either NAND or MMC flash\n");
156     }
157
158     // Erase area to be programmed
159     if ((stat = flash_erase((void *)base_addr,
160                             CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
161                             (void **)&err_addr)) != 0) {
162         diag_printf("Can't erase region at %p: %s\n",
163                     err_addr, flash_errmsg(stat));
164         return;
165     }
166     // Now program it
167     if ((stat = flash_program((void *)base_addr,
168                               (void *)SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000,
169                               CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
170                               (void **)&err_addr)) != 0) {
171         diag_printf("Can't program region at %p: %s\n",
172                     err_addr, flash_errmsg(stat));
173     }
174 }
175 RedBoot_cmd("factive",
176             "Enable one flash media for Redboot",
177             "[MMC|SPI]",
178             factive
179            );
180
181 typedef void reset_func_t(void);
182
183 extern reset_func_t reset_vector;
184
185 void factive(int argc, char *argv[])
186 {
187     unsigned long phys_addr;
188     unsigned int *fis_addr = IRAM_BASE_ADDR;
189
190     if (argc != 2) {
191         diag_printf("Invalid factive cmd\n");
192         return;
193     }
194
195     if (strcasecmp(argv[1], "MMC") == 0) {
196         *fis_addr = FROM_MMC_FLASH;
197     } else if (strcasecmp(argv[1], "SPI") == 0) {
198         *fis_addr = FROM_SPI_NOR_FLASH;
199     }
200     else {
201         diag_printf("Invalid command: %s\n", argv[1]);
202         return;
203     }
204
205     //HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
206     launchRunImg(reset_vector);
207 }
208 #endif //CYGPKG_IO_FLASH
209
210 #define POST_SDRAM_START_OFFSET         0x800000
211 #define POST_MMC_OFFSET                 0x100000
212 #define POST_SIZE                       0x100000
213 #define POST_MAGIC_MARKER               0x43
214
215
216 void imx_launch_post(void)
217 {
218     mmc_data_read(0x100000,     // ram location
219                   0x40000,      // length
220                   0x100000);    // from MMC/SD offset 0x100000
221     spi_nor_erase_block(0, 0x10000);
222     spi_nor_erase_block(0x10000, 0x10000);
223     spi_nor_erase_block(0x20000, 0x10000);
224     spi_nor_erase_block(0x30000, 0x10000);
225     // save the redboot to SPI-NOR
226     spi_nor_program_buf(0, 0x100000, 0x40000);
227
228     diag_printf("Reading POST from MMC to SDRAM...\n");
229     mmc_data_read(SDRAM_BASE_ADDR + POST_SDRAM_START_OFFSET,    // ram location
230                   0x200000,                                     // length
231                   0x200000);                                     // from MMC offset
232     diag_printf("Launching POST\n");
233     launchRunImg(SDRAM_BASE_ADDR + POST_SDRAM_START_OFFSET);
234 }
235 //RedBoot_init(imx_launch_post, RedBoot_INIT_BEFORE_NET);
236
237 #endif /* CYG_HAL_STARTUP_ROMRAM */