Support for Loongson in .NET Core and Thoughts on .NET Core Development in Embedded Systems

2019年12月15日 72点热度 1人点赞 16条评论
内容目录

Support for .NET Core on Loongson and Thoughts on Developing Embedded Systems with .NET Core

[TOC]

1. Regrettable Attempt

Not long ago, I came across a public post by Zhang on WeChat titled “Asp.Net Finally Runs on Loongson Servers: Jexus Successfully Adapts to Domestic CPU Series”. It reminded me of last week when my friend and I were experimenting with .NET Core on Loongson, and I felt compelled to write about the information regarding .NET Core on Loongson.

Jexus Web Server can run on Loongson servers, but what about ASP.NET? .NET Core? What version of Mono should be installed? The article by the Jexus author is somewhat unclear~

Last week, my friend and I spent quite a bit of effort trying to deploy a .NET project on Loongson. His company won a government project, and after developing a project with .NET Core, they found out that the deployment server was based on Loongson, making .NET Core unable to run on it.

The server has Mono 4.x installed, allowing the creation of a simple Proparm.cs file, which could be compiled and run using mono xx.exe, but we couldn't compile the project~ Attempts to compile and install Mono 6.x also failed, as some errors appeared during the process.

Naturally, there was no hope for .NET Core; it couldn't be compiled at all. After searching for information on Google, we learned that rewriting the C++ portion (porting) was necessary to compile CoreCLR on Loongson.

In the official CoreCLR source repository, we can see some scripts and build toolchains.

https://github.com/dotnet/coreclr/

RISV-C is a reduced instruction set; MIPS refers to the CPU architecture based on RISC-V, and Loongson servers use the MIPS architecture.

In the end, we couldn't deploy .NET software, and my friend's company switched to Java for development...

Earlier, I spent a lot of time manually compiling .NET Core to run on Armel CPU, but ultimately failed. I wrote a detailed article about the compilation process, titled “Chronicles of a Foolish Endeavor: Building .NET Core for Armel and Resource Compilation Tutorial”.

2. Some Shortcomings of .NET Core in Embedded Systems

In July 2018, Zhang organized a .NET meetup at my university in the Greater Bay Area, which marked the beginning of my learning journey with .NET. Since then, I transitioned from an intern to a full-time position in March 2019.

In my six months of using .NET Core for embedded development, I have summarized several issues/suggestions regarding .NET Core in the embedded field.

1. Incompatibility with Older CPUs

.NET Core cannot run on Raspberry Pi Zero (Arm v6);

It cannot run on Huawei HiSilicon A9 chips (Armel Armv7);

Although these two chips were released several years ago, .NET Core boasts its ambitions for IoT but does not support these older CPUs. Many legacy devices will still be mainstream for a while in the future.

Microsoft's official stance is:

Note: .NET Core 2.1 is supported on Raspberry Pi 2+. It isn’t supported on the Pi Zero or other devices that use an ARMv6 chip. .NET Core requires ARMv7 or ARMv8 chips, like the ARM Cortex-A53.

The support for ARM is still insufficient.

2. Limited Hardware Device Testing

Official testing for embedded devices has primarily focused on Raspberry Pi 2 / 3, and many development boards remain untested~

3. Limited Support for Compatible OS Versions

.NET Core supports many Linux systems, but this support is mainly for the latest versions. For instance, .NET Core 3.0 supports Ubuntu 16.x and 18.x, while 14.x and 17.x are ruthlessly abandoned.

The systems supported by .NET Core 3.0 are as follows:

https://github.com/dotnet/core/blob/master/release-notes/3.0/3.0-supported-os.md

4. Size Remains Too Large

For embedded development, the size of .NET Core is still too large; even .NET Core 3.0 cannot help... A simple “Hello World” application requires over 70MB+ in size.

5. Dependency Libraries are Problematic

There are frequent issues with inconsistent versions of dependency libraries like ICU, libssl, gcc, or missing libraries, which have made some developers, like Shitouge, pull their hair out over these problems.

3. Progress and Resources for .NET Core Porting on Loongson

According to community contributors, as of November 9, a Hello World instance of .NET Core has been successfully run on Loongson,

The code base was upgraded to 3.0. Hello World and several tests in coreclr can run on MIPS64 now.

This is a porting achievement for CoreCLR, but many issues still await resolution by experts.

For discussions on the porting of .NET Core on MIPS, check the Issue page:

https://github.com/dotnet/coreclr/issues/969#issuecomment-550129085

However, Microsoft currently has no plans for porting, and it is left to the community to accomplish it.

Microsoft currently has no plans or work in progress to support MIPS. Of course, we would be willing to accept external contributions towards that goal as appropriate. Note that it is, certainly, a significant amount of work to port .NET Core to a new platform.

Another significant project by a developer:

https://github.com/reignstudios/IL2X

This project will focus on translating .NET IL for non-supported .NET targets. Portability is a huge focus.

  • .NET Standard compatibility
  • Native C performance
  • C89: modern, legacy, and embedded platforms (x86, MIPS, SPARK, RISC-V, PPC, AVR, etc.)
  • CC65: 6502 platforms (Atari, C64, NES, Apple II, etc.) [CS2X may be better suited]
  • SDCC: Many targets (ColecoVision, etc.) [CS2X may be better suited]
  • Assembly: CP1610 (Intellivision) [CS2X may be better suited]
  • Retarget: Custom assembly targets via plugin system (FPGA CPU, 16bit bytes, etc.)
  • Custom Standard lib(s) for various targets.
  • Documentation

痴者工良

高级程序员劝退师

文章评论