0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

基于xmake的RT_Smart GNU移植minizip记录

冬至子 来源:TimWcx 作者:TimWcx 2023-06-07 15:42 次阅读

由于minizip除了依赖于文件一些操作函数外并不依赖于其他库,所以个人直接编译运行;另外本次移植的是使用的xmake完成移植。

移植记录

1、选择合适的移植库,xmake提供了一些可以跨平台移植的库,这里我选择了minizip来进行移植。

2、编写xmake.lua配置ToolChains并且引入minizip依赖

add_rules("mode.debug", "mode.release")

toolchain("aarch64-linux-musleabi")

set_kind("standalone")

set_sdkdir("$(projectdir)/../../tools/gnu_gcc/aarch64-linux-musleabi_for_x86_64-pc-linux-gnu")

on_load(function(toolchain)

os.setenv("PROJ_DIR", os.projectdir()) --For lua embed build script

toolchain:load_cross_toolchain()

toolchain:set("toolset", "cxx", "aarch64-linux-musleabi-g++")

toolchain:set("toolset", "cc", "aarch64-linux-musleabi-gcc")

-- add flags for aarch64

toolchain:add("cxflags", "-march=armv8-a -D__RTTHREAD__ -Wall -n --static -DHAVE_CCONFIG_H", {force = true})

toolchain:add("ldflags", "-march=armv8-a -D__RTTHREAD__ -Wall -n --static", {force = true})

toolchain:add("ldflags", "-T $(projectdir)/../../linker_scripts/aarch64/link.lds", {force = true})

if not is_config("pkg_searchdirs", "dropbear") then

toolchain:add("ldflags", "-L$(projectdir)/../../sdk/rt-thread/lib/aarch64/cortex-a -Wl,--whole-archive -lrtthread -Wl,--no-whole-archive", {force = true})

end

toolchain:add("includedirs", "$(projectdir)/../../sdk/rt-thread/include", {force = true})

toolchain:add("includedirs", "$(projectdir)/../../", {force = true})

toolchain:add("includedirs", "$(projectdir)", {force = true})

toolchain:add("includedirs", "$(projectdir)/../../sdk/rt-thread/components/dfs", {force = true})

toolchain:add("includedirs", "$(projectdir)/../../sdk/rt-thread/components/drivers", {force = true})

toolchain:add("includedirs", "$(projectdir)/../../sdk/rt-thread/components/finsh", {force = true})

toolchain:add("includedirs", "$(projectdir)/../../sdk/rt-thread/components/net", {force = true})

toolchain:add("linkdirs", "$(projectdir)/../../sdk/rt-thread/lib/aarch64", {force = true})

if is_config("kind", "debug") then

toolchain:add("cxflags", "-g -gdwarf-2", {force = true})

else

toolchain:add("cxflags", "-O2", {force = true})

end

end)

toolchain_end()

add_requires("minizip")

target("minizip")

set_toolchains("aarch64-linux-musleabi")

set_kind("binary")

add_files("src/minizip.c")

add_packages("minizip")

target("miniunz")

set_toolchains("aarch64-linux-musleabi")

set_kind("binary")

add_files("src/miniunz.c")

add_packages("minizip")

target("minizip_test")

set_toolchains("aarch64-linux-musleabi")

set_kind("binary")

add_files("src/main.c")

add_packages("minizip")

配置cconfig.h,这个文件如果用scons会自动生成,但是在xmake工程当中不会自动生成,所以需要自己实现

#ifndef CCONFIG_H__

#define CCONFIG_H__

/* Automatically generated file; DO NOT EDIT. */

/* compiler configure file for RT-Thread in GCC/MUSL */

#define HAVE_SYS_SIGNAL_H 1

#define HAVE_SYS_SELECT_H 1

#define HAVE_PTHREAD_H 1

#define HAVE_FDSET 1

#define HAVE_SIGACTION 1

#define HAVE_SIGEVENT 1

#define HAVE_SIGINFO 1

#define HAVE_SIGVAL 1

#endif

3、编写src/main.c程序,这里我用minizip实现了压缩example.txt到example.zip

/*

Copyright (c) 2006-2018, RT-Thread Development Team

SPDX-License-Identifier: GPL-2.0

  • Change Logs:

    Date Author Notes

    2023-05-17 wcx1024979076 The first version

    */

    #include "stdio.h"

    #include "zip.h"

    int main()

    {

    // 文件名

    const char *zipfile = "example.zip";

    // 需要压缩的文件

    const char *file = "example.txt";

    zipFile zf = zipOpen(zipfile, APPEND_STATUS_CREATE);

    if(zf == NULL)

    {

    printf("Error creating %s \\n", zipfile);

    return 1;

    }

    // 压缩文件

    int err = zipOpenNewFileInZip(zf, file, NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION);

    if(err != ZIP_OK)

    {

    printf("Error adding %s to %s \\n", file, zipfile);

    return 1;

    }

    // 读取文件并压缩

    FILE *f = fopen(file, "rb");

    char buf[1024];

    int len;

    while((len = fread(buf, 1, sizeof(buf), f)) > 0)

    {

    zipWriteInFileInZip(zf, buf, len);

    }

    fclose(f);

    zipCloseFileInZip(zf);

    zipClose(zf, NULL);

    printf("Successfully created %s \\n", zipfile);

    return 0;

    }

    4、xmake编译链接生成mininet可执行文件,打包进入 sd.bin

这里我使用的mcopy来实现的(用的是Codespace来写的代码,无root权限,不能使用mount挂载),具体命令为

mcopy -i sd.bin /path/of/the/minizip ::

