The guys at OpenCores released a new version of their OpenRisc core, tweaking many hardware bug but also porting Linux kernel 2.6.24 to their simulation platform, that is called or1ksim. The procedure (found here) to try Linux on the new simulator is straightforward and involves executing a script. The script hides most of the complexity of the procedure, but essentially it:
- Downloads the source code of Linux kernel, OpenRisc simulator and necessary tools
- Downloads and applies the patches to the original sources that add OpenRisc support to the compiler, the kernel and the other tools
- Compiles the compiler (
or32-elf-gcc) and the toolchain - Compiles the
or1ksimsimulator - Compiles the Linux kernel with a pre-built filesystem image (
initrd) - Runs the kernel with the simulator, opening an
xtermto connect to the simulator console.
To understand what does the script do behind the scenes, many log files remain in the build directory, and the script itself is very linear and easy to understand. A couple of things I discovered:
- If you run the script with root privileges, it modifies the
initrdimage by mounting it as anext2partition and copying a freshly built Busybox-based filesystem. - The
initrdimage is converted into an object file (initrd.o) containing a big array (2MiB) of initialized memory. The object file is then linked into thevmlinuxkernel image; the exact position can be found in the fileSystem.map, searching for the___initrd_startsymbol. - To run the simulator again, the command line is “
or32-elf-sim -f or1ksim_linux.cfg vmlinux“, but thePATHmust be set to point also to the “or1ksim-0.4.0/bin” directory; the filesor1ksim_linux.cfgandvmlinuxare in the Linux build directory “or32-build/linux-2.6.24“ - The
or1ksimuser manual is here, but a free OpenCores account is needed to download it. - To exit the simulator, type
Ctrl-Cinside the terminal whereor1ksimhas been executed, then executeq.
To study the details of the toolchain, another good starting point is to look at the patch files that are downloaded inside the “or32-download” directory and identify the parts of the original tools that are modified.
Entries
veera
2010/08/29
hi… First of all thanks for this article!… I have installed the tool chain and or1ksim using the script available in http://opencores.org/openrisc,gnu_toolchain but how do i run toolchain & ork1sim together and execute a simple hello world program!… Please help… thanks in advance!!!
Balau
2010/08/30
Hello veera,
The openrisc project has many little programs to test the hardware, you can start with these. You need an OpenCores account and Subversion (svn) to reach their repository, then you can download them with:
$ svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/orpsocv2/sw/
and compile with:
$ cd sw/utils
$ make all
$ cd ../support
$ make all
$ cd ../uart
$ make all
You will create an executable called uart-nocache.or32 that you can run in the simulator.
Then you need a cfg file for or1ksim that sets the UART at address 0×90000000, RAM starting at 0, and disabled memory controller, cache and memory management units. You can find some .cfg example files in the build directory of or1ksim (mine are in “or32-build/or1ksim-0.4.0/testsuite/or1ksim.tests/”). You can also start with the one in the linux patched kernel (“or32-build/linux-2.6.24/or1ksim_linux.cfg”) and disable the memory controller and managers.
Then run the simulator with or1ksim -f yourfile.cfg uart-nocache.or32
veera
2010/08/31
Thanks again for your reply and suggestions!!! will test and get back to you…
veera
2010/09/12
Hi!!! I went according to your suggestions and i get “No rule to make target `all` ” Error when i hit make all in uart…
Brief:
$ svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/orpsocv2/sw/(DONE)
$ cd sw/utils(DONE)
$ make all(DONE)
$ cd ../support(DONE)
$ make all(DONE)
$ cd ../uart(DONE)
$ make all(ERROR “No rule to make target all”)
How do i proceed now???
Thanks for your help in advance…
Balau
2010/09/12
Well, they changed the compilation rules under our nose
I have no time now to check the correct way to use their new compilation system, so I think it’s best to get the old version (the one that I used for my tests). To do so, instead of the svn command, do the following:
$ svn co -r 67 http://opencores.org/ocsvn/openrisc/openrisc/trunk/orpsocv2/sw/Then follow the previous steps.
veera
2010/09/13
Thank yo so much Balau!…
I am happy that Its working and i got the uart-nocache.or32 file!…
I have two questions now
1) having added two path (/root/or1ksim/bin/) and (/root/or32-elf/bin) i find only or32-elf-sim in the terminal and not or1ksim …. So how do i give this command ( or1ksim -f your.cfg uart-nocache.or32 )
2) Can you get me the exact configuration file so that i can verify it now and will explore about the other modes later…
Please help!!!
Balau
2010/09/13
1) Oh you’re right the simulator name is or32-elf-sim, I don’t know why I typed or1ksim!
2) I’m sending the configuration file to your email because it’s too long to paste here.
Robert
2010/11/19
Hi,
I’m running linux on the or1ksim 0.4.0 version. I would like to run some of my custom c programs in the simulator to try to get a better understanding of how it works. I’m trying to find some good documentation with some tutorials (if possible) that could guide me through the basic commands I can use in the simulated linux environment. I know, basically, how to use and configure busybox and how to mount and umount the ramdisk image to get my custom programs into the linux simulator, but I’m not sure how to run my programs. I just created a basic “hello world” program, but it doesn’t seem to execute. Gives me an error message saying something around the lines of : Expected “(”
when i do ./hello
I admit I’m still kind of a newbie at both linux and the simulator.
Any feedback would be much appreciated.
Thanks,
Robert
Balau
2010/11/20
Hello,
unfortunately the Linux port and the simulator are not very stable in my opinion, so maybe the error is related to a bug. The error you mention is very strange.
I think you should start first with shell scripts, then pass to statically linked programs(using the -static GCC option), then to dynamically linked programs (using .so shared libraries that are similar to Windows .dll libraries).