Litex-VexRiscv 部署Linux Soc至FPGA板上 本项目基于FPGA的Litex 框架实现,具体参考linux-on-litex-vexriscv 开源库。
环境
Xilinx Nexys4ddr A7-100T 开发板
Digilent Genesys2 开发板
PC-Ubuntu虚拟机(预留足够内存以安装Vivado及其他工具链)
实现 具体步骤如下:
先决条件 1 2 3 sudo apt install build-essential device-tree-compiler wget git python3-setuptools git clone https://github.com/litex-hub/linux-on-litex-vexriscvcd linux-on-litex-vexriscv
安装LiteX 1 2 3 wget https://raw.githubusercontent.com/enjoy-digital/litex/master/litex_setup.pychmod +x litex_setup.py ./litex_setup.py --init --install --user (--user to install to user directory)
For more information, please visit: https://github.com/enjoy-digital/litex/wiki/Installation
安装RISC-V工具链 1 2 3 wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14.tar.gz tar -xvf riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14.tar.gzexport PATH=$PATH :$PWD /riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/
安装SBT(用于自定义CPU配置所需) https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html#Installing+sbt+on+Linux
当前使用的是Ubuntu虚拟机:
1 2 3 4 5 6 7 8 sudo apt-get updatesudo apt-get install apt-transport-https curl gnupg -yqqecho "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.listecho "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo -H gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/scalasbt-release.gpg --importsudo chmod 644 /etc/apt/trusted.gpg.d/scalasbt-release.gpgsudo apt-get updatesudo apt-get install sbt
安装Verilator(用于模拟) 1 2 sudo apt install verilatorsudo apt install libevent-dev libjson-c-dev
安装OpenOCD(用于硬件测试) 1 2 3 4 5 6 7 sudo apt install libtool automake pkg-config libusb-1.0-0-dev git clone https://github.com/ntfreak/openocd.gitcd openocd ./bootstrap ./configure --enable-ftdi makesudo make install
运行LiteX模拟 先从#164 下载预构建的比特流和Linux/OpenSBI镜像,将其解压到images文件夹目录下,然后:
在这一步会遇到sdram_module_nphases, get_sdram_phy_settings这两个包找不到的报错,需要将其改为从litedram.phy.model引入,即:
1 from litedram.phy.model import SDRAMPHYModel,sdram_module_nphases, get_sdram_phy_settings
之后你应该能看到Linux启动并能与之互动:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 __ _ __ _ __ / / (_) /____ | |/_/ / /__/ / __/ -_)> < /____/_/\__/\__/_/|_| (c) Copyright 2012-2019 Enjoy-Digital (c) Copyright 2012-2015 M-Labs Ltd BIOS built on May 2 2019 18:58:54 BIOS CRC passed (97ea247b) --============ SoC info ================-- CPU: VexRiscv @ 1MHz ROM: 32KB SRAM: 4KB MAIN-RAM: 131072KB --========= Peripherals init ===========-- --========== Boot sequence =============-- Booting from serial... Press Q or ESC to abort boot completely. sL5DdSMmkekro Timeout Executing booted program at 0x20000000 --============= Liftoff! ===============-- VexRiscv Machine Mode software built May 3 2019 19:33:43 --========== Booting Linux =============-- [ 0.000000] No DTB passed to the kernel [ 0.000000] Linux version 5.0.9 (florent@lab) (gcc version 8.3.0 (Buildroot 2019.05-git-00938-g75f9fcd0c9)) [ 0.000000] Initial ramdisk at: 0x(ptrval) (8388608 bytes) [ 0.000000] Zone ranges: [ 0.000000] Normal [mem 0x00000000c0000000-0x00000000c7ffffff] [ 0.000000] Movable zone start for each node [ 0.000000] Early memory node ranges [ 0.000000] node 0: [mem 0x00000000c0000000-0x00000000c7ffffff] [ 0.000000] Initmem setup node 0 [mem 0x00000000c0000000-0x00000000c7ffffff] [ 0.000000] elf_hwcap is 0x1100 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 32512 [ 0.000000] Kernel command line: mem=128M@0x40000000 rootwait console=hvc0 root=/dev/ram0 init=/sbin/init swiotlb=32 [ 0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes) [ 0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes) [ 0.000000] Sorting __ex_table... [ 0.000000] Memory: 119052K/131072K available (1957K kernel code, 92K rwdata, 317K rodata, 104K init, 184K bss, 12020K 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] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x114c1bade8, max_idle_ns: 440795203839 ns [ 0.000155] sched_clock: 64 bits at 75MHz, resolution 13ns, wraps every 2199023255546ns [ 0.001515] Console: colour dummy device 80x25 [ 0.008297] printk: console [hvc0] enabled [ 0.009219] Calibrating delay loop (skipped), value calculated using timer frequency.. 150.00 BogoMIPS (lpj=300000) [ 0.009919] pid_max: default: 32768 minimum: 301 [ 0.016255] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.016802] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.044297] devtmpfs: initialized [ 0.061343] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns [ 0.061981] futex hash table entries: 256 (order: -1, 3072 bytes) [ 0.117611] clocksource: Switched to clocksource riscv_clocksource [ 0.251970] Unpacking initramfs... [ 2.005474] workingset: timestamp_bits=30 max_order=15 bucket_order=0 [ 2.178440] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254) [ 2.178909] io scheduler mq-deadline registered [ 2.179271] io scheduler kyber registered [ 3.031140] random: get_random_bytes called from init_oops_id+0x4c/0x60 with crng_init=0 [ 3.043743] Freeing unused kernel memory: 104K [ 3.044070] This architecture does not have kernel memory protection. [ 3.044472] Run /init as init process mount: mounting tmpfs on /dev/shm failed: Invalid argument mount: mounting tmpfs on /tmp failed: Invalid argument mount: mounting tmpfs on /run failed: Invalid argument Starting syslogd: OK Starting klogd: OK Initializing random number generator... [ 4.374589] random: dd : uninitialized urandom read (512 bytes read )done . Starting network: ip: socket: Function not implemented ip: socket: Function not implemented FAIL Welcome to Buildroot buildroot login: root login[48]: root login on 'hvc0' Built-in commands: ------------------ . : [ [[ alias bg break cd chdir command continue echo eval exec exit export false fg getopts hash help history jobs kill let local printf pwd read readonly return set shift source test times trap true type ulimit umask unalias unset wait
构建FPGA比特流 首先你需要在虚拟机上安装Vivado,安装后,构建比特流:
1 ./make.py --board=XXYY --cpu-count=X --build
加载FPGA比特流 将比特流加载到你的主板,运行:
1 ./make.py --board=XXYY --cpu-count=X --load
加载时需要跳线QSPI-JTAG
FPGA板编译成功的标识是DONE指示灯亮起,流水灯闪烁
通过串口加载Linux镜像 1 2 3 litex_term --images=images/boot.json /dev/ttyUSBX (--safe : In case of CRC Error, slower but should always work)
默认波特率会导致CRC Error,需要—safe模式
结果 Nexys4ddr验证成功;
Genesys2在加载后串口无法读取(待解决…)