5、用qemu虚拟机运行即可

运行结果:

1.jpg

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 虚拟机
    +关注

    关注

    1

    文章

    855

    浏览量

    27375
  • GNU
    GNU
    +关注

    关注

    0

    文章

    141

    浏览量

    17333
  • SRC算法
    +关注

    关注

    0

    文章

    5

    浏览量

    7397
  • RTThread
    +关注

    关注

    7

    文章

    129

    浏览量

    40518
收藏 人收藏

    评论

    相关推荐

    RT-Smart的资料合集

    时,需要使用 GDB 直接进行代码调试。本文档记录了以 RT-Thread qemu-vexpress-a9 BSP 为例,使用 GDB 对 RT-Smart 进行代码调试的方法。
    发表于 03-22 15:06

    [IMX6ULL]RT-Smart系统下的软件移植笔记推荐

    1、RT-Smart系统下的LwIP移植关于 i.MX 6ULL 的启动方式,已经老生常谈了。关于启动过程的分析,网上能搜到一堆原理讲解,不过不推荐把那个解释当作最佳答案,建议还是自行从手册入手关于
    发表于 03-25 16:25

    如何使用xmake工具来编译rt-thread工程

    在最新的 rt-thread 主仓库,支持使用 xmake 工具来编译 rt-thread 工程。xmake介绍xmake 是一个基于 Lu
    发表于 06-08 15:05

    开机体验rt-smart:webserver网关

    webserver 网关简介在 ART-Pi Smart SDK 里面提供了一个 gnu-app 示例:webserver 网关,并作为 ART-Pi Smart 的出厂 Demo。即移植
    发表于 06-30 11:17

    ART Pi Smart基于RT-Thread Smart系统的LVGL移植简介

    1、基于RT-Thread Smart系统的LVGL移植我申请测试申请的高级功能的,由于是有限的(本来要求测试一个月,但是板子只有不到一个月)。的,特别是RT-Thread智能系统还学
    发表于 08-03 16:35

    smart-build工具的menuconfig整体设计

    要编译的 gnu-app配置工具链和平台架构(arm、aarch64)保存并退出自动从仓库拉取版本的gnu-app制造APP并将生成物存放在rt-smart/userapps/root/bin根据现有
    发表于 08-26 15:32

    RT-Thread Smart已正式上线

    构建或其他的构建工具,例如xmake,cmake等,并对接 RT-Thread 在线软件包;同时支持 POSIX,方便 Linux 应用的移植
    的头像 发表于 11-29 10:31 2463次阅读

    rt-smart中的imx6ull用户态点灯

    前段时间,韦东山老师在他100ask_imx6ull移植rt-smart,刚好之前拿到一块imx6ull的板子,所以我也跟这位大佬一起学习了一下rt-smart。     移植的过程
    的头像 发表于 01-15 13:41 2549次阅读
    <b class='flag-5'>rt-smart</b>中的imx6ull用户态点灯

    树莓派上rt-smart的应用编程入门

    文章,一些介绍及树莓派上rt-smart的应用编程入门(更多的从应用程序角度入手)。后续还包括在rt-smart上的不同应用程序介绍: wget curl移植 busybox移植 sd
    的头像 发表于 05-13 14:10 2712次阅读
    树莓派上<b class='flag-5'>rt-smart</b>的应用编程入门

    rt-smart移植分析:从树莓派3b入手

    移植rt-smart到最新的板子上具体需要注意哪些细节,哪些才是移植rt-smart的关键点?本文从树莓派3b上移植
    发表于 01-25 18:48 0次下载
    <b class='flag-5'>rt-smart</b><b class='flag-5'>移植</b>分析:从树莓派3b入手

    如何使用xmake工具来编译rt-thread工程

     在最新的 rt-thread 主仓库,支持使用 xmake 工具来编译 rt-thread 工程。   
    的头像 发表于 05-11 15:03 1875次阅读
    如何使用<b class='flag-5'>xmake</b>工具来编译<b class='flag-5'>rt</b>-thread工程

    丝滑的在RT-Smart用户态运行LVGL

    开发流程 1、RT-Smart 环境搭建 下载 RT-Smart 用户态应用代码: 1 git clone https: //github.com/RT-Thread/userapps.git
    的头像 发表于 11-22 20:20 934次阅读

    基于xmakeRT-Thread Smart用户态开发教程

    RT-Thread Smart(以下简称 Smart) 是基于 RT-Thread 操作系统上的混合操作系统,简称为 rt-smart,它把
    的头像 发表于 06-07 11:44 961次阅读
    基于<b class='flag-5'>xmake</b>的<b class='flag-5'>RT</b>-Thread <b class='flag-5'>Smart</b>用户态开发教程

    RT_Smart GNU移植minizip记录

    由于minizip除了依赖于文件一些操作函数外并不依赖于其他库,所以个人直接编译运行;另外本次移植的是使用的xmake完成移植
    的头像 发表于 09-14 11:42 579次阅读
    <b class='flag-5'>RT_Smart</b> <b class='flag-5'>GNU</b><b class='flag-5'>移植</b><b class='flag-5'>minizip</b><b class='flag-5'>记录</b>

    基于xmakeRT-Thread Smart用户态开发教程

    RT-Thread Smart(以下简称 Smart) 是基于 RT-Thread 操作系统上的混合操作系统,简称为 rt-smart,它把
    的头像 发表于 09-14 11:48 708次阅读
    基于<b class='flag-5'>xmake</b>的<b class='flag-5'>RT</b>-Thread <b class='flag-5'>Smart</b>用户态开发教程