惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
L
LangChain Blog
Cyberwarzone
Cyberwarzone
美团技术团队
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
V
V2EX
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
aimingoo的专栏
aimingoo的专栏
人人都是产品经理
人人都是产品经理
F
Full Disclosure
V2EX - 技术
V2EX - 技术
The Cloudflare Blog
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Latest news
Latest news
S
Security @ Cisco Blogs
Spread Privacy
Spread Privacy
Project Zero
Project Zero
K
Kaspersky official blog
MyScale Blog
MyScale Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
罗磊的独立博客
Vercel News
Vercel News
N
News and Events Feed by Topic
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes

JieJiSS' Blog

为 SQLAlchemy Model 添加 type hint 和 type check Boot an Arch Linux RISC-V using qemu-system 关于基于机器学习的多目标对象追踪算法的文献综述 - JieJiSS' Blog RV64 板子更换 rootfs 指南 - JieJiSS' Blog ACTF2022 safer-tg-bot-{1,2} WP - JieJiSS' Blog A RISC-V gcc pitfall revealed by a glibc update 解构赋值踩坑:神秘失踪的数据 - JieJiSS' Blog How's the GDPR (used to) related to my blog Rust is incompatible with LLVM, at least partially python-mtrpacket 在 riscv64 上编译测试不通过 - JieJiSS' Blog 快速获得 RISC-V 开发环境 - JieJiSS' Blog 在 RISC-V 上编译 Node.js 16 Redmi AirDots 3 Pro 连接电脑后蓝牙类别不正确的解决方案 为什么 ArrowFunction 不能 new - JieJiSS' Blog Bilibili 2020-10-24 CTF WriteUp - JieJiSS' Blog 对于又一种对SS流式加密的攻击(奇虎团队)的详细分析 - JieJiSS' Blog 在MacOS上配置dnscrypt-proxy(免分流) - JieJiSS' Blog 市县中心点坐标(经纬度) - JieJiSS' Blog 二项式定理及其推广公式的一种简单理解办法 - JieJiSS' Blog
Setup an Arch Linux RISC-V Development Environment
2022-03-22 · via JieJiSS' Blog

文章目录

  1. 1 Prepare the Container
    1. 1.1 Install Packages
      1. For Arch Linux
      2. For Debian and Ubuntu
    2. 1.2 Download rootfs
    3. 1.3 Decompress rootfs
  2. 2 Start and Setup a Container
    1. 2.1 Check Architecture
    2. 2.2 System Upgrade
    3. 2.3 (Optional) Install Packages
    4. 2.4 (Optional) Set Default Editor
    5. 2.5 (Optional) Create a Regular User for Development
    6. 2.6 (Optional) Switch to a Regular User
  3. 3 Compile and Run a Program
    1. 3.1 Coding
    2. 3.2 Compilation
    3. 3.3 Checking for File Format
    4. 3.4 Running the Program

This is a frequently updating doc, and you can find its latest version here.

This documentation aims to help you set up an Arch Linux RISC-V (riscv64gc) development environment powered by usermode QEMU and systemd-nspawn.

Currently, the documentation contains instructions for Arch Linux, Debian and Ubuntu.

Caution: If you are using a native RISC-V board, you should skip these steps, and scroll down to the bottom of this page. The following instruction is for x86_64, etc. users.

1 Prepare the Container

1.1 Install Packages

If you are using Ubuntu/Debian as the host OS, skip to "For Debian and Ubuntu".

For Arch Linux

Add [archlinuxcn] Repo Source

We need to install some packages from [archlinuxcn] later.

Append these two lines to /etc/pacman.conf:

1
2
[archlinuxcn]
Server = https://repo.archlinuxcn.org/$arch

There is also a list of public mirrors available.

After doing so, you need to trust the archlinuxcn maintainers' PGP keys to install packages from it:

1
$ sudo pacman -Sy && sudo pacman -S archlinuxcn-keyring

Install Packages

1
$ sudo pacman -S qemu-user-static qemu-user-static-binfmt

where qemu-user-static-binfmt is for registering QEMU interpreter to execute RISC-V ELF files. Other necessary packages like zstd and systemd-nspawn are listed in the dependency tree of base meta package, so they will also be installed by the provided command, hence there's no need to install them explicitly.

