12#define WRITE_BYTE_CMD 0x10
13#define BLOCK_ERASE_CMD 0x20
14#define CLEAR_STATUS_CMD 0x50
15#define READ_STATUS_CMD 0x70
16#define READ_DEVID_CMD 0x90
17#define BLOCK_ERASE_CONFIRM_CMD 0xd0
18#define READ_ARRAY_CMD 0xff
19#define CLEARED_ARRAY_STATUS 0x00
23VirtHstiQemuFirmwareFlashCheck (
33 for (Offset = 0; Offset < EFI_PAGE_SIZE; Offset++) {
34 Ptr = (UINT8 *)(
UINTN)(Address + Offset);
36 if ((ProbeUint8 != CLEAR_STATUS_CMD) &&
37 (ProbeUint8 != READ_STATUS_CMD) &&
38 (ProbeUint8 != CLEARED_ARRAY_STATUS))
44 if (Offset >= EFI_PAGE_SIZE) {
45 DEBUG ((DEBUG_INFO,
"%a: check failed\n", __func__));
46 return QEMU_FIRMWARE_FLASH_UNKNOWN;
50 *Ptr = CLEAR_STATUS_CMD;
52 if ((OriginalUint8 != CLEAR_STATUS_CMD) &&
53 (ProbeUint8 == CLEAR_STATUS_CMD))
56 DEBUG ((DEBUG_INFO,
"%a: %p behaves as RAM\n", __func__, Ptr));
57 return QEMU_FIRMWARE_FLASH_IS_RAM;
60 *Ptr = READ_STATUS_CMD;
62 if (ProbeUint8 == OriginalUint8) {
63 DEBUG ((DEBUG_INFO,
"%a: %p behaves as ROM\n", __func__, Ptr));
64 return QEMU_FIRMWARE_FLASH_IS_ROM;
67 if (ProbeUint8 == READ_STATUS_CMD) {
69 DEBUG ((DEBUG_INFO,
"%a: %p behaves as RAM\n", __func__, Ptr));
70 return QEMU_FIRMWARE_FLASH_IS_RAM;
73 if (ProbeUint8 == CLEARED_ARRAY_STATUS) {
74 *Ptr = WRITE_BYTE_CMD;
76 *Ptr = READ_STATUS_CMD;
78 *Ptr = READ_ARRAY_CMD;
79 if (ProbeUint8 & 0x10 ) {
80 DEBUG ((DEBUG_INFO,
"%a: %p behaves as FLASH, write-protected\n", __func__, Ptr));
81 return QEMU_FIRMWARE_FLASH_READ_ONLY;
83 DEBUG ((DEBUG_INFO,
"%a: %p behaves as FLASH, writable\n", __func__, Ptr));
84 return QEMU_FIRMWARE_FLASH_WRITABLE;
88 DEBUG ((DEBUG_INFO,
"%a: check failed\n", __func__));
89 return QEMU_FIRMWARE_FLASH_UNKNOWN;
#define DEBUG(Expression)