Skip to content

Commit b88878f

Browse files
author
Frank Robijn
committed
Merge
2 parents 2284649 + b1415ee commit b88878f

12 files changed

+338
-882
lines changed

targets/netcore/littlefs/hal_littlefs.c

+10-20
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@ void hal_lfs_config()
260260
lfsConfig[i].erase = hal_lfs_getEraseHandler(i);
261261
lfsConfig[i].sync = hal_lfs_getSyncHandler(i);
262262

263-
// #ifdef LFS_THREADSAFE
264-
// lfsConfig[i].lock = &hal_lfs_lock;
265-
// lfsConfig[i].unlock = &hal_lfs_unlock;
266-
// #endif
267-
268263
// setup littlefs configurations
269264
lfsConfig[i].read_size = hal_lfs_getReadSize(i);
270265
lfsConfig[i].prog_size = hal_lfs_getProgSize(i);
@@ -315,27 +310,22 @@ void hal_lfs_mount()
315310

316311
int32_t hal_lfs_mount_partition(int32_t index, bool forceFormat)
317312
{
313+
// not used
314+
(void)forceFormat;
315+
318316
int32_t operationResult = 0;
319317

320-
// mount the file system
321-
operationResult = lfs_mount(&lfs[index], &lfsConfig[index]);
318+
operationResult = lfs_format(&lfs[index], &lfsConfig[index]);
322319

323-
if (operationResult != 0)
320+
if (operationResult != LFS_ERR_OK)
324321
{
325-
// looks like littlefs is not formated (occuring at 1st boot)
326-
327-
if (forceFormat)
328-
{
329-
// wipe out the chip
330-
hal_lfs_erase_chip(index);
331-
}
332-
333-
lfs_format(&lfs[index], &lfsConfig[index]);
334-
335-
// mount the file system again
336-
operationResult = lfs_mount(&lfs[index], &lfsConfig[index]);
322+
// failed to format
323+
return operationResult;
337324
}
338325

326+
// mount the file system
327+
operationResult = lfs_mount(&lfs[index], &lfsConfig[index]);
328+
339329
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
340330
// code block to assist testing littlefs
341331
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

targets/netcore/nanoFramework.nanoCLR.CLI/ClrInstanceOperationsOptions.cs

+1-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace nanoFramework.nanoCLR.CLI
88
[Verb(
99
"instance",
1010
HelpText = "Operations with the current nanoCLR instance.")]
11-
public class ClrInstanceOperationsOptions
11+
public class ClrInstanceOperationsOptions : CommonOptions
1212
{
1313
[Option(
1414
"getversion",
@@ -41,28 +41,5 @@ public class ClrInstanceOperationsOptions
4141
Default = null,
4242
HelpText = "Specify a version of nanoCRL to install.")]
4343
public string TargetVersion { get; set; }
44-
45-
[Option(
46-
"clrinstancepath",
47-
Required = false,
48-
Default = null,
49-
HelpText = "Path to the directory where a local version of nanoFramework.nanoCLR.dll is located.")]
50-
public string LocalInstance { get; set; }
51-
52-
/// <summary>
53-
/// Allowed values:
54-
/// q[uiet]
55-
/// m[inimal]
56-
/// n[ormal]
57-
/// d[etailed]
58-
/// diag[nostic]
59-
/// </summary>
60-
[Option(
61-
'v',
62-
"verbosity",
63-
Required = false,
64-
Default = "n",
65-
HelpText = "Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. Not supported in every command; see specific command page to determine if this option is available.")]
66-
public string Verbosity { get; set; }
6744
}
6845
}

targets/netcore/nanoFramework.nanoCLR.CLI/ClrInstanceOperationsProcessor.cs

+22-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Linq;
78
using System.Net.Http;
89
using System.Reflection;
910
using System.Threading.Tasks;
@@ -24,21 +25,21 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
2425
nanoCLRHostBuilder hostBuilder;
2526

