summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/Include/Library/NorFlashInfoLib.h
blob: 9a26159d19d68d49b7b62022a400b68d3c005317 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/** @file
*
*  Copyright (c) 2017 Marvell International Ltd.
*
*  SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/

#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