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 <cyg/hal/fsl_board.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 RedBoot_config_option("Board specifics",
61 #endif //CYGSEM_REDBOOT_FLASH_CONFIG
63 char HAL_PLATFORM_EXTRA[40] = "PASS x.x [x32 DDR]. Board Rev 2.0";
65 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
67 RedBoot_cmd("romupdate",
68 "Update Redboot with currently running image",
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 mmc_data_read (cyg_uint32 *,cyg_uint32 ,cyg_uint32);
78 extern int spi_nor_erase_block(void* block_addr, unsigned int block_size);
79 extern int spi_nor_program_buf(void *addr, void *data, int len);
80 extern void __attribute__((__noinline__)) launchRunImg(unsigned long addr);
82 #ifdef CYGPKG_IO_FLASH
83 void romupdate(int argc, char *argv[])
85 void *err_addr, *base_addr;
87 unsigned int nfc_config3_reg, temp;
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 on TO 2.0 and higher */
92 if(!emmc_set_boot_partition((cyg_uint32*)(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000), CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
94 diag_printf("Card supports MMC-4.3, programming for boot operation.\n");
96 } else if(!esd_set_boot_partition((cyg_uint32*)(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000), CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
98 diag_printf("Card supports SD-2.1, programming for boot operation.\n");
102 base_addr = (void*)0;
103 /* Read the first 1K from the card */
104 mmc_data_read((cyg_uint32*)(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000),
106 diag_printf("Programming Redboot to MMC/SD flash\n");
107 mmc_data_write((cyg_uint32*)(SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000),
108 CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
110 } else if (IS_BOOTING_FROM_SPI_NOR() || IS_FIS_FROM_SPI_NOR()) {
111 diag_printf("Updating ROM in SPI-NOR flash\n");
112 base_addr = (void*)0;
114 diag_printf("romupdate not supported\n");
115 diag_printf("Use \"factive [SPI|MMC]\" to select either NAND or MMC flash\n");
118 // Erase area to be programmed
119 if ((stat = flash_erase((void *)base_addr,
120 CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
121 (void **)&err_addr)) != 0) {
122 diag_printf("Can't erase region at %p: %s\n",
123 err_addr, flash_errmsg(stat));
127 if ((stat = flash_program((void *)base_addr,
128 (void *)SDRAM_BASE_ADDR + SDRAM_SIZE - 0x100000,
129 CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
130 (void **)&err_addr)) != 0) {
131 diag_printf("Can't program region at %p: %s\n",
132 err_addr, flash_errmsg(stat));
135 RedBoot_cmd("factive",
136 "Enable one flash media for Redboot",
141 typedef void reset_func_t(void);
143 extern reset_func_t reset_vector;
145 void factive(int argc, char *argv[])
147 unsigned int *fis_addr = IRAM_BASE_ADDR;
150 diag_printf("Invalid factive cmd\n");
154 if (strcasecmp(argv[1], "MMC") == 0) {
155 *fis_addr = FROM_MMC_FLASH;
156 } else if (strcasecmp(argv[1], "SPI") == 0) {
157 *fis_addr = FROM_SPI_NOR_FLASH;
160 diag_printf("Invalid command: %s\n", argv[1]);
164 //HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
165 launchRunImg(reset_vector);
167 #endif //CYGPKG_IO_FLASH
169 #define POST_SDRAM_START_OFFSET 0x800000
170 #define POST_MMC_OFFSET 0x100000
171 #define POST_SIZE 0x100000
172 #define POST_MAGIC_MARKER 0x43
174 void imx_launch_post(void)
176 mmc_data_read(0x100000, // ram location
178 0x100000); // from MMC/SD offset 0x100000
179 /* Need this to recognize the SPI-NOR part */
180 if (spi_norflash_hwr_init() != 0)
183 spi_nor_erase_block(0, 0x10000);
184 spi_nor_erase_block(0x10000, 0x10000);
185 spi_nor_erase_block(0x20000, 0x10000);
186 spi_nor_erase_block(0x30000, 0x10000);
187 // save the redboot to SPI-NOR
188 if (spi_nor_program_buf(0, 0x100000, 0x40000) != 0)
191 diag_printf("Reading POST from MMC to SDRAM...\n");
192 mmc_data_read(SDRAM_BASE_ADDR + POST_SDRAM_START_OFFSET, // ram location
194 0x200000); // from MMC offset
195 diag_printf("Launching POST\n");
196 launchRunImg(SDRAM_BASE_ADDR + POST_SDRAM_START_OFFSET);
198 //RedBoot_init(imx_launch_post, RedBoot_INIT_BEFORE_NET);
200 #endif /* CYG_HAL_STARTUP_ROMRAM */