Thread overview
Severin Teona - SAOC Milestone 1 Update 2 - Druntime for Microcontrollers
Sep 30, 2020
Severin Teona
Sep 30, 2020
kinke
Sep 30, 2020
IGotD-
September 30, 2020
Hi all,

This post represents the second weekly update for the first milestone for #SAoC2020.

After the first week, my plan for this week was:
- to build the runtime for the target architecture (ARM Cortex-M4 based MCUs), in order to have a working environment for the runtime.

First, I tried compiling the runtime using the ‘ldc-build-runtime’ tool but I was using it wrong.
This week:
- thanks to kinke’s advice([1]) I managed to build the runtime for cortex-m4, but that came with a few questions.
1. During the installation, because I was using ‘arm-none-eabi-gcc’, I got the following messages:

— The C compiler identification is GNU 9.3.1
— Detecting C compiler ABI info
— Detecting C compiler ABI info - failed
— Detecting C compile features
— Detecting C compile features - done
— The ASM compiler identification is GNU
— Found assembler: /home/teona/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gcc
— Looking for sys/types.h
— Looking for sys/types.h - not found
— Looking for stdint.h
— Looking for stdint.h - not found
— Looking for stddef.h
— Looking for stddef.h - not found
— Check size of void*
— Check size of void* - failed
— Looking for unistd.h
— Looking for unistd.h - not found
— Configuring done
— Generating done

Both the build and the linking parts were succesful, but I wanted to ask you if I should care about those messages, or if they appear because I wasn’t using ‘gcc’.

2. Also, I tried building the runtime without ‘BUILD_SHARED_LIBS=OFF’ and it failed, as it was looking for some dynamic libraries (-lpthread, -ldl, -lrt, and so on). My question here is, does abynody here know if there exists a set of dynamic libraries, compiled for this architecture? With TockOS, I’ve been using newlib([2]) as C standard library, but newlib is a static library. Would it make a big difference if I used a dynamic library?

My plan for next week is:
- to try to emulate a Cortex-M4 device using qemu - the biggest issue I have here is that there are just 2 Cortex-M4 based devices that can be emulated, and the resources(64KB of RAM and 256KB of flash) are way smaller than what I need (>2.5MB flash - the current size of the compiled runtime).
- to try to compile and run using qemu a basic `int main() { return 0;}` application in C, in D (using -betterC), in D (linked with the compiled druntime) and finally, a bigger application that uses GC from the compiled druntime (such as using a class or string concatenation)
- lastly, I will try to move and run all my work on a docker.

There is a strong possibility I won’t be able to test the druntime using qemu. Do you have any advice about what should I do next? (the board I am using has only 2MB of flash).

Thank you so much!

[1]: https://forum.dlang.org/post/vgnlauzerzezwfrgnrkv@forum.dlang.org
[2]: https://sourceware.org/newlib/

September 30, 2020
On Wednesday, 30 September 2020 at 16:35:05 UTC, Severin Teona wrote:
> 1. During the installation, because I was using ‘arm-none-eabi-gcc’, I got the following messages:
>
> — The C compiler identification is GNU 9.3.1
> — Detecting C compiler ABI info
> — Detecting C compiler ABI info - failed
> — Detecting C compile features
> — Detecting C compile features - done
> — The ASM compiler identification is GNU
> — Found assembler: /home/teona/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gcc
> — Looking for sys/types.h
> — Looking for sys/types.h - not found
> — Looking for stdint.h
> — Looking for stdint.h - not found
> — Looking for stddef.h
> — Looking for stddef.h - not found
> — Check size of void*
> — Check size of void* - failed
> — Looking for unistd.h
> — Looking for unistd.h - not found
> — Configuring done
> — Generating done
>
> Both the build and the linking parts were succesful, but I wanted to ask you if I should care about those messages, or if they appear because I wasn’t using ‘gcc’.

Seems okay for the moment, although the failing `size of void*` test certainly isn't ideal (IIRC, we make use of it in the CMake script). But no need to worry for now if things seem to be working.

> 2. Also, I tried building the runtime without ‘BUILD_SHARED_LIBS=OFF’ and it failed, as it was looking for some dynamic libraries (-lpthread, -ldl, -lrt, and so on). My question here is, does abynody here know if there exists a set of dynamic libraries, compiled for this architecture? With TockOS, I’ve been using newlib([2]) as C standard library, but newlib is a static library. Would it make a big difference if I used a dynamic library?

I strongly suggest not caring about the shared druntime/Phobos libs for now, those introduce lots of complexity, especially wrt. TLS, so focus on the static libs first (or even exclusively).

> My plan for next week is:
> - to try to emulate a Cortex-M4 device using qemu - the biggest issue I have here is that there are just 2 Cortex-M4 based devices that can be emulated, and the resources(64KB of RAM and 256KB of flash) are way smaller than what I need (>2.5MB flash - the current size of the compiled runtime).

I'm definitely no qemu expert, but are you sure you can't use the generic `virt` machine via something like `-M virt -m 1024 -cpu cortex-m4`?

For reference, here's what I use for emulating AArch64 (on a Windows host), giving it 3 cores and 6 GB of RAM:

"C:\Program Files\qemu\qemu-system-aarch64" -M virt -m 6144 -cpu cortex-a57 -smp 3 -kernel vmlinuz -initrd initrd.img -append "root=/dev/vda1" -drive if=none,file=disk.raw,format=raw,id=hd -device virtio-blk-device,drive=hd -netdev user,id=mynet,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=mynet
September 30, 2020
On Wednesday, 30 September 2020 at 16:35:05 UTC, Severin Teona wrote:
>
> 2. Also, I tried building the runtime without ‘BUILD_SHARED_LIBS=OFF’ and it failed, as it was looking for some dynamic libraries (-lpthread, -ldl, -lrt, and so on). My question here is, does abynody here know if there exists a set of dynamic libraries, compiled for this architecture? With TockOS, I’ve been using newlib([2]) as C standard library, but newlib is a static library. Would it make a big difference if I used a dynamic library?
>

Dynamic libraries and microcontrollers usually don't make any sense. Microcontrollers often don't have an MMU which means you don't win anything by having shared libraries.

I would just skip druntime and phobos and try to use the OS API directly from D.