| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2010, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: flash data store abstraction |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | #if !defined(__BFDS_H__) |
|---|
| 24 | #define __BFDS_H__ |
|---|
| 25 | |
|---|
| 26 | /* Flash store handle */ |
|---|
| 27 | typedef struct bfds_state * bfds_handle; |
|---|
| 28 | |
|---|
| 29 | typedef struct bfds_properties { |
|---|
| 30 | unsigned flash_sector_size; /* size of minimum erasable block */ |
|---|
| 31 | unsigned flash_page_size; /* size of maximum writable block */ |
|---|
| 32 | unsigned flash_total_size; /* size of flash */ |
|---|
| 33 | } bfds_properties; |
|---|
| 34 | |
|---|
| 35 | #define BFDS_OK 0 |
|---|
| 36 | #define BFDS_ERROR 1 |
|---|
| 37 | |
|---|
| 38 | /*************************************************************************** |
|---|
| 39 | Summary: |
|---|
| 40 | Open block device. |
|---|
| 41 | |
|---|
| 42 | Description: |
|---|
| 43 | Open block device for reading and writing. |
|---|
| 44 | |
|---|
| 45 | Returns: |
|---|
| 46 | BFDS_OK or BFDS_ERROR on failure. |
|---|
| 47 | |
|---|
| 48 | See Also: |
|---|
| 49 | bfds_close() |
|---|
| 50 | |
|---|
| 51 | ****************************************************************************/ |
|---|
| 52 | int bfds_open ( |
|---|
| 53 | bfds_handle * handle /* [out] return device handle */ |
|---|
| 54 | ); |
|---|
| 55 | |
|---|
| 56 | /*************************************************************************** |
|---|
| 57 | Summary: |
|---|
| 58 | Close block device. |
|---|
| 59 | |
|---|
| 60 | Description: |
|---|
| 61 | Close block device and release resources. |
|---|
| 62 | |
|---|
| 63 | Returns: |
|---|
| 64 | BFDS_OK or BFDS_ERROR on failure. |
|---|
| 65 | |
|---|
| 66 | See Also: |
|---|
| 67 | bfds_open() |
|---|
| 68 | |
|---|
| 69 | ****************************************************************************/ |
|---|
| 70 | int bfds_close( |
|---|
| 71 | bfds_handle handle /* [in] device handle */ |
|---|
| 72 | ); |
|---|
| 73 | |
|---|
| 74 | /*************************************************************************** |
|---|
| 75 | Summary: |
|---|
| 76 | Read from device at offset. |
|---|
| 77 | |
|---|
| 78 | Description: |
|---|
| 79 | Read from device at offset, copying data into the buffer provided. |
|---|
| 80 | |
|---|
| 81 | Returns: |
|---|
| 82 | BFDS_OK or BFDS_ERROR on failure. |
|---|
| 83 | |
|---|
| 84 | See Also: |
|---|
| 85 | bfds_open() |
|---|
| 86 | |
|---|
| 87 | ****************************************************************************/ |
|---|
| 88 | int bfds_read( |
|---|
| 89 | bfds_handle handle, /* [in] device handle */ |
|---|
| 90 | unsigned offset, /* [in] offset in bytes */ |
|---|
| 91 | void * data, /* [out] buffer to copy data into at offset */ |
|---|
| 92 | unsigned size /* [in] size of the buffer */ |
|---|
| 93 | ); |
|---|
| 94 | /*************************************************************************** |
|---|
| 95 | Summary: |
|---|
| 96 | Erase the sector/block at offset. |
|---|
| 97 | |
|---|
| 98 | Description: |
|---|
| 99 | Erase the sector/block at offset. |
|---|
| 100 | |
|---|
| 101 | Returns: |
|---|
| 102 | BFDS_OK or BFDS_ERROR on failure. |
|---|
| 103 | |
|---|
| 104 | See Also: |
|---|
| 105 | bfds_open(), bfds_page_program() |
|---|
| 106 | |
|---|
| 107 | ****************************************************************************/ |
|---|
| 108 | int bfds_sector_erase( |
|---|
| 109 | bfds_handle handle, /* [in] device handle */ |
|---|
| 110 | unsigned offset /* [in] offset in bytes */ |
|---|
| 111 | ); |
|---|
| 112 | /*************************************************************************** |
|---|
| 113 | Summary: |
|---|
| 114 | Program the sector/block at offset. |
|---|
| 115 | |
|---|
| 116 | Description: |
|---|
| 117 | Program the sector/block at offset with the contents of the buffer provided in data. |
|---|
| 118 | Normaly for flash devices bfds_sector_erase should be called prior to any programming. |
|---|
| 119 | |
|---|
| 120 | Returns: |
|---|
| 121 | BFDS_OK or BFDS_ERROR on failure. |
|---|
| 122 | |
|---|
| 123 | See Also: |
|---|
| 124 | bfds_open(), bfds_sector_erase() |
|---|
| 125 | |
|---|
| 126 | ****************************************************************************/ |
|---|
| 127 | int bfds_page_program( |
|---|
| 128 | bfds_handle handle, /* [in] device handle */ |
|---|
| 129 | unsigned offset, /* [in] offset in bytes */ |
|---|
| 130 | void * data, /* [in] buffer to program at offset */ |
|---|
| 131 | unsigned size /* [in] size of the buffer */ |
|---|
| 132 | ); |
|---|
| 133 | /*************************************************************************** |
|---|
| 134 | Summary: |
|---|
| 135 | Retrieve parameters of flash device. |
|---|
| 136 | |
|---|
| 137 | Description: |
|---|
| 138 | Retrieve parameters of flash device such as sector and page sizes. |
|---|
| 139 | |
|---|
| 140 | Returns: |
|---|
| 141 | BFDS_OK or BFDS_ERROR on failure. |
|---|
| 142 | |
|---|
| 143 | See Also: |
|---|
| 144 | bfds_open() |
|---|
| 145 | |
|---|
| 146 | ****************************************************************************/ |
|---|
| 147 | int bfds_get_properties ( |
|---|
| 148 | bfds_handle handle, /* [in] device handle */ |
|---|
| 149 | bfds_properties * properties /* [out] details of flash device */ |
|---|
| 150 | ); |
|---|
| 151 | |
|---|
| 152 | #endif |
|---|