For Debian and Ubuntu

1
$ sudo apt install zstd qemu-user-static systemd-container

where zstd is for decompressing the Arch Linux RISC-V rootfs compressed tarball, and systemd-container is for the systemd-nspawn command, which we'll use later to spawn a container from the rootfs.

1.2 Download rootfs

1
$ curl -O https://archriscv.felixc.at/images/archriscv-20220727.tar.zst

If you have poor connectivity upon reaching archriscv.felixc.at, you can also download the rootfs from mirror sites. They are listed at https://archriscv.felixc.at/.

root user's password is sifive, but probably you don't need it if you are creating a container with this rootfs to chroot into it later.

1.3 Decompress rootfs

Arch Linux

1
2
$ mkdir archriscv
$ sudo bsdtar -xf archriscv-20220727.tar.zst -C archriscv

Debian and Ubuntu

1
2
$ mkdir archriscv
$ sudo tar -I zstd -xf archriscv-20220727.tar.zst -C archriscv

tar may spit out some warnings, which turn out to be harmless and we can safely ignore them.

2 Start and Setup a Container

1
$ sudo systemd-nspawn -D ./archriscv -a -U

where -D provides the root directory for the container, -a for preventing processes with PID 1 from not reaping zombie children, -U for preventing processes in container from using the same UID range as those used outside the container.

2.1 Check Architecture

1
2
# uname -m
riscv64

2.2 System Upgrade

1
# pacman -Syu

2.3 (Optional) Install Packages

For example, if you want to install vim:

1
# pacman -S vim

2.4 (Optional) Set Default Editor

1
# echo 'export EDITOR=vim' >> ~/.bashrc && source ~/.bashrc

2.5 (Optional) Create a Regular User for Development

1
# useradd -m <username>

where -m means to create a home directory for the user to be added.

Use visudo if you'd like to grant sudo privilege for this user, and append this line under ## User privilege specification:

1
<username> ALL=(ALL) NOPASSWD: ALL

2.6 (Optional) Switch to a Regular User

1
2
3
4
5
# exec su username
$ cd ~
$ pwd
/home/<username>
$ echo 'export EDITOR=vim' >> ~/.bashrc && source ~/.bashrc

3 Compile and Run a Program

This guide is about compile & run a program manually. If you want to start your development from a git repo or so, jump to 3.2 Compile for instructions on how to install git and other packages needed by your toolchain. If you are trying to create or modify an Arch Linux package (i.e. dealing with a PKGBUILD), you may refer to related ArchWiki pages.

3.1 Coding

Run vim hello.c and type:

1
2
3
4
5
6
#include <stdio.h>

int main(int argc, char *argv[]) {
printf("Hello RISC-V!\n");
return 0;
}

Exit with esc and :wqEnter, as this S/O answer suggested :-P

3.2 Compilation

First of all, update your local packages repo data from remote package sources (like sudo apt-get update):

1
$ sudo pacman -Sy

You should run this prior to any attempt to install a package, unless you are sure that your local copy of package info is up-to-date.

Then, install your development toolchain:

1
$ sudo pacman -S gcc cmake foo bar bah

Compile your code:

1
$ gcc -o hello hello.c

3.3 Checking for File Format

1
2
$ file hello
hello: ELF 64-bit LSB pie executable, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, BuildID[sha1]=4a75c57e4e99654dca0d6dc91689dffbbe7dc581, for GNU/Linux 4.15.0, not stripped

3.4 Running the Program

1
2
$ ./hello
Hello RISC-V!

For native RISC-V board users:

Edit your /etc/pacman.conf with the following settings:

1
2
3
4
5
6
7
8
9
10
11
[core]
Server = https://archriscv.felixc.at/repo/$repo

[extra]
Server = https://archriscv.felixc.at/repo/$repo

[community]
Server = https://archriscv.felixc.at/repo/$repo

[unsupported]
Server = https://archriscv.felixc.at/repo/$repo

Finally, add the packager's public key to your keyring:

1
$ pacman-key --recv-keys "B5971F2C5C10A9A08C60030F786C63F330D7CB92"  

来源:https://blog.jiejiss.com/