Xilinx PetaLinux 工具链交叉编译xilinx_axidma源码

本文详细介绍了如何在XilinxPetaLinux环境下,对xilinx_axidma驱动源码进行修改和交叉编译。涉及的修改包括源代码的特定行数的更新,config.mk和makefile的配置,以及编译命令的执行。最终成功生成了库文件、示例程序和设备驱动模块。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Xilinx PetaLinux 工具链交叉编译xilinx_axidma源码

修改\xilinx_axidma\driver\axidma_chrdev.c文件

227: 【of_dma_configure(dev->device, NULL);】 -> 【of_dma_configure(dev->device, NULL,1);】

329: 【if (!readonly && !access_ok(VERIFY_WRITE, arg, size)) {】 -> 【if (!readonly && !access_ok(arg, size)) {】

333: 【} else if (!access_ok(VERIFY_READ, arg, size)) {】 -> 【} else if (!access_ok(arg, size)) {】

修改\xilinx_axidma\driver\axidma_dma.c文件

146: 【struct siginfo sig_info;】 -> 【struct kernel_siginfo sig_info;】

修改\xilinx_axidma\driver\axi_dma.c文件

15: 增加:【#include <linux/mod_devicetable.h>】

复制config_template.mk文件到config.mk并进行以下修改:

# Makefile Configuration Template
#
# This file is a template for the 'config.mk' file, which stores the
# values of variables used in the Makefile. This can be used instead of
# specifying the variables on the command line, which can quickly become
# cumbersome.
#
# To make use of this functionality, copy this file to 'config.mk', and then
# fill in the values as desired. Any of these variables can be overridden from
# the command line, so the variables are not permanent.

# TODO: Copy this file to 'config.mk' and uncomment and assign the variables

################################################################################
# Cross Compilation Options
################################################################################

# This controls the cross compiler that is used to compile all of the code. This
# should be a compiler prefix (e.g. `arm-linux-gnueabihf-`). The code will be
# compiled with the program `$(CROSS_COMPILE)gcc`
CROSS_COMPILE = arm-xilinx-linux-gnueabi-

# This variable informs the kernel Makefile what architecture you're targeting.
# This is required when building the driver, if CROSS_COMPILE is defined.
ARCH = arm

################################################################################
# Build Options
################################################################################

# The path to the top-level directory of kernel source tree that you want to
# compile the driver against. If unspecified, the system default
# `/lib/modules/$(uname -r)/build` is used. If CROSS_COMPILE is defined, then
# this variable must also be defined. This path can be absolute, or relative.
KBUILD_DIR = /home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2

# The path to the output directory, where all of the compiled files, the
# driver's kernel object, the example executables, and the AXI DMA shared
# library file are placed. If unspecified, the files are stored in `outputs` in
# the top level of the repository. This path can either be relative or absolute.
OUTPUT_DIR = outputs

# This specifies to fixup the path that the file `xilinx_dma.h` is located at in
# the kernel that you're compiling against. The location of this header file was
# changed between the 3.x and 4.x Xilinx kernel versions. However, some 4.x
# kernels still have the file at the old location. This variable specifies the
# Makefile to define a macro that fixes this issue. Uncomment this (no value is
# required), if the driver fails to compile with an error like:
#     `fatal error: linux/dma/xilinx_dma.h: No such file or directory`
#XILINX_DMA_INCLUDE_PATH_FIXUP = /home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2/include

修改xilinx_axidma目录下的makefile文件:

注释掉下面这一行(这一行会覆盖掉petlinux中的环境变量CC:/opt/petalinux/2020.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi)

#CC = $(CROSS_COMPILE)gcc

编译源码:

执行以下命令:

make library

make examples

make driver
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make library
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -fPIC -shared -Wno-missing-field-initializers -I include library/libaxidma.c -o library/libaxidma.so
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make examples
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -I include examples/axidma_benchmark.c examples/util.c -o examples/axidma_benchmark \
	-L outputs -l axidma -Wl,-rpath,'$ORIGIN'
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -I include examples/axidma_display_image.c examples/util.c -o examples/axidma_display_image \
	-L outputs -l axidma -Wl,-rpath,'$ORIGIN'
arm-xilinx-linux-gnueabi-gcc  -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/petalinux/2020.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi -Wall -Wextra -Werror -std=gnu99 -g -O0 -I include examples/axidma_transfer.c examples/util.c -o examples/axidma_transfer \
	-L outputs -l axidma -Wl,-rpath,'$ORIGIN'
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ make driver
make -C /home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2 M=/home/ubuntu/worksapce/xilinx_axidma/driver modules
make[1]: Entering directory '/home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2'
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axi_dma.o
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma_chrdev.o
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma_dma.o
  CC [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma_of.o
  LD [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma.o
  Building modules, stage 2.
  MODPOST 1 modules
  LD [M]  /home/ubuntu/worksapce/xilinx_axidma/driver/axidma.ko
make[1]: Leaving directory '/home/ubuntu/worksapce/kernel-driver/linux-xlnx-xlnx_rebase_v5.4_2020.2'
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ 
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ ll
total 172
drwxrwxrwx 7 ubuntu ubuntu   4096 Jun 29 01:56 ./
drwxrwxr-x 5 ubuntu ubuntu   4096 Jun 27 01:54 ../
-rwxrwxrwx 1 ubuntu ubuntu   2704 Jun 28 20:27 config.mk*
-rwxrwxrwx 1 ubuntu ubuntu   2600 Nov 19  2018 config_template.mk*
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 29 01:56 driver/
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 29 01:56 examples/
-rwxrwxrwx 1 ubuntu ubuntu    690 Nov 19  2018 .gitignore*
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 27 00:37 include/
-rwxrwxrwx 1 ubuntu ubuntu 100312 Nov 19  2018 libaxidma.dox*
drwxrwxrwx 2 ubuntu ubuntu   4096 Jun 29 01:56 library/
-rwxrwxrwx 1 ubuntu ubuntu   1171 Nov 19  2018 LICENSE*
-rwxrwxrwx 1 ubuntu ubuntu   5707 Jun 29 01:56 Makefile*
drwxrwxr-x 2 ubuntu ubuntu   4096 Jun 28 20:27 outputs/
-rwxrwxrwx 1 ubuntu ubuntu  15787 Nov 19  2018 README.md*
-rwxrwxrwx 1 ubuntu ubuntu    987 Nov 19  2018 .travis.yml*
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ ll outputs/
total 624
drwxrwxr-x 2 ubuntu ubuntu   4096 Jun 28 20:27 ./
drwxrwxrwx 7 ubuntu ubuntu   4096 Jun 29 01:56 ../
-rwxrwxr-x 1 ubuntu ubuntu  30916 Jun 29 01:56 axidma_benchmark*
-rwxrwxr-x 1 ubuntu ubuntu  28296 Jun 29 01:56 axidma_display_image*
-rw-rw-r-- 1 ubuntu ubuntu 511792 Jun 29 01:56 axidma.ko
-rwxrwxr-x 1 ubuntu ubuntu  27384 Jun 29 01:56 axidma_transfer*
-rwxrwxr-x 1 ubuntu ubuntu  25276 Jun 29 01:56 libaxidma.so*
ubuntu@ubuntu:~/worksapce/xilinx_axidma$ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值