Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork217
QSPIFormat: default partition scheme#1058
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
ca1cd95 QSPIFormat: use BlockDevice::get_default_instance()
pennamb9f1b32 QSPIFormat: use mbed namespace
pennam70aa369 added an additional parition for provisioning in QSPIFormat sketch
andreagilardonid6fecc0 QSPIFormat: remove partition scheme selection
pennam35c5c0e removed trailing spaces
andreagilardoni12ed482 erasing MBR table before creating a new partitioning scheme
andreagilardoni236ea5c QSPIFormat: Added confirmation request before reformatting fs
andreagilardoniedeaf3d QSPIFormat: add option to restore WiFi firmware and certificates
pennam45c9eae QSPIFormat: fix warnings
pennam752c1e9 QSPIFlash: add note about LittleFS and OPTA PLC runtime
pennama831fd2 QSPIFormat: add option to perform a full erase
pennamFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
193 changes: 143 additions & 50 deletionslibraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,112 +1,205 @@ | ||
| #include "BlockDevice.h" | ||
| #include "MBRBlockDevice.h" | ||
| #include "LittleFileSystem.h" | ||
| #include "FATFileSystem.h" | ||
| #include "wiced_resource.h" | ||
| #include "certificates.h" | ||
| #ifndef CORE_CM7 | ||
| #error Format QSPI flash by uploading the sketch to the M7 core instead of the M4 core. | ||
| #endif | ||
| using namespace mbed; | ||
| BlockDevice* root = BlockDevice::get_default_instance(); | ||
| MBRBlockDevice wifi_data(root, 1); | ||
| MBRBlockDevice ota_data(root, 2); | ||
| MBRBlockDevice kvstore_data(root, 3); | ||
| MBRBlockDevice user_data(root, 4); | ||
| FATFileSystem wifi_data_fs("wlan"); | ||
| FATFileSystem ota_data_fs("fs"); | ||
| FileSystem * user_data_fs; | ||
| bool waitResponse() { | ||
| bool confirmation = false; | ||
| bool proceed = false; | ||
| while (confirmation == false) { | ||
| if (Serial.available()) { | ||
| char choice = Serial.read(); | ||
| switch (choice) { | ||
| case 'y': | ||
| case 'Y': | ||
| confirmation = true; | ||
| proceed = true; | ||
| break; | ||
| case 'n': | ||
| case 'N': | ||
| confirmation = true; | ||
| proceed = false; | ||
| break; | ||
| default: | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| return proceed; | ||
| } | ||
| void printProgress(uint32_t offset, uint32_t size, uint32_t threshold, bool reset) { | ||
| static int percent_done = 0; | ||
| if (reset == true) { | ||
| percent_done = 0; | ||
| Serial.println("Flashed " + String(percent_done) + "%"); | ||
| } else { | ||
| uint32_t percent_done_new = offset * 100 / size; | ||
| if (percent_done_new >= percent_done + threshold) { | ||
| percent_done = percent_done_new; | ||
| Serial.println("Flashed " + String(percent_done) + "%"); | ||
| } | ||
| } | ||
| } | ||
| void setup() { | ||
| Serial.begin(115200); | ||
| while (!Serial); | ||
| Serial.println("\nWARNING! Running the sketch all the content of the QSPI flash will be erased."); | ||
| Serial.println("The following partitions will be created:"); | ||
| Serial.println("Partition 1: WiFi firmware and certificates 1MB"); | ||
| Serial.println("Partition 2: OTA 5MB"); | ||
| Serial.println("Partition 3: Provisioning KVStore 1MB"); | ||
| Serial.println("Partition 4: User data / OPTA PLC runtime 7MB"), | ||
| Serial.println("Do you want to proceed? Y/[n]"); | ||
| if (true == waitResponse()) { | ||
| if (root->init() != BD_ERROR_OK) { | ||
| Serial.println(F("Error: QSPI init failure.")); | ||
| return; | ||
| } | ||
| Serial.println("Do you want to perform a full erase of the QSPI flash before proceeding? Y/[n]"); | ||
| if (true == waitResponse()) { | ||
| root->erase(0x0, root->size()); | ||
| } else { | ||
| // Erase only the first sector containing the MBR | ||
| root->erase(0x0, root->get_erase_size()); | ||
| } | ||
| MBRBlockDevice::partition(root, 1, 0x0B, 0, 1 * 1024 * 1024); | ||
| MBRBlockDevice::partition(root, 2, 0x0B, 1 * 1024 * 1024, 6 * 1024 * 1024); | ||
| MBRBlockDevice::partition(root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024); | ||
| MBRBlockDevice::partition(root, 4, 0x0B, 7 * 1024 * 1024, 14 * 1024 * 1024); | ||
| // use space from 15.5MB to 16 MB for another fw, memory mapped | ||
| bool reformat = true; | ||
| if(!wifi_data_fs.mount(&wifi_data)) { | ||
| Serial.println("\nPartition 1 already contains a filesystem, do you want to reformat it? Y/[n]"); | ||
| wifi_data_fs.unmount(); | ||
| reformat = waitResponse(); | ||
| } | ||
| if (reformat && wifi_data_fs.reformat(&wifi_data)) { | ||
| Serial.println("Error formatting WiFi partition"); | ||
| return; | ||
| } | ||
| bool restore = true; | ||
| if (reformat) { | ||
| Serial.println("\nDo you want to restore the WiFi firmware and certificates? Y/[n]"); | ||
| restore = waitResponse(); | ||
| } | ||
| if (reformat && restore) { | ||
| flashWiFiFirmwareAndCertificates(); | ||
| } | ||
| reformat = true; | ||
| if(!ota_data_fs.mount(&ota_data)) { | ||
| Serial.println("\nPartition 2 already contains a filesystem, do you want to reformat it? Y/[n]"); | ||
| ota_data_fs.unmount(); | ||
| reformat = waitResponse(); | ||
| } | ||
| if (reformat && ota_data_fs.reformat(&ota_data)) { | ||
| Serial.println("Error formatting OTA partition"); | ||
| return; | ||
| } | ||
| Serial.println("\nDo you want to use LittleFS to format user data partition? Y/[n]"); | ||
| Serial.println("If No, FatFS will be used to format user partition."); | ||
| Serial.println("Note: LittleFS is not supported by the OPTA PLC runtime."); | ||
| if (true == waitResponse()) { | ||
| Serial.println("Formatting user partition with LittleFS."); | ||
| user_data_fs = new mbed::LittleFileSystem("user"); | ||
| } else { | ||
| Serial.println("Formatting user partition with FatFS."); | ||
| user_data_fs = new mbed::FATFileSystem("user"); | ||
| } | ||
| reformat = true; | ||
| if(!user_data_fs->mount(&user_data)) { | ||
| Serial.println("\nPartition 4 already contains a filesystem, do you want to reformat it? Y/[n]"); | ||
| user_data_fs->unmount(); | ||
| reformat = waitResponse(); | ||
| } | ||
| if (reformat && user_data_fs->reformat(&user_data)) { | ||
| Serial.println("Error formatting user partition"); | ||
| return; | ||
| } | ||
| Serial.println("\nQSPI Flash formatted!"); | ||
| } | ||
| Serial.println("It's now safe to reboot or disconnect your board."); | ||
| } | ||
| void flashWiFiFirmwareAndCertificates() { | ||
| extern const unsigned char wifi_firmware_image_data[]; | ||
| FILE* fp = fopen("/wlan/4343WA1.BIN", "wb"); | ||
| const uint32_t file_size = 421098; | ||
| uint32_t chunck_size = 1024; | ||
| uint32_t byte_count = 0; | ||
| Serial.println("Flashing WiFi firmware"); | ||
| printProgress(byte_count, file_size, 10, true); | ||
| while (byte_count < file_size) { | ||
| if(byte_count + chunck_size > file_size) | ||
| chunck_size = file_size - byte_count; | ||
| int ret = fwrite(&wifi_firmware_image_data[byte_count], chunck_size, 1, fp); | ||
| if (ret != 1) { | ||
| Serial.println("Error writing firmware data"); | ||
| break; | ||
| } | ||
| byte_count += chunck_size; | ||
| printProgress(byte_count, file_size, 10, false); | ||
| } | ||
| fclose(fp); | ||
| fp = fopen("/wlan/cacert.pem", "wb"); | ||
| Serial.println("Flashing certificates"); | ||
| chunck_size = 128; | ||
| byte_count = 0; | ||
| printProgress(byte_count, cacert_pem_len, 10, true); | ||
| while (byte_count < cacert_pem_len) { | ||
| if(byte_count + chunck_size > cacert_pem_len) | ||
| chunck_size = cacert_pem_len - byte_count; | ||
| int ret = fwrite(&cacert_pem[byte_count], chunck_size, 1 ,fp); | ||
| if (ret != 1) { | ||
| Serial.println("Error writing certificates"); | ||
| break; | ||
| } | ||
| byte_count += chunck_size; | ||
| printProgress(byte_count, cacert_pem_len, 10, false); | ||
| } | ||
| fclose(fp); | ||
| } | ||
| void loop() { | ||
| } |
1 change: 1 addition & 0 deletionslibraries/STM32H747_System/examples/QSPIFormat/certificates.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../WiFiFirmwareUpdater/certificates.h |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.