2025年12月6日星期六

AXI4 with pulp-platform axi

During use the pulp-axi component with AXI4 peripheral, the  parameter ATOP should be set to 0. 

Assign the atop signal of AXI4 master, slave to 0 especially in axi_width_converter, otherwise it will not work properly. 

Anyway, axi_atop_filter could also be used to filter the ATOP signal.

run linux/freebsd on qemu

Get the qemu, compiler tool-chain and below software package
  • qemu-system-riscv64
  • riscv64-linux-gnu-
  • busybox
  • linux
  • opensbi (optional)
  • u-boot (optional)

 

Reference:

https://risc-v-machines.readthedocs.io/en/latest/linux/simple/#pull

https://www.qemu.org/docs/master/system/riscv/virt.html

https://gitlab.inf.ethz.ch/project-openenzian/applications/risc-v/riscv-gnu-toolchain

 

Build the Linux 

export CROSS_COMPILE=riscv64-linux-gnu- 

make ARCH=riscv defconfig 

make ARCH=riscv -j 8 

the image will be generated at arch/riscv/boot/Image

 

Build the Busybox 

export CROSS_COMPILE=riscv64-linux-gnu-

make ARCH=riscv menuconfig

make it as static library

make ARCH=riscv

After fix the compile error (set CONFIG_SHA1_HWACCEL=0), busybox will be generated 


Build the initramfs

mkdir initramfs

cd initramfs

mkdir -p {bin,sbin,dev,etc,home,mnt,proc,sys,usr,tmp}

mkdir -p usr/{bin,sbin}

mkdir -p proc/sys/kernel

cd dev sudo mknod sda b 8 0

sudo mknod console c 5 1

cd ..

cp ../busybox/busybox ./bin/

 

vi init  #Change the init file as: 

#!/bin/busybox sh

# Make symlinks 

/bin/busybox --install -s

# Mount system

mount -t devtmpfs devtmpfs /dev

mount -t proc proc /proc

mount -t sysfs sysfs /sys

mount -t tmpfs tmpfs /tmp

# Busybox TTY fix

setsid cttyhack sh

# https://git.busybox.net/busybox/tree/docs/mdev.txt?h=1_32_stable

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev -s

sh

 

Quit the vi, add the +x permission 

chmod +x init

Pack as cpio.gz format 

find . -print0 | cpio --null -ov --format=newc | gzip -9 > initramfs.cpio.gz

 

Boot the Linux kernel

qemu-system-riscv64 -machine virt  -m 2G  -nographic  -kernel linux/arch/riscv/boot/Image -initrd initramfs/initramfs.cpio.gz


Compile u-boot

riscv64_smode_defconfig 


Boot the FreeBSD

Download the FreeBSD, choose zfs.raw.xz format

Uncompress the file by using xz command and convert to qcow2 format 

qemu-system-riscv64 -machine virt -m 2G -nographic -kernel u-boot.bin -drive file=freebsd-zfs.qcow2,format=qcow2,id=hd0 -device virtio-blk-device, drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0

2024年12月14日星期六

mesi protocol

For any given pair of caches, the permitted states of a given cache line are as follows:

M E S I
M X X X O
E X X X O
S X X O O
I O O O O
Curstate Operation NextState SOther Core
INVALID Read case EXCLUSIVE if other core is INVALID INVALID (No operation)

case SHARED if other core contains data SHARED (no operation)
MODIFIED -> Flush -> SHARED
EXCLUSIVE -> SHARED
INVALID Write MODIFIED INVALID (no operation)
SHARED -> INVALID
MODIFIED -> Flush -> INVALID
EXCLUSIVE -> INVALID
EXCLUSIVE Read EXCLUSIVE INVALID (No operation)
EXCLUSIVE Write MODIFIED INVALID (No operation)
SHARED Read SHARED INVALID (no operation)
SHARED (no operation)
SHARED Write MODIFIED INVALID (no operation)
SHARED -> INVALID
MODIFIED Read MODIFIED INVALID (No operation)
MODIFIED Write MODIFIED INVALID (No operation)

Reference: https://github.com/Yefei100/Cache_coherence_protocol/blob/master/main.cc

2023年10月22日星期日

run riscv on qemu-system-riscv32

Sightly modify riscv.ld (download riscv.ld):

  1. Ensure the rom starts from 0x80000000. (matched with virt machine type)
  2. Set _init as entry function, place .text.init at 0x80000000.
  3. Add stack pointer initial location
