Created
April 4, 2021 20:53
-
-
Save giuliocorradini/d2095d4908659375a13886d186cef4df to your computer and use it in GitHub Desktop.
Dump and check bios for Intel DH61 Motherboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include "SPIMemory.h" | |
| #include <SPI.h> | |
| #include <SD.h> | |
| #define BLOCK_SIZE 1024 | |
| SPIClass hspi(HSPI); | |
| SPIClass vspi(VSPI); | |
| SPIFlash *flash; | |
| File sd_log; | |
| File dump; | |
| struct sd_info { | |
| uint32_t capacity; | |
| int man_id; | |
| uint32_t max_pages; | |
| uint64_t uni_id; | |
| }; | |
| struct sd_info get_flash_info() { | |
| struct sd_info info = { | |
| .capacity = flash->getCapacity(), | |
| .man_id = flash->getManID(), | |
| .max_pages = flash->getMaxPage(), | |
| .uni_id = flash->getUniqueID() | |
| }; | |
| return info; | |
| } | |
| void setup() { | |
| Serial.begin(115200); | |
| while(!Serial); | |
| Serial.println("Welcome to ESP32 serial flasher for Winbond memories"); | |
| Serial.println("Initializing SD card"); | |
| hspi.begin(14, 12, 13, 27); | |
| while(!SD.begin(27, hspi)) { | |
| Serial.println("Card initialization failed."); | |
| Serial.println("Retrying in 50ms..."); | |
| delay(50); | |
| } | |
| Serial.println("Successful SD card initialization"); | |
| //vspi.begin(18, 19, 23, 5); | |
| flash = new SPIFlash((uint8_t)5, &SPI); | |
| flash->begin(); | |
| Serial.println("Initialization done."); | |
| sd_log = SD.open("/chip.txt", FILE_WRITE); | |
| if(sd_log) { | |
| struct sd_info info = get_flash_info(); | |
| sd_log.printf("cap: %ld, pages: %ld, man_id: %d, unique_id: %lld\n", | |
| info.capacity, info.max_pages, info.man_id, info.uni_id | |
| ); | |
| Serial.printf("cap: %ld, pages: %ld, man_id: %d, unique_id: %lld\n", | |
| info.capacity, info.max_pages, info.man_id, info.uni_id | |
| ); | |
| } else { | |
| Serial.println("Error in opening file chip.txt for write."); | |
| abort(); | |
| } | |
| } | |
| void dump_content() { | |
| dump = SD.open("/dump.bin", FILE_WRITE); | |
| uint32_t capacity = flash->getCapacity(); | |
| int nblock = capacity / BLOCK_SIZE; | |
| uint8_t block_content[BLOCK_SIZE]; | |
| Serial.println("Starting dump"); | |
| for(uint32_t i=0; i<nblock; i++) { | |
| flash->readByteArray(i * BLOCK_SIZE, block_content, BLOCK_SIZE); | |
| dump.write(block_content, BLOCK_SIZE); | |
| Serial.printf("Written block %d\n", i); | |
| } | |
| dump.close(); | |
| } | |
| void write_content() { | |
| File target = SD.open("/dh61.BIN", FILE_READ); | |
| if(!target) { | |
| Serial.println("Can't open dh61.BIN from sd card"); | |
| abort(); | |
| } | |
| uint32_t capacity = flash->getCapacity(); | |
| int nblock = capacity / BLOCK_SIZE; | |
| uint8_t block_content[BLOCK_SIZE]; | |
| Serial.println("Starting writing dh61.BIN"); | |
| flash->eraseChip(); | |
| for(uint32_t i=0; i<nblock; i++) { | |
| target.readBytes((char *)block_content, BLOCK_SIZE); | |
| flash->writeByteArray(i * BLOCK_SIZE, block_content, BLOCK_SIZE, true); | |
| Serial.printf("Written block %d\n", i); | |
| } | |
| target.close(); | |
| } | |
| void loop() { | |
| write_content(); | |
| dump_content(); | |
| sd_log.close(); | |
| while(true);; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment