1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * Flash memory definitions File: dev_newflash.h 5 * 6 * Stuff we use when manipulating flash memory devices. 7 * 8 * Author: Mitch Lichtenberg (mpl@broadcom.com) 9 * 10 ********************************************************************* 11 * 12 * Copyright 2000,2001,2002,2003 13 * Broadcom Corporation. All rights reserved. 14 * 15 * This software is furnished under license and may be used and 16 * copied only in accordance with the following terms and 17 * conditions. Subject to these conditions, you may download, 18 * copy, install, use, modify and distribute modified or unmodified 19 * copies of this software in source and/or binary form. No title 20 * or ownership is transferred hereby. 21 * 22 * 1) Any source code used, modified or distributed must reproduce 23 * and retain this copyright notice and list of conditions 24 * as they appear in the source file. 25 * 26 * 2) No right is granted to use any trade name, trademark, or 27 * logo of Broadcom Corporation. The "Broadcom Corporation" 28 * name may not be used to endorse or promote products derived 29 * from this software without the prior written permission of 30 * Broadcom Corporation. 31 * 32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR 33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 44 * THE POSSIBILITY OF SUCH DAMAGE. 45 ********************************************************************* */ 46 47#ifndef __ASSEMBLER__ 48#include "cfe_device.h" 49#include "cfe_iocb.h" 50#endif 51 52/* ********************************************************************* 53 * Configuration 54 ********************************************************************* */ 55 56/* Bits for compile-time removal of features */ 57#define FLASH_DRIVER_INTEL 1 /* support Intel cmd sets */ 58#define FLASH_DRIVER_AMD 2 /* support AMD cmd sets */ 59#define FLASH_DRIVER_CFI 4 /* support auto probing */ 60#define FLASH_DRIVER_SST 8 /* support for SST cmd sets */ 61 62/* Default value unless overridden in bsp_config.h */ 63#ifndef FLASH_DRIVERS 64#define FLASH_DRIVERS (FLASH_DRIVER_SST | FLASH_DRIVER_INTEL | FLASH_DRIVER_AMD | FLASH_DRIVER_CFI) 65#endif 66 67/* ********************************************************************* 68 * Flash magic numbers 69 ********************************************************************* */ 70 71/* 72 * AMD Flash commands and magic offsets 73 */ 74 75#define AMD_FLASH_MAGIC_ADDR_1 0x555 /* AAA for 16-bit devices in 8-bit mode */ 76#define AMD_FLASH_MAGIC_ADDR_2 0x2AA /* 554 for 16-bit devices in 8-bit mode */ 77 78#define AMD_FLASH_RESET 0xF0 79#define AMD_FLASH_MAGIC_1 0xAA 80#define AMD_FLASH_MAGIC_2 0x55 81#define AMD_FLASH_AUTOSEL 0x90 82#define AMD_FLASH_DEVCODE8 0x2 83#define AMD_FLASH_DEVCODE16 0x1 84#define AMD_FLASH_DEVCODE16B 0x2 85#define AMD_FLASH_MANID 0x0 86#define AMD_FLASH_PROGRAM 0xA0 87#define AMD_FLASH_UNLOCK_BYPASS 0x20 88#define AMD_FLASH_ERASE_3 0x80 89#define AMD_FLASH_ERASE_4 0xAA 90#define AMD_FLASH_ERASE_5 0x55 91#define AMD_FLASH_ERASE_ALL_6 0x10 92#define AMD_FLASH_ERASE_SEC_6 0x30 93 94/* 95 * SST Flash commands and magic offsets 96 */ 97 98#define SST_FLASH_MAGIC_ADDR_1 0x5555 99#define SST_FLASH_MAGIC_ADDR_2 0x2AAA 100 101#define SST_FLASH_RESET 0xF0 102#define SST_FLASH_MAGIC_1 0xAA 103#define SST_FLASH_MAGIC_2 0x55 104#define SST_FLASH_AUTOSEL 0x90 105#define SST_FLASH_DEVCODE8 0x2 106#define SST_FLASH_DEVCODE16 0x1 107#define SST_FLASH_DEVCODE16B 0x2 108#define SST_FLASH_MANID 0x0 109#define SST_FLASH_PROGRAM 0xA0 110#define SST_FLASH_UNLOCK_BYPASS 0x20 111#define SST_FLASH_ERASE_3 0x80 112#define SST_FLASH_ERASE_4 0xAA 113#define SST_FLASH_ERASE_5 0x55 114#define SST_FLASH_ERASE_ALL_6 0x10 115#define SST_FLASH_ERASE_SEC_6 0x30 116 117/* 118 * INTEL Flash commands and magic offsets 119 */ 120 121#define INTEL_FLASH_READ_MODE 0xFF 122#define INTEL_FLASH_ERASE_BLOCK 0x20 123#define INTEL_FLASH_ERASE_CONFIRM 0xD0 124#define INTEL_FLASH_PROGRAM 0x40 125#define INTEL_FLASH_WRITE_BUFFER 0xE8 126#define INTEL_FLASH_WRITE_BUFFER_SIZE 32 127#define INTEL_FLASH_WRITE_CONFIRM 0xD0 128#define INTEL_FLASH_READ_STATUS 0x70 129#define INTEL_FLASH_CONFIG_SETUP 0x60 130#define INTEL_FLASH_LOCK 0x01 131#define INTEL_FLASH_UNLOCK 0xD0 132#define INTEL_FLASH_LOCKDOWN 0x2F 133 134 135/* INTEL Flash commands for 16-bit mode */ 136#define INTEL_FLASH_16BIT_READ_MODE 0xFF00 137#define INTEL_FLASH_16BIT_ERASE_BLOCK 0x2000 138#define INTEL_FLASH_16BIT_ERASE_CONFIRM 0xD000 139#define INTEL_FLASH_16BIT_PROGRAM 0x4000 140#define INTEL_FLASH_8BIT 0 141#define INTEL_FLASH_16BIT 1 142 143 144/* 145 * Common Flash Interface (CFI) commands and offsets 146 */ 147 148#define FLASH_CFI_QUERY_ADDR 0x55 149#define FLASH_CFI_QUERY_MODE 0x98 150#define FLASH_CFI_QUERY_EXIT 0xFF 151 152#define FLASH_CFI_MANUFACTURER 0x00 153#define FLASH_CFI_DEVICE 0x01 154#define FLASH_CFI_SIGNATURE 0x10 155#define FLASH_CFI_QUERY_STRING 0x10 156#define FLASH_CFI_COMMAND_SET 0x13 157#define FLASH_CFI_DEVICE_SIZE 0x27 158#define FLASH_CFI_DEVICE_INTERFACE 0x28 159#define FLASH_CFI_REGION_COUNT 0x2C 160#define FLASH_CFI_REGION_TABLE 0x2D 161 162#define FLASH_CFI_CMDSET_INTEL_ECS 0x0001 /* Intel extended */ 163#define FLASH_CFI_CMDSET_AMD_STD 0x0002 /* AMD Standard */ 164#define FLASH_CFI_CMDSET_INTEL_STD 0x0003 /* Intel Standard */ 165#define FLASH_CFI_CMDSET_AMD_ECS 0x0004 /* AMD Extended */ 166#define FLASH_CFI_CMDSET_SST 0x0701 /* SST Standard */ 167 168#define FLASH_CFI_DEVIF_X8 0x0000 /* 8-bit asynchronous */ 169#define FLASH_CFI_DEVIF_X16 0x0001 /* 16-bit asynchronous */ 170#define FLASH_CFI_DEVIF_X8X16 0x0002 /* 8 or 16-bit with BYTE# pin */ 171#define FLASH_CFI_DEVIF_X32 0x0003 /* 32-bit asynchronous */ 172 173/* 174 * JEDEC offsets 175 */ 176 177#define FLASH_JEDEC_OFFSET_MFR 0 178#define FLASH_JEDEC_OFFSET_DEV 1 179 180/* Vendor-specific flash identifiers */ 181 182#define FLASH_MFR_HYUNDAI 0xAD 183#define FLASH_MFR_AMD 0x01 184 185/* ********************************************************************* 186 * Macros for defining custom sector tables 187 ********************************************************************* */ 188 189#define FLASH_SECTOR_RANGE(nblks,size) (((nblks)-1) << 16) + ((size)/256) 190#define FLASH_SECTOR_NBLKS(x) (((x) >> 16)+1) 191#define FLASH_SECTOR_SIZE(x) (((x) & 0xFFFF)*256) 192#define FLASH_MAXSECTORS 8 193 194/* ********************************************************************* 195 * Flashop engine constants and structures 196 * The flashop engine interprets a little table of commands 197 * to manipulate flash parts - we do this so we can operate 198 * on the flash that we're currently running from. 199 ********************************************************************* */ 200 201/* 202 * Structure of the "instruction" table is six words, 203 * size dependant on the machine word size (32 or 64 bits). 204 * 205 * opcode 206 * flash base 207 * destination 208 * source 209 * length 210 * result 211 */ 212 213#define FEINST_OP _TBLIDX(0) 214#define FEINST_BASE _TBLIDX(1) 215#define FEINST_DEST _TBLIDX(2) 216#define FEINST_SRC _TBLIDX(3) 217#define FEINST_CNT _TBLIDX(4) 218#define FEINST_RESULT _TBLIDX(5) 219#define FEINST_SIZE _TBLIDX(6) /* size of an instruction */ 220 221#ifndef __ASSEMBLER__ 222typedef struct flashinstr_s { /* must match offsets above */ 223 long fi_op; 224 long fi_base; 225 long fi_dest; 226 long fi_src; 227 long fi_cnt; 228 long fi_result; 229} flashinstr_t; 230#endif 231 232/* 233 * Flash opcodes 234 */ 235 236#define FEOP_RETURN 0 /* return to CFE */ 237#define FEOP_REBOOT 1 /* Reboot system */ 238#define FEOP_READ8 2 /* read, 8 bits at a time */ 239#define FEOP_READ16 3 /* read, 16 bits at a time */ 240#define FEOP_CFIQUERY8 4 /* CFI Query 8-bit */ 241#define FEOP_CFIQUERY16 5 /* CFI Query 16-bit */ 242#define FEOP_CFIQUERY16B 6 /* CFI Query 16-bit */ 243#define FEOP_MEMCPY 7 /* generic memcpy */ 244#define FEOP_AMD_ERASE8 8 /* AMD-style 8-bit erase-sector */ 245#define FEOP_AMD_ERASE16 9 /* AMD-style 16-bit erase-sector */ 246#define FEOP_AMD_ERASE16B 10 /* AMD-style 16-bit erase-sector */ 247#define FEOP_AMD_PGM8 11 /* AMD-style 8-bit program */ 248#define FEOP_AMD_PGM16 12 /* AMD-style 16-bit program */ 249#define FEOP_AMD_PGM16B 13 /* AMD-style 16-bit program */ 250#define FEOP_AMD_DEVCODE8 14 /* AMD-style 8-bit Boot Block Info */ 251#define FEOP_AMD_DEVCODE16 15 /* AMD-style 8-bit Boot Block Info */ 252#define FEOP_AMD_DEVCODE16B 16 /* AMD-style 8-bit Boot Block Info */ 253#define FEOP_AMD_MANID8 17 /* AMD-style 8-bit Boot Block Info */ 254#define FEOP_AMD_MANID16 18 /* AMD-style 8-bit Boot Block Info */ 255#define FEOP_AMD_MANID16B 19 /* AMD-style 8-bit Boot Block Info */ 256#define FEOP_INTEL_ERASE8 20 /* Intel-style 8-bit erase-sector */ 257#define FEOP_INTEL_ERASE16 21 /* Intel-style 16-bit erase-sector */ 258#define FEOP_INTEL_PGM8 22 /* Intel-style 8-bit program */ 259#define FEOP_INTEL_PGM16 23 /* Intel-style 16-bit program */ 260#define FEOP_SST_CFIQUERY16 24 /* CFI Query that includes the SST unlock */ 261#define FEOP_SST_ERASE16 25 /* SST-style 16-bit erase-sector */ 262#define FEOP_SST_PGM16 26 /* SST-style 16-bit program */ 263#define FEOP_INTELEXT_ERASE8 27 /* Intel-extended 8-bit erase-sector */ 264#define FEOP_INTELEXT_ERASE16 28 /* Intel-extended 16-bit erase-sector */ 265#define FEOP_INTELEXT_PGM8 29 /* Intel-extended 8-bit program */ 266#define FEOP_INTELEXT_PGM16 30 /* Intel-extended 16-bit program */ 267 268/* 269 * Flashop result values. 270 */ 271 272#define FERES_OK 0 273#define FERES_ERROR -1 274 275 276 277/* ********************************************************************* 278 * Structures 279 ********************************************************************* */ 280 281/* 282 * Flags. If you instantiate the driver with probe_a = physical 283 * address and probe_b = size, you should also OR in the 284 * bus and device width below. 285 */ 286 287#define FLASH_FLG_AUTOSIZE 0x00000002 /* resize to actual device size */ 288#define FLASH_FLG_BUS8 0 289#define FLASH_FLG_BUS16 0x00000004 /* ROM is connected to 16-bit bus */ 290#define FLASH_FLG_DEV8 0 291#define FLASH_FLG_DEV16 0x00000010 /* ROM has 16-bit data width */ 292#define FLASH_FLG_MANUAL 0x00000008 /* Not CFI, manual sectoring */ 293#define FLASH_FLG_MASK 0x000000FF /* mask of probe bits for flags */ 294#define FLASH_SIZE_MASK 0xFFFFFF00 /* mask of probe bits for size */ 295/* you don't have to shift the size, we assume it's in multiples of 256bytes */ 296 297#ifndef __ASSEMBLER__ 298 299/* 300 * Partition structure - use this to define a flash "partition." 301 * The partitions are assigned in order from the beginning of the flash. 302 * The special size '0' means 'fill to end of flash', and you can 303 * have more partitions after that which are aligned with the top 304 * of the flash. 305 * Therefore if you have a 1MB flash and set up 306 * partitions for 256KB, 0, 128KB, the 128KB part will be aligned 307 * to the top of the flash and the middle block will be 768KB. 308 * Partitions can be on byte boundaries. 309 */ 310 311typedef struct newflash_part_t { 312 int fp_size; 313 char *fp_name; 314} newflash_part_t; 315#define FLASH_MAX_PARTITIONS 8 316 317/* 318 * Probe structure - this is used when we want to describe to the flash 319 * driver the layout of our flash, particularly when you want to 320 * manually describe the sectors. 321 */ 322 323typedef struct newflash_probe_t { 324 long flash_phys; /* physical address of flash */ 325 int flash_size; /* total flash size */ 326 int flash_flags; /* flags (FLASH_FLG_xxx) */ 327 int flash_type; /* FLASH_TYPE_xxx */ 328 /* The following are used when manually sectoring */ 329 int flash_cmdset; /* FLASH_CMDSET_xxx */ 330 int flash_nsectors; /* number of ranges */ 331 int flash_sectors[FLASH_MAXSECTORS]; 332 /* This says how many contiguous flash chips are in this region */ 333 int flash_nchips; /* "flash_size" is just for one chip */ 334 /* The following are used for partitioned flashes */ 335 int flash_nparts; /* zero means not partitioned */ 336 newflash_part_t flash_parts[FLASH_MAX_PARTITIONS]; 337 /* The following are used for whacky, weird flashes */ 338 int (*flash_ioctl_hook)(cfe_devctx_t *ctx,iocb_buffer_t *buffer); 339 /* You can replace the flash engine with your own */ 340 int (*flash_engine_hook)(flashinstr_t *prog); 341} newflash_probe_t; 342 343 344/* ********************************************************************* 345 * PRIVATE STRUCTURES 346 * 347 * These structures are actually the "property" of the 348 * flash driver. The only reason a board package might 349 * want to dig around in here is if it implements a hook 350 * or overrides functions to support special, weird flash parts. 351 ********************************************************************* */ 352 353typedef struct flashdev_s flashdev_t; 354 355typedef struct flashpart_s { 356 flashdev_t *fp_dev; 357 int fp_offset; 358 int fp_size; 359} flashpart_t; 360 361#define FLASH_MAX_CFIDATA 256 /* total size of CFI Data */ 362#define FLASH_MAX_INST 8 /* instructions we use during probing */ 363 364struct flashdev_s { 365 newflash_probe_t fd_probe; /* probe information */ 366 367 uint8_t fd_erasefunc; /* Erase routine to use */ 368 uint8_t fd_pgmfunc; /* program routine to use */ 369 uint8_t fd_readfunc; /* Read routine to use */ 370 flashpart_t fd_parts[FLASH_MAX_PARTITIONS]; 371 372 uint8_t *fd_sectorbuffer; /* sector copy buffer */ 373 int fd_ttlsect; /* total sectors on one device */ 374 int fd_ttlsize; /* total size of all devices (flash size * nchips) */ 375 376 int fd_iptr; /* flashop engine instructions */ 377 flashinstr_t *fd_inst; 378}; 379 380 381 382#endif 383 384 385 386