* [Buildroot] [PATCH v2 0/2] Adding support for gpiod v2.0 and higher
@ 2023-11-20 10:32 Boerge Struempfel
2023-11-20 10:32 ` [Buildroot] [PATCH v2 1/2] package/libgpiod2: new package Boerge Struempfel
2023-11-20 10:32 ` [Buildroot] [PATCH v2 2/2] package/swupdate: Add compatibility to libgpiod2 Boerge Struempfel
0 siblings, 2 replies; 4+ messages in thread
From: Boerge Struempfel @ 2023-11-20 10:32 UTC (permalink / raw)
Cc: vfazio, bonet, bstruempfel, buildroot, boerge.struempfel
Since libgpiod v2.0 breaks its api, and leads to
compilation issues with multiple other packages,
we introduce libgpiod v2.0 as a new package libgpiod2.
Furthermore swupdate is updated to support both the
old libpgiod and the new libgpiod2 package.
---
v1: https://lists.buildroot.org/pipermail/buildroot/2023-November/679675.html
Changes from v1:
- Added myself to DEVELOPERS for the new libgpiod2 package
- Removed the dependency on the linux headers
- Updated from version 2.0.2 to 2.1
- Added comment in the commit message to swap the dependency in the future
- Added a note in the commit message, that the libgpiod2 does not correspond to the libgpiod2 debian package
- Updated the help text to explain the difference between libgpiod and libgpiod2
Boerge Struempfel (2):
package/libgpiod2: new package
package/swupdate: Add compatibility to libgpiod2
DEVELOPERS | 3 +
package/Config.in | 1 +
package/libgpiod2/Config.in | 27 +++
package/libgpiod2/libgpiod2.hash | 4 +
package/libgpiod2/libgpiod2.mk | 44 ++++
...cfw-Refactored-switch_mode-signature.patch | 74 +++++++
...pio-chip-and-lines-in-gpio-structure.patch | 129 +++++++++++
.../0004-ucfw-Refactored-gpio-handling.patch | 132 +++++++++++
...d-compatibility-with-libgpiod-v2-api.patch | 209 ++++++++++++++++++
package/swupdate/Config.in | 4 +-
package/swupdate/swupdate.mk | 5 +-
11 files changed, 629 insertions(+), 3 deletions(-)
create mode 100644 package/libgpiod2/Config.in
create mode 100644 package/libgpiod2/libgpiod2.hash
create mode 100644 package/libgpiod2/libgpiod2.mk
create mode 100644 package/swupdate/0002-ucfw-Refactored-switch_mode-signature.patch
create mode 100644 package/swupdate/0003-ucfw-Save-the-gpio-chip-and-lines-in-gpio-structure.patch
create mode 100644 package/swupdate/0004-ucfw-Refactored-gpio-handling.patch
create mode 100644 package/swupdate/0005-ucfw-Add-compatibility-with-libgpiod-v2-api.patch
--
2.42.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Buildroot] [PATCH v2 1/2] package/libgpiod2: new package
2023-11-20 10:32 [Buildroot] [PATCH v2 0/2] Adding support for gpiod v2.0 and higher Boerge Struempfel
@ 2023-11-20 10:32 ` Boerge Struempfel
2023-11-20 10:46 ` Baruch Siach via buildroot
2023-11-20 10:32 ` [Buildroot] [PATCH v2 2/2] package/swupdate: Add compatibility to libgpiod2 Boerge Struempfel
1 sibling, 1 reply; 4+ messages in thread
From: Boerge Struempfel @ 2023-11-20 10:32 UTC (permalink / raw)
Cc: vfazio, bonet, bstruempfel, buildroot, boerge.struempfel
From: Boerge Struempfel <boerge.struempfel@gmail.com>
Due to a significant api change as well as more recent kernel version
requirements, we introduce a separate package for version 2.0 and higher.
The newpackage is incompatible to libgpiod 1.x. This allows for iteratively
updating all dependent packages without breaking anything as a result.
For now we will have libgpiod2 depend on !libgpiod. However, in the
future, it might be preferable to have it the other way around,
such that packages, which select libgpiod2 don't have to also add the
the !libgpiod dependency.
Note that this package does not correspond to the debian libgpiod2 package,
which currently uses only version 1.6.3
Signed-off-by: Boerge Struempfel <bstruempfel@ultratronik.de>
---
DEVELOPERS | 3 +++
package/Config.in | 1 +
package/libgpiod2/Config.in | 27 ++++++++++++++++++++
package/libgpiod2/libgpiod2.hash | 4 +++
package/libgpiod2/libgpiod2.mk | 44 ++++++++++++++++++++++++++++++++
5 files changed, 79 insertions(+)
create mode 100644 package/libgpiod2/Config.in
create mode 100644 package/libgpiod2/libgpiod2.hash
create mode 100644 package/libgpiod2/libgpiod2.mk
diff --git a/DEVELOPERS b/DEVELOPERS
index 1f26e9bc81..cb06b69ffb 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -524,6 +524,9 @@ N: Bilal Wasim <bilalwasim676@gmail.com>
F: board/chromebook/elm/
F: configs/chromebook_elm_defconfig
+N: Boerge Struempfel <boerge.struempfel@gmail.com>
+F: package/libgpiod2/
+
N: Bogdan Radulescu <bogdan@nimblex.net>
F: package/iftop/
F: package/ncdu/
diff --git a/package/Config.in b/package/Config.in
index 5a3410d758..33d4ef3baa 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1718,6 +1718,7 @@ menu "Hardware handling"
source "package/libftdi1/Config.in"
source "package/libgphoto2/Config.in"
source "package/libgpiod/Config.in"
+ source "package/libgpiod2/Config.in"
source "package/libgudev/Config.in"
source "package/libhid/Config.in"
source "package/libiio/Config.in"
diff --git a/package/libgpiod2/Config.in b/package/libgpiod2/Config.in
new file mode 100644
index 0000000000..9775ed42f9
--- /dev/null
+++ b/package/libgpiod2/Config.in
@@ -0,0 +1,27 @@
+config BR2_PACKAGE_LIBGPIOD2
+ bool "libgpiod2"
+ depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_10
+ depends on !BR2_PACKAGE_LIBGPIOD
+ help
+ This is a C library that abstracts the GPIO character
+ device operations on linux.
+
+ https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
+
+ This package is the continuation of the libgpiod package
+ for versions 2.0 and above.
+
+ Note that a kernel of 5.10 or above is required for the
+ ioctls to work.
+
+if BR2_PACKAGE_LIBGPIOD2
+
+config BR2_PACKAGE_LIBGPIOD2_TOOLS
+ bool "install tools"
+ help
+ Include a set of command-line tools for managing GPIOs.
+
+endif
+
+comment "Consider upgrading to libgpiod2"
+ depends on BR2_PACKAGE_LIBGPIOD
diff --git a/package/libgpiod2/libgpiod2.hash b/package/libgpiod2/libgpiod2.hash
new file mode 100644
index 0000000000..b5488496b2
--- /dev/null
+++ b/package/libgpiod2/libgpiod2.hash
@@ -0,0 +1,4 @@
+# From https://www.kernel.org/pub/software/libs/libgpiod/sha256sums.asc
+sha256 fa4024a080121c958502f9a46a5bda44bea85e7a4dd7fcb3dead463b6fc4261c libgpiod-2.1.tar.xz
+# Hash for license file
+sha256 eb17a56966db5d986bec449ee44ed61f01f9e3fafa952e527db67a8f9594fd11 COPYING
diff --git a/package/libgpiod2/libgpiod2.mk b/package/libgpiod2/libgpiod2.mk
new file mode 100644
index 0000000000..e9e68339a8
--- /dev/null
+++ b/package/libgpiod2/libgpiod2.mk
@@ -0,0 +1,44 @@
+################################################################################
+#
+# libgpiod2
+#
+################################################################################
+
+# Be careful when bumping versions.
+# Dependency on kernel header versions may change.
+LIBGPIOD2_VERSION = 2.1
+LIBGPIOD2_SOURCE = libgpiod-$(LIBGPIOD2_VERSION).tar.xz
+LIBGPIOD2_SITE = https://www.kernel.org/pub/software/libs/libgpiod
+LIBGPIOD2_LICENSE = LGPL-2.1+
+LIBGPIOD2_LICENSE_FILES = COPYING
+LIBGPIOD2_INSTALL_STAGING = YES
+LIBGPIOD2_DEPENDENCIES = host-pkgconf host-autoconf-archive
+# We're patching configure.ac
+LIBGPIOD2_AUTORECONF = YES
+LIBGPIOD2_AUTORECONF_OPTS = --include=$(HOST_DIR)/share/autoconf-archive
+LIBGPIOD2_CONF_OPTS = --disable-tests --disable-examples
+
+ifeq ($(BR2_PACKAGE_LIBGPIOD2_TOOLS),y)
+LIBGPIOD2_CONF_OPTS += --enable-tools
+else
+LIBGPIOD2_CONF_OPTS += --disable-tools
+endif
+
+ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
+LIBGPIOD2_CONF_OPTS += --enable-bindings-cxx
+else
+LIBGPIOD2_CONF_OPTS += --disable-bindings-cxx
+endif
+
+ifeq ($(BR2_PACKAGE_PYTHON3),y)
+LIBGPIOD2_CONF_OPTS += --enable-bindings-python
+LIBGPIOD2_DEPENDENCIES += python3
+LIBGPIOD2_CONF_ENV += \
+ PYTHON=$(HOST_DIR)/bin/python3 \
+ PYTHON_CPPFLAGS="`$(STAGING_DIR)/usr/bin/python3-config --includes`" \
+ PYTHON_LIBS="`$(STAGING_DIR)/usr/bin/python3-config --ldflags`"
+else
+LIBGPIOD2_CONF_OPTS += --disable-bindings-python
+endif
+
+$(eval $(autotools-package))
--
2.42.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Buildroot] [PATCH v2 2/2] package/swupdate: Add compatibility to libgpiod2
2023-11-20 10:32 [Buildroot] [PATCH v2 0/2] Adding support for gpiod v2.0 and higher Boerge Struempfel
2023-11-20 10:32 ` [Buildroot] [PATCH v2 1/2] package/libgpiod2: new package Boerge Struempfel
@ 2023-11-20 10:32 ` Boerge Struempfel
1 sibling, 0 replies; 4+ messages in thread
From: Boerge Struempfel @ 2023-11-20 10:32 UTC (permalink / raw)
Cc: vfazio, bonet, bstruempfel, buildroot, boerge.struempfel
From: Boerge Struempfel <boerge.struempfel@gmail.com>
The corresponding patch series has already been accepted to the swupdate master branch
Signed-off-by: Boerge Struempfel <bstruempfel@ultratronik.de>
---
...cfw-Refactored-switch_mode-signature.patch | 74 +++++++
...pio-chip-and-lines-in-gpio-structure.patch | 129 +++++++++++
.../0004-ucfw-Refactored-gpio-handling.patch | 132 +++++++++++
...d-compatibility-with-libgpiod-v2-api.patch | 209 ++++++++++++++++++
package/swupdate/Config.in | 4 +-
package/swupdate/swupdate.mk | 5 +-
6 files changed, 550 insertions(+), 3 deletions(-)
create mode 100644 package/swupdate/0002-ucfw-Refactored-switch_mode-signature.patch
create mode 100644 package/swupdate/0003-ucfw-Save-the-gpio-chip-and-lines-in-gpio-structure.patch
create mode 100644 package/swupdate/0004-ucfw-Refactored-gpio-handling.patch
create mode 100644 package/swupdate/0005-ucfw-Add-compatibility-with-libgpiod-v2-api.patch
diff --git a/package/swupdate/0002-ucfw-Refactored-switch_mode-signature.patch b/package/swupdate/0002-ucfw-Refactored-switch_mode-signature.patch
new file mode 100644
index 0000000000..dd514b8687
--- /dev/null
+++ b/package/swupdate/0002-ucfw-Refactored-switch_mode-signature.patch
@@ -0,0 +1,74 @@
+From c8eb1a17a84242266984533be8388d2489fff366 Mon Sep 17 00:00:00 2001
+From: Boerge Struempfel <boerge.struempfel@gmail.com>
+Date: Fri, 20 Oct 2023 14:33:12 +0200
+Subject: [PATCH] ucfw: Refactored switch_mode signature
+
+This commit aims to reduce the number of parameters, which have to be
+given to the switch_mode function. This makes it much easier to add a
+different variation of this function depending on the installed libgpiod
+version.
+
+Upstream: https://github.com/sbabic/swupdate/commit/c8eb1a17a84242266984533be8388d2489fff366
+Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
+Acked-by: Stefano Babic <stefano.babic@swupdate.org>
+---
+ handlers/ucfw_handler.c | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
+
+diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
+index 8d10a54..5bf23c0 100644
+--- a/handlers/ucfw_handler.c
++++ b/handlers/ucfw_handler.c
+@@ -109,16 +109,17 @@ struct handler_priv {
+ unsigned int nbytes;
+ };
+
+-static int switch_mode(char *devreset, int resoffset, char *devprog, int progoffset, int mode)
++
++static int switch_mode(struct handler_priv *priv, int mode)
+ {
+ struct gpiod_chip *chipreset, *chipprog;
+ struct gpiod_line *linereset, *lineprog;
+ int ret = 0;
+ int status;
+
+- chipreset = gpiod_chip_open(devreset);
+- if (strcmp(devreset, devprog))
+- chipprog = gpiod_chip_open(devprog);
++ chipreset = gpiod_chip_open(priv->reset.gpiodev);
++ if (strcmp(priv->reset.gpiodev, priv->prog.gpiodev))
++ chipprog = gpiod_chip_open(priv->prog.gpiodev);
+ else
+ chipprog = chipreset;
+
+@@ -128,13 +129,13 @@ static int switch_mode(char *devreset, int resoffset, char *devprog, int progoff
+ goto freegpios;
+ }
+
+- linereset = gpiod_chip_get_line(chipreset, resoffset);
+- lineprog = gpiod_chip_get_line(chipprog, progoffset);
++ linereset = gpiod_chip_get_line(chipreset, priv->reset.offset);
++ lineprog = gpiod_chip_get_line(chipprog, priv->prog.offset);
+
+ if (!linereset || !lineprog) {
+ ERROR("Cannot get requested GPIOs: %d on %s and %d on %s",
+- resoffset, devreset,
+- progoffset, devprog);
++ priv->reset.offset, priv->reset.gpiodev,
++ priv->prog.offset, priv->prog.gpiodev);
+ ret =-ENODEV;
+ goto freegpios;
+ }
+@@ -378,8 +379,7 @@ static int prepare_update(struct handler_priv *priv,
+ char msg[128];
+ int len;
+
+- ret = switch_mode(priv->reset.gpiodev, priv->reset.offset,
+- priv->prog.gpiodev, priv->prog.offset, MODE_PROG);
++ ret = switch_mode(priv, MODE_PROG);
+ if (ret < 0) {
+ return -ENODEV;
+ }
+--
+2.42.0
+
diff --git a/package/swupdate/0003-ucfw-Save-the-gpio-chip-and-lines-in-gpio-structure.patch b/package/swupdate/0003-ucfw-Save-the-gpio-chip-and-lines-in-gpio-structure.patch
new file mode 100644
index 0000000000..04be6f6b74
--- /dev/null
+++ b/package/swupdate/0003-ucfw-Save-the-gpio-chip-and-lines-in-gpio-structure.patch
@@ -0,0 +1,129 @@
+From 43005ed30c8a4568b4f4b39e1ed7e297de655749 Mon Sep 17 00:00:00 2001
+From: Boerge Struempfel <boerge.struempfel@gmail.com>
+Date: Fri, 20 Oct 2023 14:33:13 +0200
+Subject: [PATCH] ucfw: Save the gpio chip and lines in gpio structure
+
+This is a prerequisite for splitting the switch_mode function into a
+the initialization phase, the actual mode-setting phase and then a
+cleanup phase.
+
+Upstream: https://github.com/sbabic/swupdate/commit/43005ed30c8a4568b4f4b39e1ed7e297de655749
+Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
+---
+ handlers/ucfw_handler.c | 43 ++++++++++++++++++++++-------------------
+ 1 file changed, 23 insertions(+), 20 deletions(-)
+
+diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
+index 5bf23c0..6b986f5 100644
+--- a/handlers/ucfw_handler.c
++++ b/handlers/ucfw_handler.c
+@@ -91,6 +91,8 @@ struct mode_setup {
+ char gpiodev[SWUPDATE_GENERAL_STRING_SIZE];
+ unsigned int offset;
+ bool active_low;
++ struct gpiod_chip *chip;
++ struct gpiod_line *line;
+ };
+
+ enum {
+@@ -109,30 +111,27 @@ struct handler_priv {
+ unsigned int nbytes;
+ };
+
+-
+ static int switch_mode(struct handler_priv *priv, int mode)
+ {
+- struct gpiod_chip *chipreset, *chipprog;
+- struct gpiod_line *linereset, *lineprog;
+ int ret = 0;
+ int status;
+
+- chipreset = gpiod_chip_open(priv->reset.gpiodev);
++ priv->reset.chip = gpiod_chip_open(priv->reset.gpiodev);
+ if (strcmp(priv->reset.gpiodev, priv->prog.gpiodev))
+- chipprog = gpiod_chip_open(priv->prog.gpiodev);
++ priv->prog.chip = gpiod_chip_open(priv->prog.gpiodev);
+ else
+- chipprog = chipreset;
++ priv->prog.chip = priv->reset.chip;
+
+- if (!chipreset || !chipprog) {
++ if (!priv->reset.chip || !priv->prog.chip) {
+ ERROR("Cannot open gpio driver");
+ ret =-ENODEV;
+ goto freegpios;
+ }
+
+- linereset = gpiod_chip_get_line(chipreset, priv->reset.offset);
+- lineprog = gpiod_chip_get_line(chipprog, priv->prog.offset);
++ priv->reset.line = gpiod_chip_get_line(priv->reset.chip, priv->reset.offset);
++ priv->prog.line = gpiod_chip_get_line(priv->prog.chip, priv->prog.offset);
+
+- if (!linereset || !lineprog) {
++ if (!priv->reset.line || !priv->prog.line) {
+ ERROR("Cannot get requested GPIOs: %d on %s and %d on %s",
+ priv->reset.offset, priv->reset.gpiodev,
+ priv->prog.offset, priv->prog.gpiodev);
+@@ -140,13 +139,13 @@ static int switch_mode(struct handler_priv *priv, int mode)
+ goto freegpios;
+ }
+
+- status = gpiod_line_request_output(linereset, RESET_CONSUMER, 0);
++ status = gpiod_line_request_output(priv->reset.line, RESET_CONSUMER, 0);
+ if (status) {
+ ret =-ENODEV;
+ ERROR("Cannot request reset line");
+ goto freegpios;
+ }
+- status = gpiod_line_request_output(lineprog, PROG_CONSUMER, mode);
++ status = gpiod_line_request_output(priv->prog.line, PROG_CONSUMER, mode);
+ if (status) {
+ ret =-ENODEV;
+ ERROR("Cannot request prog line");
+@@ -156,22 +155,27 @@ static int switch_mode(struct handler_priv *priv, int mode)
+ /*
+ * A reset is always done
+ */
+- gpiod_line_set_value(linereset, 0);
++ gpiod_line_set_value(priv->reset.line, 0);
+
+ /* Set programming mode */
+- gpiod_line_set_value(lineprog, mode);
++ gpiod_line_set_value(priv->prog.line, mode);
+
+ usleep(20000);
+
+ /* Remove reset */
+- gpiod_line_set_value(linereset, 1);
++ gpiod_line_set_value(priv->reset.line, 1);
+
+ usleep(20000);
+
+ freegpios:
+- if (chipreset) gpiod_chip_close(chipreset);
+- if (chipprog && (chipprog != chipreset)) gpiod_chip_close(chipprog);
+-
++ if (priv->prog.chip && (priv->prog.chip != priv->reset.chip)){
++ gpiod_chip_close(priv->prog.chip);
++ priv->reset.chip = NULL;
++ }
++ if (priv->reset.chip) {
++ gpiod_chip_close(priv->reset.chip);
++ priv->reset.chip = NULL;
++ }
+ return ret;
+ }
+
+@@ -449,8 +453,7 @@ static int finish_update(struct handler_priv *priv)
+ int ret;
+
+ close(priv->fduart);
+- ret = switch_mode(priv->reset.gpiodev, priv->reset.offset,
+- priv->prog.gpiodev, priv->prog.offset, MODE_NORMAL);
++ ret = switch_mode(priv, MODE_NORMAL);
+ if (ret < 0) {
+ return -ENODEV;
+ }
+--
+2.42.0
+
diff --git a/package/swupdate/0004-ucfw-Refactored-gpio-handling.patch b/package/swupdate/0004-ucfw-Refactored-gpio-handling.patch
new file mode 100644
index 0000000000..0ce6363f75
--- /dev/null
+++ b/package/swupdate/0004-ucfw-Refactored-gpio-handling.patch
@@ -0,0 +1,132 @@
+From 808676152a0ed5732b53d7e6cada0c0c1912f0f6 Mon Sep 17 00:00:00 2001
+From: Boerge Struempfel <boerge.struempfel@gmail.com>
+Date: Fri, 20 Oct 2023 14:33:14 +0200
+Subject: [PATCH] ucfw: Refactored gpio handling
+
+This commit splits the switch_mode function into the
+gpio-initialization, the actual mode switch and the cleanup phases. This
+is mainly done in order to prepare for adding gpiolib v2 api capability
+but has the added advantage, that the gpios are no longer released
+during the update, which for one prevents the gpios from floating, and
+for another, stops other processes from taking over the pins during an
+update phase.
+
+Upstream: https://github.com/sbabic/swupdate/commit/808676152a0ed5732b53d7e6cada0c0c1912f0f6
+Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
+---
+ handlers/ucfw_handler.c | 60 ++++++++++++++++++++++++++++++-----------
+ 1 file changed, 45 insertions(+), 15 deletions(-)
+
+diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
+index 6b986f5..0296f17 100644
+--- a/handlers/ucfw_handler.c
++++ b/handlers/ucfw_handler.c
+@@ -111,8 +111,18 @@ struct handler_priv {
+ unsigned int nbytes;
+ };
+
+-static int switch_mode(struct handler_priv *priv, int mode)
+-{
++static void free_gpios(struct handler_priv *priv) {
++ if (priv->prog.chip && (priv->prog.chip != priv->reset.chip)){
++ gpiod_chip_close(priv->prog.chip);
++ priv->reset.chip = NULL;
++ }
++ if (priv->reset.chip) {
++ gpiod_chip_close(priv->reset.chip);
++ priv->reset.chip = NULL;
++ }
++}
++
++static int register_gpios(struct handler_priv *priv){
+ int ret = 0;
+ int status;
+
+@@ -145,37 +155,51 @@ static int switch_mode(struct handler_priv *priv, int mode)
+ ERROR("Cannot request reset line");
+ goto freegpios;
+ }
+- status = gpiod_line_request_output(priv->prog.line, PROG_CONSUMER, mode);
++ status = gpiod_line_request_output(priv->prog.line, PROG_CONSUMER, 0);
+ if (status) {
+ ret =-ENODEV;
+ ERROR("Cannot request prog line");
+ goto freegpios;
+ }
+
++ return ret;
++freegpios:
++ free_gpios(priv);
++ return ret;
++}
++
++static int switch_mode(struct handler_priv *priv, int mode)
++{
++ int ret = 0;
++ if (!priv->reset.line || !priv->prog.line) return -ENODEV;
++
+ /*
+ * A reset is always done
+ */
+- gpiod_line_set_value(priv->reset.line, 0);
++ ret = gpiod_line_set_value(priv->reset.line, 0);
++ if (ret){
++ ERROR("unable to set reset to 0");
++ return ret;
++ }
+
+ /* Set programming mode */
+- gpiod_line_set_value(priv->prog.line, mode);
++ ret = gpiod_line_set_value(priv->prog.line, mode);
++ if (ret){
++ ERROR("unable to set prog to %i",mode);
++ return ret;
++ }
+
+ usleep(20000);
+
+ /* Remove reset */
+- gpiod_line_set_value(priv->reset.line, 1);
++ ret = gpiod_line_set_value(priv->reset.line, 1);
++ if (ret){
++ ERROR("unable to set reset to 1");
++ return ret;
++ }
+
+ usleep(20000);
+
+-freegpios:
+- if (priv->prog.chip && (priv->prog.chip != priv->reset.chip)){
+- gpiod_chip_close(priv->prog.chip);
+- priv->reset.chip = NULL;
+- }
+- if (priv->reset.chip) {
+- gpiod_chip_close(priv->reset.chip);
+- priv->reset.chip = NULL;
+- }
+ return ret;
+ }
+
+@@ -383,6 +407,11 @@ static int prepare_update(struct handler_priv *priv,
+ char msg[128];
+ int len;
+
++ ret = register_gpios(priv);
++ if (ret < 0) {
++ return -ENODEV;
++ }
++
+ ret = switch_mode(priv, MODE_PROG);
+ if (ret < 0) {
+ return -ENODEV;
+@@ -454,6 +483,7 @@ static int finish_update(struct handler_priv *priv)
+
+ close(priv->fduart);
+ ret = switch_mode(priv, MODE_NORMAL);
++ free_gpios(priv);
+ if (ret < 0) {
+ return -ENODEV;
+ }
+--
+2.42.0
+
diff --git a/package/swupdate/0005-ucfw-Add-compatibility-with-libgpiod-v2-api.patch b/package/swupdate/0005-ucfw-Add-compatibility-with-libgpiod-v2-api.patch
new file mode 100644
index 0000000000..40e9b44ab0
--- /dev/null
+++ b/package/swupdate/0005-ucfw-Add-compatibility-with-libgpiod-v2-api.patch
@@ -0,0 +1,209 @@
+From 72433e64c2fdcf43b8b5c627cfc0e715ab4dd742 Mon Sep 17 00:00:00 2001
+From: Boerge Struempfel <boerge.struempfel@gmail.com>
+Date: Fri, 20 Oct 2023 14:33:15 +0200
+Subject: [PATCH] ucfw: Add compatibility with libgpiod v2 api
+
+In order to detect the libgpiod api version, we use
+GPIOD_LINE_BULK_MAX_LINES, since this is only defined in v1 and not in
+v2.
+
+Upstream: https://github.com/sbabic/swupdate/commit/72433e64c2fdcf43b8b5c627cfc0e715ab4dd742
+Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
+---
+ handlers/ucfw_handler.c | 157 ++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 157 insertions(+)
+
+diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
+index 0296f17..ad33f05 100644
+--- a/handlers/ucfw_handler.c
++++ b/handlers/ucfw_handler.c
+@@ -80,6 +80,14 @@
+ #define PROG_CONSUMER RESET_CONSUMER
+ #define DEFAULT_TIMEOUT 2
+
++/*
++ * Use GPIOD_LINE_BULK_MAX_LINES in order to determine,
++ * whether this is compiled using libgpio v1 or v2.
++ */
++#ifdef GPIOD_LINE_BULK_MAX_LINES
++#define USE_GPIOD_API_V1
++#endif
++
+ void ucfw_handler(void);
+
+ /*
+@@ -91,8 +99,12 @@ struct mode_setup {
+ char gpiodev[SWUPDATE_GENERAL_STRING_SIZE];
+ unsigned int offset;
+ bool active_low;
++#ifdef USE_GPIOD_API_V1
+ struct gpiod_chip *chip;
+ struct gpiod_line *line;
++#else
++ struct gpiod_line_request *request;
++#endif
+ };
+
+ enum {
+@@ -111,6 +123,7 @@ struct handler_priv {
+ unsigned int nbytes;
+ };
+
++#ifdef USE_GPIOD_API_V1
+ static void free_gpios(struct handler_priv *priv) {
+ if (priv->prog.chip && (priv->prog.chip != priv->reset.chip)){
+ gpiod_chip_close(priv->prog.chip);
+@@ -203,6 +216,150 @@ static int switch_mode(struct handler_priv *priv, int mode)
+ return ret;
+ }
+
++#else
++/* Implementation for LIBGPIOD V2 api*/
++
++static void free_gpios(struct handler_priv *priv) {
++ if(priv->reset.request){
++ gpiod_line_request_release(priv->reset.request);
++ priv->reset.request = NULL;
++ }
++ if(priv->prog.request){
++ gpiod_line_request_release(priv->prog.request);
++ priv->prog.request = NULL;
++ }
++}
++
++static int register_gpios(struct handler_priv *priv) {
++ struct gpiod_line_settings *settings;
++ struct gpiod_request_config *req_cfg;
++ struct gpiod_line_config *reset_cfg, *prog_cfg;
++ struct gpiod_chip *chip;
++ int ret = 0;
++
++ settings = gpiod_line_settings_new();
++ if (!settings) {
++ ERROR("Unable to allocate line settings");
++ return -ENODEV;
++ }
++ gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_OUTPUT);
++
++ req_cfg = gpiod_request_config_new();
++ if (!req_cfg) {
++ ERROR("Unable to allocate the request config structure");
++ ret =-ENODEV;
++ goto freesettings;
++ }
++ gpiod_request_config_set_consumer(req_cfg, RESET_CONSUMER);
++
++ reset_cfg = gpiod_line_config_new();
++ if (!reset_cfg) {
++ ERROR("Unable to allocate the reset line config structure");
++ ret =-ENODEV;
++ goto freerequestconfig;
++ }
++ ret = gpiod_line_config_add_line_settings(reset_cfg, &priv->reset.offset, 1, settings);
++ if (ret) {
++ ERROR("Unable to add reset line settings");
++ goto freeresetconfig;
++ }
++
++ prog_cfg = gpiod_line_config_new();
++ if (!prog_cfg) {
++ ERROR("Unable to allocate the prog line config structure");
++ ret =-ENODEV;
++ goto freeresetconfig;
++ }
++
++ ret = gpiod_line_config_add_line_settings(prog_cfg, &priv->prog.offset, 1, settings);
++ if (ret) {
++ ERROR("Unable to add reset line settings");
++ goto freeprogconfig;
++ }
++
++ TRACE("Request lines for reset");
++ chip = gpiod_chip_open(priv->reset.gpiodev);
++ if (!chip) {
++ ERROR("Unable to open chip '%s'",priv->reset.gpiodev);
++ ret =-ENODEV;
++ goto freeprogconfig;
++ }
++
++ priv->reset.request = gpiod_chip_request_lines(chip, req_cfg, reset_cfg);
++ gpiod_chip_close(chip);
++ if (!priv->reset.request) {
++ ERROR("Unable to request lines on chip '%s'", priv->reset.gpiodev);
++ goto freeprogconfig;
++ }
++
++ TRACE("Request lines for prog");
++ chip = gpiod_chip_open(priv->prog.gpiodev);
++ if (!chip) {
++ ERROR("Unable to open chip '%s'", priv->prog.gpiodev);
++ ret =-ENODEV;
++ goto freelinerequest;
++ }
++
++ priv->prog.request = gpiod_chip_request_lines(chip, req_cfg, prog_cfg);
++ gpiod_chip_close(chip);
++ if (!priv->prog.request) {
++ ERROR("unable to request lines on chip '%s'", priv->prog.gpiodev);
++ ret =-ENODEV;
++ }
++
++ goto freeprogconfig; // clean up everything except for the gpiod_line_requests
++
++freelinerequest:
++ gpiod_line_request_release(priv->reset.request);
++ priv->reset.request = NULL;
++freeprogconfig:
++ gpiod_line_config_free(prog_cfg);
++freeresetconfig:
++ gpiod_line_config_free(reset_cfg);
++freerequestconfig:
++ gpiod_request_config_free(req_cfg);
++freesettings:
++ gpiod_line_settings_free(settings);
++ return ret;
++}
++
++
++static int switch_mode(struct handler_priv *priv, int mode)
++{
++
++ int ret = 0;
++
++ /*
++ * A reset is always done
++ */
++ ret = gpiod_line_request_set_value(priv->reset.request, priv->reset.offset, 0);
++ if (ret){
++ ERROR("Unable to set reset to 0");
++ return ret;
++ }
++
++ /* Set programming mode */
++ ret = gpiod_line_request_set_value(priv->prog.request, priv->prog.offset, mode);
++ if (ret){
++ ERROR("Unable to set prog to %i", mode);
++ return ret;
++ }
++
++ usleep(20000);
++
++ /* Remove reset */
++ ret = gpiod_line_request_set_value(priv->reset.request, priv->reset.offset, 1);
++ if (ret){
++ ERROR("Unable to set reset to 1");
++ return ret;
++ }
++
++ usleep(20000);
++
++ return ret;
++}
++#endif
++
+ static bool verify_chksum(char *buf, unsigned int *size)
+ {
+ int i;
+--
+2.42.0
+
diff --git a/package/swupdate/Config.in b/package/swupdate/Config.in
index 7d9fc90e10..c6256b9a03 100644
--- a/package/swupdate/Config.in
+++ b/package/swupdate/Config.in
@@ -39,8 +39,8 @@ config BR2_PACKAGE_SWUPDATE
rdiff handler.
* Select BR2_PACKAGE_LIBUBOOTENV to add support for setting
the U-Boot environment.
- * Select BR2_PACKAGE_LIBGPIOD to add support for
- microcontroller firmware update.
+ * Select BR2_PACKAGE_LIBGPIOD or BR2_PACKAGE_LIBGPIOD2 to add
+ support for microcontroller firmware update.
* Select BR2_PACKAGE_EFIBOOTMGR to add support for EFI Boot
Guard.
* Select BR2_PACKAGE_LIBCURL, BR2_PACKAGE_JSON_C,
diff --git a/package/swupdate/swupdate.mk b/package/swupdate/swupdate.mk
index ea4a5a62e5..1ca4408de4 100644
--- a/package/swupdate/swupdate.mk
+++ b/package/swupdate/swupdate.mk
@@ -78,7 +78,10 @@ else
SWUPDATE_MAKE_ENV += HAVE_LIBFDISK=n
endif
-ifeq ($(BR2_PACKAGE_LIBGPIOD),y)
+ifeq ($(BR2_PACKAGE_LIBGPIOD2),y)
+SWUPDATE_DEPENDENCIES += libgpiod2
+SWUPDATE_MAKE_ENV += HAVE_LIBGPIOD=y
+else ifeq ($(BR2_PACKAGE_LIBGPIOD),y)
SWUPDATE_DEPENDENCIES += libgpiod
SWUPDATE_MAKE_ENV += HAVE_LIBGPIOD=y
else
--
2.42.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Buildroot] [PATCH v2 1/2] package/libgpiod2: new package
2023-11-20 10:32 ` [Buildroot] [PATCH v2 1/2] package/libgpiod2: new package Boerge Struempfel
@ 2023-11-20 10:46 ` Baruch Siach via buildroot
0 siblings, 0 replies; 4+ messages in thread
From: Baruch Siach via buildroot @ 2023-11-20 10:46 UTC (permalink / raw)
To: Boerge Struempfel; +Cc: buildroot, vfazio, bonet, bstruempfel
Hi Boerge,
On Mon, Nov 20 2023, Boerge Struempfel wrote:
> diff --git a/package/libgpiod2/libgpiod2.mk b/package/libgpiod2/libgpiod2.mk
> new file mode 100644
> index 0000000000..e9e68339a8
> --- /dev/null
> +++ b/package/libgpiod2/libgpiod2.mk
> @@ -0,0 +1,44 @@
> +################################################################################
> +#
> +# libgpiod2
> +#
> +################################################################################
> +
> +# Be careful when bumping versions.
> +# Dependency on kernel header versions may change.
> +LIBGPIOD2_VERSION = 2.1
> +LIBGPIOD2_SOURCE = libgpiod-$(LIBGPIOD2_VERSION).tar.xz
> +LIBGPIOD2_SITE = https://www.kernel.org/pub/software/libs/libgpiod
> +LIBGPIOD2_LICENSE = LGPL-2.1+
> +LIBGPIOD2_LICENSE_FILES = COPYING
> +LIBGPIOD2_INSTALL_STAGING = YES
> +LIBGPIOD2_DEPENDENCIES = host-pkgconf host-autoconf-archive
> +# We're patching configure.ac
Are we? I don't see patches here. It looks like the tar file includes a
generated configure script. Is autoreconf still necessary?
baruch
> +LIBGPIOD2_AUTORECONF = YES
> +LIBGPIOD2_AUTORECONF_OPTS = --include=$(HOST_DIR)/share/autoconf-archive
> +LIBGPIOD2_CONF_OPTS = --disable-tests --disable-examples
> +
> +ifeq ($(BR2_PACKAGE_LIBGPIOD2_TOOLS),y)
> +LIBGPIOD2_CONF_OPTS += --enable-tools
> +else
> +LIBGPIOD2_CONF_OPTS += --disable-tools
> +endif
> +
> +ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
> +LIBGPIOD2_CONF_OPTS += --enable-bindings-cxx
> +else
> +LIBGPIOD2_CONF_OPTS += --disable-bindings-cxx
> +endif
> +
> +ifeq ($(BR2_PACKAGE_PYTHON3),y)
> +LIBGPIOD2_CONF_OPTS += --enable-bindings-python
> +LIBGPIOD2_DEPENDENCIES += python3
> +LIBGPIOD2_CONF_ENV += \
> + PYTHON=$(HOST_DIR)/bin/python3 \
> + PYTHON_CPPFLAGS="`$(STAGING_DIR)/usr/bin/python3-config --includes`" \
> + PYTHON_LIBS="`$(STAGING_DIR)/usr/bin/python3-config --ldflags`"
> +else
> +LIBGPIOD2_CONF_OPTS += --disable-bindings-python
> +endif
> +
> +$(eval $(autotools-package))
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-20 10:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-20 10:32 [Buildroot] [PATCH v2 0/2] Adding support for gpiod v2.0 and higher Boerge Struempfel
2023-11-20 10:32 ` [Buildroot] [PATCH v2 1/2] package/libgpiod2: new package Boerge Struempfel
2023-11-20 10:46 ` Baruch Siach via buildroot
2023-11-20 10:32 ` [Buildroot] [PATCH v2 2/2] package/swupdate: Add compatibility to libgpiod2 Boerge Struempfel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox