3

For a university project I was tasked with implementing privilege levels on an existing RISC-V (rv32i) processor with the end goal to have it run Linux. Due to complexity, my project ended with the privelege levels and now I am tasked with finishing this as my part time job (quite neat).

The processor is now a rv32ima with msu privilege levels and sv32 MMU without TLB.

This processor is implemented in a strict subset of SystemC. Linux is run by calling the bootloader through a simulation environment.

I have been researching a lot. However, at this point I feel I am forced to seek assistance.

Update: Forgot to add that there is no hard drive on this system, so the idea is to run the system using the initramfs as the real root filesystem.

I cross compile my minimal linux with initramfs built in. My initramfs is cross compiled with the same toolchain.

My initramfs is a simple statically linked busybox, only containing sh, echo, ls, ash, stty, mount and some others.
This is my /dev:

 crw-rw-rw- 1 root    root    5, 1 Jan 11 14:51 console
lrwxrwxrwx 1 ovsthus ovsthus   15 Jan 11 15:10 fd -> ../proc/self/fd
crw-rw-rw- 1 root    root    1, 3 Jan 11 14:52 null
drwxr-xr-x 2 ovsthus ovsthus 4096 Jan 11 15:04 pts
drwxr-xr-x 2 ovsthus ovsthus 4096 Jan 11 15:05 shm
lrwxrwxrwx 1 ovsthus ovsthus   17 Jan 11 15:09 stderr -> ../proc/self/fd/2
lrwxrwxrwx 1 ovsthus ovsthus   17 Jan 11 15:09 stdin -> ../proc/self/fd/0
lrwxrwxrwx 1 ovsthus ovsthus   17 Jan 11 15:09 stdout -> ../proc/self/fd/1

On my host computer these symlinks are red with black background

I am not sure what i need here yet, but I want to start out with some console outputs.

Initramfs is cpio.gz compressed using the shell script in linux initramfs documentation.

Kernel command line: console=ttySIF0 mem=512M earlycon=sbi

I get plenty of output from early console, and in the end it switches over to ttySIF0 console and that seems to work as well, support for it is built into the kernel.

As soon as my boot reaches this part: Run /init as init process
Things start to go wrong, or not go at all.

I try having this as my init:

#!/bin/sh 
echo "some text"

but nothing gets printed out, and after some time kernel panics for attempting to kill init. I tried exec'ing a c program that just adds an unlikely number after echo, and look for that number in the register, and that does appear after Run /init as init process so I know it can do something.

Running any busybox binary results in it being stuck on init. Also trying to mount devtmpfs from init results in it being stuck.

I can see that my system is running user level system calls indefinitely but I have no idea what it is trying to do.

Update: I am able to operate the console with hvc, and boot into /bin/sh. From here I can use commands like echo 'something' or printf with no problem as long as they are built into the shell.
If I have wrong syntax I get error message, and if i misuse a command it gives me error message. But if i use a command like mount, ls, rm etc.. the program hangs, console still seem to function.

ls prints the list of directories but it seems to never return.

cd'ing into /dev I can see the folder doesn't look very populated besides from the files already present in the initramfs.cpio. My theory is that this is why console can't be operated with console=ttySIF0

Regardless, I would be happy to use hvc but my system is not very useful if all it can do is print to console or use ls just once.

I don't know if I need a very specific kernel + filesystem config to fix this or if I only need the correct boot arguments. I tried adding rw since it seems to just not be able to interact with the files in the filesystem, but it did't seem to have any effect.

current kernel command line: rw earlycon=sbi

I am posting the entire (new) bootlog in case that helps:
Here I type the ls command twice.
I dont know why I get the sh: Poll: function not implemented message. That wasn't there on another configuration but now I can't get rid of it.

bbl loader
              vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
                  vvvvvvvvvvvvvvvvvvvvvvvvvvvv