2627
// are we to use a local DLL?
27-
if (options.LocalInstance != null)
28+
if (options.PathToCLRInstance != null)
2829
{
2930
if (options.UpdateCLR)
3031
{
3132
// These options cannot be combined
32-
throw new CLIException(ExitCode.E9009);
33+
throw new CLIException(ExitCode.E9010);
3334
}
3435

3536
// check if path exists
36-
if (!Directory.Exists(options.LocalInstance))
37+
if (!Directory.Exists(options.PathToCLRInstance))
3738
{
3839
throw new CLIException(ExitCode.E9009);
3940
}
4041

41-
hostBuilder = nanoCLRHost.CreateBuilder(options.LocalInstance);
42+
hostBuilder = nanoCLRHost.CreateBuilder(options.PathToCLRInstance);
4243
}
4344
else
4445
{
@@ -68,22 +69,19 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
6869
if (options.GetNativeAssemblies)
6970
{
7071
List<NativeAssemblyDetails>? nativeAssemblies = hostBuilder.GetNativeAssemblies();
72+
7173
if (nativeAssemblies is not null)
7274
{
7375
if (options.GetCLRVersion)
7476
{
7577
Console.WriteLine();
7678
}
77-
Console.WriteLine("Native assembly,Version,Checksum");
7879

79-
foreach (NativeAssemblyDetails assembly in nativeAssemblies)
80-
{
81-
Console.WriteLine($"{assembly.Name},{assembly.Version},0x{assembly.CheckSum:x}");
82-
}
80+
OutputNativeAssembliesList(nativeAssemblies);
8381
}
8482
else if (Program.VerbosityLevel > VerbosityLevel.Normal)
8583
{
86-
Console.WriteLine("CLR instance is too old; native assembly information not available.");
84+
return (int)ExitCode.E9011;
8785
}
8886
}
8987

@@ -93,6 +91,20 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
9391
return (int)ExitCode.OK;
9492
}
9593

94+
private static void OutputNativeAssembliesList(List<NativeAssemblyDetails> nativeAssemblies)
95+
{
96+
Console.WriteLine("Native assemblies:");
97+
98+
// do some math to get a tidy output
99+
int maxAssemblyNameLength = nativeAssemblies.Max(assembly => assembly.Name.Length);
100+
int maxAssemblyVersionLength = nativeAssemblies.Max(assembly => assembly.Version.ToString().Length);
101+
102+
foreach (NativeAssemblyDetails assembly in nativeAssemblies)
103+
{
104+
Console.WriteLine($" {assembly.Name.PadRight(maxAssemblyNameLength)} v{assembly.Version.ToString().PadRight(maxAssemblyVersionLength)} 0x{assembly.CheckSum:X8}");
105+
}
106+
}
107+
96108
private static async Task<ExitCode> UpdateNanoCLRAsync(
97109
string targetVersion,
98110
string currentVersion,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using CommandLine;
6+
7+
namespace nanoFramework.nanoCLR.CLI
8+
{
9+
public class CommonOptions
10+
{
11+
[Option(
12+
"clrpath",
13+
Required = false,
14+
Default = null,
15+
HelpText = "Path to the directory from which to load a specific version of nanoFramework.nanoCLR.dll.")]
16+
public string PathToCLRInstance { get; set; }
17+
18+
[Obsolete("This option is deprecated and will be removed in a future version. Use --clrpath instead.")]
19+
[Option(
20+
"localinstance",
21+
Required = false,
22+
Default = null,
23+
Hidden = true,
24+
HelpText = "Path to a local instance of the nanoCLR.")]
25+
public string LocalInstance
26+
{
27+
set
28+
{
29+
PathToCLRInstance = value;
30+
}
31+
}
32+
33+
34+
/// <summary>
35+
/// Allowed values:
36+
/// q[uiet]
37+
/// m[inimal]
38+
/// n[ormal]
39+
/// d[etailed]
40+
/// diag[nostic]
41+
/// </summary>
42+
[Option(
43+
'v',
44+
"verbosity",
45+
Required = false,
46+
Default = "n",
47+
HelpText = "Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. Not supported in every command; see specific command page to determine if this option is available.")]
48+
public string Verbosity { get; set; }
49+
}
50+
}

targets/netcore/nanoFramework.nanoCLR.CLI/ExecuteCommandLineOptions.cs

+1-25
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace nanoFramework.nanoCLR.CLI
1111
[Verb(
1212
"run",
1313
HelpText = "Run nanoCLR assembly.")]
14-
public class ExecuteCommandLineOptions
14+
public class ExecuteCommandLineOptions : CommonOptions
1515
{
1616
[Option(
1717
'a',
@@ -106,29 +106,5 @@ public class ExecuteCommandLineOptions
106106
Default = false,
107107
HelpText = "Option to force heap compaction after each GC run.")]
108108
public bool PerformHeapCompaction { get; set; }
109-
110-
[Option(
111-
"localinstance",
112-
Required = false,
113-
Default = null,
114-
Hidden = true,
115-
HelpText = "Path to a local instance of the nanoCLR.")]
116-
public string LocalInstance { get; set; }
117-
118-
/// <summary>
119-
/// Allowed values:
120-
/// q[uiet]
121-
/// m[inimal]
122-
/// n[ormal]
123-
/// d[etailed]
124-
/// diag[nostic]
125-
/// </summary>
126-
[Option(
127-
'v',
128-
"verbosity",
129-
Required = false,
130-
Default = "n",
131-
HelpText = "Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. Not supported in every command; see specific command page to determine if this option is available.")]
132-
public string Verbosity { get; set; }
133109
}
134110
}

