From 63f32ec99d8f8c371e3a18eb9446b0bae956cfc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 24 Jul 2019 11:59:20 +0100 Subject: [PATCH] Improvements on ESP32 flash operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add support for all supported partition sizes: 2, 4, 8 and 16 MB. - Improve feedback messages. - Bump version to 1.0.6-preview. Signed-off-by: José Simões --- source/nanoFirmwareFlasher/Esp32Firmware.cs | 16 ++++++++-------- source/nanoFirmwareFlasher/Esp32Operations.cs | 17 +++++++++++------ source/nanoFirmwareFlasher/Program.cs | 5 ++++- source/version.json | 2 +- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/source/nanoFirmwareFlasher/Esp32Firmware.cs b/source/nanoFirmwareFlasher/Esp32Firmware.cs index 0a41eb2f..c173a4a4 100644 --- a/source/nanoFirmwareFlasher/Esp32Firmware.cs +++ b/source/nanoFirmwareFlasher/Esp32Firmware.cs @@ -17,9 +17,9 @@ namespace nanoFramework.Tools.FirmwareFlasher internal class Esp32Firmware : FirmwarePackage { /// - /// ESP32 nanoCLR is only available for 2MB and 4MB flash sizes + /// ESP32 nanoCLR is available for 2MB, 4MB, 8MB and 16MB flash sizes /// - internal List SupportedFlashSizes => new List { 0x200000, 0x400000 }; + internal List SupportedFlashSizes => new List { 0x200000, 0x400000, 0x800000, 0x1000000 }; internal Dictionary FlashPartitions; @@ -36,13 +36,13 @@ public Esp32Firmware(string targetName, string fwVersion, bool stable) internal async System.Threading.Tasks.Task DownloadAndExtractAsync(int flashSize) { - if (!SupportedFlashSizes.Contains(flashSize)) - { - string humanReadable = flashSize >= 0x10000 ? $"{ flashSize / 0x10000 }MB" : $"{ flashSize / 0x400 }kB"; + string humanReadable = flashSize >= 0x10000 ? $"{ flashSize / 0x100000 }MB" : $"{ flashSize / 0x400 }kB"; + if (!SupportedFlashSizes.Contains(flashSize)) + { if (Verbosity >= VerbosityLevel.Detailed) { - Console.WriteLine($"There is no firmware available for ESP32 with {humanReadable} flash size!{Environment.NewLine}Only the following flash sizes are supported: {string.Join(", ", SupportedFlashSizes.Select(size => size >= 0x10000 ? $"{ size / 0x10000 }MB" : $"{ size / 0x400 }kB."))}"); + Console.WriteLine($"There is no firmware available for ESP32 with {humanReadable} flash size!{Environment.NewLine}Only the following flash sizes are supported: {string.Join(", ", SupportedFlashSizes.Select(size => size >= 0x10000 ? $"{ size / 0x100000 }MB" : $"{ size / 0x400 }kB."))}"); } return ExitCodes.E4001; @@ -62,8 +62,8 @@ internal async System.Threading.Tasks.Task DownloadAndExtractAsync(in // nanoCLR goes to 0x10000 { 0x10000, Path.Combine(LocationPath, "nanoCLR.bin") }, - // partition table goes to 0x8000; there is on partition table for 2MB flash and one for 4MB flash - { 0x8000, Path.Combine(LocationPath, flashSize == 0x200000 ? "partitions_2mb.bin" : "partitions_4mb.bin") } + // partition table goes to 0x8000; there are partition tables for 2MB, 4MB, 8MB and 16MB flash sizes + { 0x8000, Path.Combine(LocationPath, $"partitions_{humanReadable.ToLowerInvariant()}.bin") } }; } diff --git a/source/nanoFirmwareFlasher/Esp32Operations.cs b/source/nanoFirmwareFlasher/Esp32Operations.cs index 73758504..b198d399 100644 --- a/source/nanoFirmwareFlasher/Esp32Operations.cs +++ b/source/nanoFirmwareFlasher/Esp32Operations.cs @@ -123,25 +123,30 @@ internal static async System.Threading.Tasks.Task UpdateFirmwareAsync } } - if (verbosity >= VerbosityLevel.Detailed) + if (verbosity >= VerbosityLevel.Normal) { - Console.WriteLine($"Erasing flash..."); + Console.Write($"Erasing flash..."); } // erase flash espTool.EraseFlash(); - if (verbosity >= VerbosityLevel.Detailed) + if (verbosity >= VerbosityLevel.Normal) { - Console.WriteLine($"Flashing firmware..."); + Console.WriteLine("OK"); + } + + if (verbosity >= VerbosityLevel.Normal) + { + Console.Write($"Flashing firmware..."); } // write to flash espTool.WriteFlash(firmware.FlashPartitions); - if (verbosity >= VerbosityLevel.Detailed) + if (verbosity >= VerbosityLevel.Normal) { - Console.WriteLine("ESP32 successfully flashed!"); + Console.WriteLine("OK"); } } diff --git a/source/nanoFirmwareFlasher/Program.cs b/source/nanoFirmwareFlasher/Program.cs index 96e190ec..0fbb844d 100644 --- a/source/nanoFirmwareFlasher/Program.cs +++ b/source/nanoFirmwareFlasher/Program.cs @@ -238,7 +238,10 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) { Console.WriteLine($"Connected to ESP32 { esp32Device.ChipName } with MAC address { esp32Device.MacAddress }"); Console.WriteLine($"features { esp32Device.Features }"); - Console.WriteLine($"Flash information: manufacturer 0x{ esp32Device.FlashManufacturerId } device 0x{ esp32Device.FlashDeviceModelId } size { esp32Device.FlashSize }"); + + string flashSize = esp32Device.FlashSize >= 0x10000 ? $"{ esp32Device.FlashSize / 0x100000 }MB" : $"{ esp32Device.FlashSize / 0x400 }kB"; + + Console.WriteLine($"Flash information: manufacturer 0x{ esp32Device.FlashManufacturerId } device 0x{ esp32Device.FlashDeviceModelId } size { flashSize }"); } // set verbosity diff --git a/source/version.json b/source/version.json index 98a0501a..ebd75a9e 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.0.5-preview.{height}", + "version": "1.0.6-preview.{height}", "release": { "branchName" : "release-v{version}", "versionIncrement" : "minor",