-
Notifications
You must be signed in to change notification settings - Fork 3
/
readnor.c
91 lines (77 loc) · 2.38 KB
/
readnor.c
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
#include <uefi.h>
#define IN
#define OUT
typedef uintn_t EFI_STATUS;
typedef uint32_t UINT32;
typedef uint8_t UINT8;
#define HISI_SPI_FLASH_PROTOCOL_GUID {0x339132DC, 0xCED7, 0x4f84, {0xAA, 0xE7, 0x2E, 0xC4, 0xF9, 0x14, 0x38, 0x2F}}
typedef struct _HISI_SPI_FLASH_PROTOCOL HISI_SPI_FLASH_PROTOCOL;
typedef
EFI_STATUS
(EFIAPI *HISI_SPI_FLASH_ERASE_INTERFACE) (
IN HISI_SPI_FLASH_PROTOCOL *This,
IN UINT32 Offset,
IN UINT32 ulLength
);
typedef
EFI_STATUS
(EFIAPI *HISI_SPI_FLASH_WRITE_INTERFACE) (
IN HISI_SPI_FLASH_PROTOCOL *This,
IN UINT32 Offset,
IN UINT8 *Buffer,
IN UINT32 ulLength
);
typedef
EFI_STATUS
(EFIAPI *HISI_SPI_FLASH_READ_INTERFACE) (
IN HISI_SPI_FLASH_PROTOCOL *This,
IN UINT32 Offset,
IN OUT UINT8 *Buffer,
IN UINT32 ulLength
);
typedef
EFI_STATUS
(EFIAPI *HISI_SPI_FLASH_ERASE_WRITE_INTERFACE) (
IN HISI_SPI_FLASH_PROTOCOL *This,
IN UINT32 Offset,
IN UINT8 *Buffer,
IN UINT32 ulLength
);
struct _HISI_SPI_FLASH_PROTOCOL {
HISI_SPI_FLASH_ERASE_INTERFACE Erase;
HISI_SPI_FLASH_WRITE_INTERFACE Write;
HISI_SPI_FLASH_READ_INTERFACE Read;
HISI_SPI_FLASH_ERASE_WRITE_INTERFACE EraseWrite;
};
int main(int argc, const char **argv) {
int ret;
const efi_guid_t norGuid = HISI_SPI_FLASH_PROTOCOL_GUID;
const char *dst = "dump.bin";
if (argc > 1) {
dst = argv[1];
}
HISI_SPI_FLASH_PROTOCOL *norp;
ret = BS->LocateProtocol((void*)&norGuid, NULL, (void**)&norp);
if (EFI_SUCCESS != ret) {
printf("failed LocateProtocol HISI_SPI_FLASH_PROTOCOL: %d\n", ret);
return 1;
}
printf("LocateProtocol HISI_SPI_FLASH_PROTOCOL success\n");
FILE *fp = fopen(dst, "wb");
if (NULL == fp) {
printf("failed open file %s\n", dst);
return 1;
}
unsigned char buf[4096];
for (uint32_t offset = 0; offset < 16 * 1024 * 1024; offset += sizeof(buf)) {
ret = norp->Read(norp, offset, buf, sizeof(buf));
if (EFI_SUCCESS != ret) {
printf("failed read nor: %d\n", ret);
return 1;
}
fwrite(buf, 1, sizeof(buf), fp);
}
fflush(fp);
fclose(fp);
return 0;
}