]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/flash/arm/mxc/v2_0/src/mxcflash_wrapper.c
Initial revision
[karo-tx-redboot.git] / packages / devs / flash / arm / mxc / v2_0 / src / mxcflash_wrapper.c
1 //==========================================================================
2 //
3 //      mxcflash_wrapper.c
4 //
5 //      Flash programming wrapper to support both NOR and NAND flashes
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 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):    Kevin Zhang <k.zhang@freescale.com>
44 // Contributors: Kevin Zhang <k.zhang@freescale.com>
45 // Date:         2006-01-23
46 // Purpose:      
47 // Description:  
48 //              
49 //####DESCRIPTIONEND####
50 //
51 //==========================================================================
52
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>
57 #include <redboot.h>
58
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);
67
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);
76
77 static int mxc_flash_warning_done = 0;
78
79 void flash_query(void* data)
80 {
81     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
82         norflash_query(data);
83     } else if (IS_BOOTING_FROM_NAND() || IS_FIS_FROM_NAND()) {
84         nandflash_query(data);
85     } else {
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");
89         }
90     }
91 }
92
93 int flash_hwr_init(void)
94 {
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();
99     } else {
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");
103         return -1;
104     }
105 }
106
107 int flash_hwr_map_error(int e)
108 {
109     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
110         return norflash_hwr_map_error(e);
111     } else {
112         return nandflash_hwr_map_error(e);
113     }
114 }
115
116 bool flash_code_overlaps(void *start, void *end)
117 {
118     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
119         return norflash_code_overlaps(start, end);
120     } else {
121         return nandflash_code_overlaps(start, end);
122     }
123 }
124
125 int flash_erase_block(void* block, unsigned int size)
126 {
127     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
128         return norflash_erase_block(block, size);
129     } else {
130         return nandflash_erase_block(block, size);
131     }
132 }
133
134 int flash_program_buf(void* addr, void* data, int len)
135 {
136     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
137         return norflash_program_buf(addr, data, len);
138     } else {
139         return nandflash_program_buf(addr, data, len);
140     }
141 }
142
143 int flash_lock_block(void* block)
144 {
145     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
146         return norflash_lock_block(block);
147     } else {
148         return nandflash_lock_block(block);
149     }
150 }
151
152 int flash_unlock_block(void* block, int block_size, int blocks)
153 {
154     if (IS_BOOTING_FROM_NOR() || IS_FIS_FROM_NOR()) {
155         return norflash_unlock_block(block, block_size, blocks);
156     } else {
157         return nandflash_unlock_block(block, block_size, blocks);
158     }
159 }
160
161 extern void mxc_nfc_print_info(void);
162
163 static void mxc_flash_print_info(void)
164 {
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");
174     } else {
175         diag_printf("\n!!!Warning: Unknown boot source !!!\n");
176     }
177     diag_printf("\n");
178 }
179
180 RedBoot_init(mxc_flash_print_info, RedBoot_INIT_LAST);