-
Notifications
You must be signed in to change notification settings - Fork 18
spi flash write operations #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: xtensa-esp8266
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ | |
| #include "qemu/error-report.h" | ||
| #include "bootparam.h" | ||
|
|
||
| #define DEBUG_LOG(...) fprintf(stderr, __VA_ARGS__) | ||
| #define DEBUG_LOG(...) // fprintf(stderr, __VA_ARGS__) | ||
|
|
||
| #define DEFINE_BITS(prefix, reg, field, shift, len) \ | ||
| prefix##_##reg##_##field##_SHIFT = shift, \ | ||
|
|
@@ -372,6 +372,10 @@ enum { | |
|
|
||
| enum { | ||
| ESP8266_SPI_FLASH_BITS(CMD, USR, 18, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, CE, 22, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, BE, 23, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, SE, 24, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, PP, 25, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, WRDI, 29, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, WREN, 30, 1), | ||
| ESP8266_SPI_FLASH_BITS(CMD, READ, 31, 1), | ||
|
|
@@ -422,12 +426,19 @@ static uint64_t esp8266_spi_read(void *opaque, hwaddr addr, unsigned size) | |
| Esp8266SpiState *s = opaque; | ||
|
|
||
| DEBUG_LOG("%s: +0x%02x: ", __func__, (uint32_t)addr); | ||
| if (addr / 4 >= ESP8266_SPI_MAX || addr % 4 || size != 4) { | ||
| if (addr / 4 >= ESP8266_SPI_MAX || addr % 4 || size > 4) { | ||
| DEBUG_LOG("0\n"); | ||
| return 0; | ||
| } | ||
| DEBUG_LOG("0x%08x\n", s->reg[addr / 4]); | ||
| return s->reg[addr / 4]; | ||
| else if (size == 4) { | ||
| DEBUG_LOG("0x%08x\n", s->reg[addr / 4]); | ||
| return s->reg[addr / 4]; | ||
| } | ||
|
|
||
| uint32_t ret = 0; | ||
| memcpy(&ret, s->reg + ESP8266_SPI_FLASH_C0, size); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure about FLASH_C0 here? Specifically, shouldn't it be addr / 4?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake, I changed and tested it. |
||
| DEBUG_LOG("0x%08x\n", ret); | ||
| return ret; | ||
| } | ||
|
|
||
| static void esp8266_spi_cmd(Esp8266SpiState *s, hwaddr addr, | ||
|
|
@@ -458,6 +469,32 @@ static void esp8266_spi_cmd(Esp8266SpiState *s, hwaddr addr, | |
| ESP8266_SPI_GET(s, USER2, COMMAND_VALUE), | ||
| ESP8266_SPI_GET(s, USER2, COMMAND_BITLEN)); | ||
| } | ||
| if (val & ESP8266_SPI_FLASH_CMD_SE) { | ||
| DEBUG_LOG("%s: SECTOR ERASE @0x%08x\n", | ||
| __func__, | ||
| ESP8266_SPI_GET(s, ADDR, OFFSET) & 0xfff); | ||
| memset(s->flash_image + (ESP8266_SPI_GET(s, ADDR, OFFSET) & ~0xfff), 0xff, 4096); | ||
| } | ||
| if (val & ESP8266_SPI_FLASH_CMD_BE) { | ||
| DEBUG_LOG("%s: BLOCK ERASE @0x%08x\n", | ||
| __func__, | ||
| ESP8266_SPI_GET(s, ADDR, OFFSET) & 0xffff); | ||
| memset(s->flash_image + (ESP8266_SPI_GET(s, ADDR, OFFSET) & ~0xffff), 0xff, 65536); | ||
| } | ||
| if (val & ESP8266_SPI_FLASH_CMD_BE) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that should be ESP8266_SPI_FLASH_CMD_CE, right?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course, you are right. Thanks. I changed it. |
||
| DEBUG_LOG("%s: CHIP ERASE\n", | ||
| __func__); | ||
| memset(s->flash_image, 0xff, ESP8266_MAX_FLASH_SZ); | ||
| } | ||
| if (val & ESP8266_SPI_FLASH_CMD_PP) { | ||
| DEBUG_LOG("%s: WRITE FLASH 0x%02x@0x%08x\n", | ||
| __func__, | ||
| ESP8266_SPI_GET(s, ADDR, LENGTH), | ||
| ESP8266_SPI_GET(s, ADDR, OFFSET)); | ||
| memcpy(s->flash_image + ESP8266_SPI_GET(s, ADDR, OFFSET), | ||
| s->reg + ESP8266_SPI_FLASH_C0, | ||
| (ESP8266_SPI_GET(s, ADDR, LENGTH) + 3) & 0x3c); | ||
| } | ||
| } | ||
|
|
||
| static void esp8266_spi_write_ctrl(Esp8266SpiState *s, hwaddr addr, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't really belong here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I disabled it because of so many outputs and forgot to change it back before commit. I changed it.