|
From: Christopher H. <ch...@mu...> - 2003-11-27 08:50:30
|
This is my code, so please stick my name and add an HP copyright on it.
-ch
> -----Original Message-----
> From: blo...@li...
> [mailto:blo...@li...] On
> Behalf Of Russ Dill
> Sent: Thursday, November 27, 2003 12:03 AM
> To: blo...@li...
> Subject: CVS: blob/src/lib cfi16.c,NONE,1.1 cfi32.c,NONE,1.1
> Makefile.am,1.34,1.35
>
>
> Update of /cvsroot/blob/blob/src/lib
> In directory sc8-pr-cvs1:/tmp/cvs-serv9521/src/lib
>
> Modified Files:
> Makefile.am
> Added Files:
> cfi16.c cfi32.c
> Log Message:
> flesh out cfi probing, and only compile it in if requested by
> the arch file
>
> --- NEW FILE: cfi16.c ---
> /*
> * cfi16: CFI functions for 16 bit flash
> *
> * Copyright (C) 2001 Erik Mouw (J.A...@it...)
> * Copyright (C) 1999 Jan-Derk Bakker (J.D...@it...)
> *
> * This program is free software; you can redistribute it
> and/or modify
> * it under the terms of the GNU General Public License as
> published by
> * the Free Software Foundation; either version 2 of the License, or
> * (at your option) any later version.
> *
> * This program is distributed in the hope that it will be useful,
> * but WITHOUT ANY WARRANTY; without even the implied warranty of
> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> * GNU General Public License for more details.
> *
> * You should have received a copy of the GNU General Public License
> * along with this program; if not, write to the Free Software
> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> 02111-1307 USA
> *
> */
>
> #ident "$Id: cfi16.c,v 1.1 2003/11/27 08:02:30 russd Exp $"
>
> #ifdef HAVE_CONFIG_H
> # include <blob/config.h>
> #endif
>
> #include <blob/errno.h>
> #include <blob/flash.h>
> #include <blob/util.h>
> #include <blob/debug.h>
> #include <blob/cfi.h>
>
> /* flash commands for a single 16 bit cfi flash chip */
> #define READ_ARRAY 0x000000FF
> #define READ_QUERY 0x00000098
>
>
> /* automatic descriptor support */
>
> #define MAX_AUTO_DESCRIPTORS 4
> static flash_descriptor_t auto_descriptors[MAX_AUTO_DESCRIPTORS + 1];
>
> int flash_query_descriptors_cfi16(u32 *flashAddr,
> flash_descriptor_t **out) {
> u16 *addr = (u16 *) flashAddr;
> int result, nregions, n;
>
> addr[0x55] = READ_QUERY;
> barrier();
>
> if (addr[0x10] != 'Q' && addr[0x11] != 'R' &&
> addr[0x12] != 'Y') {
> result = -EINVAL;
> goto out;
> }
>
> dprintf("cfi16: manuf_code = %02X\n", addr[CFI16_MANUF_CODE]);
> dprintf("cfi16: device code = %02X\n", addr[CFI16_DEVICE_CODE]);
> dprintf("cfi16: device size = 2^%d bytes\n",
> addr[CFI16_DEVICE_SIZE_LG2]);
>
> nregions = addr[CFI16_ERASE_REGION_COUNT];
>
> #define READ_U16LE(off) ((addr[(off)]) | (addr[(off) + 1]<<8))
>
> for (n = 0; n < nregions && n < MAX_AUTO_DESCRIPTORS; n++) {
> u32 xcount = READ_U16LE(CFI16_ERASE_REGION_XBLKS(n));
> u32 count = xcount + 1;
> u32 xsize = READ_U16LE(CFI16_ERASE_REGION_XSIZE(n));
> u32 size = (xsize == 0) ? 128 : xsize * 256;
>
> dprintf("cfi16: erase region #%d\n", n);
> dprintf("cfi16: count = %d\n", count);
> dprintf("cfi16: size = %d\n", size);
>
> auto_descriptors[n].size = size;
> auto_descriptors[n].num = count;
> auto_descriptors[n].lockable = 1; /* fix me */
> }
>
> #undef READ_U16LE
>
> auto_descriptors[n].size = 0;
> auto_descriptors[n].num = 0;
>
> *out = auto_descriptors;
> result = 0;
>
> out:
> /* put flash back into Read Array mode */
> barrier();
>
> *addr = READ_ARRAY;
> barrier();
>
> return result;
> }
>
> --- NEW FILE: cfi32.c ---
> /*
> * cfi32: CFI functions for 32 bit flash
> *
> * Copyright (C) 2001 Erik Mouw (J.A...@it...)
> * Copyright (C) 1999 Jan-Derk Bakker (J.D...@it...)
> *
> * This program is free software; you can redistribute it
> and/or modify
> * it under the terms of the GNU General Public License as
> published by
> * the Free Software Foundation; either version 2 of the License, or
> * (at your option) any later version.
> *
> * This program is distributed in the hope that it will be useful,
> * but WITHOUT ANY WARRANTY; without even the implied warranty of
> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> * GNU General Public License for more details.
> *
> * You should have received a copy of the GNU General Public License
> * along with this program; if not, write to the Free Software
> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> 02111-1307 USA
> *
> */
>
> #ident "$Id: cfi32.c,v 1.1 2003/11/27 08:02:31 russd Exp $"
>
> #ifdef HAVE_CONFIG_H
> # include <blob/config.h>
> #endif
>
> #include <blob/errno.h>
> #include <blob/flash.h>
> #include <blob/util.h>
> #include <blob/debug.h>
> #include <blob/cfi.h>
>
> /* flash commands for two interleaved 16 bit flash chips */
> #define READ_ARRAY 0x00FF00FF
> #define READ_QUERY 0x00980098
>
>
> /* automatic descriptor support */
>
> #define MAX_AUTO_DESCRIPTORS 4
> static flash_descriptor_t auto_descriptors[MAX_AUTO_DESCRIPTORS + 1];
>
> int flash_query_descriptors_cfi32(u32 *addr,
> flash_descriptor_t **out) {
> int result, nregions, n;
>
> addr[0x55] = READ_QUERY;
> barrier();
>
> if (addr[0x10] != ('Q' | ('Q' << 16)) &&
> addr[0x11] != ('R' | ('R' << 16)) &&
> addr[0x12] != ('Y' | ('Y' << 16))) {
> result = -EINVAL;
> goto out;
> }
>
> dprintf("cfi32: manuf_code = %02X\n",
> addr[CFI32_MANUF_CODE] & 0xff);
> dprintf("cfi32: device code = %02X\n",
> addr[CFI32_DEVICE_CODE] & 0xff);
> dprintf("cfi32: device size = 2^%d bytes\n",
> addr[CFI32_DEVICE_SIZE_LG2] & 0xff);
>
> dprintf("cfi32: manuf_code = %02X\n",
> addr[CFI32_MANUF_CODE] >> 16);
> dprintf("cfi32: device code = %02X\n",
> addr[CFI32_DEVICE_CODE] >> 16);
> dprintf("cfi32: device size = 2^%d bytes\n",
> addr[CFI32_DEVICE_SIZE_LG2] >> 16);
>
> /* From here on out, assume both chips return the same data */
> nregions = addr[CFI32_ERASE_REGION_COUNT] & 0xffff;
>
> #define READ_U16LE(off) ((addr[(off)] & 0xff) |
> ((addr[(off) + 1] & 0xff)<<8))
>
> for (n = 0; n < nregions && n < MAX_AUTO_DESCRIPTORS; n++) {
> u32 xcount = READ_U16LE(CFI32_ERASE_REGION_XBLKS(n));
> u32 count = xcount + 1;
> u32 xsize = READ_U16LE(CFI32_ERASE_REGION_XSIZE(n));
> u32 size = (xsize == 0) ? 128 : xsize * 256;
>
> dprintf("cfi32: erase region #%d\n", n);
> dprintf("cfi32: count = %d\n", count);
> dprintf("cfi32: size = %d\n", size);
>
> auto_descriptors[n].size = size;
> auto_descriptors[n].num = count;
> auto_descriptors[n].lockable = 1; /* fix me */
> }
>
> #undef READ_U32LE
>
> auto_descriptors[n].size = 0;
> auto_descriptors[n].num = 0;
>
> *out = auto_descriptors;
> result = 0;
>
> out:
> /* put flash back into Read Array mode */
> barrier();
>
> *addr = READ_ARRAY;
> barrier();
>
> return result;
> }
>
> Index: Makefile.am
> ===================================================================
> RCS file: /cvsroot/blob/blob/src/lib/Makefile.am,v
> retrieving revision 1.34
> retrieving revision 1.35
> diff -u -d -r1.34 -r1.35
> --- Makefile.am 10 Nov 2003 17:06:41 -0000 1.34
> +++ Makefile.am 27 Nov 2003 08:02:31 -0000 1.35
> @@ -26,6 +26,8 @@
>
>
> libblob_a_SOURCES = \
> + cfi16.c \
> + cfi32.c \
> command.c \
> crc32.c \
> download.c \
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us
> help YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> blob-cvs-commit mailing list blo...@li...
> https://lists.sourceforge.net/lists/listinfo/blob-cvs-commit
>
|