]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx51/3stack/v2_0/src/redboot_cmds.c
TX51 pre-release
[karo-tx-redboot.git] / packages / hal / arm / mx51 / 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[40] = "PASS x.x [x32 DDR]";
64
65 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
66
67 RedBoot_cmd("romupdate",
68                         "Update Redboot with currently running image",
69                         "",
70                         romupdate
71         );
72
73 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
74 extern int flash_erase(void *addr, int len, void **err_addr);
75 extern char *flash_errmsg(int err);
76 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
77 extern cyg_uint32 emmc_set_boot_partition (cyg_uint32 *src_ptr, cyg_uint32 length);
78 extern cyg_uint32 esd_set_boot_partition(cyg_uint32 *src_ptr, cyg_uint32 length);
79 extern cyg_uint32 mmc_data_write(cyg_uint32 *src_ptr, cyg_uint32 length, cyg_uint32 offset);
80 extern cyg_uint32 mmc_data_read(cyg_uint32 *dest_ptr, cyg_uint32 length, cyg_uint32 offset);
81
82 #ifdef CYGPKG_IO_FLASH
83 void romupdate(int argc, char *argv[])
84 {
85         void *err_addr, *base_addr;
86         int stat;
87         unsigned int nfc_config3_reg = 0, temp;
88
89         if (IS_FIS_FROM_MMC() || IS_BOOTING_FROM_MMC()) {
90                 diag_printf("Updating ROM in MMC/SD flash\n");
91                 /* eMMC 4.3 and eSD 2.1 supported only on TO 2.0 and higher */
92                 if (((system_rev >> MAJOR_NUMBER_OFFSET) & 0xf) >= 0x2) {
93                         if(!emmc_set_boot_partition((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
94                                 /* eMMC 4.3 */
95                                 diag_printf("Card supports MMC-4.3, programming for boot operation.\n");
96                                 return;
97                         } else if(!esd_set_boot_partition((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
98                                 /* eSD 2.1 */
99                                 diag_printf("Card supports SD-2.1, programming for boot operation.\n");
100                                 return;
101                         }
102                 }
103                 base_addr = NULL;
104                 /* Read the first 1K from the card */
105                 mmc_data_read((cyg_uint32*)ram_end, 0x400, (cyg_uint32)base_addr);
106                 diag_printf("Programming Redboot to MMC/SD flash\n");
107                 mmc_data_write((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
108
109                 return;
110         } else if (IS_FIS_FROM_NAND() || IS_BOOTING_FROM_NAND()) {
111                 diag_printf("Updating ROM in NAND flash\n");
112                 base_addr = NULL;
113                 nfc_config3_reg = readl(NFC_FLASH_CONFIG3_REG);
114                 temp = nfc_config3_reg & ~0x7003;
115                 writel(temp, NFC_FLASH_CONFIG3_REG);
116         } else if (IS_BOOTING_FROM_SPI_NOR() || IS_FIS_FROM_SPI_NOR()) {
117                 diag_printf("Updating ROM in SPI-NOR flash\n");
118                 base_addr = NULL;
119         } else {
120                 diag_printf("romupdate not supported\n");
121                 diag_printf("Use \"factive [NAND|MMC|SPI]\" to select either NAND, MMC or SPI flash\n");
122         }
123
124         // Erase area to be programmed
125         if ((stat = flash_erase(base_addr,
126                                                                         CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
127                                                                         &err_addr)) != 0) {
128                 diag_printf("Can't erase region at %p: %s\n",
129                                         err_addr, flash_errmsg(stat));
130                 return;
131         }
132         // Now program it
133         if ((stat = flash_program((void *)base_addr, (void *)ram_end,
134                                                                         CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
135                                                                         (void **)&err_addr)) != 0) {
136                 diag_printf("Can't program region at %p: %s\n",
137                                         err_addr, flash_errmsg(stat));
138         }
139         if (IS_FIS_FROM_NAND() || IS_BOOTING_FROM_NAND())
140                 writel(nfc_config3_reg, NFC_FLASH_CONFIG3_REG);
141 }
142 RedBoot_cmd("factive",
143                         "Enable one flash media for Redboot",
144                         "[NAND | MMC | SPI]",
145                         factive
146         );
147
148 typedef void reset_func_t(void);
149
150 extern reset_func_t reset_vector;
151
152 static void launchRunImg(unsigned long addr)
153 {
154         asm volatile ("mov r1, r0;");
155         HAL_MMU_OFF();
156         asm volatile (
157                 "mov r11, #0;"
158                 "mov r12, #0;"
159                 "mrs r10, cpsr;"
160                 "bic r10, r10, #0xF0000000;"
161                 "msr cpsr_f, r10;"
162                 "mov pc, r1"
163                 );
164 }
165
166 void factive(int argc, char *argv[])
167 {
168         unsigned int *fis_addr = (unsigned int *)IRAM_BASE_ADDR;
169
170         if (argc != 2) {
171                 diag_printf("Invalid factive cmd\n");
172                 return;
173         }
174
175         if (strcasecmp(argv[1], "NOR") == 0) {
176                 diag_printf("Not supported\n");
177                 return;
178         } else if (strcasecmp(argv[1], "NAND") == 0) {
179 #ifndef MXCFLASH_SELECT_NAND
180                 diag_printf("Not supported\n");
181                 return;
182 #endif
183                 *fis_addr = FROM_NAND_FLASH;
184         } else if (strcasecmp(argv[1], "MMC") == 0) {
185 #ifndef MXCFLASH_SELECT_MMC
186                 diag_printf("Not supported\n");
187                 return;
188 #else
189                 *fis_addr = FROM_MMC_FLASH;
190 #endif
191         } else if (strcasecmp(argv[1], "SPI") == 0) {
192 #ifndef IMXFLASH_SELECT_SPI_NOR
193                 diag_printf("Not supported\n");
194                 return;
195 #else
196                 *fis_addr = FROM_SPI_NOR_FLASH;
197 #endif
198         } else {
199                 diag_printf("Invalid command: %s\n", argv[1]);
200                 return;
201         }
202
203         //HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
204         launchRunImg((unsigned long)reset_vector);
205 }
206 #endif //CYGPKG_IO_FLASH
207 #endif /* CYG_HAL_STARTUP_ROMRAM */