From ed5992e229547395fa3e7d3b5923383b3ada8f32 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Wed, 17 Nov 2021 10:02:59 +0300 Subject: [PATCH 1/7] fix deployment app esp32 --- README.md | 7 +++---- nanoFirmwareFlasher/Esp32Operations.cs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 463566da..c6dfc4a5 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,11 @@ nanoff --target ESP32_PSRAM_REV0 --serialport COM12 --deploy --image "E:\GitHub\ ### Update the firmware of an ESP32 target along with a managed application -To update the firmware of an ESP32 target connected to COM31, to the latest available development version. -You have to specify the path to the managed application. -This example uses the binary format file that was saved on a previous backup operation. +To deploy an application on an ESP32 target connected to COM31, with your application, you have to specify the path to the managed application and the deployment address. +This example uses the binary format file that you can find when you are building an application. Note, as only application can run, when you are building a library, a bin file is not created automatically. Only for application. ```console -nanoff --update --target ESP32_PSRAM_REV0 --serialport COM31 --deployment "c:\eps32-backups\my_awesome_app.bin" +nanoff --target ESP32_PSRAM_REV0 --serialport COM31 --deploy --image "c:\eps32-backups\my_awesome_app.bin" --address 0x1B000 ``` ## STMP32 usage examples diff --git a/nanoFirmwareFlasher/Esp32Operations.cs b/nanoFirmwareFlasher/Esp32Operations.cs index 9859fa1b..ad5eb03c 100755 --- a/nanoFirmwareFlasher/Esp32Operations.cs +++ b/nanoFirmwareFlasher/Esp32Operations.cs @@ -294,8 +294,8 @@ internal static async System.Threading.Tasks.Task UpdateFirmwareAsync // need to get deployment address here // length must both be multiples of the SPI flash erase sector size. This is 0x1000 (4096) bytes for supported flash chips. - - var fileStream = File.OpenRead(firmware.BootloaderPath); + string bootpath = firmware.BootloaderPath ?? Path.Combine("esp32bootloader", "bootloader.bin"); + var fileStream = File.OpenRead(bootpath); uint fileLength = (uint)Math.Ceiling((decimal)fileStream.Length / 0x1000) * 0x1000; From fc150913c3b2c53fcd632590b3c1794b30fa2510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 17 Nov 2021 09:02:14 +0000 Subject: [PATCH 2/7] Fix default address for deployment partition --- nanoFirmwareFlasher/Esp32Firmware.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nanoFirmwareFlasher/Esp32Firmware.cs b/nanoFirmwareFlasher/Esp32Firmware.cs index 265d7688..d03e5923 100755 --- a/nanoFirmwareFlasher/Esp32Firmware.cs +++ b/nanoFirmwareFlasher/Esp32Firmware.cs @@ -33,9 +33,9 @@ internal class Esp32Firmware : FirmwarePackage internal PartitionTableSize? _partitionTableSize; /// - /// Address of the deployment partition. + /// Default address of the deployment partition. /// - internal int DeploymentPartitionAddress => 0x110000; + internal int DeploymentPartitionAddress => 0x1B0000; public Esp32Firmware( string targetName, From e9d89f57624e88819d83f1026d600801f6b61e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 17 Nov 2021 09:03:58 +0000 Subject: [PATCH 3/7] Deployment address is not mandatory anymore --- nanoFirmwareFlasher/Program.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nanoFirmwareFlasher/Program.cs b/nanoFirmwareFlasher/Program.cs index 4a1d0b79..00b579da 100644 --- a/nanoFirmwareFlasher/Program.cs +++ b/nanoFirmwareFlasher/Program.cs @@ -449,18 +449,13 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) if (o.Deploy) { // need to take care of flash address - string appFlashAddress = null; + string appFlashAddress = string.Empty; if (o.FlashAddress.Any()) { // take the first address, it should be the only one valid appFlashAddress = o.FlashAddress.ElementAt(0); } - else - { - _exitCode = ExitCodes.E9009; - return; - } // this to flash a deployment image without updating the firmware try From cea3c5d8baf84f4df71338a16711002df4e3ad0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 17 Nov 2021 09:04:45 +0000 Subject: [PATCH 4/7] Missing target name when calling UpdateFirmwareAsync for deploy operation --- nanoFirmwareFlasher/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanoFirmwareFlasher/Program.cs b/nanoFirmwareFlasher/Program.cs index 00b579da..296c74db 100644 --- a/nanoFirmwareFlasher/Program.cs +++ b/nanoFirmwareFlasher/Program.cs @@ -464,7 +464,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) _exitCode = await Esp32Operations.UpdateFirmwareAsync( espTool, esp32Device, - null, + o.TargetName, false, null, false, From a079b65b008b21dcb9aeee8036df0cb0db1a67a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 17 Nov 2021 09:07:16 +0000 Subject: [PATCH 5/7] Fix code to deploy only operation - Consider that deploy address is not mandatory (we have either a default one or one from the target partition table). - No need to flash bootloader when flashing to deployment partition (even if it's the only operation executing). --- nanoFirmwareFlasher/Esp32Operations.cs | 59 ++++++++++++-------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/nanoFirmwareFlasher/Esp32Operations.cs b/nanoFirmwareFlasher/Esp32Operations.cs index ad5eb03c..b932b459 100755 --- a/nanoFirmwareFlasher/Esp32Operations.cs +++ b/nanoFirmwareFlasher/Esp32Operations.cs @@ -251,10 +251,10 @@ internal static async System.Threading.Tasks.Task UpdateFirmwareAsync // check application file if (File.Exists(applicationPath)) { - if (!updateFw) + // this operation includes a deployment image + // try parsing the deployment address from parameter, if provided + if (!string.IsNullOrEmpty(deploymentAddress)) { - // this is a deployment operation only - // try parsing the deployment address from parameter // need to remove the leading 0x and to specify that hexadecimal values are allowed if (!uint.TryParse(deploymentAddress.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out address)) { @@ -263,10 +263,12 @@ internal static async System.Threading.Tasks.Task UpdateFirmwareAsync } string applicationBinary = new FileInfo(applicationPath).FullName; + + // add DEPLOYMENT partition with the address provided in the command OR the address from the partition table firmware.FlashPartitions = new Dictionary() { { - updateFw ? firmware.DeploymentPartitionAddress : (int)address, + address != 0 ? (int)address : firmware.DeploymentPartitionAddress, applicationBinary } }; @@ -277,44 +279,35 @@ internal static async System.Threading.Tasks.Task UpdateFirmwareAsync } } - if (verbosity >= VerbosityLevel.Normal) - { - Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine($"Erasing flash..."); - } - if (updateFw) { + // updating fw calls for a flash erase + if (verbosity >= VerbosityLevel.Normal) + { + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine($"Erasing flash..."); + } + // erase flash operationResult = espTool.EraseFlash(); - } - else - { - // erase flash segment - - // need to get deployment address here - // length must both be multiples of the SPI flash erase sector size. This is 0x1000 (4096) bytes for supported flash chips. - string bootpath = firmware.BootloaderPath ?? Path.Combine("esp32bootloader", "bootloader.bin"); - var fileStream = File.OpenRead(bootpath); - - uint fileLength = (uint)Math.Ceiling((decimal)fileStream.Length / 0x1000) * 0x1000; - operationResult = espTool.EraseFlashSegment(address, fileLength); + if (operationResult == ExitCodes.OK) + { + if (verbosity >= VerbosityLevel.Normal) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("OK"); + } + else + { + Console.WriteLine(""); + } + } } if (operationResult == ExitCodes.OK) { - if (verbosity >= VerbosityLevel.Normal) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("OK"); - } - else - { - Console.WriteLine(""); - } - - Console.ForegroundColor = ConsoleColor.White; + Console.ForegroundColor = ConsoleColor.White; if (verbosity >= VerbosityLevel.Normal) { From c01e6390270007202b5f2b4056146eb1d2880c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 17 Nov 2021 09:07:52 +0000 Subject: [PATCH 6/7] Bump version to 1.29 --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 00c47c61..d457eac1 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.28", + "version": "1.29", "assemblyVersion": { "precision": "minor" }, From 4ad7fe6c5fedaf4f2787641331bf9be103599e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 17 Nov 2021 09:11:51 +0000 Subject: [PATCH 7/7] Update README - Improve descriptions for deploy option. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c6dfc4a5..4a85894a 100644 --- a/README.md +++ b/README.md @@ -138,21 +138,21 @@ nanoff --platform esp32 --serialport COM31 --devicedetails ### Deploy a managed application to an ESP32 target -To deploy a managed application to an ESP32_PSRAM_REV0 target connected to COM31, which has the deployment region at 0x190000 flash address. +To deploy a managed application to an ESP32_PSRAM_REV0 target connected to COM31. >Note: The binary file with the deployment image can be found on the Release or Debug folder of a Visual Studio project after a successful build. This file contains everything that's required to deploy a managed application to a target (meaning application executable and all referenced libraries and assemblies). ```console -nanoff --target ESP32_PSRAM_REV0 --serialport COM12 --deploy --image "E:\GitHub\nf-Samples\samples\Blinky\Blinky\bin\Debug\Blinky.bin" --address 0x190000 +nanoff --target ESP32_PSRAM_REV0 --serialport COM12 --deploy --image "E:\GitHub\nf-Samples\samples\Blinky\Blinky\bin\Debug\Blinky.bin" ``` ### Update the firmware of an ESP32 target along with a managed application -To deploy an application on an ESP32 target connected to COM31, with your application, you have to specify the path to the managed application and the deployment address. -This example uses the binary format file that you can find when you are building an application. Note, as only application can run, when you are building a library, a bin file is not created automatically. Only for application. +To deploy an application on an ESP32 target connected to COM31, with your application, you have to specify the path to the managed application. Optionally you can provide an address which will override the default deployment address. +This example uses the binary format file that you can find when you are building an application. Note, as only application can run, when you are building a library, a bin file is not created automatically. Only for applications. ```console -nanoff --target ESP32_PSRAM_REV0 --serialport COM31 --deploy --image "c:\eps32-backups\my_awesome_app.bin" --address 0x1B000 +nanoff --target ESP32_PSRAM_REV0 --update --serialport COM31 --deploy --image "c:\eps32-backups\my_awesome_app.bin" --address 0x1B000 ``` ## STMP32 usage examples