Running Linux on new OpenRisc simulator or1ksim 0.4.0

Posted on 2010/07/13

13


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 or1ksim simulator
  • Compiles the Linux kernel with a pre-built filesystem image (initrd)
  • Runs the kernel with the simulator, opening an xterm to 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 initrd image by mounting it as an ext2 partition and copying a freshly built Busybox-based filesystem.
  • The initrd image is converted into an object file (initrd.o) containing a big array (2MiB) of initialized memory. The object file is then linked into the vmlinux kernel image; the exact position can be found in the file System.map, searching for the ___initrd_start symbol.
  • To run the simulator again, the command line is “or32-elf-sim -f or1ksim_linux.cfg vmlinux“, but the PATH must be set to point also to the “or1ksim-0.4.0/bin” directory; the files or1ksim_linux.cfg and vmlinux are in the Linux build directory “or32-build/linux-2.6.24
  • The or1ksim user manual is here, but a free OpenCores account is needed to download it.
  • To exit the simulator, type Ctrl-C inside the terminal where or1ksim has been executed, then execute q.

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.

About these ads
Posted in: Embedded