imx8 交叉编译libgpiod

下载 libgpiod-1.6.2.tar.gz
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/

解压
tar -zxf libgpiod-1.6.2.tar.gz

打 patch
cd libgpiod-1.6.2
patch -p1 < ../libgpiod-1.6.2.patch

编译
. /opt/fsl-imx-xwayland/5.4-zeus/environment-setup-aarch64-poky-linux
make
 

libgpiod-1.6.2.patch文件如下

diff -uprN libgpiod-1.6.2-old/lib/core.c libgpiod-1.6.2-new/lib/core.c
--- libgpiod-1.6.2-old/lib/core.c	2020-11-30 23:03:42.000000000 +0800
+++ libgpiod-1.6.2-new/lib/core.c	2021-01-28 18:23:36.046731290 +0800
@@ -21,6 +21,7 @@
 #include <sys/sysmacros.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <libgen.h>
 
 /*
  * These are symbols first available in linux v5.5. In order to allow to build
diff -uprN libgpiod-1.6.2-old/lib/Makefile libgpiod-1.6.2-new/lib/Makefile
--- libgpiod-1.6.2-old/lib/Makefile	1970-01-01 08:00:00.000000000 +0800
+++ libgpiod-1.6.2-new/lib/Makefile	2021-01-28 18:23:36.046731290 +0800
@@ -0,0 +1,26 @@
+SDKTARGETSYSROOT=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux
+CC  = aarch64-poky-linux-gcc --sysroot=$(SDKTARGETSYSROOT)
+CXX = aarch64-poky-linux-g++ --sysroot=$(SDKTARGETSYSROOT)
+LD  = aarch64-poky-linux-ld  --sysroot=$(SDKTARGETSYSROOT)
+AR  = aarch64-poky-linux-ar
+
+export INCLUDE=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/include
+export C_INCLUDE_PATH=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/include
+export CPLUS_INCLUDE_PATH=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/include
+
+CFLAGS = -I../include
+CFLAGS += -Wall -Wextra -g -std=gnu89 -fvisibility=hidden -DKERNEL_PRE_5_5 -D_GNU_SOURCE
+
+gpiod_LIB = libgpiod.a
+gpiod_SOURCES = core.c ctxless.c helpers.c iter.c misc.c
+
+default: clean
+	make build
+
+build: $(gpiod_SOURCES:.c=.o)
+	$(AR) -r $(gpiod_LIB) $(gpiod_SOURCES:.c=.o)
+
+clean:
+	rm -f $(gpiod_SOURCES:.c=.o)
+	rm -f $(gpiod_LIB)
+
diff -uprN libgpiod-1.6.2-old/lib/misc.c libgpiod-1.6.2-new/lib/misc.c
--- libgpiod-1.6.2-old/lib/misc.c	2020-11-30 23:03:42.000000000 +0800
+++ libgpiod-1.6.2-new/lib/misc.c	2021-01-28 18:23:36.046731290 +0800
@@ -9,6 +9,10 @@
 
 #include <gpiod.h>
 
+#if 1    //  2021-01-27 13:13  By  Flinger
+#define GPIOD_VERSION_STR "1.6.2"
+#endif
+
 const char *gpiod_version_string(void)
 {
 	return GPIOD_VERSION_STR;
diff -uprN libgpiod-1.6.2-old/Makefile libgpiod-1.6.2-new/Makefile
--- libgpiod-1.6.2-old/Makefile	1970-01-01 08:00:00.000000000 +0800
+++ libgpiod-1.6.2-new/Makefile	2021-01-28 18:24:28.906599414 +0800
@@ -0,0 +1,80 @@
+SDKTARGETSYSROOT=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux
+CC  = aarch64-poky-linux-gcc --sysroot=$(SDKTARGETSYSROOT)
+CXX = aarch64-poky-linux-g++ --sysroot=$(SDKTARGETSYSROOT)
+LD  = aarch64-poky-linux-ld  --sysroot=$(SDKTARGETSYSROOT)
+AR  = aarch64-poky-linux-ar
+
+export INCLUDE=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/include
+export C_INCLUDE_PATH=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/include
+export CPLUS_INCLUDE_PATH=/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/include
+
+CFLAGS = -I./include -I./tools
+CFLAGS += -Wall -Wextra -g -std=gnu89 -D_GNU_SOURCE
+
+gpiodetect_BIN = ./tools/gpiodetect
+gpioinfo_BIN   = ./tools/gpioinfo
+gpioget_BIN    = ./tools/gpioget
+gpioset_BIN    = ./tools/gpioset
+gpiomon_BIN    = ./tools/gpiomon
+gpiofind_BIN   = ./tools/gpiofind
+
+gpiodetect_SOURCES = ./tools/tools-common.c ./tools/gpiodetect.c
+gpioinfo_SOURCES   = ./tools/tools-common.c ./tools/gpioinfo.c
+gpioget_SOURCES    = ./tools/tools-common.c ./tools/gpioget.c
+gpioset_SOURCES    = ./tools/tools-common.c ./tools/gpioset.c
+gpiomon_SOURCES    = ./tools/tools-common.c ./tools/gpiomon.c
+gpiofind_SOURCES   = ./tools/tools-common.c ./tools/gpiofind.c
+
+LDFLAGS = ./lib/libgpiod.a
+
+
+default: clean
+	make -C ./lib
+	make gpiodetect
+	make gpioinfo
+	make gpioget
+	make gpioset
+	make gpiomon
+	make gpiofind
+
+gpiodetect: $(gpiodetect_SOURCES:.c=.o)
+	$(CC) -o $(gpiodetect_BIN) $(gpiodetect_SOURCES:.c=.o) $(LDFLAGS)
+
+gpioinfo: $(gpioinfo_SOURCES:.c=.o)
+	$(CC) -o $(gpioinfo_BIN) $(gpioinfo_SOURCES:.c=.o) $(LDFLAGS)
+
+gpioget: $(gpioget_SOURCES:.c=.o)
+	$(CC) -o $(gpioget_BIN) $(gpioget_SOURCES:.c=.o) $(LDFLAGS)
+
+gpioset: $(gpioset_SOURCES:.c=.o)
+	$(CC) -o $(gpioset_BIN) $(gpioset_SOURCES:.c=.o) $(LDFLAGS)
+
+gpiomon: $(gpiomon_SOURCES:.c=.o)
+	$(CC) -o $(gpiomon_BIN) $(gpiomon_SOURCES:.c=.o) $(LDFLAGS)
+
+gpiofind: $(gpiofind_SOURCES:.c=.o)
+	$(CC) -o $(gpiofind_BIN) $(gpiofind_SOURCES:.c=.o) $(LDFLAGS)
+
+install:
+	cp -f $(gpiodetect_BIN) ../../../customer/bin/
+	cp -f $(gpioinfo_BIN)   ../../../customer/bin/
+	cp -f $(gpioget_BIN)    ../../../customer/bin/
+	cp -f $(gpioset_BIN)    ../../../customer/bin/
+	cp -f $(gpiomon_BIN)    ../../../customer/bin/
+	cp -f $(gpiofind_BIN)   ../../../customer/bin/
+
+clean:
+	make -C ./lib clean
+	rm -f $(gpiodetect_SOURCES:.c=.o)
+	rm -f $(gpioinfo_SOURCES:.c=.o)
+	rm -f $(gpioget_SOURCES:.c=.o)
+	rm -f $(gpioset_SOURCES:.c=.o)
+	rm -f $(gpiomon_SOURCES:.c=.o)
+	rm -f $(gpiofind_SOURCES:.c=.o)
+	rm -f $(gpiodetect_BIN)
+	rm -f $(gpioinfo_BIN)
+	rm -f $(gpioget_BIN)
+	rm -f $(gpioset_BIN)
+	rm -f $(gpiomon_BIN)
+	rm -f $(gpiofind_BIN)
+
diff -uprN libgpiod-1.6.2-old/tools/tools-common.c libgpiod-1.6.2-new/tools/tools-common.c
--- libgpiod-1.6.2-old/tools/tools-common.c	2020-11-30 23:03:42.000000000 +0800
+++ libgpiod-1.6.2-new/tools/tools-common.c	2021-01-28 18:23:36.046731290 +0800
@@ -19,6 +19,11 @@
 
 #include "tools-common.h"
 
+#if 1    //  2021-01-27 13:13  By  Flinger
+#define program_invocation_name "libgpiod"
+#define program_invocation_short_name "libgpiod"
+#endif
+
 const char *get_progname(void)
 {
 	return program_invocation_name;

命令的用法:参考

https://www.eefocus.com/toradex/blog/20-07/440345_c35cb.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cfl927096306

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值