rrrrrrrrrrrrr       vvvvvvvvvvvvvvvvvvvvvvvvvv
rrrrrrrrrrrrrrrr      vvvvvvvvvvvvvvvvvvvvvvvv
rrrrrrrrrrrrrrrrrr    vvvvvvvvvvvvvvvvvvvvvvvv
rrrrrrrrrrrrrrrrrr    vvvvvvvvvvvvvvvvvvvvvvvv
rrrrrrrrrrrrrrrrrr    vvvvvvvvvvvvvvvvvvvvvvvv
rrrrrrrrrrrrrrrr      vvvvvvvvvvvvvvvvvvvvvv  
rrrrrrrrrrrrr       vvvvvvvvvvvvvvvvvvvvvv    
rr                vvvvvvvvvvvvvvvvvvvvvv      
rr            vvvvvvvvvvvvvvvvvvvvvvvv      rr
rrrr      vvvvvvvvvvvvvvvvvvvvvvvvvv      rrrr
rrrrrr      vvvvvvvvvvvvvvvvvvvvvv      rrrrrr
rrrrrrrr      vvvvvvvvvvvvvvvvvv      rrrrrrrr
rrrrrrrrrr      vvvvvvvvvvvvvv      rrrrrrrrrr
rrrrrrrrrrrr      vvvvvvvvvv      rrrrrrrrrrrr
rrrrrrrrrrrrrr      vvvvvv      rrrrrrrrrrrrrr
rrrrrrrrrrrrrrrr      vv      rrrrrrrrrrrrrrrr
rrrrrrrrrrrrrrrrrr          rrrrrrrrrrrrrrrrrr
rrrrrrrrrrrrrrrrrrrr      rrrrrrrrrrrrrrrrrrrr
rrrrrrrrrrrrrrrrrrrrrr  rrrrrrrrrrrrrrrrrrrrrr

       INSTRUCTION SETS WANT TO BE FREE
[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000
[    0.000000] Linux version 5.4.0-rc5-00034-g23fdb198ae81-dirty (ovsthus@ovsthus-8943G) (gcc version 9.2.0 (GCC)) #301 Sun Jan 19 09:54:12 CET 2020
[    0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
[    0.000000] printk: bootconsole [sbi0] enabled
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000080400000-0x000000009fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080400000-0x000000009fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x000000009fffffff]
[    0.000000] elf_hwcap is 0x1101
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 128778
[    0.000000] Kernel command line: rw earlycon=sbi
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
[    0.000000] Sorting __ex_table...
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 511396K/520192K available (2014K kernel code, 88K rwdata, 330K rodata, 656K init, 189K bss, 8796K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 0, nr_irqs: 0, preallocated irqs: 0
[    0.000000] plic: mapped 53 interrupts with 0 handlers for 1 contexts.
[    0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0]
[    0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns
[    0.000034] sched_clock: 64 bits at 1000MHz, resolution 1ns, wraps every 4398046511103ns
[    0.000300] printk: console [hvc0] enabled
[    0.000300] printk: console [hvc0] enabled
[    0.000493] printk: bootconsole [sbi0] disabled
[    0.000493] printk: bootconsole [sbi0] disabled
[    0.000753] Calibrating delay loop (skipped), value calculated using timer frequency.. 2000.00 BogoMIPS (lpj=4000000)
[    0.001039] pid_max: default: 32768 minimum: 301
[    0.001689] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.001895] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.007399] devtmpfs: initialized
[    0.010812] random: get_random_u32 called from bucket_table_alloc.isra.0+0x70/0x1d8 with crng_init=0
[    0.011403] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.011637] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.019014] clocksource: Switched to clocksource riscv_clocksource
[    0.295837] workingset: timestamp_bits=30 max_order=17 bucket_order=0
[    0.339655] Freeing unused kernel memory: 656K
[    0.339774] This architecture does not have kernel memory protection.
[    0.339922] Run /init as init process

BusyBox v1.31.1 (2020-01-18 13:05:03 CET) built-in shell (ash)

/ # sh: poll: Function not implemented

lsh: poll: Function not implemented 
ssh: poll: Function not implemented

bin      etc      lib      proc     run      sys      usr
dev      init     linuxrc  mnt      root     sbin     tmp

ls

I am very grateful for any advice or discussion!

  • 1
    If all you do is echo and then quit, the "attempt to kill init" panic is normal and expected (because the init process exits after echo, then what?). Whether the echo itself works also depends on your busybox/initrd configuration (and kernel configuration for a working terminal/console). It's hard to debug such things remotely... – frostschutz Jan 13 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.