Skip to content
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

Can we have a Bootloader? #44

Open
NoNamedCat opened this issue Mar 14, 2022 · 1 comment
Open

Can we have a Bootloader? #44

NoNamedCat opened this issue Mar 14, 2022 · 1 comment

Comments

@NoNamedCat
Copy link

NoNamedCat commented Mar 14, 2022

I'm thinking of writing a Bootloader for all the emulators.
So... this is what i'm thinking:

*The emulators are in the app0 partition
*The roms are stored using the CrapFS in the app1 partition
*The first time the emulator is launched it copy the roms in the spiffs to the app1 partition....

With the CornN64 fork that uses an SD card to store the roms we can have the spiffs partition free and...

*Use the partition app0 to store the bootloader.
*The bootloader is a menu that read a folder called "emulators", display the binary files and the user select what emulator is going to run
*When an emulator is selected from the SD card, the bootloader copy the binary to the app1 and mark the partition as boot source. Then the bootloader restart the ESP booting the app1 (the emulator) partition.
*When the app1 (the emulator) start, mark the app0 as the boot source. After that it start the emulator.
*The partition for ROMS (CRAPFS) is the FFAT or SPIFFS where the roms are copied from the SD.

Can this work?
Im planning to use this library for writing the Menu:
https://github.com/Roger-random/ESP_8_BIT_composite

And this is the code that i use to switch between the apps partitions:

#include "esp_partition.h"
#include "esp_image_format.h"
#include "esp_flash_partitions.h"
#include "esp_ota_ops.h"

esp_err_t err;

void setup() {
  const esp_partition_t *partition_running = esp_ota_get_running_partition();
  const esp_partition_t *partition_boot = esp_ota_get_boot_partition();
  const esp_partition_t *partition_ota0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL);
  const esp_partition_t *partition_ota1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);

  switch (partition_boot->address) {
    case 0x00010000:
      ESP_LOGI(LOG_TAG_MAIN, "Boot partition: ota_0");
      break;
    case 0x00150000:
      ESP_LOGI(LOG_TAG_MAIN, "Boot partition: ota_1");
      break;

    default:
      ESP_LOGE(LOG_TAG_MAIN, "Boot partition: unknown");
      break;
  }


  switch (partition_running->address) {
    case 0x00010000:
      ESP_LOGI(LOG_TAG_MAIN, "Running partition: ota_0");
      err = esp_ota_set_boot_partition(partition_ota1);
      if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
      }
      else{
        ESP_LOGI(LOG_TAG_MAIN, "esp_ota_set_boot_partition ota_1 OK");
        
      }
      break;
    case 0x00150000:
      ESP_LOGI(LOG_TAG_MAIN, "Running partition: ota_1");
      err = esp_ota_set_boot_partition(partition_ota0);
      if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
      }
      else{
        ESP_LOGI(LOG_TAG_MAIN, "esp_ota_set_boot_partition ota_0 OK");
        
      }
      break;

    default:
      ESP_LOGE(LOG_TAG_MAIN, "Running partition: unknown");
      break;
  }
  delay(5000);
  esp_restart(); 
}

void loop() {
}

@NoNamedCat
Copy link
Author

The code above is just a test for marking the app0 or app1 as a boot source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant