1 //==========================================================================
5 // Flash programming wrapper to support both NOR and NAND flashes
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 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
43 // Author(s): Kevin Zhang <k.zhang@freescale.com>
44 // Contributors: Kevin Zhang <k.zhang@freescale.com>
49 //####DESCRIPTIONEND####
51 //==========================================================================
53 #include <pkgconf/hal.h>
54 #include <cyg/hal/hal_arch.h>
55 #include <cyg/hal/hal_cache.h>
56 #include <cyg/hal/hal_misc.h>
59 extern void norflash_query(void* data);
60 extern int norflash_hwr_init(void);
61 extern int norflash_hwr_map_error(int e);
62 extern bool norflash_code_overlaps(void *start, void *end);
63 extern int norflash_erase_block(void* block, unsigned int size);
64 extern int norflash_program_buf(void* addr, void* data, int len);
65 extern int norflash_lock_block(void* block);
66 extern int norflash_unlock_block(void* block, int block_size, int blocks);
68 extern void nandflash_query(void* data);
69 extern int nandflash_hwr_init(void);
70 extern int nandflash_hwr_map_error(int e);
71 extern bool nandflash_code_overlaps(void *start, void *end);
72 extern int nandflash_erase_block(void* block, unsigned int size);
73 extern int nandflash_program_buf(void* addr, void* data, int len);
74 extern int nandflash_lock_block(void* block);
75 extern int nandflash_unlock_block(void* block, int block_size, int blocks);
77 static int mxc_flash_warning_done = 0;
79 void flash_query(void* data)
81 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
83 } else if (IS_BOOTING_FROM_NAND() || IS_FIS_FROM_NAND()) {
84 nandflash_query(data);
86 if (!mxc_flash_warning_done) {
87 mxc_flash_warning_done = 1;
88 diag_printf("1: Use \"factive [NOR|NAND]\" to select either NOR or NAND flash\n");
93 int flash_hwr_init(void)
95 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
96 return norflash_hwr_init();
97 } else if (IS_BOOTING_FROM_NAND() || IS_FIS_FROM_NAND()) {
98 return nandflash_hwr_init();
100 if (!mxc_flash_warning_done)
101 mxc_flash_warning_done = 1;
102 diag_printf("2: Use \"factive [NOR|NAND]\" to select either NOR or NAND flash\n");
107 int flash_hwr_map_error(int e)
109 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
110 return norflash_hwr_map_error(e);
112 return nandflash_hwr_map_error(e);
116 bool flash_code_overlaps(void *start, void *end)
118 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
119 return norflash_code_overlaps(start, end);
121 return nandflash_code_overlaps(start, end);
125 int flash_erase_block(void* block, unsigned int size)
127 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
128 return norflash_erase_block(block, size);
130 return nandflash_erase_block(block, size);
134 int flash_program_buf(void* addr, void* data, int len)
136 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
137 return norflash_program_buf(addr, data, len);
139 return nandflash_program_buf(addr, data, len);
143 int flash_lock_block(void* block)
145 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
146 return norflash_lock_block(block);
148 return nandflash_lock_block(block);
152 int flash_unlock_block(void* block, int block_size, int blocks)
154 if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
155 return norflash_unlock_block(block, block_size, blocks);
157 return nandflash_unlock_block(block, block_size, blocks);
161 extern void mxc_nfc_print_info(void);
163 static void mxc_flash_print_info(void)
165 if (IS_BOOTING_FROM_NOR()) {
166 diag_printf("\nBooting from [NOR flash]\n");
167 MXC_ASSERT_NOR_BOOT();
168 } else if (IS_BOOTING_FROM_NAND()) {
169 diag_printf("\nBooting from [NAND flash]\n");
170 MXC_ASSERT_NAND_BOOT();
171 mxc_nfc_print_info();
172 } else if (IS_BOOTING_FROM_SDRAM()) {
173 diag_printf("\nBooting from [SDRAM]\n");
175 diag_printf("\n!!!Warning: Unknown boot source !!!\n");
180 RedBoot_init(mxc_flash_print_info, RedBoot_INIT_LAST);