What is XV6
XV6 is an Operating System. It is a reimplementation of Unix version 6 developed by MIT for educational purposes in 2006. Originally Unix V6 ran on PDP-11 and was written in an old version of C. XV6 was written for x66 PCs in ANSI C with a little assembly code.
The source code of Unix V6 and XV6 is openly available. XV6 is only about 6000 lines of code and is well-written; individual parts of the OS are easily recognisable. Although it would be challenging to understand it all, this is the ultimate way of familiarising yourself with Operating System functions and code in general and Unix / Linux in particular.
Build XV6
Michael Engel has adapted xv6 to run on an Allwinner Nezha RISC-V system and provided the source plus instructions on github. The instructions look straightforward but it has taken me a while to get them to work.
I then found riscv-unknown-elf on github together with instructions to build it. Not as easy as installing a package with apt, but worth a shot.
The instructions were good, I followed them carefully and a few hours and 6.65GB later the build said it was successful.
Next step is to build XV6 using riscv-unknown-elf, so I cloned Micahel Engel's xv6 and built it. There was a compilation error when building fs.img but google provided a resolution. I now have a file kernel.bin containing my very own Unix v6 OS which I need to load into Nezha RAM.
FEL mode
There isn't a way to put xv6 on an SD card, as it doesn't contain a disk driver so we have to load it into RAM. Allwinner provide low level routine to do this:
The Allwinner user community Sunxi, provides wonderful resources for using Allwinner SoCs. They explain how to install / use the xfel tool in conjunction with a Nezha in FEL mode.
I have built a real (but rather primitive) RISC-V Unix OS which I can tinker with or add to as much as I like.
Alternative XV6
I spent a few minutes doing this and now have a second version available to me. In all honesty it will be much easier to use WSL rather than a Nezha in FEL mode to tinker, but I have both available, they both "look" the same and are likely to be interchangeable. I could easily develop on WSL before finalising on Nezha.
No comments:
Post a Comment