User avatar
Gavinmc42
Posts: 4528
Joined: Wed Aug 28, 2013 3:31 am

Re: Announce: RusPiRo - a kernel the Rust way ;)

Sun Sep 15, 2019 7:14 am

https://www.funtoo.org/Welcome

Is there a Linux OS that is optimised for best performance on Aarch64?
Anyway the point is to get away from Linux.

Are you a "nightly build" Rust tester?
Rust updated 16 minutes ago, Crates-io-index 2 minutes ago :lol:

One thing that surprises me is how well some Laz/FPC/Delphi libs just port and work in Ultibo.
If Rust crates can do the same thing for this RasPiRo :o
Time to try Rustng RasPRo on Gentoo64.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Heater
Posts: 16003
Joined: Tue Jul 17, 2012 3:02 pm

Re: Announce: RusPiRo - a kernel the Rust way ;)

Sun Sep 15, 2019 11:25 am

Gavinmc42,
Are you a "nightly build" Rust tester?
Not in any official way. It's just that I wanted to use some features that are only available in nightly builds just now. I have reported a couple of bugs in Rust crates, not in Rust itself, and not in any mainstream crates.

Hmm... However I now find I have one Rust program that won't build on the Pi using nightly in --release mode. rustc craps out with "signal: 11, SIGSEGV: invalid memory reference".
Memory in C++ is a leaky abstraction .

Schnoogle
Posts: 129
Joined: Sun Feb 11, 2018 4:47 pm

Re: Announce: RusPiRo - a kernel the Rust way - Bootloader ready

Fri Dec 20, 2019 9:29 am

Hi there,

long time no see :)

It really took me a time to get use to aarch64 on the Raspberry Pi, but now I can share that I've released a Bootloader for the RusPiRo journey.
It's written mainly in Rust - the bootstrapping is assembly. The Repo can be found here: https://github.com/RusPiRo/ruspiro-loader.

The Bootloader kicks the Raspberry Pi in Aarch64 mode in EL2 and depending on the new kernel that will be loaded it will either switch to Aarch32(SVC) or Aarch64(EL1). As the bootloader deployed to the Raspberry Pi expects the new kernel image file to be send via miniUART in a specific "protocol" there is also a development machine (host) application available. This is build as a subcommand for the rust build tool cargo and could be easily installed with

Code: Select all

$> cargo install cargo-ruspiro-push
For more details checkout the README:https://github.com/RusPiRo/ruspiro-load ... /README.md.

A general bootstraper to be used in your own bare metal Rust kernel project could be found here: https://github.com/RusPiRo/ruspiro-boot. This bootstrapper does the most common low-level tasks to hand over execution to the entry point written in high level language rust. The minimal initialization does:
  • Setup all stack pointers
  • Configure the MMU with basic 1:1 mapping
  • Initialize the miniUART with a baud rate of 115200 to be used as debug console.
  • Prepare default exception vector table and provide dummy handler that could be easily "overridden"
To get a quick start with all the initial Rust project setup you could use the project templates available here: https://github.com/RusPiRo/ruspiro_templates (even though it's only one at the moment to be honest ;) )

I'd love to get your feedback ...
I've tested the stuff on Raspberry Pi 3B+ hardware only, but should work fine on all other Raspberry Pi 3 versions as well.
Due to a different MMIO Peripheral start address it currently does not work on Raspberry Pi Zero, 1, 2. Event though it's not difficult to enable those hardware as there is already a corresponding feature gate built in I'm not able to test this on real hardware, which lead to the fact that I might not port it because of this.

Regards,
Schnoogle

User avatar
rahealy
Posts: 24
Joined: Thu Dec 19, 2019 5:30 pm

Re: Announce: RusPiRo - a kernel the Rust way - Bootloader ready

Fri Jan 03, 2020 8:01 pm

Schnoogle wrote:
Fri Dec 20, 2019 9:29 am
Hi there,

long time no see :)

It really took me a time to get use to aarch64 on the Raspberry Pi, but now I can share that I've released a Bootloader for the RusPiRo journey.
It's written mainly in Rust - the bootstrapping is assembly. The Repo can be found here: https://github.com/RusPiRo/ruspiro-loader.
...
I'd love to get your feedback ...
...
Regards,
Schnoogle
Greetings,

I suggest adding an option to enable JTAG.

My JTAG adapter doesn't work and haven't got a job yet to buy a new one. My JTAG specific code is untested and WIP.

For background I used earlier revisions of these tutorials:

https://github.com/rust-embedded/rust-r ... hainloader
https://github.com/rust-embedded/rust-r ... debug_JTAG

Here's a bootloader (rx folder contains rpi3 code):

https://github.com/rahealy/rpi3fxproc/b ... ootloader/

Here's my code to set JTAG pins (again untested):

https://github.com/rahealy/rpi3fxproc/b ... el.rs#L249

I also suggest looking into a way to pass argument strings to the kernel for configuration options.

Kind Regards,

-Richard Healy

Schnoogle
Posts: 129
Joined: Sun Feb 11, 2018 4:47 pm

Re: Announce: RusPiRo - a kernel the Rust way ;)

Sat Jan 04, 2020 4:49 pm

Hey,
thanks for your suggestions.
If I got your references right, than there seem to be nothing required to be supported from bare-metal kernel point of view to enable JTAG debugging. https://github.com/rust-embedded/rust-r ... ware-setup

So you only need to place a config .txt file with your kernel8.img onto the SD card where the config.txt contains the activation of JTAG supprt. This shall configure the GPIO pins used to be connected to your JTAG controller. However, I do not have any experience with JTAG so far but thought it might make sense to investigate into this, so I just ordered one and will check if I can get it to work as suggested there.
I also suggest looking into a way to pass argument strings to the kernel for configuration options.
Regarding kernel configuration with files or argument strings I've mixed thoughts. I'd rather like to provide Rust feature gates to build the kernel files with specific configurations. This way I can rely on compile time check during implementation as much as possible and do not need to implement additional runtime checks that verify that the given configuration is valid. But it could be that future developments might require this sort of external configuration if there is a need to use pre-compiled bare metal images that still should support some configurable flexibility.

Best regards
Schnoogle

User avatar
rahealy
Posts: 24
Joined: Thu Dec 19, 2019 5:30 pm

Re: Announce: RusPiRo - a kernel the Rust way ;)

Tue Jan 07, 2020 1:04 am

Schnoogle wrote:
Sat Jan 04, 2020 4:49 pm
Hey,
thanks for your suggestions.
If I got your references right, than there seem to be nothing required to be supported from bare-metal kernel point of view to enable JTAG debugging. https://github.com/rust-embedded/rust-r ... ware-setup

So you only need to place a config .txt file with your kernel8.img onto the SD card where the config.txt contains the activation of JTAG supprt.
Oh! I apologize. Looks like the tutorial author changed that part from what it was in the first revision. For development I find removing/inserting a sdcard is a hassle, so I prefer to do as much in software as possible. Looks like the author might have removed the old version that explained how to do that. :|
Regarding kernel configuration with files or argument strings I've mixed thoughts. I'd rather like to provide Rust feature gates to build the kernel files with specific configurations. This way I can rely on compile time check during implementation as much as possible and do not need to implement additional runtime checks that verify that the given configuration is valid. But it could be that future developments might require this sort of external configuration if there is a need to use pre-compiled bare metal images that still should support some configurable flexibility.
FWIW, here's what I've learned so far: I've only been using rust for about 6 months now but I appreciate how the currently slow compilation times add up quickly in a compile-test cycle compared to more mature (er, ancient ;) ) language tools I've used. So, it might be worth using arguments where it makes sense while testing and developing the OS then moving over to gates when the feature works. I've found that anything over 60kB program size starts to feel slow when loading over UART at 115200 baud - so at some point there will be diminishing returns in having everything in the executable when testing on actual hardware.

Anyway, back to trying to figure out why my DMA code isn't working. :?

Best Wishes,

-Richard

Schnoogle
Posts: 129
Joined: Sun Feb 11, 2018 4:47 pm

Re: Announce: RusPiRo - a kernel the Rust way ;)

Wed Jan 08, 2020 8:44 am

rahealy wrote:
Tue Jan 07, 2020 1:04 am
I've found that anything over 60kB program size starts to feel slow when loading over UART at 115200 baud - so at some point there will be diminishing returns in having everything in the executable when testing on actual hardware.
Well you are totally right, as the kernel size grows this might get cumbersome to transfer using UART. My plan is - as this will be a really special purpose kind of an OS - to make “updates” to the base functionality via Bluetooth. So mainly I’m aiming for a core stable kernel that could be enhanced with skills and behaviors via Bluetooth uploads. Let’s see how far I get with this idea of a modular robot OS :)

Unfortunately I’ve not touched DMA stuff so can’t help there ...
Best regards

Schnoogle

User avatar
Gavinmc42
Posts: 4528
Joined: Wed Aug 28, 2013 3:31 am

Re: Announce: RusPiRo - a kernel the Rust way ;)

Wed Jan 08, 2020 10:41 am

I've had the idea of compiled commands that are called by scripts.
An interpreted language that runs modules.
A shell scripted linux? Which is where I got the idea.

Linux is very complex, i have no idea what 99.99% of the files do?
PiCore is the smallest I use and I know some of the files.
It is very useful as it has Micropython etc but still has vulnerabilities as it is a kernel with busybox I I don't know how to secure it. .

Update over the air microkernals are common in the Bluetooth IoT arena now.
Is there an Open Source version?
The ones I have been using since 2011 are propriety.

The idea of just updating one module and not the whole OS is interesting.
Am watching with interest your progress.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Heater
Posts: 16003
Joined: Tue Jul 17, 2012 3:02 pm

Re: Announce: RusPiRo - a kernel the Rust way ;)

Wed Jan 08, 2020 2:11 pm

jcyr,
Like Rust, Ada is 'amazingly' verbose, to its detriment.
I have to disagree there. Ada was famously known as being verbose. Rust certainly is not. For example, what is verbose about this Rust:

Code: Select all

    fn free(&mut self, k: PrimeType, l: PrimeType) -> bool {
        let n = l / k;
        let lmin = (k + 1) * n + 2;
        let lmax = (k - 1) * (n + 1) - 2;
        (lmin <= l) && (l <= lmax)
    }
Compared to the C version:

Code: Select all

    static int tfree(k,l) long k,l; {
        long n = l / k;
        long lmin = (k + 1) * n + 2;
        long lmax =(k - 1) * (n + 1) -2 ;
        return lmin <= l && l <= lmax;
    }
Rust is nowhere near comparable to Ada in verbosity, or Java or even C++ etc. It's more in line with C.
I'm quite happy to have the compiler assume an integer to float conversion instead of having to instruct it to do so. I, for one, am not a fan of OPCS (Obsessively Pedantic Compiler Syndrome).
As far as I can tell Rust is no more pedantic than is required to ensure memory safety in the program. As we all know, those silent type coercions of C have been the source of many bugs in C/C++ programs over the decades. If one does not value correctness in ones programs I guess it can be seen as pedantic.

When I want minimal verbosity for a quick hack I use Javascript.

You might be interested in this project description and code: "Rewriting m4vgalib in Rust" : http://cliffle.com/blog/m4vga-in-rust/#continue-reading. Before pronouncing on the verbosity and pedantry of Rust.
Memory in C++ is a leaky abstraction .

jahboater
Posts: 5801
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Announce: RusPiRo - a kernel the Rust way ;)

Wed Jan 08, 2020 7:24 pm

Heater wrote:
Wed Jan 08, 2020 2:11 pm
As far as I can tell Rust is no more pedantic than is required to ensure memory safety in the program.
Yes, I agree. Though memory safety is one aspect only of program correctness (see CERT, MISRA etc).
Heater wrote:
Wed Jan 08, 2020 2:11 pm
As we all know, those silent type coercions of C have been the source of many bugs in C/C++ programs over the decades.
Only for twerps that turn off the warnings. GCC nowadays is very precise and informative about type coercions that might change the value, lose precision, lose a qualifier, lose alignment etc.
Heater wrote:
Wed Jan 08, 2020 2:11 pm
If one does not value correctness in ones programs I guess it can be seen as pedantic.
+1 !!

LdB
Posts: 1581
Joined: Wed Dec 07, 2016 2:29 pm

Re: Announce: RusPiRo - a kernel the Rust way ;)

Thu Jan 09, 2020 3:34 am

Heater wrote:
Wed Jan 08, 2020 2:11 pm
Ada was famously known as being verbose. Rust certainly is not.
tooption.as_ref().unwrap().borrow() definitely not verbose :-)

User avatar
Gavinmc42
Posts: 4528
Joined: Wed Aug 28, 2013 3:31 am

Re: Announce: RusPiRo - a kernel the Rust way ;)

Fri Feb 07, 2020 1:55 am

Been learning VC6 3D without x11 and came across this, it looks like there is a Rust GBM/DRM/KMS example?
https://github.com/ds-hwang/gbm_es2_demo

PI4 OpenGLES on DRM etc
https://www.raspberrypi.org/forums/view ... 8&t=264084
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Bare metal, Assembly language”