2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
14 /*--------------------------------------------------------------------*/
15 void flash_print_info (flash_info_t * info)
20 volatile unsigned char *flash;
22 printf (" Size: %ld KB in %d Sectors\n",
23 info->size >> 10, info->sector_count);
24 printf (" Sector Start Addresses:");
25 for (i = 0; i < info->sector_count; ++i) {
27 /* Check if whole sector is erased */
28 if (i != (info->sector_count - 1))
29 size = info->start[i + 1] - info->start[i];
31 size = info->start[0] + info->size - info->start[i];
33 flash = (volatile unsigned char *) info->start[i];
34 for (k = 0; k < size; k++) {
35 if (*flash++ != 0xff) {
44 printf (" %08lX%s%s", info->start[i], erased ? " E" : " ",
45 info->protect[i] ? "RO " : " ");
50 /*-------------------------------------------------------------------*/
53 int flash_erase (flash_info_t * info, int s_first, int s_last)
55 volatile CONFIG_SYS_FLASH_WORD_SIZE *addr = (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[0]);
56 volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2;
61 /* Some sanity checking */
62 if ((s_first < 0) || (s_first > s_last)) {
63 printf ("- no sectors to erase\n");
68 for (sect = s_first; sect <= s_last; ++sect) {
69 if (info->protect[sect]) {
74 printf ("- Warning: %d protected sectors will not be erased!\n",
81 for (sect = s_first; sect <= s_last; sect++) {
82 printf("- Erase: Sect: %i @ 0x%08x\n", sect, info->start[sect]);
86 /* NOTE: disabling interrupts on Nios can be very bad since it
87 * also disables the LO_LIMIT exception. It's better here to
88 * set the interrupt priority to 3 & restore it when we're done.
92 /* It's ok to erase multiple sectors provided we don't delay more
93 * than 50 usec between cmds ... at which point the erase time-out
94 * occurs. So don't go and put printf() calls in the loop ... it
95 * won't be very helpful ;-)
97 for (sect = s_first; sect <= s_last; sect++) {
98 if (info->protect[sect] == 0) { /* not protected */
99 addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *) (info->start[sect]);
106 /* Now just wait for 0xff & provide some user
107 * feedback while we wait. Here we have to grant
108 * timer interrupts. Otherwise get_timer() can't
111 start = get_timer (0);
112 while (*addr2 != 0xff) {
113 udelay (1000 * 1000);
115 if (get_timer (start) > CONFIG_SYS_FLASH_ERASE_TOUT) {
116 printf ("timeout\n");
120 oldpri = ipri (3); /* disallow non important irqs again */
126 /* Restore interrupt priority */
132 /*-----------------------------------------------------------------------
133 * Copy memory to flash, returns:
136 * 2 - Flash not erased
139 int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
142 vu_char *cmd = (vu_char *) info->start[0];
143 vu_char *dst = (vu_char *) addr;
149 /* Check for sufficient erase */
151 if ((*dst & b) != b) {
152 printf ("%02x : %02x\n", *dst, b);
156 /* Disable interrupts other than window underflow
157 * (interrupt priority 2)
166 start = get_timer (0);
168 if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {