文章目录
- 开发板介绍
- 下载仓库
- 环境安装
- 仿真测试
- 上板测试
- 添加targets
- 工程构建
- 开启TFTP Server
- 工程测试
- Linux启动(netboot)
- HDMI测试
- SD Card
- 网络测试
- TFTP测试
- Linux启动(sdcardboot)
- LiteX工具烧录
- BIOS烧录(好像有问题,先别用)
- 启动测试
- 开发板信息
开发板介绍
手头目前只有一个购买的BoChenK7开发板,后续会用它来进行LiteX FPGA SoC的构建
测试可能会包括:
- LED:【LiteX】【开发板】【BoChenK7】使用Python开发FPGA【Hello World、LED点灯、Memory测速、替换BIOS】
- DDR:【LiteX】【开发板】【BoChenK7】使用Python开发FPGA【SDRAM/DDR/Bootloader】
- QSPI Flash:【LiteX】【开发板】【BoChenK7】使用Python开发FPGA【QSPI Flash】
- SD Card
- Ethernet以太网
- HDMI视频输入输出
- PCIe
- Linux:本篇文章
下载仓库
LiteX有一个生态库叫做litex-boards,里面包含了上百种开发板(比如Xilinx、Digilent等品牌)
若是你手中有现成的开发板,可以直接使用litex-boards仓库:https://github.com/litex-hub/litex-boards
而我目前手头的是BoChenK7开发板我自己作了一个litex-boards-vacajk仓库:https://github.com/vacajk/litex-boards-vacajk
BoChenK7开发板在Python代码中的名称为:bochen_kintex7_base
litex-boards-vacajk仓库依赖LiteX开发环境,环境搭建方法可以跳转:【LiteX】使用Python实现FPGA SoC构建的开源工具
# 激活conda环境
conda activate <your conda env name>
# 进入litex环境目录
cd ~/Study/litex/env/litex
# 下载仓库
git clone git@github.com:vacajk/litex-boards-vacajk.git
# 安装仓库
cd litex-boards-vacajk
pip install --editable .
环境安装
为了快速的实现Linux集成,我们需要使用到LiteX开源的仓库:https://github.com/litex-hub/linux-on-litex-vexriscv
# install build tools
$ sudo apt-get install build-essential device-tree-compiler
$ sudo apt-get install libevent-dev libjson-c-dev
$ sudo apt-get install verilator
$ sudo apt-get install tftpd-hpa
# 激活conda环境
$ conda activate <your conda env name>
# 进入litex环境目录
$ cd /home/vacajk/Study/litex/env
# 下载linux-on-litex-vexriscv仓库
$ git clone https://github.com/litex-hub/linux-on-litex-vexriscv
$ cd linux-on-litex-vexriscv
# 复制FPGA Program配置到linux-on-litex-vexriscv环境
$ cp -R ../litex-boards-vacajk/litex_boards_vacajk/prog ./
# pre-build Linux image
$ cd /home/vacajk/Study/litex/env/linux-on-litex-vexriscv/images
$ wget https://github.com/litex-hub/linux-on-litex-vexriscv/files/8331338/linux_2022_03_23.zip
$ unzip -d ./ linux_2022_03_23.zip
仿真测试
linux-on-litex-vexriscv仓库根目录下的sim.py直接能实现仿真
$ cd /home/vacajk/Study/litex/env/linux-on-litex-vexriscv
$ sim.py
log打印
__ _ __ _ __
/ / (_) /____ | |/_/
/ /__/ / __/ -_)> <
/____/_/\__/\__/_/|_|
Build your hardware, easily!
(c) Copyright 2012-2024 Enjoy-Digital
(c) Copyright 2007-2015 M-Labs
BIOS built on Aug 17 2024 23:51:55
BIOS CRC passed (a52a380e)
LiteX git sha1: 35498b468
--=============== SoC ==================--
CPU: VexRiscv SMP-LINUX @ 100MHz
BUS: wishbone 32-bit @ 4GiB
CSR: 32-bit data
ROM: 64.0KiB
SRAM: 8.0KiB
SDRAM: 64.0MiB 32-bit @ 100MT/s (CL-2 CWL-2)
MAIN-RAM: 64.0MiB
--========== Initialization ============--
Initializing SDRAM @0x40000000...
Switching SDRAM to software control.
Switching SDRAM to hardware control.
--============== Boot ==================--
Booting from serial...
Press Q or ESC to abort boot completely.
sL5DdSMmkekro
Timeout
Executing booted program at 0x40f00000
--============= Liftoff! ===============--
OpenSBI v0.8-1-gecf7701
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : LiteX / VexRiscv-SMP
Platform Features : timer,mfdeleg
Platform HART Count : 8
Boot HART ID : 0
Boot HART ISA : rv32imasu
BOOT HART Features : pmp,scounteren,mcounteren,time
BOOT HART PMP Count : 16
Firmware Base : 0x40f00000
Firmware Size : 124 KB
Runtime SBI Version : 0.2
MIDELEG : 0x00000222
MEDELEG : 0x0000b109
[ 0.000000] Linux version 5.14.0 (florent@panda) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.08-381-g279167ee8d) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP Tue Sep 21 12:57:31 CEST 2021
[ 0.000000] Machine model: sim
[ 0.000000] earlycon: liteuart0 at I/O port 0x0 (options '')
[ 0.000000] Malformed early option 'console'
[ 0.000000] earlycon: liteuart0 at MMIO 0xf0001000 (options '')
[ 0.000000] printk: bootconsole [liteuart0] enabled
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000040000000-0x0000000043ffffff]
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000040000000-0x0000000043ffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x0000000043ffffff]
[ 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 v0.2 HSM extension detected
[ 0.000000] riscv: ISA extensions aimp
[ 0.000000] riscv: ELF capabilities aim
[ 0.000000] percpu: Embedded 8 pages/cpu s11340 r0 d21428 u32768
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 16256
[ 0.000000] Kernel command line: console=liteuart earlycon=liteuart,0xf0001000 rootwait root=/dev/ram0
[ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[ 0.000000] Sorting __ex_table...
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 48644K/65536K available (5685K kernel code, 572K rwdata, 883K rodata, 209K init, 221K bss, 16892K reserved, 0K cma-reserved)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] riscv-intc: 32 local interrupts mapped
[ 0.000000] plic: interrupt-controller@f0c00000: mapped 32 interrupts with 1 handlers for 2 contexts.
[ 0.000000] random: get_random_bytes called from start_kernel+0x4ac/0x63c with crng_init=0
[ 0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0]
[ 0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x171024e7e0, max_idle_ns: 440795205315 ns
[ 0.000017] sched_clock: 64 bits at 100MHz, resolution 10ns, wraps every 4398046511100ns
[ 0.002157] Console: colour dummy device 80x25
[ 0.003092] Calibrating delay loop (skipped), value calculated using timer frequency.. 200.00 BogoMIPS (lpj=400000)
[ 0.004628] pid_max: default: 32768 minimum: 301
[ 0.008071] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.009105] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.029661] ASID allocator using 9 bits (512 entries)
[ 0.032256] rcu: Hierarchical SRCU implementation.
[ 0.037719] smp: Bringing up secondary CPUs ...
[ 0.038281] smp: Brought up 1 node, 1 CPU
[ 0.043687] devtmpfs: initialized
[ 0.067646] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[ 0.069253] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[ 0.076698] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[ 0.220379] pps_core: LinuxPPS API ver. 1 registered
[ 0.221174] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[ 0.222330] PTP clock support registered
[ 0.225771] FPGA manager framework
[ 0.238862] clocksource: Switched to clocksource riscv_clocksource
[ 0.389558] NET: Registered PF_INET protocol family
[ 0.391698] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[ 0.399235] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.400562] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.401787] TCP bind hash table entries: 1024 (order: 1, 8192 bytes, linear)
[ 0.402999] TCP: Hash tables configured (established 1024 bind 1024)
[ 0.404429] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.405521] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.423426] Unpacking initramfs...
[ 0.459237] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[ 0.666204] io scheduler mq-deadline registered
[ 0.667068] io scheduler kyber registered
[ 0.911699] LiteX SoC Controller driver initialized
[ 4.161695] Freeing initrd memory: 8192K
[ 4.660793] f0001000.serial: ttyLXU0 at MMIO 0x0 (irq = 0, base_baud = 0) is a liteuart
[ 4.662076] printk: console [liteuart0] enabled
[ 4.662076] printk: console [liteuart0] enabled
[ 4.663006] printk: bootconsole [liteuart0] disabled
[ 4.663006] printk: bootconsole [liteuart0] disabled
[ 4.683903] i2c_dev: i2c /dev entries driver
[ 4.720883] NET: Registered PF_INET6 protocol family
[ 4.734397] Segment Routing with IPv6
[ 4.735476] In-situ OAM (IOAM) with IPv6
[ 4.737017] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[ 4.749936] NET: Registered PF_PACKET protocol family
[ 4.761553] Freeing unused kernel image (initmem) memory: 204K
[ 4.762331] Kernel memory protection not selected by kernel config.
[ 4.763601] Run /init as init process
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Saving random seed: [ 6.818853] random: dd: uninitialized urandom read (512 bytes read)
OK
Starting network: OK
Welcome to Buildroot
buildroot login: root
__ _
/ / (_)__ __ ____ __
/ /__/ / _ \/ // /\ \ /
/____/_/_//_/\_,_//_\_\
/ _ \/ _ \
__ _ __ _ _\___/_//_/ ___ _
/ / (_) /____ | |/_/__| | / /____ __ / _ \(_)__ _____ __
/ /__/ / __/ -_)> </___/ |/ / -_) \ // , _/ (_-</ __/ |/ /
/____/_/\__/\__/_/|_|____|___/\__/_\_\/_/|_/_/___/\__/|___/
/ __/ |/ / _ \
_\ \/ /|_/ / ___/
/___/_/ /_/_/
32-bit RISC-V Linux running on LiteX / VexRiscv-SMP.
login[70]: root login on 'console'
root@buildroot:~#
root@buildroot:~#
root@buildroot:~# cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv32i2p0_ma
mmu : sv32
root@buildroot:~#
上板测试
linux-on-litex-vexriscv仓库根目录下的main.py直接能完成FPGA SoC的构建
添加targets
在构建之前需要将BoChenK7开发板的相关配置(如下方代码)
# 修改board.py
#---------------------------------------------------------------------------------------------------
# BoChen Boards
#---------------------------------------------------------------------------------------------------
# BoChenK7 support ------------------------------------------------------------------------------------
class BoChenK7Base(Board):
soc_kwargs = {"with_sdram": True, "with_ethernet": True}
def __init__(self):
from litex_boards_vacajk.targets import bochen_kintex7_base
Board.__init__(self, bochen_kintex7_base.BaseSoC, soc_capabilities={
# Communication
"serial",
"ethernet",
# Storage
"spiflash",
"sdcard",
# GPIOs
"leds",
# Video
"framebuffer",
})
# 修改main.py
# if args.flash:
prog = soc.platform.create_programmer_vivado()
prog.flash(0, builder.get_bitstream_filename(mode="flash"))
工程构建
首先需要确认之后用于netboot主机的IP地址,我的主机IP地址为:192.168.1.106
$ ifconfig
eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.106 netmask 255.255.255.0 broadcast 192.168.1.255
# 加载vivado开发环境
$ source ~/Xilinx/Vitis/2021.1/settings64.sh
# 进入linux-on-litex-vexriscv目录
$ cd /home/vacajk/Study/litex/env/linux-on-litex-vexriscv
# 编译BIOS、综合、布局、布线、生成bitstream
# --board=<board name>:class BoChenK7Base(Board)对应的board名称为bo_chen_k7base
# --remote-ip=<ip address>:需要配置为PC主机IP地址
$ ./make.py --board=bo_chen_k7base --remote-ip=192.168.1.106 --build
# 程序运行结束后会自动更新dtb
$ ll images/rv32.dts
-rwxrwxrwx 1 vacajk vacajk 3093 8月 17 00:30 images/rv32.dts*
开启TFTP Server
修改TFTP配置
- TFTP_DIRECTORY:指向linux-on-litex-vexriscv/images文件夹
- Linux Images文件都比较大,无法通过FPGA内部ROM/RAM直接启动,BIOS会通过以太网实现boot
- TFTP_ADDRESS:指向本机固定IP
- TFTP_OPTIONS:参数配置
vim /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/vacajk/Study/litex/env/linux-on-litex-vexriscv/images"
TFTP_ADDRESS="192.168.1.106:69"
TFTP_OPTIONS="-l -c -s"
启动TFTP Server
service xinetd stop
service tftpd-hpa restart
工程测试
连接JTAG(USB)、UART(USB)、电源(USB)到BoChenK7开发板
连接网线到BoChenK7开发板网口(ETH1),并确保该网线与PC连接到同一个路由器
连接HDMI线缆到到BoChenK7开发板HDMI输出接口(HDMI2),并同时连接一个HDMI显示器
# 查看USB转串口设备名
$ ls /dev/ttyUSB*
/dev/ttyUSB0
# +x属性到USB转串口设备
$ sudo chmod +x /dev/ttyUSB0
提前打开新的BASH Shell,使用litex_term打开串口监听
# BASH B
$ cd /home/vacajk/Study/litex/env/linux-on-litex-vexriscv
$ litex_term /dev/ttyUSB0
打开litex_term后,再进行FPGA bitstream下载
# BASH A
$ cd /home/vacajk/Study/litex/env/linux-on-litex-vexriscv
$ ./make.py --board=bo_chen_k7base --remote-ip=192.168.1.106 --load
Linux启动(netboot)
__ _ __ _ __
/ / (_) /____ | |/_/
/ /__/ / __/ -_)> <
/____/_/\__/\__/_/|_|
Build your hardware, easily!
(c) Copyright 2012-2024 Enjoy-Digital
(c) Copyright 2007-2015 M-Labs
BIOS CRC passed (a57e9d36)
LiteX git sha1: 35498b468
--=============== SoC ==================--
CPU: VexRiscv SMP-LINUX @ 100MHz
BUS: wishbone 32-bit @ 4GiB
CSR: 32-bit data
ROM: 64.0KiB
SRAM: 6.0KiB
SDRAM: 1.0GiB 32-bit @ 800MT/s (CL-6 CWL-5)
MAIN-RAM: 1.0GiB
--========== Initialization ============--
Ethernet init...
Initializing SDRAM @0x40000000...
Switching SDRAM to software control.
Write leveling:
tCK equivalent taps: 32
Cmd/Clk scan (0-16)
|1111111111100000| best: 0
Setting Cmd/Clk delay to 0 taps.
Data scan:
m0: |000000001111111111111110| delay: 08
m1: |000000001111111111111110| delay: 08
m2: |000000000011111111111111| delay: 10
m3: |000000000011111111111111| delay: 10
Write latency calibration:
m0:0 m1:0 m2:0 m3:0
Write DQ-DQS training:
m0: |111111111111111100000000000000000| delays: 07+-07
m1: |011111111111111100000000000000000| delays: 07+-06
m2: |000111111111111111000000000000000| delays: 09+-06
m3: |000111111111111111000000000000000| delays: 09+-06
Read leveling:
m0, b00: |00000000000000000000000000000000| delays: -
m0, b01: |00011111111111111100000000000000| delays: 10+-07
m0, b02: |00000000000000000000111111111111| delays: 25+-05
m0, b03: |00000000000000000000000000000000| delays: -
m0, b04: |00000000000000000000000000000000| delays: -
m0, b05: |00000000000000000000000000000000| delays: -
m0, b06: |00000000000000000000000000000000| delays: -
m0, b07: |00000000000000000000000000000000| delays: -
best: m0, b01 delays: 10+-07
m1, b00: |00000000000000000000000000000000| delays: -
m1, b01: |00011111111111111100000000000000| delays: 10+-07
m1, b02: |00000000000000000000111111111111| delays: 25+-06
m1, b03: |00000000000000000000000000000000| delays: -
m1, b04: |00000000000000000000000000000000| delays: -
m1, b05: |00000000000000000000000000000000| delays: -
m1, b06: |00000000000000000000000000000000| delays: -
m1, b07: |00000000000000000000000000000000| delays: -
best: m1, b01 delays: 10+-07
m2, b00: |00000000000000000000000000000000| delays: -
m2, b01: |01111111111111110000000000000000| delays: 08+-07
m2, b02: |00000000000000000011111111111110| delays: 24+-06
m2, b03: |00000000000000000000000000000000| delays: -
m2, b04: |00000000000000000000000000000000| delays: -
m2, b05: |00000000000000000000000000000000| delays: -
m2, b06: |00000000000000000000000000000000| delays: -
m2, b07: |00000000000000000000000000000000| delays: -
best: m2, b01 delays: 08+-07
m3, b00: |00000000000000000000000000000000| delays: -
m3, b01: |01111111111111110000000000000000| delays: 08+-07
m3, b02: |00000000000000000001111111111111| delays: 25+-06
m3, b03: |00000000000000000000000000000000| delays: -
m3, b04: |00000000000000000000000000000000| delays: -
m3, b05: |00000000000000000000000000000000| delays: -
m3, b06: |00000000000000000000000000000000| delays: -
m3, b07: |00000000000000000000000000000000| delays: -
best: m3, b01 delays: 08+-07
Switching SDRAM to hardware control.
Memtest at 0x40000000 (2.0MiB)...
Write: 0x40000000-0x40200000 2.0MiB
Read: 0x40000000-0x40200000 2.0MiB
Memtest OK
Memspeed at 0x40000000 (Sequential, 2.0MiB)...
Write speed: 156.0MiB/s
Read speed: 77.8MiB/s
--============== Boot ==================--
Booting from serial...
Press Q or ESC to abort boot completely.
sL5DdSMmkekro
Cancelled
--============= Console ================--
litex>
litex> netboot
Booting from network...
Local IP: 192.168.1.50
Remote IP: 192.168.1.106
Booting from boot.json...
Copying Image to 0x40000000... (7531468 bytes)
Copying rv32.dtb to 0x40ef0000... (3432 bytes)
Copying rootfs.cpio to 0x41000000... (3781632 bytes)
Copying opensbi.bin to 0x40f00000... (53640 bytes)
Executing booted program at 0x40f00000
--============= Liftoff! ===============--
OpenSBI v0.8-1-gecf7701
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : LiteX / VexRiscv-SMP
Platform Features : timer,mfdeleg
Platform HART Count : 8
Boot HART ID : 0
Boot HART ISA : rv32imasu
BOOT HART Features : pmp,scounteren,mcounteren,time
BOOT HART PMP Count : 16
Firmware Base : 0x40f00000
Firmware Size : 124 KB
Runtime SBI Version : 0.2
MIDELEG : 0x00000222
MEDELEG : 0x0000b109
[ 0.000000] Linux version 5.14.0 (florent@panda) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.08-381-g279167ee8d) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP Tue Sep 21 12:57:31 CEST 2021
[ 0.000000] Machine model: bochen_kintex7_base
[ 0.000000] earlycon: liteuart0 at I/O port 0x0 (options '')
[ 0.000000] Malformed early option 'console'
[ 0.000000] earlycon: liteuart0 at MMIO 0xf0001000 (options '')
[ 0.000000] printk: bootconsole [liteuart0] enabled
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x000000007fffffff]
[ 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 v0.2 HSM extension detected
[ 0.000000] riscv: ISA extensions aimp
[ 0.000000] riscv: ELF capabilities aim
[ 0.000000] percpu: Embedded 8 pages/cpu s11340 r0 d21428 u32768
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 260096
[ 0.000000] Kernel command line: console=liteuart earlycon=liteuart,0xf0001000 rootwait root=/dev/ram0 ip=192.168.1.50:192.168.1.106:192.168.1.106:255.255.255.0::eth0:off:::
[ 0.000000] Unknown command line parameters: ip=192.168.1.50:192.168.1.106:192.168.1.106:255.255.255.0::eth0:off:::
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[ 0.000000] Sorting __ex_table...
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 1022084K/1048576K available (5685K kernel code, 572K rwdata, 883K rodata, 209K init, 221K bss, 26492K reserved, 0K cma-reserved)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] riscv-intc: 32 local interrupts mapped
[ 0.000000] plic: interrupt-controller@f0c00000: mapped 32 interrupts with 1 handlers for 2 contexts.
[ 0.000000] random: get_random_bytes called from start_kernel+0x4ac/0x63c with crng_init=0
[ 0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0]
[ 0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x171024e7e0, max_idle_ns: 440795205315 ns
[ 0.000019] sched_clock: 64 bits at 100MHz, resolution 10ns, wraps every 4398046511100ns
[ 0.009377] Console: colour dummy device 80x25
[ 0.013567] Calibrating delay loop (skipped), value calculated using timer frequency.. 200.00 BogoMIPS (lpj=400000)
[ 0.024297] pid_max: default: 32768 minimum: 301
[ 0.032145] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[ 0.039541] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[ 0.069719] ASID allocator using 9 bits (512 entries)
[ 0.076194] rcu: Hierarchical SRCU implementation.
[ 0.085985] smp: Bringing up secondary CPUs ...
[ 0.089913] smp: Brought up 1 node, 1 CPU
[ 0.099751] devtmpfs: initialized
[ 0.137035] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[ 0.146956] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[ 0.161148] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[ 0.363099] pps_core: LinuxPPS API ver. 1 registered
[ 0.367420] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[ 0.376889] PTP clock support registered
[ 0.383704] FPGA manager framework
[ 0.400961] clocksource: Switched to clocksource riscv_clocksource
[ 0.411969] simple-framebuffer 40c00000.framebuffer: framebuffer at 0x40c00000, 0x12c000 bytes
[ 0.420793] simple-framebuffer 40c00000.framebuffer: format=a8b8g8r8, mode=640x480x32, linelength=2560
[ 0.518530] Console: switching to colour frame buffer device 80x30
[ 0.595112] simple-framebuffer 40c00000.framebuffer: fb0: simplefb registered!
[ 0.774217] NET: Registered PF_INET protocol family
[ 0.780296] IP idents hash table entries: 16384 (order: 5, 131072 bytes, linear)
[ 0.807939] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.817094] TCP established hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.825907] TCP bind hash table entries: 8192 (order: 4, 65536 bytes, linear)
[ 0.834383] TCP: Hash tables configured (established 8192 bind 8192)
[ 0.841589] UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
[ 0.848274] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
[ 0.875161] Unpacking initramfs...
[ 0.986152] workingset: timestamp_bits=30 max_order=18 bucket_order=0
[ 1.232961] io scheduler mq-deadline registered
[ 1.236912] io scheduler kyber registered
[ 1.553656] LiteX SoC Controller driver initialized
[ 2.323002] Initramfs unpacking failed: invalid magic at start of compressed archive
[ 2.414293] Freeing initrd memory: 8192K
[ 3.152120] f0001000.serial: ttyLXU0 at MMIO 0x0 (irq = 0, base_baud = 0) is a liteuart
[ 3.160848] printk: console [liteuart0] enabled
[ 3.160848] printk: console [liteuart0] enabled
[ 3.169479] printk: bootconsole [liteuart0] disabled
[ 3.169479] printk: bootconsole [liteuart0] disabled
[ 3.213739] liteeth f0002000.mac eth0: irq 2 slots: tx 2 rx 2 size 2048
[ 3.223582] i2c_dev: i2c /dev entries driver
[ 3.270041] NET: Registered PF_INET6 protocol family
[ 3.290808] Segment Routing with IPv6
[ 3.294229] In-situ OAM (IOAM) with IPv6
[ 3.298759] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[ 3.318114] NET: Registered PF_PACKET protocol family
[ 3.344938] litex-mmc f0006000.mmc: Requested clk_freq=12500000: set to 12500000 via div=8
[ 3.382669] Freeing unused kernel image (initmem) memory: 204K
[ 3.388285] Kernel memory protection not selected by kernel config.
[ 3.394605] Run /init as init process
[ 3.401245] litex-mmc f0006000.mmc: Requested clk_freq=0: set to 390625 via div=256
[ 3.429486] litex-mmc f0006000.mmc: Requested clk_freq=12500000: set to 12500000 via div=8
[ 3.475900] litex-mmc f0006000.mmc: Requested clk_freq=25000000: set to 25000000 via div=4
[ 3.484834] mmc0: new SDHC card at address 0007
[ 3.513627] mmcblk0: mmc0:0007 SD16G 14.5 GiB
[ 3.554748] mmcblk0: p1
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Saving random seed: [ 5.854272] random: dd: uninitialized urandom read (512 bytes read)
OK
Starting network: OK
Welcome to Buildroot
buildroot login: root
__ _
/ / (_)__ __ ____ __
/ /__/ / _ \/ // /\ \ /
/____/_/_//_/\_,_//_\_\
/ _ \/ _ \
__ _ __ _ _\___/_//_/ ___ _
/ / (_) /____ | |/_/__| | / /____ __ / _ \(_)__ _____ __
/ /__/ / __/ -_)> </___/ |/ / -_) \ // , _/ (_-</ __/ |/ /
/____/_/\__/\__/_/|_|____|___/\__/_\_\/_/|_/_/___/\__/|___/
/ __/ |/ / _ \
_\ \/ /|_/ / ___/
/___/_/ /_/_/
32-bit RISC-V Linux running on LiteX / VexRiscv-SMP.
login[73]: root login on 'console'
root@buildroot:~# uname -a
Linux buildroot 5.14.0 #1 SMP Tue Sep 21 12:57:31 CEST 2021 riscv32 GNU/Linux
root@buildroot:~# cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv32i2p0_ma
mmu : sv32
可以看到BIOS完成初始化后,通过TFTP从PC主机中根据boot.json文件j配置,将Linux Images下载到了SDRAM指定位置,包括:
- Image
- rv32.dtb
- rootfs.cpio
- opensbi.bin
待所有Linux Images下载完毕后,就会跳转并启动Linux
启动后输入用户名root即可进入到SHELL命令行
HDMI测试
Linux启动后,可以看到HDMI显示器上有一个小企鹅
TODO:照片
给fb0(Frame Buffer)写数据
root@buildroot:~# cat /dev/urandom > /dev/fb0
cat: write error: No space left on device
cat: can't open '�': No such file or directory
命令执行完成后,可以看到HDMI显示器上显示了雪花马赛克
TODO:照片
SD Card
我们在生成SoC时使能了SD Card,SD Card也提前格式化成FAT32,并放入了一个文件
root@buildroot:/mnt# fdisk -l
Disk /dev/mmcblk0: 14 GB, 15560867840 bytes, 30392320 sectors
1891 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 * 0,130,3 1023,254,63 8192 30392319 30384128 14.4G b Win95 FAT32
root@buildroot:~# mount /dev/mmcblk0p1 /mnt
root@buildroot:~# cd /mnt
root@buildroot:/mnt# ls
test.bin
root@buildroot:/mnt# echo "hello world" > test.txt
root@buildroot:/mnt# cat test.txt
hello world
root@buildroot:/mnt# cd ../
root@buildroot:~# umount /mnt
网络测试
给FPGA SoC配置静态IP地址:192.168.1.50
root@buildroot:/mnt# ifconfig -a
eth0 Link encap:Ethernet HWaddr FA:82:80:B6:85:EC
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:2
root@buildroot:/mnt# ifconfig eth0 192.168.1.50
root@buildroot:/mnt# ifconfig -a
eth0 Link encap:Ethernet HWaddr FA:82:80:B6:85:EC
inet addr:192.168.1.50 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::f882:80ff:feb6:85ec/64 Scope:Link
inet6 addr: 240e:359:ae7:a00:f882:80ff:feb6:85ec/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:47 errors:0 dropped:1 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21631 (21.1 KiB) TX bytes:602 (602.0 B)
Interrupt:2
Ping PC主机
root@buildroot:/mnt# ping 192.168.1.106
PING 192.168.1.106 (192.168.1.106): 56 data bytes
64 bytes from 192.168.1.106: seq=0 ttl=64 time=2.772 ms
64 bytes from 192.168.1.106: seq=1 ttl=64 time=1.473 ms
64 bytes from 192.168.1.106: seq=2 ttl=64 time=1.435 ms
64 bytes from 192.168.1.106: seq=3 ttl=64 time=1.472 ms
TFTP测试
前面的Linux启动使用了netboot,需要PC主机提前准备号TFTP Server,以供SoC通过网络下载Linux Images,然后再去启动
查看文件:litex/litex/soc/software/bios/main.c,可以知道LiteX的启动顺序是:
- serialboot:CSR_UART_BASE
- flashboot:需要特殊设置:FLASH_BOOT_ADDRESS
- romboot:需要特殊设置:ROM_BOOT_ADDRESS
- sdcardboot:CSR_SDCARD_CORE_BASE
- sataboot:CSR_SATA_SECTOR2MEM_BASE
- netboot:CSR_ETHMAC_BASE
可以看到netboot(TFTP方式)是最后一个步骤,如果前面的步骤响应或符合boot要求,则会提前开始进行boot
因此
- 可以将Linux Images与boot.json复制到SD Card中实现sdcardboot
- 可以将BIOS.bin复制到SD Card中,然后借助BIOS.bin中的命令程序烧录bitstream到QSPI Flash中,实现断电可重新启动Linux的目的
# Linux PC BASH
cd /home/vacajk/Study/litex/env/linux-on-litex-vexriscv
cp build/bo_chen_k7base/gateware/bo_chen_k7base.bin images/
# LiteX SoC Linux SHELL
root@buildroot:~# mount /dev/mmcblk0p1 /mnt
root@buildroot:~# cd /mnt
root@buildroot:/mnt# ls
test.bin test.txt
root@buildroot:/mnt# tftp 192.168.1.106 -l boot.json -g boot.json
root@buildroot:/mnt# tftp 192.168.1.106 -l Image -g Image
root@buildroot:/mnt# tftp 192.168.1.106 -l rv32.dtb -g rv32.dtb
root@buildroot:/mnt# tftp 192.168.1.106 -l rootfs.cpio -g rootfs.cpio
root@buildroot:/mnt# tftp 192.168.1.106 -l opensbi.bin -g opensbi.bin
root@buildroot:/mnt# tftp 192.168.1.106 -l bo_chen_k7base.bin -g bo_chen_k7base.bin
root@buildroot:/mnt# cat boot.json
{
"Image": "0x40000000",
"rv32.dtb": "0x40ef0000",
"rootfs.cpio": "0x41000000",
"opensbi.bin": "0x40f00000"
}
root@buildroot:/mnt# ls
Image rootfs.cpio test.txt
bo_chen_k7base.bin rv32.dtb
boot.json test.bin
root@buildroot:/mnt# cd ../
root@buildroot:~# umount /mnt
可以看到这几个与Linux启动的文件均下载到了SD Card中
- boot.json
- Image
- rv32.dtb
- rootfs.cpio
- opensbi.bin
Linux启动(sdcardboot)
可以使用Vivado工具,或是使用BIOS命令将FPGA bitstream烧写到QSPI Flash
LiteX工具烧录
./make.py --board=bo_chen_k7base --remote-ip=192.168.1.106 --flash
BIOS烧录(好像有问题,先别用)
# LiteX SoC Linux SHELL
# 重启
root@buildroot:~# reboot
# 按着ESC不放,取消boot处理
--============== Boot ==================--
Booting from serial...
Press Q or ESC to abort boot completely.
sL5DdSMmkekro
Cancelled
--============= Console ================--
litex>
# 擦除QSPI Flash
# 由于bo_chen_k7base.bin有3MB多,我们擦除4MB空间
litex> flash_erase_range 0x0 0x400000
Erase SPI Flash @0x00000000..
Erase SPI Flash @0x00010000..
......
Erase SPI Flash @0x003e0000..
Erase SPI Flash @0x003f0000..
# 从SD Card中读取文件并烧写到QSPI Flash
litex> flash_from_sdcard bo_chen_k7base.bin
启动测试
按下BoChenK7开发板的RST按键,从QSPI Flash自动启动
--============== Boot ==================--
Booting from serial...
Press Q or ESC to abort boot completely.
sL5DdSMmkekro
Timeout
Booting from SDCard in SD-Mode...
Booting from boot.json...
Copying Image to 0x40000000 (7531468 bytes)...
[########################################]
Copying rv32.dtb to 0x40ef0000 (3432 bytes)...
[########################################]
Copying rootfs.cpio to 0x41000000 (3781632 bytes)...
[########################################]
Copying opensbi.bin to 0x40f00000 (53640 bytes)...
[########################################]
Executing booted program at 0x40f00000
--============= Liftoff! ===============--
OpenSBI v0.8-1-gecf7701
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : LiteX / VexRiscv-SMP
Platform Features : timer,mfdeleg
Platform HART Count : 8
Boot HART ID : 0
Boot HART ISA : rv32imasu
BOOT HART Features : pmp,scounteren,mcounteren,time
BOOT HART PMP Count : 16
Firmware Base : 0x40f00000
Firmware Size : 124 KB
Runtime SBI Version : 0.2
MIDELEG : 0x00000222
MEDELEG : 0x0000b109
[ 0.000000] Linux version 5.14.0 (florent@panda) (riscv32-buildroot-linux-gnu-gcc.br_real (Buildroot 2021.08-381-g279167ee8d) 10.3.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP Tue Sep 21 12:57:31 CEST 2021
[ 0.000000] Machine model: bochen_kintex7_base
可以从log中看到,此次启动是从SD Card完成Linux Boot的
开发板信息
BoChenK7开发板的接口如下图,还是比较丰富的