Skip to content

Instantly share code, notes, and snippets.

@cyring
Last active March 12, 2025 06:17
Show Gist options
  • Save cyring/adb32ec352cffcecba278e1b1c73b32b to your computer and use it in GitHub Desktop.
Save cyring/adb32ec352cffcecba278e1b1c73b32b to your computer and use it in GitHub Desktop.
RISC-V Ready
@cyring
Copy link
Author

cyring commented Feb 22, 2025

Recover Password

qemu-system-riscv64 -kernel target/boot/vmlinuz-6.11.0-17-generic \
-initrd target/boot/initrd.img-6.11.0-17-generic \
-append "root=/dev/vda2 nokaslr audit=0 init=/bin/sh" \
-machine virt -nographic -m 2048 -smp 4 \
-drive file=ubuntu_rv64.img -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 -device virtio-rng-pci
mount -o remount,rw /
passwd
passwd: password updated successfully
usermod -l cyril ubuntu
groupmod -n cyril ubuntu
usermod cyril -c Cyril
usermod cyril -d /home/cyril
mv -v /home/ubuntu /home/cyril
mount -o remount,ro /
poweroff -f

Boot nominal

qemu-system-riscv64 -kernel target/boot/vmlinuz-6.11.0-17-generic \
-initrd target/boot/initrd.img-6.11.0-17-generic \
-append "root=/dev/vda2 nokaslr audit=0 quiet" \
-machine virt -nographic -m 2048 -smp 4 \
-drive file=ubuntu_rv64.img -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 -device virtio-rng-pci

2025-02-22-065230_642x563_scrot

root@localhost:~# lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda    253:0    0  25G  0 disk 
├─vda1 253:1    0   1M  0 part 
└─vda2 253:2    0  25G  0 part /
root@localhost:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda2        25G  4.8G   19G  21% /
root@localhost:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            1955         209        1639           0         182        1746
Swap:           2047           0        2047
root@localhost:~# uname -a
Linux localhost 6.11.0-17-generic #17.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 29 02:24:01 UTC 2025 riscv64 riscv64 riscv64 GNU/Linux
root@localhost:~# lspci
00:00.0 Host bridge: Red Hat, Inc. QEMU PCIe Host bridge
00:01.0 Unclassified device [00ff]: Red Hat, Inc. Virtio RNG
00:02.0 SCSI storage controller: Red Hat, Inc. Virtio block device

@cyring
Copy link
Author

cyring commented Feb 22, 2025

Ubuntu 24.10 localhost ttyS0

localhost login: cyril

## you should already have git and the kernel headers
sudo apt install make gcc

mkdir ~/src && cd ~/src
git clone -b riscv64 https://github.com/cyring/CoreFreq.git
cd CoreFreq 
make -j

@cyring
Copy link
Author

cyring commented Mar 6, 2025

OpenSBI

git clone linux.git
git clone opensbi.git

cd linux
make -j8 ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- Image

cd opensbi
CROSS_COMPILE=riscv64-unknown-linux-gnu- make PLATFORM=generic FW_PAYLOAD_PATH=../linux/arch/riscv/boot/Image

qemu-system-riscv64 -M virt -m 256M -nographic -bios build/platform/generic/firmware/fw_payload.elf
OpenSBI v0.8-85-g0d49c3b
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : timer,mfdeleg
Platform HART Count       : 2
Firmware Base             : 0x80000000
Firmware Size             : 124 KB
Runtime SBI Version       : 0.2
...
[    0.000000] Linux version 6.3.0-rc3-00021-ga1effab7a3a3 ([email protected]) (riscv64-unknown-linux-gnu-gcc (g5964b5cd727) 11.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP Thu Mar  6 15:02:11 CET 2025
[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[    0.000000] Machine model: riscv-virtio,qemu
[    0.000000] efi: UEFI not found.
[    0.000000] OF: reserved mem: 0x0000000080000000..0x000000008001ffff (128 KiB) map non-reusable mmode_resv0@80000000
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080200000-0x000000008fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080200000-0x000000008fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x000000008fffffff]
[    0.000000] On node 0, zone DMA32: 512 pages in unavailable ranges
[    0.000000] SBI specification v0.2 detected
[    0.000000] SBI implementation ID=0x1 Version=0x8
[    0.000000] SBI TIME extension detected
[    0.000000] SBI IPI extension detected
[    0.000000] SBI RFENCE extension detected
[    0.000000] SBI HSM extension detected
[    0.000000] riscv: base ISA extensions acdfim
[    0.000000] riscv: ELF capabilities acdfim
[    0.000000] percpu: Embedded 19 pages/cpu s39992 r8192 d29640 u77824
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 64008
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment