Skip to content

Commit

Permalink
Fix deployment operation for ESP32 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellerbach authored Nov 17, 2021
1 parent f3263fb commit fb147f0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 49 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +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 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. 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 --update --target ESP32_PSRAM_REV0 --serialport COM31 --deployment "c:\eps32-backups\my_awesome_app.bin"
nanoff --target ESP32_PSRAM_REV0 --update --serialport COM31 --deploy --image "c:\eps32-backups\my_awesome_app.bin" --address 0x1B000
```

## STMP32 usage examples
Expand Down
4 changes: 2 additions & 2 deletions nanoFirmwareFlasher/Esp32Firmware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ internal class Esp32Firmware : FirmwarePackage
internal PartitionTableSize? _partitionTableSize;

/// <summary>
/// Address of the deployment partition.
/// Default address of the deployment partition.
/// </summary>
internal int DeploymentPartitionAddress => 0x110000;
internal int DeploymentPartitionAddress => 0x1B0000;

public Esp32Firmware(
string targetName,
Expand Down
59 changes: 26 additions & 33 deletions nanoFirmwareFlasher/Esp32Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ internal static async System.Threading.Tasks.Task<ExitCodes> 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))
{
Expand All @@ -263,10 +263,12 @@ internal static async System.Threading.Tasks.Task<ExitCodes> 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<int, string>()
{
{
updateFw ? firmware.DeploymentPartitionAddress : (int)address,
address != 0 ? (int)address : firmware.DeploymentPartitionAddress,
applicationBinary
}
};
Expand All @@ -277,44 +279,35 @@ internal static async System.Threading.Tasks.Task<ExitCodes> 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.

var fileStream = File.OpenRead(firmware.BootloaderPath);

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)
{
Expand Down
9 changes: 2 additions & 7 deletions nanoFirmwareFlasher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -469,7 +464,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
_exitCode = await Esp32Operations.UpdateFirmwareAsync(
espTool,
esp32Device,
null,
o.TargetName,
false,
null,
false,
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down

0 comments on commit fb147f0

Please sign in to comment.