linux 创建新用户_开发者分享 | 在 Zynq UltraScale 器件上通过 Vitis 创建 Linux 用户应用...

b579958009cf05cbb83d8cb74d76e1f6.gif

点击“蓝字”关注我们

Linux 嵌入式设计中最基本的任务之一是创建用户应用程序。

在本篇博文中,我们将探讨如何在 Vitis™ 中使用 UIO 驱动框架创建简单的 Linux 用户应用。

1

硬件设计

本次使用的是 Zynq UltraScale+ MPSoC ZCU104 评估板。但是,无论您使用任何器件,下列步骤都应适用。 

先使用 Vivado® 来创建了块设计。建立了 Zynq UltraScale PS,并把 AXI GPIO 连接到 ZCU104 评估板上的 4 个 LED。

87160e91f740e8f0e1b3f72f5b682fb7.png

地址映射如下所示:

5433c637bf58c91744cf0ea8b0db1394.png

首先 在创建 XSA 时使用了以下选项:

3501f7562aa50d62e931ddfa72f5d762.png

a8512084422f3e4fd65f6ac37f7e3ef4.png

2

 Linux 镜像

如果您使用开发板,则建议使用 BSP(如果存在)。

但在本示例中,我们使用模板来创建镜像。已经添加了 UIO 驱动程序,用于 AXI GPIO。

然后创建了 sysroot,在 Vitis 中需要使用它来进行交叉编译。

petalinux-create -t project --template zynqMP -n zcu104_linux

cd zcu104_linux

petalinux-config --get-hw-description=

依次选择“DTG Settings -> (zcu104-revc)MACHINE_NAME”

petalinux-config -c kernel
Select Device Drivers -> Userspace I/O drivers
Userspace I/O platform driver with generic IRQ handing
Userspace platform driver with generic irq and dynamic memory

将 system-user.dtsi 替换为:

/include/ "system-conf.dtsi"

/ {

    chosen {

        bootargs = "earlycon clk_ignore_unused   uio_pdrv_genirq.of_id=generic-uio";

        stdout-path = "serial0:115200n8";

    };

};

&axi_gpio_0 {

    compatible = "generic-uio";

};

然后,运行以下命令:

petalinux-build

cd images/linux
petalinux-build --sdk
petalinux-package --sysroot

3

创建平台

这并非必要步骤,因为用户只需在 Vitis 中使用 sysroot 即可。

但为了便于使用,我们可以创建一个平台并在 Vitis 中使用此平台来创建 Linux 应用。

首先,设置平台文件。 

把平台文件组织为一种文件夹结构。这并非必要步骤,但用户需要注意 BIF 中的文件路径。

在 Bootgen 中使用 BIF 来创建可启动的镜像。此处我们仅使用占位符文件名。

mkdir -p sw_comp/src/a53/xrt/image
mkdir sw_comp/src/boot

  • 将 image.ub、boot.scr 和 rootfs.cpio.gz 文件从 PetaLinux image/linux 文件夹复制到sw_comp/src/a53/image 

  • 将 system.bit、bl31.elf、uboot.elf、zynqmp_fsbl(已重命名为 fsbl.elf)和 pmufw.elf 文件从 PetaLinux image/linux 文件夹复制到sw_comp/src/boot

创建 BIF:

the_ROM_image:

{

  [fsbl_config] a53_x64

  [bootloader]

  [pmufw_image]

  [destination_device=pl]

  [destination_cpu=a53-0, exception_level=el-3, trustzone]

  [destination_cpu=a53-0, exception_level=el-2]

}

将 linux.bif 复制到sw_comp/src/boot。现在,在 Vitis 中创建一个新平台工程,如下所示:

2e5e5113d1cb080f0f3796cb16c9bcb6.png

171320baf7090cde2fbf23c39c0663d1.png

0fb812683c74a3138128d9589733c492.png

93b106750bb06990aec1a0bc31905b40.png

d267b8692609016ab7c1bb0f5f56cd62.png

c216698d6c62d04380e33740a1532232.png

这样就会在zcu104_base/export中创建平台。

4

在 Vitis 中创建 Linux 镜像

40a5bc5d1cde06c38b9cd712ab4a2b2a.png

选择“从存储库中选择平台 (Select a platform from therepository)”,单击 + 图标并浏览至您的平台。

205486b57f1dd5ea183611bb7ff21b47.png

8f37c37b9355062fa4d61a82f8b02877.png

创建新应用:

ca11a986093f32324e67b5986f5400a4.png

此处可以看到,“应用设置 (Application settings)”默认使用的是平台中的设置。

aeb707f0529b6c429841a2a1e0ef39a0.png

选择“空白应用 (Empty Application)”模板,因为我们将创建自己的自定义应用。

7a71f7b8233697697b5ed55dd5f6b3df.png

右键单击 led_test 应用下的 src 文件夹,然后选择“新建 (New)”->“文件 (File)”

6eb538511c153be309f19931da368576.png

指定其文件名 (.c),然后单击“完成 (Finish)”。

f59f4f5fadecee9b3465b0e325eb3d8f.png

现在,即可将以下代码复制到其中。这是一个简单的 UIO 示例,可用于开关 LED。

#include

#include

#include

#include

#include

#define GPIO_MAP_SIZE           0x10000

#define GPIO_DATA               0x00

#define GPIO_TRI                0x04

#define LED_NUM             256

#define LED_DELAY             10000000

int main(int argc, char *argv[])

{

    int fd;

    char *uiod = "/dev/uio0";

    void *gpio_ptr;

    volatile int Delay;

    printf("AXI GPIO UIO test.\n");

    // open the UIO device file to allow access to the device in user space

    fd = open(uiod, O_RDWR);

    if (fd < 1) {

        printf("Invalid UIO device file:%s.\n", uiod);

        return -1;

    }

    // mmap the GPIO device into user space

    gpio_ptr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

    if (gpio_ptr == MAP_FAILED) {

        printf("Mmap call failure.\n");

        return -1;

    }

    // set bit0 on the GPIO to be output

    // see pg144 for ref

    *((volatile unsigned *)(gpio_ptr + GPIO_TRI)) = 0x0;

    // Toggle the LED

    while (1) {

        int i;

        unsigned char led_pin = 0x0;

        for (i = 0; i < LED_NUM; i++) {

            *((volatile unsigned *)(gpio_ptr + GPIO_DATA)) = led_pin;

            for (Delay = 0; Delay < LED_DELAY; Delay++);

            *((volatile unsigned *)(gpio_ptr + GPIO_DATA)) = 0x0;

            led_pin++;

        }

    }

    // unmap the GPIO device from user space

    munmap(gpio_ptr, 4096);

    return 0;

}

选择系统工程,然后单击锤子图标。这样即可构建可执行文件,并创建启动镜像。

5be435da12894ab0f355bc5bed2a18a6.png

5

在硬件上执行测试

将所有镜像从led_app_system\Debug\sd_card复制到 SD 卡上。

edbc9ade510987758a44cb46662e6eaa.png

启动后,将自动装载 SD 卡。

在此处更改目录,并执行led_app.elf,如下所示:

7bdfc1fb339a3205ceddf9a97097ba54.png

同时,您在板上应该还可以看到 LED 闪烁。

使用 Ctrl + c 即可取消。

3f83e75574c472b74d8b98f68abd1a85.gif afd22bc52d252ca805f1f974a261a429.gif 553962fe4bad31bff49f5c0f74477ebd.png afd22bc52d252ca805f1f974a261a429.gif 关注我们

f8e648865f7ed7f38da801e517d596a0.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值