diff options
author | Marcin Wojtas <mw@semihalf.com> | 2017-11-03 18:55:17 +0100 |
---|---|---|
committer | Leif Lindholm <leif.lindholm@linaro.org> | 2017-11-07 15:26:41 +0000 |
commit | 7046610163d3dd0f6b410ae0b3a564917db4ed0a (patch) | |
tree | 8b16ed490aee68012fe13d41708348dabbee82f8 /EmbeddedPkg/Include/Library | |
parent | 62ba0febf517138a01c7a5f6d221ce6a2e4c28b6 (diff) | |
download | edk2-7046610163d3dd0f6b410ae0b3a564917db4ed0a.tar.gz edk2-7046610163d3dd0f6b410ae0b3a564917db4ed0a.tar.bz2 edk2-7046610163d3dd0f6b410ae0b3a564917db4ed0a.zip |
EmbeddedPkg: Implement NorFlashInfoLib
The SPI NOR flash drivers which base on ArmPlatformPkg's
NorFlashDxe usually make use of static declarations of the
flash instances with their type and parameters. As a result
it implies hardcoding the exact way of flash handling, not to
mention the code does not look very nice. Much better solution
would be obtaining the flash ID and hence its description
in runtime.
JEDEC compliant SPI NOR devices allow to obtain their IDs with
READ_ID command (0x9f), which should return the vendor ID byte,
followed by 2 to 4 following device ID bytes. Use this capability
for implementing a NorFlashInfoLib that gives an access to the
NOR flash description data, such as name, page size, sector
(block) size and others, of more than 50 different models.
The new library user should pass an output array from issuing
READ_ID command to the NorFlashGetInfo () routine - if the
match is found, an allocated (optionally for RT) pool with
the flash description copy will be returned.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Diffstat (limited to 'EmbeddedPkg/Include/Library')
-rw-r--r-- | EmbeddedPkg/Include/Library/NorFlashInfoLib.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/EmbeddedPkg/Include/Library/NorFlashInfoLib.h b/EmbeddedPkg/Include/Library/NorFlashInfoLib.h new file mode 100644 index 0000000000..c3761108bc --- /dev/null +++ b/EmbeddedPkg/Include/Library/NorFlashInfoLib.h @@ -0,0 +1,96 @@ +/** @file
+*
+* Copyright (c) 2017 Marvell International Ltd.
+*
+* This program and the accompanying materials
+* are licensed and made available under the terms and conditions of the BSD License
+* which accompanies this distribution. The full text of the license may be found at
+* http://opensource.org/licenses/bsd-license.php
+*
+* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#ifndef __NOR_FLASH_ID_LIB_H__
+#define __NOR_FLASH_ID_LIB_H__
+
+#include <Uefi/UefiBaseType.h>
+
+#define NOR_FLASH_MAX_ID_LEN 6
+
+typedef struct {
+ /* Device name */
+ UINT16 *Name;
+
+ /*
+ * JEDEC ID
+ */
+ UINT8 Id[NOR_FLASH_MAX_ID_LEN];
+ UINT8 IdLen;
+
+ UINT16 PageSize;
+
+ /*
+ * Below parameters can be referred as BlockSize
+ * and BlockCount, when treating the NorFlash as
+ * block device.
+ */
+ UINT32 SectorSize;
+ UINT32 SectorCount;
+
+ UINT16 Flags;
+#define NOR_FLASH_ERASE_4K (1 << 0) /* Use 4 KB erase blocks and CMD_ERASE_4K */
+#define NOR_FLASH_ERASE_32K (1 << 1) /* Use 32 KB erase blocks and CMD_ERASE_32K */
+#define NOR_FLASH_WRITE_FSR (1 << 2) /* Use flag status register for write */
+#define NOR_FLASH_4B_ADDR (1 << 3) /* Use 4B addressing */
+} NOR_FLASH_INFO;
+
+/* Vendor IDs */
+#define NOR_FLASH_ID_ATMEL 0x1f
+#define NOR_FLASH_ID_EON 0x1c
+#define NOR_FLASH_ID_GIGADEVICE 0xc8
+#define NOR_FLASH_ID_ISSI 0x9d
+#define NOR_FLASH_ID_MACRONIX 0xc2
+#define NOR_FLASH_ID_SPANSION 0x01
+#define NOR_FLASH_ID_STMICRO 0x20
+#define NOR_FLASH_ID_SST 0xbf
+#define NOR_FLASH_ID_WINDBOND 0xef
+
+/**
+ Return an allocated copy pool of the NOR flash information structure.
+
+ @param[in] Id Pointer to an array with JEDEC ID obtained
+ from the NOR flash with READ_ID command
+ (0x9f)
+ @param[in out] FlashInfo Pointer to NOR flash information structure
+ @param[in] AllocateForRuntime A flag specifying a type of a copy pool
+ allocation (TRUE for runtime, FALSE for
+ normal)
+
+ @retval EFI_SUCCESS Operation completed successfully
+ @retval EFI_NOT_FOUND No matching entry in NOR ID table found
+ @retval EFI_OUT_OF_RESOURCES No pool memory available
+
+**/
+EFI_STATUS
+EFIAPI
+NorFlashGetInfo (
+ IN UINT8 *Id,
+ IN OUT NOR_FLASH_INFO **FlashInfo,
+ IN BOOLEAN AllocateForRuntime
+ );
+
+/**
+ Print NOR flash information basing on data stored in
+ the NOR_FLASH_INFO structure.
+
+ @param[in] FlashInfo Pointer to NOR flash information structure
+
+**/
+VOID
+EFIAPI
+NorFlashPrintInfo (
+ IN NOR_FLASH_INFO *Info
+ );
+#endif
|