1 /***************************************************************************
2 * Copyright (C) 2007 by Pavel Chromy *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
27 #define BUFSIZE 1024 /* words, i.e. 4 KiB */
30 void cmd_flash(uint32 cmd)
35 unsigned int bi; /* buffer index */
36 unsigned int bi_start; /* receive start mark */
37 unsigned int bi_end; /* receive end mark */
44 ofs = adr%flash_page_size;
46 bi_end = (ofs + len + 3)/4;
48 if (bi_end > BUFSIZE) {
49 dcc_wr(OCL_BUFF_OVER);
53 chksum = OCL_CHKS_INIT;
54 for (bi = 0; bi < bi_end; bi++) chksum^=buffer[bi]=dcc_rd();
56 if (dcc_rd() != chksum) {
57 dcc_wr(OCL_CHKS_FAIL);
61 /* fill in unused positions with unprogrammed values */
62 for (bi = 0; bi < bi_start; bi++) buffer[bi]=0xffffffff;
63 for (bi = bi_end; bi%flash_page_size; bi++) buffer[bi]=0xffffffff;
66 pagenum = adr/flash_page_size;
67 for (bi = 0; bi < bi_end; bi += flash_page_size/4) {
68 result = flash_page_program(buffer + bi, pagenum++);
72 /* verify written data */
73 if (!result) result = flash_verify(adr, len, ((uint8 *)buffer) + ofs);
75 dcc_wr(OCL_CMD_DONE | result);
85 switch (cmd&OCL_CMD_MASK) {
87 dcc_wr(OCL_CMD_DONE | flash_init());
88 dcc_wr(0x100000); /* base */
89 dcc_wr(flash_page_count*flash_page_size); /* size */
90 dcc_wr(1); /* num_sectors */
91 dcc_wr(4096 | ((unsigned long) flash_page_size << 16)); /* buflen and bufalign */
94 dcc_wr(OCL_CMD_DONE | flash_erase_all());
100 /* unknown command */
106 return(0); /* we shall never get here, just to supress compiler warning */