targets/netcore/nanoFramework.nanoCLR.CLI/ExecuteCommandProcessor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// See LICENSE file in the project root for full license information.
44
//
@@ -25,15 +25,15 @@ public static int ProcessVerb(
2525
nanoCLRHostBuilder hostBuilder;
2626

2727
// are we to use a local DLL?
28-
if (options.LocalInstance != null)
28+
if (options.PathToCLRInstance != null)
2929
{
3030
// check if path exists
31-
if (!File.Exists(options.LocalInstance))
31+
if (!Directory.Exists(options.PathToCLRInstance))
3232
{
3333
throw new CLIException(ExitCode.E9009);
3434
}
3535

36-
hostBuilder = nanoCLRHost.CreateBuilder(Path.GetDirectoryName(options.LocalInstance));
36+
hostBuilder = nanoCLRHost.CreateBuilder(Path.GetDirectoryName(options.PathToCLRInstance));
3737
}
3838
else
3939
{

targets/netcore/nanoFramework.nanoCLR.CLI/ExitCode.cs

+12
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,17 @@ public enum ExitCode
106106
/// </summary>
107107
[Display(Name = " Specified nanoCLR DLL file does not exist.")]
108108
E9009 = 9009,
109+
110+
/// <summary>
111+
/// Specified nanoCLR DLL file does not exist.
112+
/// </summary>
113+
[Display(Name = "Cannot update the CLR instance when requesting to load a specific version of it.")]
114+
E9010 = 9010,
115+
116+
/// <summary>
117+
/// Cannot retrieve list of native assemblies.
118+
/// </summary>
119+
[Display(Name = "Cannot retrieve list of native assemblies.")]
120+
E9011 = 9011,
109121
}
110122
}

targets/netcore/nanoFramework.nanoCLR.Host/Interop/nanoCLR.cs

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ internal static string DllPath
2323

2424
set
2525
{
26+
// Ensure the path includes a trailing path separator
27+
if (!value.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
28+
{
29+
value += Path.DirectorySeparatorChar;
30+
}
31+
2632
_dllPath = value;
2733

2834
// set path to search nanoCLR DLL

targets/netcore/nanoFramework.nanoCLR.Host/NanoClrHostBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public nanoCLRHostBuilder UseWireProtocolPort(IPort port)
9191
public string GetCLRVersion() =>
9292
Interop.nanoCLR.nanoCLR_GetVersion();
9393

94-
public List<NativeAssemblyDetails>? GetNativeAssemblies()
94+
public List<NativeAssemblyDetails>? GetNativeAssemblies() =>
9595
=> NativeAssemblyDetails.Get();
9696

9797
public nanoCLRHostBuilder UseSerialPortWireProtocol(string comPort) =>

0 commit comments

Comments
 (0)