diff --git a/.github/workflows/firmware.yml b/.github/workflows/firmware.yml index ffafdcd2..ec8f497a 100644 --- a/.github/workflows/firmware.yml +++ b/.github/workflows/firmware.yml @@ -32,7 +32,7 @@ jobs: ./.pio key: ${{ runner.os }}-keira - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: '3.12' @@ -98,12 +98,14 @@ jobs: PLATFORMIO_BUILD_FLAGS=-D$lang pio run -e v2 cp .pio/build/v2/firmware.bin out/keira_${lang}.bin cp .pio/build/v2/partitions.bin out/partitions.bin - cp .pio/build/v2/bootloader.bin out/bootloader.bin + cp boot/lilka_v2/bootloader.bin out/bootloader.bin pip install esptool + # boot_app0.bin is a blank otadata: the board starts Keira (app0) after flashing esptool.py --chip esp32s3 merge_bin \ -o out/KeiraOS_merged_${lang}.bin \ 0x0 out/bootloader.bin \ 0x8000 out/partitions.bin \ + 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin \ 0x10000 out/keira_${lang}.bin done else @@ -111,12 +113,13 @@ jobs: pio run -e v2 cp .pio/build/v2/firmware.bin out/keira.bin cp .pio/build/v2/partitions.bin out/partitions.bin - cp .pio/build/v2/bootloader.bin out/bootloader.bin + cp boot/lilka_v2/bootloader.bin out/bootloader.bin pip install esptool esptool.py --chip esp32s3 merge_bin \ -o out/KeiraOS_merged.bin \ 0x0 out/bootloader.bin \ 0x8000 out/partitions.bin \ + 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin \ 0x10000 out/keira.bin fi diff --git a/README.md b/README.md index ce9986bb..60b59223 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ KeiraOS, операційна система для консолей [![Lilka](h ## 🛠️ Як прошити Lilka (KeiraOS) +Найпростіше прошити Лілку через [flasher.lilka.dev](https://flasher.lilka.dev/): виберіть версію, підключіть Лілку і натисніть «Прошити». + +`KeiraOS_merged*.bin` містить Keira разом із boot-меню та таблицею розділів [lilka-bootloader](https://github.com/lilka-dev/lilka-bootloader): +- затисніть **START** під час увімкнення, щоб вибрати Keira OS, Retro-Go або прошивку з SD-картки; +- Retro-Go встановлюється з самої Keira: відкрийте `retro-go_lilka.img` у файловому менеджері. + +Детальніше: [boot/README.md](boot/README.md). Нижче — прошивка вручну через ESPTool. + ### 1. Відкрити інструмент прошивки Перейдіть на сторінку [ESPTool (в браузері)](https://espressif.github.io/esptool-js/) > ⚠️ Працює лише в Google Chrome або Chromium-браузерах. diff --git a/boot/README.md b/boot/README.md new file mode 100644 index 00000000..beeffd5e --- /dev/null +++ b/boot/README.md @@ -0,0 +1,27 @@ +# Boot menu and partition table + +Keira for Lilka v2 is built with the boot menu and the partition table from +[lilka-bootloader](https://github.com/lilka-dev/lilka-bootloader) instead of the stock Arduino ones +(see `platformio.ini`). They're the same on every board, so `KeiraOS_merged*.bin` from the releases +writes all of it at `0x0`, e.g. with [flasher.lilka.dev](https://flasher.lilka.dev/). + +- `lilka_v2/bootloader.bin`: boot menu (hold START on reset): Keira OS, Retro-Go, firmware from the SD card +- `lilka_v2/partitions.csv`: Keira `app0`/`app1`, Retro-Go apps, SPIFFS + +Retro-Go is installed from Keira: open `retro-go_lilka.img` from the SD card (or the catalog) in the +file manager. + +Boards flashed with the stock layout keep it on OTA updates (only the app is updated); flash +`KeiraOS_merged*.bin` once over USB to switch. + +## Updating + +Built from lilka-bootloader `b070661`: + +```bash +make bootloader # in lilka-bootloader +cp bootloader/build-docker/bootloader/bootloader.bin /boot/lilka_v2/ +cp partitions.csv /boot/lilka_v2/ +``` + +Keep this file's commit reference in sync. diff --git a/boot/bootloader.py b/boot/bootloader.py new file mode 100644 index 00000000..eb5323ee --- /dev/null +++ b/boot/bootloader.py @@ -0,0 +1,10 @@ +# PlatformIO pre-script: build Keira with the lilka-bootloader boot menu (see boot/README.md). +# `board_build.arduino.custom_bootloader` is resolved inside the framework's variants dir, +# so pass it as an absolute path. +from os.path import join + +Import("env") + +env.BoardConfig().update( + "build.arduino.custom_bootloader", join(env.subst("$PROJECT_DIR"), "boot", "lilka_v2", "bootloader.bin") +) diff --git a/boot/lilka_v2/bootloader.bin b/boot/lilka_v2/bootloader.bin new file mode 100644 index 00000000..2e7cee09 Binary files /dev/null and b/boot/lilka_v2/bootloader.bin differ diff --git a/boot/lilka_v2/partitions.csv b/boot/lilka_v2/partitions.csv new file mode 100644 index 00000000..c9165ba3 --- /dev/null +++ b/boot/lilka_v2/partitions.csv @@ -0,0 +1,16 @@ +# Lilka v2 (16 MB): Keira OS + Keira multiboot slot + Retro-Go, booted by lilka_boot. +# Retro-Go finds its apps by label, Keira expects app0/app1 as ota_0/ota_1. +# Name, Type, SubType, Offset, Size +nvs, data, nvs, 0x9000, 0x5000 +otadata, data, ota, 0xe000, 0x2000 +app0, app, ota_0, 0x10000, 0x400000 +app1, app, ota_1, 0x410000, 0x300000 +launcher, app, ota_2, 0x710000, 0x100000 +retro-core, app, ota_3, 0x810000, 0xd0000 +prboom-go, app, ota_4, 0x8e0000, 0xd0000 +snes9x, app, ota_5, 0x9b0000, 0xa0000 +gwenesis, app, ota_6, 0xa50000, 0x100000 +fmsx, app, ota_7, 0xb50000, 0xa0000 +gbsp, app, ota_8, 0xbf0000, 0xd0000 +spiffs, data, spiffs, 0xcc0000, 0x330000 +coredump, data, coredump, 0xff0000, 0x10000 diff --git a/platformio.ini b/platformio.ini index 5912e552..f40444d9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -36,7 +36,11 @@ lib_deps = bitbank2/AnimatedGIF@2.1.0 bitbank2/JPEGDEC@1.8.4 lib_extra_dirs = ./lib -extra_scripts = targets.py +; Boot menu + partition table shared with Retro-Go, see boot/README.md +extra_scripts = + pre:boot/bootloader.py + targets.py +board_build.partitions = boot/lilka_v2/partitions.csv build_flags = -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 diff --git a/src/apps/flashimage/flashimage.cpp b/src/apps/flashimage/flashimage.cpp new file mode 100644 index 00000000..7663a88c --- /dev/null +++ b/src/apps/flashimage/flashimage.cpp @@ -0,0 +1,151 @@ +#include "flashimage.h" +#include "keira/keira.h" +#include "keira/ksystem.h" +#include "keira/utils/defer.h" +#include "keira/utils/string.h" + +#include + +// Layout of a full ESP32 flash image: partition table entries at 0x8000 +static constexpr uint32_t IMAGE_PARTITION_TABLE_OFFSET = 0x8000; +static constexpr uint16_t IMAGE_PARTITION_MAGIC = 0x50AA; +static constexpr size_t IMAGE_PARTITION_MAX_ENTRIES = 95; +static constexpr uint8_t IMAGE_PARTITION_TYPE_APP = 0x00; +static constexpr size_t FLASH_SECTOR_SIZE = 4096; + +struct __attribute__((packed)) ImagePartitionEntry { + uint16_t magic; + uint8_t type; + uint8_t subtype; + uint32_t offset; + uint32_t size; + char label[16]; + uint32_t flags; +}; + +static_assert(sizeof(ImagePartitionEntry) == 32, "partition table entry is 32 bytes"); + +FlashImageApp::FlashImageApp(const String& path) : App("FlashImage"), path(path) { + setktStackSize(8192); +} + +bool FlashImageApp::isFlashImage(const String& path) { + FILE* file = fopen(path.c_str(), "rb"); + if (!file) return false; + Defer closeFile([file]() { fclose(file); }); + + ImagePartitionEntry entry; + return fseek(file, IMAGE_PARTITION_TABLE_OFFSET, SEEK_SET) == 0 && fread(&entry, sizeof(entry), 1, file) == 1 && + entry.magic == IMAGE_PARTITION_MAGIC; +} + +bool FlashImageApp::collectParts(FILE* file, std::vector& parts) { + if (fseek(file, 0, SEEK_END) != 0) return false; + uint32_t fileSize = ftell(file); + if (fseek(file, IMAGE_PARTITION_TABLE_OFFSET, SEEK_SET) != 0) return false; + + std::vector entries; + ImagePartitionEntry entry; + while (entries.size() < IMAGE_PARTITION_MAX_ENTRIES && fread(&entry, sizeof(entry), 1, file) == 1 && + entry.magic == IMAGE_PARTITION_MAGIC) { + entries.push_back(entry); + } + + const esp_partition_t* running = esp_ota_get_running_partition(); + for (const auto& e : entries) { + if (e.type != IMAGE_PARTITION_TYPE_APP || e.offset >= fileSize) continue; + char label[sizeof(e.label) + 1] = {0}; + memcpy(label, e.label, sizeof(e.label)); + + // Only apps that have a home in Keira's partition table, and never Keira itself + const esp_partition_t* target = + esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, label); + if (!target || target == running) continue; + + uint32_t size = std::min(e.size, fileSize - e.offset); + if (size > target->size) { + error = StringFormat(K_S_FLASHIMAGE_TOO_BIG_FMT, label); + return false; + } + parts.push_back({target, e.offset, size}); + } + if (parts.empty()) { + error = K_S_FLASHIMAGE_NO_PARTS; + return false; + } + return true; +} + +bool FlashImageApp::writePart(FILE* file, const ImagePart& part, uint32_t& written, uint32_t total) { + uint32_t eraseSize = (part.size + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE * FLASH_SECTOR_SIZE; + esp_err_t err = esp_partition_erase_range(part.target, 0, eraseSize); + if (err != ESP_OK || fseek(file, part.offset, SEEK_SET) != 0) { + error = StringFormat(K_S_FLASHIMAGE_WRITE_ERROR_FMT, part.target->label, esp_err_to_name(err)); + return false; + } + + uint8_t* buf = static_cast(calloc(1, FLASH_SECTOR_SIZE)); + if (!buf) { + error = StringFormat(K_S_FLASHIMAGE_WRITE_ERROR_FMT, part.target->label, esp_err_to_name(ESP_ERR_NO_MEM)); + return false; + } + Defer freeBuf([buf]() { free(buf); }); + + lilka::ProgressDialog dialog(K_S_FLASHIMAGE_TITLE, part.target->label); + for (uint32_t off = 0; off < part.size; off += FLASH_SECTOR_SIZE) { + size_t chunk = std::min(FLASH_SECTOR_SIZE, part.size - off); + if (fread(buf, 1, chunk, file) != chunk) { + error = StringFormat(K_S_FLASHIMAGE_WRITE_ERROR_FMT, part.target->label, "read"); + return false; + } + err = esp_partition_write(part.target, off, buf, chunk); + if (err != ESP_OK) { + error = StringFormat(K_S_FLASHIMAGE_WRITE_ERROR_FMT, part.target->label, esp_err_to_name(err)); + return false; + } + written += chunk; + dialog.setProgress(static_cast(written) * 100 / total); + dialog.draw(canvas); + queueDraw(); + } + return true; +} + +void FlashImageApp::run() { + FILE* file = fopen(path.c_str(), "rb"); + if (!file) { + alert(K_S_ERROR, StringFormat(K_S_FLASHIMAGE_WRITE_ERROR_FMT, path.c_str(), strerror(errno))); + return; + } + Defer closeFile([file]() { fclose(file); }); + + std::vector parts; + if (!collectParts(file, parts)) { + alert(K_S_ERROR, error); + return; + } + + String labels; + uint32_t total = 0; + for (const auto& part : parts) { + labels += (labels.isEmpty() ? "" : ", ") + String(part.target->label); + total += part.size; + } + String about = + StringFormat(K_S_FLASHIMAGE_CONFIRM_FMT, labels.c_str(), lilka::fileutils.getHumanFriendlySize(total).c_str()); + if (!confirm(K_S_FLASHIMAGE_TITLE, about)) return; + + uint32_t written = 0; + for (const auto& part : parts) { + if (!writePart(file, part, written, total)) { + alert(K_S_ERROR, error); + return; + } + } + + // Image's first app is its entry point (e.g. Retro-Go's launcher) + const esp_partition_t* entry = parts.front().target; + if (confirm(K_S_FLASHIMAGE_TITLE, StringFormat(K_S_FLASHIMAGE_DONE_FMT, entry->label))) { + KeiraSystem::bootPartition(entry); + } +} diff --git a/src/apps/flashimage/flashimage.h b/src/apps/flashimage/flashimage.h new file mode 100644 index 00000000..9973c876 --- /dev/null +++ b/src/apps/flashimage/flashimage.h @@ -0,0 +1,30 @@ +#pragma once +#include "keira/app.h" + +#include +#include + +// Installs the apps of a full flash image (e.g. retro-go_*_lilka.img) into the partitions with the +// same labels. The image's bootloader and partition table are ignored, Keira itself is never touched. +class FlashImageApp : public App { +public: + explicit FlashImageApp(const String& path); + + // True when the file looks like a full flash image (partition table at 0x8000) + static bool isFlashImage(const String& path); + + void run() override; + +private: + struct ImagePart { + const esp_partition_t* target; + uint32_t offset; // in the image file + uint32_t size; + }; + + bool collectParts(FILE* file, std::vector& parts); + bool writePart(FILE* file, const ImagePart& part, uint32_t& written, uint32_t total); + + String path; + String error; +}; diff --git a/src/apps/fmanager/fmanager.cpp b/src/apps/fmanager/fmanager.cpp index ecb62d98..6881a917 100644 --- a/src/apps/fmanager/fmanager.cpp +++ b/src/apps/fmanager/fmanager.cpp @@ -305,7 +305,7 @@ FMEntry FileManagerApp::pathToEntry(const String& path) { newEntry.type = FT_NES_ROM; newEntry.icon = FT_NES_ICON; newEntry.color = FT_NES_ROM_COLOR; - } else if (lowerCasedPath.endsWith(".bin")) { + } else if (lowerCasedPath.endsWith(".bin") || lowerCasedPath.endsWith(".img")) { newEntry.type = FT_BIN; newEntry.icon = FT_BIN_ICON; newEntry.color = FT_BIN_COLOR; diff --git a/src/apps/keiraupdate/keiraupdate.cpp b/src/apps/keiraupdate/keiraupdate.cpp index 50637a6e..4f8396a0 100644 --- a/src/apps/keiraupdate/keiraupdate.cpp +++ b/src/apps/keiraupdate/keiraupdate.cpp @@ -182,6 +182,12 @@ void KeiraUpdateApp::install(const FirmwareVersion& fw) { httpConfig.buffer_size_tx = KEIRA_UPDATE_TX_BUFFER; httpConfig.keep_alive_enable = true; + // esp_https_ota always writes the next OTA partition, which isn't Keira's when other apps share the flash + if (esp_ota_get_next_update_partition(NULL) != KeiraSystem::getUpdatePartition()) { + alert(K_S_ERROR, K_S_KEIRA_UPDATE_SLOT_ERROR); + return; + } + esp_https_ota_config_t otaConfig = {}; otaConfig.http_config = &httpConfig; diff --git a/src/apps/launcher/launcher.cpp b/src/apps/launcher/launcher.cpp index 60b1faf6..45d547f5 100644 --- a/src/apps/launcher/launcher.cpp +++ b/src/apps/launcher/launcher.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "keira/utils/mem.h" #include "keira/keira.h" #include "launcher.h" @@ -68,6 +69,9 @@ #include "keira/ksystem.h" #include "keira/utils/string.h" +// Partition label of Retro-Go's launcher (see boot/lilka_v2/partitions.csv) +static constexpr const char* RETRO_GO_PARTITION = "launcher"; + // Home screen wallpaper, Lua script takes priority over images, first existing image is used static const char* const WALLPAPER_LUA_PATH = "/sd/wallpaper.lua"; static const char* const WALLPAPER_PATHS[] = @@ -146,6 +150,17 @@ void LauncherApp::run() { appsItems.insert(appsItems.begin(), ITEM::APP(lastOTA.c_str(), [this]() { this->runApp(); })); } + // Retro-Go installed next to Keira (see FlashImageApp) has its launcher in its own partition. + // The app description check skips empty partitions and leftovers of an older layout. + const esp_partition_t* retroGo = + esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, RETRO_GO_PARTITION); + esp_app_desc_t retroGoDesc; + if (retroGo && esp_ota_get_partition_description(retroGo, &retroGoDesc) == ESP_OK) { + appsItems.insert(appsItems.begin(), ITEM::APP(K_S_LAUNCHER_RETRO_GO, [retroGo]() { + KeiraSystem::bootPartition(retroGo); + })); + } + item_t root_item = ITEM::SUBMENU( K_S_LAUNCHER_MAIN_MENU, { diff --git a/src/apps/lilcatalog/lilcatalog.cpp b/src/apps/lilcatalog/lilcatalog.cpp index 2b543200..f42b4fb8 100644 --- a/src/apps/lilcatalog/lilcatalog.cpp +++ b/src/apps/lilcatalog/lilcatalog.cpp @@ -897,7 +897,7 @@ ExecutionType LilCatalogApp::detectTypeByExtension(const String& location) { String loc = location; loc.toLowerCase(); if (loc.endsWith(".lua")) return EXEC_TYPE_LUA; - if (loc.endsWith(".bin")) return EXEC_TYPE_BINARY; + if (loc.endsWith(".bin") || loc.endsWith(".img")) return EXEC_TYPE_BINARY; if (loc.endsWith(".so")) return EXEC_TYPE_DYNAPP; if (loc.endsWith(".zip") || loc.endsWith(".tar") || loc.endsWith(".gz")) return EXEC_TYPE_ARCHIVE; return EXEC_TYPE_UNKNOWN; diff --git a/src/keira/keira.h b/src/keira/keira.h index 4b9c10f1..d13dbfc4 100644 --- a/src/keira/keira.h +++ b/src/keira/keira.h @@ -30,6 +30,7 @@ #include "apps/nes/nesapp.h" #include "apps/dynapp/dynapp.h" #include "apps/multiboot/multiboot.h" +#include "apps/flashimage/flashimage.h" #include "apps/imageviewer/imageviewer.h" /////////////////////////////////////////////////////////////////////////////////////////////////////// // FILETYPE HANDLERS: //////////////////////////////////////////////////////////////////////////////// @@ -39,8 +40,9 @@ #define K_FT_SOUND_HANDLER(X) ksystem.apps.spawn(new MadPlayerApp(X)) #define K_FT_LT_HANDLER(X) ksystem.apps.spawn(new LilTrackerApp(X)) #define K_FT_SO_HANDLER(X) ksystem.apps.spawn(new DynApp(X)) -#define K_FT_BIN_HANDLER(X) ksystem.apps.spawn(new MultiBootApp(X)) -#define K_FT_IMAGE_HANDLER(X) ksystem.apps.spawn(new ImageViewerApp(X)) +#define K_FT_BIN_HANDLER(X) \ + ksystem.apps.spawn(FlashImageApp::isFlashImage(X) ? static_cast(new FlashImageApp(X)) : new MultiBootApp(X)) +#define K_FT_IMAGE_HANDLER(X) ksystem.apps.spawn(new ImageViewerApp(X)) /////////////////////////////////////////////////////////////////////////////////////////////////////// // GUIDELINE: Use Keira global filetype handlers(K_FT_) if possible diff --git a/src/keira/ksystem.cpp b/src/keira/ksystem.cpp index f3e27673..ab150385 100644 --- a/src/keira/ksystem.cpp +++ b/src/keira/ksystem.cpp @@ -3,6 +3,7 @@ // Boot: #include #include +#include // Services: #ifdef KEIRA_WATCHDOG @@ -36,9 +37,6 @@ // Utils: #include "keira/utils/string.h" -// VFS -#include "keira/vfs/spiram/spiram.h" - ////////////////////////////////////////////////////////////////////////////// // GUIDELINE: external libraries to use <> in includes ////////////////////////////////////////////////////////////////////////////// @@ -176,9 +174,25 @@ void KeiraSystem::verifyOTA() { } } +const esp_partition_t* KeiraSystem::getUpdatePartition() { + const esp_partition_t* running = esp_ota_get_running_partition(); + const char* other = strcmp(running->label, "app0") == 0 ? "app1" : "app0"; + return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, other); +} + +void KeiraSystem::bootPartition(const esp_partition_t* partition) { + esp_err_t err = esp_ota_set_boot_partition(partition); + if (err != ESP_OK) { + lilka::serial.err("Failed to set boot partition %s: %s", partition->label, esp_err_to_name(err)); + return; + } + esp_restart(); +} + void KeiraSystem::registerFileSystems() { - // TODO:To be registered as a system unit - this->vfs.push_back(new SPIRamVFS(LILKA_TMP_ROOT)); + // SPIRamVFS (/tmp) isn't registered: ESP-IDF 4.4 has only 8 VFS slots (VFS_MAX_COUNT), + // console + stdio + SD + SPIFFS + RootVFS + lwip sockets already take all of them. + // TODO: register it again once a slot is free (e.g. by serving /tmp from RootVFS) // Prepare RootVFS. Better to register it last this->rootVFS = new RootVFS(""); @@ -211,6 +225,13 @@ void KeiraSystem::showStartupScreen() { // Prepare system to launch void KeiraSystem::setup() { + // Init the network stack before any filesystem gets mounted: lwip sockets take one of the 8 + // VFS slots, and WiFi aborts on start if the filesystems have used them all up + esp_err_t err = esp_netif_init(); + if (err != ESP_OK) { + lilka::serial.err("esp_netif_init failed: %s", esp_err_to_name(err)); + } + // Init Hardware lilka::begin(); diff --git a/src/keira/ksystem.h b/src/keira/ksystem.h index 805b61ac..6dc48ce7 100644 --- a/src/keira/ksystem.h +++ b/src/keira/ksystem.h @@ -13,6 +13,7 @@ #include "keira/appmanager.h" // Libraries #include +#include //#include // VFS(Virtual File Systems): @@ -44,6 +45,16 @@ class KeiraSystem { return version; } + //======================================================================== + // Boot partitions + //======================================================================== + // Slot to update Keira into: the other one of app0/app1. Don't rely on + // esp_ota_get_next_update_partition(): with other apps sharing the flash + // (e.g. Retro-Go next to Keira) the next OTA partition may belong to them. + static const esp_partition_t* getUpdatePartition(); + // Restart into another app installed in its own OTA partition + static void bootPartition(const esp_partition_t* partition); + //======================================================================== // Arduino-like entry points //======================================================================== diff --git a/src/keira/localizations/lang_en.h b/src/keira/localizations/lang_en.h index 21812d10..94194170 100644 --- a/src/keira/localizations/lang_en.h +++ b/src/keira/localizations/lang_en.h @@ -81,6 +81,7 @@ #define K_S_LAUNCHER_LILCATALOG "LilCatalogue" #define K_S_LAUNCHER_LILTRACKER "LilTracker" #define K_S_LAUNCHER_LETRIS "Letris" +#define K_S_LAUNCHER_RETRO_GO "Retro-Go" #define K_S_LAUNCHER_TAMAGOTCHI "Tamagotchi" #define K_S_LAUNCHER_WEATHER "Weather" #define K_S_LAUNCHER_PASTEBIN "Pastebin" @@ -236,6 +237,12 @@ #define K_S_FMANAGER_MULTIBOOT_STARTING "Starting..." #define K_S_FMANAGER_MULTIBOOT_ERROR_FMT "Stage: %d\nCode: %d" +#define K_S_FLASHIMAGE_TITLE "Install apps" +#define K_S_FLASHIMAGE_CONFIRM_FMT "Install from image:\n%s\n\nSize: %s" +#define K_S_FLASHIMAGE_DONE_FMT "Installed. Start %s now?" +#define K_S_FLASHIMAGE_NO_PARTS "The image has no apps for this partition table" +#define K_S_FLASHIMAGE_TOO_BIG_FMT "%s doesn't fit its partition" +#define K_S_FLASHIMAGE_WRITE_ERROR_FMT "%s: %s" #define K_S_FMANAGER_SORTING "Sorting..." #define K_S_FMANAGER_ALMOST_DONE "Almost ready..." #define K_S_FMANAGER_THIS_OP_WOULD_DELETE_FILE "This operation would delete file\n" @@ -594,6 +601,7 @@ #define K_S_KEIRA_UPDATE_CONFIRM_FMT "Install v%s?\n\nCurrent: v%s\nLanguage: %s\nSize: %s\nDate: %s\n\nSTART - continue\nB - exit" #define K_S_KEIRA_UPDATE_DOWNLOADING_FMT "Installing v%s...\n\nB - cancel" #define K_S_KEIRA_UPDATE_ERROR_FMT "Update failed\n\n%s" +#define K_S_KEIRA_UPDATE_SLOT_ERROR "Update would overwrite another app.\nUpdate via web interface or USB" #define K_S_KEIRA_UPDATE_SUCCESS "Update installed!\n\nSystem will reboot." /////////////////////////////////////////////////////////////////////////////////////////////////////// // clang-format on diff --git a/src/keira/localizations/lang_uk.h b/src/keira/localizations/lang_uk.h index 85a81cbb..26100445 100644 --- a/src/keira/localizations/lang_uk.h +++ b/src/keira/localizations/lang_uk.h @@ -80,6 +80,7 @@ #define K_S_LAUNCHER_LILCATALOG "ЛілКаталог" #define K_S_LAUNCHER_LILTRACKER "ЛілТрекер" #define K_S_LAUNCHER_LETRIS "Летріс" +#define K_S_LAUNCHER_RETRO_GO "Retro-Go" #define K_S_LAUNCHER_TAMAGOTCHI "Тамагочі" #define K_S_LAUNCHER_WEATHER "Погода" #define K_S_LAUNCHER_PASTEBIN "Pastebin" @@ -228,6 +229,12 @@ #define K_S_FMANAGER_MULTIBOOT_STARTING "Починаємо..." #define K_S_FMANAGER_MULTIBOOT_ERROR_FMT "Етап: %d\nКод: %d" +#define K_S_FLASHIMAGE_TITLE "Встановлення застосунків" +#define K_S_FLASHIMAGE_CONFIRM_FMT "Встановити з образу:\n%s\n\nРозмір: %s" +#define K_S_FLASHIMAGE_DONE_FMT "Встановлено. Запустити %s?" +#define K_S_FLASHIMAGE_NO_PARTS "В образі немає застосунків для цієї таблиці розділів" +#define K_S_FLASHIMAGE_TOO_BIG_FMT "%s не вміщається у свій розділ" +#define K_S_FLASHIMAGE_WRITE_ERROR_FMT "%s: %s" #define K_S_FMANAGER_SORTING "Сортування..." #define K_S_FMANAGER_ALMOST_DONE "Майже готово..." #define K_S_FMANAGER_THIS_OP_WOULD_DELETE_FILE "Ця операція видалить файл\n" @@ -586,6 +593,7 @@ #define K_S_KEIRA_UPDATE_CONFIRM_FMT "Встановити v%s?\n\nПоточна: v%s\nМова: %s\nРозмір: %s\nДата: %s\n\nSTART - продовжити\nB - скасувати" #define K_S_KEIRA_UPDATE_DOWNLOADING_FMT "Встановлення v%s...\n\nB - скасувати" #define K_S_KEIRA_UPDATE_ERROR_FMT "Помилка оновлення\n\n%s" +#define K_S_KEIRA_UPDATE_SLOT_ERROR "Оновлення перезапише інший застосунок.\nОновіть через веб-інтерфейс або USB" #define K_S_KEIRA_UPDATE_SUCCESS "Оновлення встановлено!\n\nСистему буде перезавантажено." /////////////////////////////////////////////////////////////////////////////////////////////////////// // clang-format on diff --git a/src/services/web/web.cpp b/src/services/web/web.cpp index bb733e17..427fbf74 100644 --- a/src/services/web/web.cpp +++ b/src/services/web/web.cpp @@ -1015,9 +1015,8 @@ static esp_err_t upload_handler(httpd_req_t* req) { int contentLength = getContentLength(req); lilka::serial.log("FW upload binary size %d", contentLength); - auto current_partition = esp_ota_get_running_partition(); - auto ota_partition = esp_ota_get_next_update_partition(current_partition); - esp_err_t err = esp_ota_begin(ota_partition, contentLength, &ota_handle); + auto ota_partition = KeiraSystem::getUpdatePartition(); + esp_err_t err = ota_partition ? esp_ota_begin(ota_partition, contentLength, &ota_handle) : ESP_ERR_NOT_FOUND; if (err == ESP_OK) { char* buf = static_cast(malloc(WEB_BUFFER_FLASH_OP));