In start.S, add _init function to setup sp and gp register:

.extern _start
.section .text.init
        .globl _init
_init:
        lui gp, %hi(ROM_START)     #_rom_start = 0x80000000 in linker script
        addi gp, gp, %lo(ROM_START)
        lui sp, %hi(init_sp)
        addi  sp, sp, %lo(init_sp)
        j  _start

riscv-none-elf-gcc -o helloworld.elf -march=rv32imad start.S helloworld.c -T riscv.ld

riscv-none-elf-objdump -D helloworld.elf > helloworld.S

qemu-system-riscv32 --machine virt -bios helloworld.elf -m 128M -nographic -singlestep -d exec,int,cpu 2>&1 | tee ins.log

Add cpu option above can dump the register value per step.

printf(...) require override _write() which could be found in newlib/libgross library.



2023年10月15日星期日

Increase swap size in WSL

In windows command prompt,

cd ~

notepad .wslconfig

[wsl2]
memory=16GB
swap=64GB
swapFile=D:\\swap.vhdx

Then, type

wsl --shutdown

to shutdown the Linux and wait for at least 8 seconds.

Remove Windows paths in WSL

In WSL,

sudo vi /etc/wsl.conf

[interop]
appendWindowsPath = false

In windows command prompt,

wsl --shutdown to restart the Linux

echo $PATH

to verify the path is correct


2021年12月30日星期四

aircrack-ng and hashcat

Mac changer:

sudo macchanger --mac=12:34:56:78:9a:bc wlan0   

 

Start monitor mode:

sudo airmon-ng start wlan0

 

Get bssid:

sudo airodump-ng wlan0mon

 

Dump handshake packet (channel = 7, bssid=aa:bb:cc:dd:ee):

sudo airodump-ng -c 7 --bssid aa:bb:cc:dd:ee:ff -w test wlan0mon

 

Deauth target:

sudo aireplay-ng -0 10 -a aa:bb:cc:dd:ee:ff -c 11:22:33:44:55:66 wlan0mon

 

Aircrack by dictionary:

sudo aircrack -w ~/pw/pw_list.txt ~/test.cap


Convert to hc22000 format

https://hashcat.net/cap2hashcat/


Hashcat by dictionary:

hashcat -m 22000 test.hc22000 ~/pw/pw_list.txt


Hashcat by brute force:

For example, 8 lowercase character,

increment rule:-i --increment-min 8 --increment-max 12

hashcat -a3 -m 22000 -i test.hc22000  ?l?l?l?l?l?l?l?l

 

Hashcat by custom pattern mixed with dictionary:

hashcat -m 22000 -i -a 6 test.hc22000 ~/pw/pw_list.txt ?d?d?d?d

2021年4月13日星期二

Generate function call-graph by valgrind

sudo apt install kcachegrind valgrind 


Build compiler flags:

CFLAGS / CPPFLAGS: -g (or -ggdb3 -O0)


# Generate a callgrind.out.<PID> file.
valgrind --tool=callgrind ./main


 # Generate the callgrind.out.<PID> files per thread.
valgrind --tool=callgrind --separate-threads=yes  ./main


# Open a GUI tool to visualize call graph
kcachegrind callgrind.out.<PID>


2021年4月12日星期一

Use lcov to view the coverage

Assume main.c and x.c are the source files.

1) Add CFLAGS / CPPFLAG -fprofile-arcs -ftest-coverage when build the project, .gcno is generated

2) Execute the program    #.gcda are generarted

3) gcov main.c    #main.c.gcov is generated (Optional)

4) gcov x.c    #x.c.gcov is generated (Optional)

5) Gen html report

lcov -c --directory . --output-file main_coverage.info
genhtml main_coverage.info --output-directory out


2021年3月19日星期五

Vitis HLS FIFO interface

Xilinx Example - proj_filter_scalar:

void filter(data_t &x, coef_t coef[TAP], sum_t &y)
{
#pragma HLS INTERFACE ap_fifo port=x
#pragma HLS INTERFACE ap_fifo port=y
#pragma HLS INTERFACE ap_fifo port=coef
#pragma HLS PIPELINE II=4

//.....

}


After csynth,

Latency (cycles) = 6

Top function Arguments

x in ap_int<165>&

coef in ap_int<16>*

y out ap_int<34>&

read_from_fifo:  x_read and x_dout change at the same clock edge

write_to_fifo: y_in delay 1 clock cycle after y_write 

ready_state:  ap_ready delay 1 cycle after ap_done