Skip to content

Commit 7395332

Browse files
authored
Add option to specify partition table size (#52)
***NO_CI***
1 parent 27c8c24 commit 7395332

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

nanoFirmwareFlasher/Esp32Firmware.cs

100644100755
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,29 @@ internal class Esp32Firmware : FirmwarePackage
2525

2626
internal Dictionary<int, string> FlashPartitions;
2727

28+
internal PartitionTableSize? _partitionTableSize;
2829

2930
/// <summary>
3031
/// Address of the deployment partition.
3132
/// </summary>
3233
internal int DeploymentPartionAddress => 0x110000;
3334

34-
public Esp32Firmware(string targetName, string fwVersion, bool stable)
35+
public Esp32Firmware(string targetName, string fwVersion, bool stable, PartitionTableSize? partitionTableSize)
3536
:base(targetName, fwVersion, stable)
3637
{
38+
_partitionTableSize = partitionTableSize;
3739
}
3840

3941
internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(int flashSize)
4042
{
41-
string humanReadable = flashSize >= 0x10000 ? $"{ flashSize / 0x100000 }MB" : $"{ flashSize / 0x400 }kB";
43+
if (_partitionTableSize is not null)
44+
{
45+
// if specified, partition table size overrides flash size.
46+
flashSize = (int)_partitionTableSize * 0x100000;
47+
}
48+
var humanReadable = flashSize >= 0x10000 ? $"{ flashSize / 0x100000 }MB" : $"{ flashSize / 0x400 }kB";
49+
50+
// check if the option to override the partition table was set
4251

4352
if (!SupportedFlashSizes.Contains(flashSize))
4453
{

nanoFirmwareFlasher/Esp32Operations.cs

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
8989
bool stable,
9090
string applicationPath,
9191
string deploymentAddress,
92+
PartitionTableSize? partitionTableSize,
9293
VerbosityLevel verbosity)
9394
{
9495
ExitCodes operationResult = ExitCodes.OK;
@@ -103,7 +104,8 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
103104
Esp32Firmware firmware = new Esp32Firmware(
104105
targetName,
105106
fwVersion,
106-
stable)
107+
stable,
108+
partitionTableSize)
107109
{
108110
Verbosity = verbosity
109111
};

nanoFirmwareFlasher/EspTool.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ internal class EspTool
4747
/// </remarks>
4848
private readonly int _flashFrequency = 0;
4949

50+
/// <summary>
51+
/// Partition table size, when specified in the options.
52+
/// </summary>
53+
private readonly PartitionTableSize? _partitionTableSize = null;
54+
5055
/// <summary>
5156
/// The size of the flash in bytes; 4 MB = 0x40000 bytes
5257
/// </summary>
@@ -149,11 +154,13 @@ internal DeviceInfo(
149154
/// <param name="baudRate">The baud rate for the serial port.</param>
150155
/// <param name="flashMode">The flash mode for the esptool</param>
151156
/// <param name="flashFrequency">The flash frequency for the esptool</param>
157+
/// <param name="partitionTableSize">Partition table size to use</param>
152158
internal EspTool(
153159
string serialPort,
154160
int baudRate,
155161
string flashMode,
156-
int flashFrequency)
162+
int flashFrequency,
163+
PartitionTableSize? partitionTableSize)
157164
{
158165
// open/close the port to see if it is available
159166
using (SerialPort test = new SerialPort(serialPort, baudRate))
@@ -180,6 +187,7 @@ internal EspTool(
180187
_baudRate = baudRate;
181188
_flashMode = flashMode;
182189
_flashFrequency = flashFrequency;
190+
_partitionTableSize = partitionTableSize;
183191
}
184192

185193
/// <summary>

nanoFirmwareFlasher/Options.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ public class Options
9898
HelpText = "Flash frequency to use [MHz].")]
9999
public int Esp32FlashFrequency { get; set; }
100100

101+
/// <summary>
102+
/// Allowed values:
103+
/// 2
104+
/// 4
105+
/// 8
106+
/// 16
107+
/// </summary>
108+
[Option(
109+
"partitiontablesize",
110+
Required = false,
111+
Default = null,
112+
HelpText = "Partition table size to use. Valid sizes are: 2, 4, 8 and 16.")]
113+
public PartitionTableSize? Esp32PartitionTableSize { get; set; }
101114
#endregion
102115

103116

@@ -245,4 +258,11 @@ public enum VerbosityLevel
245258
Diagnostic = 4
246259
}
247260

261+
public enum PartitionTableSize
262+
{
263+
_2 = 2,
264+
_4 = 4,
265+
_8 = 8,
266+
_16 = 16,
267+
}
248268
}

nanoFirmwareFlasher/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
229229
o.SerialPort,
230230
o.BaudRate,
231231
o.Esp32FlashMode,
232-
o.Esp32FlashFrequency);
232+
o.Esp32FlashFrequency,
233+
o.Esp32PartitionTableSize);
233234
}
234235
catch(Exception)
235236
{
@@ -314,6 +315,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
314315
o.Stable,
315316
o.DeploymentImage,
316317
null,
318+
o.Esp32PartitionTableSize,
317319
verbosityLevel);
318320

319321
if (_exitCode != ExitCodes.OK)
@@ -373,6 +375,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
373375
false,
374376
o.DeploymentImage,
375377
appFlashAddress,
378+
o.Esp32PartitionTableSize,
376379
verbosityLevel);
377380

378381
if (_exitCode != ExitCodes.OK)

nanoFirmwareFlasher/nanoFirmwareFlasher.csproj

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
<ItemGroup>
4848
<PackageReference Include="CommandLineParser" Version="2.8.0" />
49-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91" PrivateAssets="All" />
49+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.194" PrivateAssets="All" />
5050
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
5151
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
5252
<PackageReference Include="System.IO.Ports" Version="4.7.0" />

0 commit comments

Comments
 (0)