Ubuntu 20.04,内核源码方式编译bpf

eBPF 完全入门指南.pdf(万字长文) - 知乎 (zhihu.com)icon-default.png?t=O83Ahttps://zhuanlan.zhihu.com/p/492185920

一、安装依赖

# apt-get update
# apt-get  install -y bison build-essential cmake flex git libedit-dev pkg-config libmnl-dev  python  zlib1g-dev libssl-dev libelf-dev libcap-dev libfl-dev llvm clang pkg-config  gcc-multilib luajit libluajit-5.1-dev libncurses5-dev libclang-dev clang-tools

二、安装内核源码

# uname -r
5.4.0-196-generic
# apt-cache search linux-source
# apt-get install linux-source-5.4.0

三、编译samples/bpf

# tar -jxvf linux-source-5.4.0.tar.bz2
# cd linux-source-5.4.0
# cp -v /boot/config-$(uname -r) .config
# make oldconfig 
# make modules_prepare
# make headers_install
# make scripts        # 可选
# make M=samples/bpf  # 如果配置出错,可以使用 make oldconfig && make prepare 修复
make -C /usr/src/linux-source-5.4.0/linux-source-5.4.0/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/usr/src/linux-source-5.4.0/linux-source-5.4.0/samples/bpf/../../ O=
Warning: Kernel ABI header at 'tools/include/uapi/linux/netlink.h' differs from latest version at 'include/uapi/linux/netlink.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'

  WARNING: Symbol version dump ./Module.symvers
           is missing; modules will have no dependencies and modversions.

  Building modules, stage 2.
  MODPOST 0 modules

编译成功后,可以在 samples/bpf 目录下看到一系列的目标文件和二进制文件。

四、hello_world

samples/bpf 目录下,内核空间程序以 _kern.c 结尾,用户空间程序以 _user.c 结尾,
可在samples/bpf目录添加自己的hello_kern.c和hello_user.c,并修改samples/bpf/Makefile,
tprogs-y += hello
hello-objs := hello_user.o $(TRACE_HELPERS)
always-y += hello_kern.o

# make M=samples/bpf
make -C /usr/src/linux-source-5.4.0/linux-source-5.4.0/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/usr/src/linux-source-5.4.0/linux-source-5.4.0/samples/bpf/../../ O=
Warning: Kernel ABI header at 'tools/include/uapi/linux/netlink.h' differs from latest version at 'include/uapi/linux/netlink.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
  HOSTCC  samples/bpf/hello_user.o
  HOSTLD  samples/bpf/hello
  CLANG-bpf  samples/bpf/hello_kern.o

  WARNING: Symbol version dump ./Module.symvers
           is missing; modules will have no dependencies and modversions.

  Building modules, stage 2.
  MODPOST 0 modules
  
# samples/bpf/hello 
The kernel didn't load BPF program

# strace samples/bpf/hello 
execve("samples/bpf/hello", ["samples/bpf/hello"], 0x7ffc9bd4c770 /* 24 vars */) = 0
 ...
openat(AT_FDCWD, "hello_kern.o", O_RDONLY) = -1 ENOENT (No such file or directory)
 ...

# cd samples/bpf
# ./hello
           <...>-33177   [000] .... 22887.611008: 0: Hello BPF from houmin!  


 

要在Ubuntu 20.04上搭建RK3588源码编译环境,您可以按照以下步骤进行操作: 1. 安装所需的软件和工具: - 确保您的系统已更新并安装了必要的软件源。 - 安装Git版本控制系统,运行以下命令: ``` sudo apt-get install git ``` - 安装JDK(Java开发工具包),运行以下命令: ``` sudo apt-get install openjdk-8-jdk ``` - 安装依赖库和工具,运行以下命令: ``` sudo apt-get install build-essential libssl-dev libncurses5-dev unzip ``` 2. 克隆RK3588源码仓库: - 进入您想要存储源代码的目录,运行以下命令: ``` cd <存储源码的目录> ``` - 克隆RK3588源码仓库,运行以下命令: ``` git clone https://github.com/rockchip-linux/rk3588-manifest.git ``` - 切换到源码目录,运行以下命令: ``` cd rk3588-manifest ``` 3. 初始化并同步源码: - 初始化源码,运行以下命令: ``` repo init -u https://github.com/rockchip-linux/manifests -b rk3588 -m rk3588.xml ``` - 同步源码,运行以下命令: ``` repo sync ``` 4. 编译源码: - 设置环境变量,运行以下命令: ``` source build/envsetup.sh ``` - 选择您要编译的目标,例如"rk3588-userdebug",运行以下命令: ``` lunch rk3588-userdebug ``` - 开始编译,运行以下命令: ``` make -j$(nproc) ``` 请注意,以上步骤仅提供了RK3588源码编译环境搭建的基本过程。具体的操作细节可能因您的系统配置和需求而有所不同。在执行上述步骤时,如果遇到任何错误或问题,请您参考相关文档或搜索相关资源进行解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值