wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | |
| 30 | #define FLASH_BANK_SIZE 0x400000 |
| 31 | #define MAIN_SECT_SIZE 0x20000 |
| 32 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | /*----------------------------------------------------------------------- |
| 37 | */ |
| 38 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 39 | ulong flash_init (void) |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 40 | { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 41 | int i, j; |
| 42 | ulong size = 0; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 45 | ulong flashbase = 0; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 46 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 47 | flash_info[i].flash_id = |
| 48 | (INTEL_MANUFACT & FLASH_VENDMASK) | |
| 49 | (INTEL_ID_28F128J3 & FLASH_TYPEMASK); |
| 50 | flash_info[i].size = FLASH_BANK_SIZE; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 51 | flash_info[i].sector_count = CONFIG_SYS_MAX_FLASH_SECT; |
| 52 | memset (flash_info[i].protect, 0, CONFIG_SYS_MAX_FLASH_SECT); |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 53 | switch (i) { |
| 54 | case 0: |
| 55 | flashbase = PHYS_FLASH_1; |
| 56 | break; |
| 57 | case 1: |
| 58 | flashbase = PHYS_FLASH_2; |
| 59 | break; |
| 60 | default: |
| 61 | panic ("configured too many flash banks!\n"); |
| 62 | break; |
| 63 | } |
| 64 | for (j = 0; j < flash_info[i].sector_count; j++) { |
| 65 | flash_info[i].start[j] = |
| 66 | flashbase + j * MAIN_SECT_SIZE; |
| 67 | } |
| 68 | size += flash_info[i].size; |
| 69 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 70 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 71 | /* Protect monitor and environment sectors |
| 72 | */ |
| 73 | flash_protect (FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 74 | CONFIG_SYS_FLASH_BASE, |
| 75 | CONFIG_SYS_FLASH_BASE + monitor_flash_len - 1, |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 76 | &flash_info[0]); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 77 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 78 | flash_protect (FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 79 | CONFIG_ENV_ADDR, |
| 80 | CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1, &flash_info[0]); |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 81 | |
| 82 | return size; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /*----------------------------------------------------------------------- |
| 86 | */ |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 87 | void flash_print_info (flash_info_t * info) |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 88 | { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 89 | int i, j; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 90 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | for (j = 0; j < CONFIG_SYS_MAX_FLASH_BANKS; j++) { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 92 | switch (info->flash_id & FLASH_VENDMASK) { |
| 93 | case (INTEL_MANUFACT & FLASH_VENDMASK): |
| 94 | printf ("Intel: "); |
| 95 | break; |
| 96 | default: |
| 97 | printf ("Unknown Vendor "); |
| 98 | break; |
| 99 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 100 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 101 | switch (info->flash_id & FLASH_TYPEMASK) { |
| 102 | case (INTEL_ID_28F320J3A & FLASH_TYPEMASK): |
| 103 | printf ("28F320J3A (32Mbit)\n"); |
| 104 | break; |
| 105 | case (INTEL_ID_28F128J3 & FLASH_TYPEMASK): |
| 106 | printf ("28F128J3 (128Mbit)\n"); |
| 107 | break; |
| 108 | default: |
| 109 | printf ("Unknown Chip Type\n"); |
| 110 | goto Done; |
| 111 | break; |
| 112 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 113 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 114 | printf (" Size: %ld MB in %d Sectors\n", |
| 115 | info->size >> 20, info->sector_count); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 116 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 117 | printf (" Sector Start Addresses:"); |
| 118 | for (i = 0; i < info->sector_count; i++) { |
| 119 | if ((i % 5) == 0) { |
| 120 | printf ("\n "); |
| 121 | } |
| 122 | printf (" %08lX%s", info->start[i], |
| 123 | info->protect[i] ? " (RO)" : " "); |
| 124 | } |
| 125 | printf ("\n"); |
| 126 | info++; |
| 127 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 128 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 129 | Done: ; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /*----------------------------------------------------------------------- |
| 133 | */ |
| 134 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 135 | int flash_erase (flash_info_t * info, int s_first, int s_last) |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 136 | { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 137 | int flag, prot, sect; |
| 138 | int rc = ERR_OK; |
Graeme Russ | f8b82ee | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 139 | ulong start; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 140 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 141 | if (info->flash_id == FLASH_UNKNOWN) |
| 142 | return ERR_UNKNOWN_FLASH_TYPE; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 143 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 144 | if ((s_first < 0) || (s_first > s_last)) { |
| 145 | return ERR_INVAL; |
| 146 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 147 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 148 | if ((info->flash_id & FLASH_VENDMASK) != |
| 149 | (INTEL_MANUFACT & FLASH_VENDMASK)) { |
| 150 | return ERR_UNKNOWN_FLASH_VENDOR; |
| 151 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 152 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 153 | prot = 0; |
| 154 | for (sect = s_first; sect <= s_last; ++sect) { |
| 155 | if (info->protect[sect]) { |
| 156 | prot++; |
| 157 | } |
| 158 | } |
| 159 | if (prot) |
| 160 | return ERR_PROTECTED; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 161 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 162 | /* |
| 163 | * Disable interrupts which might cause a timeout |
| 164 | * here. Remember that our exception vectors are |
| 165 | * at address 0 in the flash, and we don't want a |
| 166 | * (ticker) exception to happen while the flash |
| 167 | * chip is in programming mode. |
| 168 | */ |
| 169 | flag = disable_interrupts (); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 170 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 171 | /* Start erase on unprotected sectors */ |
| 172 | for (sect = s_first; sect <= s_last && !ctrlc (); sect++) { |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 173 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 174 | printf ("Erasing sector %2d ... ", sect); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 175 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 176 | /* arm simple, non interrupt dependent timer */ |
Graeme Russ | f8b82ee | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 177 | start = get_timer(0); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 178 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 179 | if (info->protect[sect] == 0) { /* not protected */ |
| 180 | vu_short *addr = (vu_short *) (info->start[sect]); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 181 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 182 | *addr = 0x20; /* erase setup */ |
| 183 | *addr = 0xD0; /* erase confirm */ |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 184 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 185 | while ((*addr & 0x80) != 0x80) { |
Graeme Russ | f8b82ee | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 186 | if (get_timer(start) > |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 187 | CONFIG_SYS_FLASH_ERASE_TOUT) { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 188 | *addr = 0xB0; /* suspend erase */ |
| 189 | *addr = 0xFF; /* reset to read mode */ |
| 190 | rc = ERR_TIMOUT; |
| 191 | goto outahere; |
| 192 | } |
| 193 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 194 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 195 | /* clear status register command */ |
| 196 | *addr = 0x50; |
| 197 | /* reset to read mode */ |
| 198 | *addr = 0xFF; |
| 199 | } |
| 200 | printf ("ok.\n"); |
| 201 | } |
| 202 | if (ctrlc ()) |
| 203 | printf ("User Interrupt!\n"); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 204 | |
| 205 | outahere: |
| 206 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 207 | /* allow flash to settle - wait 10 ms */ |
| 208 | udelay_masked (10000); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 209 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 210 | if (flag) |
| 211 | enable_interrupts (); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 212 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 213 | return rc; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /*----------------------------------------------------------------------- |
| 217 | * Copy memory to flash |
| 218 | */ |
| 219 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 220 | static int write_word (flash_info_t * info, ulong dest, ushort data) |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 221 | { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 222 | vu_short *addr = (vu_short *) dest, val; |
| 223 | int rc = ERR_OK; |
| 224 | int flag; |
Graeme Russ | f8b82ee | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 225 | ulong start; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 226 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 227 | /* Check if Flash is (sufficiently) erased |
| 228 | */ |
| 229 | if ((*addr & data) != data) |
| 230 | return ERR_NOT_ERASED; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 231 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 232 | /* |
| 233 | * Disable interrupts which might cause a timeout |
| 234 | * here. Remember that our exception vectors are |
| 235 | * at address 0 in the flash, and we don't want a |
| 236 | * (ticker) exception to happen while the flash |
| 237 | * chip is in programming mode. |
| 238 | */ |
| 239 | flag = disable_interrupts (); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 240 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 241 | /* clear status register command */ |
| 242 | *addr = 0x50; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 243 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 244 | /* program set-up command */ |
| 245 | *addr = 0x40; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 246 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 247 | /* latch address/data */ |
| 248 | *addr = data; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 249 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 250 | /* arm simple, non interrupt dependent timer */ |
Graeme Russ | f8b82ee | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 251 | start = get_timer(0); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 252 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 253 | /* wait while polling the status register */ |
| 254 | while (((val = *addr) & 0x80) != 0x80) { |
Graeme Russ | f8b82ee | 2011-07-15 23:31:37 +0000 | [diff] [blame] | 255 | if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 256 | rc = ERR_TIMOUT; |
| 257 | /* suspend program command */ |
| 258 | *addr = 0xB0; |
| 259 | goto outahere; |
| 260 | } |
| 261 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 262 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 263 | if (val & 0x1A) { /* check for error */ |
| 264 | printf ("\nFlash write error %02x at address %08lx\n", |
| 265 | (int) val, (unsigned long) dest); |
| 266 | if (val & (1 << 3)) { |
| 267 | printf ("Voltage range error.\n"); |
| 268 | rc = ERR_PROG_ERROR; |
| 269 | goto outahere; |
| 270 | } |
| 271 | if (val & (1 << 1)) { |
| 272 | printf ("Device protect error.\n"); |
| 273 | rc = ERR_PROTECTED; |
| 274 | goto outahere; |
| 275 | } |
| 276 | if (val & (1 << 4)) { |
| 277 | printf ("Programming error.\n"); |
| 278 | rc = ERR_PROG_ERROR; |
| 279 | goto outahere; |
| 280 | } |
| 281 | rc = ERR_PROG_ERROR; |
| 282 | goto outahere; |
| 283 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 284 | |
| 285 | outahere: |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 286 | /* read array command */ |
| 287 | *addr = 0xFF; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 288 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 289 | if (flag) |
| 290 | enable_interrupts (); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 291 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 292 | return rc; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /*----------------------------------------------------------------------- |
| 296 | * Copy memory to flash. |
| 297 | */ |
| 298 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 299 | int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 300 | { |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 301 | ulong cp, wp; |
| 302 | ushort data; |
| 303 | int l; |
| 304 | int i, rc; |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 305 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 306 | wp = (addr & ~1); /* get lower word aligned address */ |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 307 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 308 | /* |
| 309 | * handle unaligned start bytes |
| 310 | */ |
| 311 | if ((l = addr - wp) != 0) { |
| 312 | data = 0; |
| 313 | for (i = 0, cp = wp; i < l; ++i, ++cp) { |
| 314 | data = (data >> 8) | (*(uchar *) cp << 8); |
| 315 | } |
| 316 | for (; i < 2 && cnt > 0; ++i) { |
| 317 | data = (data >> 8) | (*src++ << 8); |
| 318 | --cnt; |
| 319 | ++cp; |
| 320 | } |
| 321 | for (; cnt == 0 && i < 2; ++i, ++cp) { |
| 322 | data = (data >> 8) | (*(uchar *) cp << 8); |
| 323 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 324 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 325 | if ((rc = write_word (info, wp, data)) != 0) { |
| 326 | return (rc); |
| 327 | } |
| 328 | wp += 2; |
| 329 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 330 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 331 | /* |
| 332 | * handle word aligned part |
| 333 | */ |
| 334 | while (cnt >= 2) { |
| 335 | data = *((vu_short *) src); |
| 336 | if ((rc = write_word (info, wp, data)) != 0) { |
| 337 | return (rc); |
| 338 | } |
| 339 | src += 2; |
| 340 | wp += 2; |
| 341 | cnt -= 2; |
| 342 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 343 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 344 | if (cnt == 0) { |
| 345 | return ERR_OK; |
| 346 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 347 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 348 | /* |
| 349 | * handle unaligned tail bytes |
| 350 | */ |
| 351 | data = 0; |
| 352 | for (i = 0, cp = wp; i < 2 && cnt > 0; ++i, ++cp) { |
| 353 | data = (data >> 8) | (*src++ << 8); |
| 354 | --cnt; |
| 355 | } |
| 356 | for (; i < 2; ++i, ++cp) { |
| 357 | data = (data >> 8) | (*(uchar *) cp << 8); |
| 358 | } |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 359 | |
wdenk | 5fa9b39 | 2004-10-09 22:32:26 +0000 | [diff] [blame] | 360 | return write_word (info, wp, data); |
wdenk | ea8015b | 2002-10-26 16:43:06 +0000 | [diff] [blame] | 361 | } |