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

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

3天内不再提示

RT_Smart GNU移植minizip记录

冬至子 来源:TimWcx 作者:TimWcx 2023-09-14 11: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
  • RT-Thread
    +关注

    关注

    31

    文章

    1148

    浏览量

    38869
  • SRC算法
    +关注

    关注

    0

    文章

    5

    浏览量

    7397
  • for循环
    +关注

    关注

    0

    文章

    61

    浏览量

    2420
收藏 人收藏

    评论

    相关推荐

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

    ART-Pi Smart开发板为RT-Thread联合百问科技出品,使用的是 NXP 公司的 i.MX6ULL 处理器,具备单核 ARM Cortex-A7,最高运行频率可以达到 800MHz。
    的头像 发表于 11-29 14:29 743次阅读
    ART Pi <b class='flag-5'>Smart</b>基于<b class='flag-5'>RT</b>-Thread <b class='flag-5'>Smart</b>系统的LVGL<b class='flag-5'>移植</b>

    RT-Thread Smart 入门指南

    版本工具链下载:Windows 版本工具链请根据自己的开发环境选择对用的工具链下载使用。下载下来后分别解压展开到 rt-smart/tools/gnu_gcc 目录下,rt-smart 目录
    发表于 03-29 06:40

    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

    如何在RT-Thread Smart下使用gcc交叉编译工具链呢

    前言RT-Thread Smart的BSP rt-smartspd1-allwinner-nezha,也全志D1s的哪吒开发板,基于RISCV64平台,需要CV64的就是交叉编译环境RISCV64
    发表于 06-17 11:13

    开机体验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

    RT-Thread Smart快速上手

    的RISC-V芯片等。本是程序板程序RT-Thread Smart 移植到C100S(ARM90S-2EJ-2EJ-1000)目录,所有的bin0S指向S指向,可运行在基于F1C10S芯片的C10S芯片支派
    发表于 10-26 14:48

    RT-Thread Smart已正式上线

    rt-smart内核即可包含基本功能,同时也可定制裁剪。rt-smart用户态应用环境采用musl libc提供POSIX接口调用及C运行环境,延续 RT-Thread 原有的生态,使用scons
    的头像 发表于 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入手

    优雅的在D1S上运行RT-Smart

    前言 最近在学习 RT-Smart ,正巧有在全志开发者论坛看到这么一篇帖子【惊】在麻雀上运行国产rt-smart系统,看到很多人都在关注 D1S 在 Smart 上的运行情况。如今该 BSP 已经
    的头像 发表于 11-16 20:15 1908次阅读

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

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

    基于xmake的RT_Smart GNU移植minizip记录

    由于minizip除了依赖于文件一些操作函数外并不依赖于其他库,所以个人直接编译运行;另外本次移植的是使用的xmake完成移植
    的头像 发表于 06-07 15:42 573次阅读
    基于xmake的<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>