Skip to contentSkip to conversation

manage CAN devices on MMU-less systems

PATCH In review Dario Binacchi 2 participants 6 messages May 9, 2023 – May 13, 2023

lore
Share & tools
lore
#0 lore raw

cover manage CAN devices on MMU-less systems

This series is the result of the work done to add support for the bxCAN controller to the Linux kernel ([1], [2]). Since these are MMU-less systems, I had to apply some patches to the userspace tools required to test the driver. I also submitted a patch to busybox ([3]), but it has not been accepted yet, and I don't know if it will be in the future. In the meantime, the rtnl-link-can application can be used.

This series allows the use of CAN devices on MMU-less systems before it is possible to bump can-utils and libmnl to the new versions containing these patches.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] http://lists.busybox.net/pipermail/busybox/2023-April/090294.html

Dario Binacchi (4):
package/can-utils: bump to version 2023.03 package/can-utils: enable compilation on MMU-less systems package/libmnl: add rtnl-link-can example package/libmnl: simplify LIBMNL_EXAMPLES_INSTALL_TARGETS setting

 ...ograms-using-fork-on-MMU-less-system.patch | 257 +++++++++
 package/can-utils/Config.in                   |   1 -
 package/can-utils/can-utils.hash              |   2 +-
 package/can-utils/can-utils.mk                |   2 +-
 .../0001-examples-add-rtnl-link-can.patch     | 504 ++++++++++++++++++
 package/libmnl/libmnl.mk                      |  15 +-
 6 files changed, 770 insertions(+), 11 deletions(-)
 create mode 100644 package/can-utils/0001-Don-t-compile-programs-using-fork-on-MMU-less-system.patch
 create mode 100644 package/libmnl/0001-examples-add-rtnl-link-can.patch
Signature · 6 lines
2.32.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/4 package/can-utils: bump to version 2023.03

Release notes: https://github.com/linux-can/can-utils/releases/tag/v2023.03

---
 package/can-utils/can-utils.hash | 2 +-
 package/can-utils/can-utils.mk   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
package/can-utils/can-utils.hash +1 -1
index 4e47143f313b..e539e05b4569 100644
@@ -1,4 +1,4 @@
 # Locally computed
-sha256  c9b8f29515ad34af7f78450ec55c983abc5393e86b1f128a92ac0dfd141baaf7  can-utils-2021.08.0.tar.gz
+sha256  2790dfb57fe3ec22b6fd512838c6480c39f7c9ae193e59f1ae01221216505a7e  can-utils-2023.03.tar.gz
 sha256  c3dc748f5e725cf5ed89784fe78e4ff1b05d309bf1e7ade4c572e8fde1b8406c  LICENSES/BSD-3-Clause
 sha256  995a31f60a9ddb4c609214cc7d17ca94cc3cbc7f37e1e64dba81e7f8ea9d4f91  LICENSES/GPL-2.0-only.txt
package/can-utils/can-utils.mk +1 -1
index 5b8a2aeea3b8..462e123c6d92 100644
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-CAN_UTILS_VERSION = 2021.08.0
+CAN_UTILS_VERSION = 2023.03
 CAN_UTILS_SITE = $(call github,linux-can,can-utils,v$(CAN_UTILS_VERSION))
 CAN_UTILS_LICENSE = BSD-3-Clause or GPL-2.0
 CAN_UTILS_LICENSE_FILES = LICENSES/BSD-3-Clause LICENSES/GPL-2.0-only.txt
Signature · 6 lines
2.32.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

PATCH 2/4 package/can-utils: enable compilation on MMU-less systems

In reply to Dario Binacchi

Systems that lack a MMU cannot use fork() to create the child process. The added upstream patch does not compile the affected programs on MMU-less systems.

---
 ...ograms-using-fork-on-MMU-less-system.patch | 257 ++++++++++++++++++
 package/can-utils/Config.in                   |   1 -
 2 files changed, 257 insertions(+), 1 deletion(-)
 create mode 100644 package/can-utils/0001-Don-t-compile-programs-using-fork-on-MMU-less-system.patch
package/can-utils/0001-Don-t-compile-programs-using-fork-on-MMU-less-system.patch new file +257 -0
new file mode 100644
index 000000000000..3a18183b3d85
@@ -0,0 +1,257 @@
+From 5ed3b4ded6cf3e4de6fc8c8739b84231b0285b0e Mon Sep 17 00:00:00 2001
+From: Dario Binacchi <[email protected]>
+Date: Fri, 5 May 2023 08:57:45 +0200
+Subject: [PATCH] Don't compile programs using fork() on MMU-less systems
+
+Systems that lack a MMU cannot use fork() to create the child process.
+The patch does not compile the affected programs on MMU-less systems.
+
+Co-developed-by: Marc Kleine-Budde <[email protected]>
+Signed-off-by: Marc Kleine-Budde <[email protected]>
+Signed-off-by: Dario Binacchi <[email protected]>
+Upstream: https://github.com/linux-can/can-utils/pull/426
+---
+ CMakeLists.txt | 15 ++++++++++++---
+ GNUmakefile.am | 10 +++++++---
+ Makefile       | 16 +++++++++++++---
+ check_cc.sh    | 16 ++++++++++++++++
+ configure.ac   |  2 ++
+ fork_test.c    | 27 +++++++++++++++++++++++++++
+ 6 files changed, 77 insertions(+), 9 deletions(-)
+ create mode 100755 check_cc.sh
+ create mode 100644 fork_test.c
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 09ccd805de66..aee8ff7fca02 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.3)
+ 
+ project(can-utils LANGUAGES C)
+ 
++include (CheckFunctionExists)
+ include (CheckSymbolExists)
+ include (GNUInstallDirs)
+ 
+@@ -25,12 +26,13 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TXTIME=SO_TXTIME")
+ include_directories (.)
+ include_directories (./include)
+ 
++check_function_exists(fork HAVE_FORK)
++
+ set(PROGRAMS_CANLIB
+     asc2log
+     canbusload
+     candump
+     cangen
+-    canlogserver
+     canplayer
+     cansend
+     cansequence
+@@ -39,6 +41,10 @@ set(PROGRAMS_CANLIB
+     slcanpty
+ )
+ 
++if(HAVE_FORK)
++    list(APPEND PROGRAMS_CANLIB canlogserver)
++endif()
++
+ set(PROGRAMS_J1939
+     j1939acd
+     j1939cat
+@@ -49,7 +55,6 @@ set(PROGRAMS_J1939
+ 
+ set(PROGRAMS
+     ${PROGRAMS_CANLIB}
+-    bcmserver
+     canfdtest
+     cangw
+     cansniffer
+@@ -57,13 +62,17 @@ set(PROGRAMS
+     isotpperf
+     isotprecv
+     isotpsend
+-    isotpserver
+     isotpsniffer
+     isotptun
+     slcan_attach
+     slcand
+ )
+ 
++if(HAVE_FORK)
++    list(APPEND PROGRAMS bcmserver)
++    list(APPEND PROGRAMS isotpserver)
++endif()
++
+ add_executable(can-calc-bit-timing
+     calc-bit-timing/can-calc-bit-timing.c
+ )
+diff --git a/GNUmakefile.am b/GNUmakefile.am
+index 5a7ad75f682e..e818754db3a4 100644
+--- a/GNUmakefile.am
++++ b/GNUmakefile.am
+@@ -75,14 +75,12 @@ EXTRA_DIST += \
+ 
+ bin_PROGRAMS = \
+ 	asc2log \
+-	bcmserver \
+ 	can-calc-bit-timing \
+ 	canbusload \
+ 	candump \
+ 	canfdtest \
+ 	cangen \
+ 	cangw \
+-	canlogserver \
+ 	canplayer \
+ 	cansend \
+ 	cansequence \
+@@ -91,7 +89,6 @@ bin_PROGRAMS = \
+ 	isotpperf \
+ 	isotprecv \
+ 	isotpsend \
+-	isotpserver \
+ 	isotpsniffer \
+ 	isotptun \
+ 	j1939acd \
+@@ -106,6 +103,13 @@ bin_PROGRAMS = \
+ 	slcanpty \
+ 	testj1939
+ 
++if HAVE_FORK
++bin_PROGRAMS += \
++	bcmserver \
++	canlogserver \
++	isotpserver
++endif
++
+ j1939acd_LDADD = libj1939.la
+ j1939cat_LDADD = libj1939.la
+ j1939spy_LDADD = libj1939.la
+diff --git a/Makefile b/Makefile
+index 29eef997b290..a26ff3d75e67 100644
+--- a/Makefile
++++ b/Makefile
+@@ -45,6 +45,8 @@ MAKEFLAGS := -k
+ 
+ CFLAGS := -O2 -Wall -Wno-parentheses
+ 
++HAVE_FORK := $(shell ./check_cc.sh "$(CC)" fork_test.c)
++
+ CPPFLAGS += \
+ 	-I. \
+ 	-Iinclude \
+@@ -66,10 +68,14 @@ PROGRAMS_ISOTP := \
+ 	isotpperf \
+ 	isotprecv \
+ 	isotpsend \
+-	isotpserver \
+ 	isotpsniffer \
+ 	isotptun
+ 
++ifeq ($(HAVE_FORK),1)
++PROGRAMS_ISOTP += \
++	isotpserver
++endif
++
+ PROGRAMS_J1939 := \
+ 	j1939acd \
+ 	j1939cat \
+@@ -87,14 +93,12 @@ PROGRAMS := \
+ 	$(PROGRAMS_J1939) \
+ 	$(PROGRAMS_SLCAN) \
+ 	asc2log \
+-	bcmserver \
+ 	can-calc-bit-timing \
+ 	canbusload \
+ 	candump \
+ 	canfdtest \
+ 	cangen \
+ 	cansequence \
+-	canlogserver \
+ 	canplayer \
+ 	cansend \
+ 	cansniffer \
+@@ -103,6 +107,12 @@ PROGRAMS := \
+ 	mcp251xfd-dump \
+ 	slcanpty
+ 
++ifeq ($(HAVE_FORK),1)
++PROGRAMS += \
++	canlogserver \
++	bcmserver
++endif
++
+ all: $(PROGRAMS)
+ 
+ clean:
+diff --git a/check_cc.sh b/check_cc.sh
+new file mode 100755
+index 000000000000..d85ad129da9d
+--- /dev/null
++++ b/check_cc.sh
+@@ -0,0 +1,16 @@
++#!/bin/sh
++# SPDX-License-Identifier: GPL-2.0-only
++# check_cc.sh - Helper to test userspace compilation support
++# Copyright (c) 2015 Andrew Lutomirski
++
++CC="$1"
++TESTPROG="$2"
++shift 2
++
++if [ -n "$CC" ] && $CC -o /dev/null "$TESTPROG" -O0 "$@"; then
++    echo 1
++else
++    echo 0
++fi
++
++exit 0
+diff --git a/configure.ac b/configure.ac
+index 5493c9c7ccdf..9bf62a5c6409 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -76,6 +76,8 @@ AC_CHECK_FUNCS([ \
+ 	strtoul \
+ ])
+ 
++AM_CONDITIONAL(HAVE_FORK, test "$ac_cv_func_fork_works" = "yes")
++
+ # glibc versions before 2.17 needs to link with -lrt for clock_nanosleep
+ AC_SEARCH_LIBS([clock_nanosleep], [rt])
+ 
+diff --git a/fork_test.c b/fork_test.c
+new file mode 100644
+index 000000000000..036692392483
+--- /dev/null
++++ b/fork_test.c
+@@ -0,0 +1,27 @@
++/* SPDX-License-Identifier: GPL-2.0-only */
++/*
++ * Copyright (C) 2023 Dario Binacchi <[email protected]>
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the version 2 of the GNU General Public License
++ * as published by the Free Software Foundation
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, see <http://www.gnu.org/licenses/>.
++ */
++
++#include <stdio.h>
++#include <sys/types.h>
++#include <unistd.h>
++
++int main(int argc, char **argv)
++{
++	fork();
++
++	return 0;
++}
+-- 
+2.32.0
+
package/can-utils/Config.in +0 -1
index bdc84b461afc..a33919a20867 100644
@@ -1,6 +1,5 @@
 config BR2_PACKAGE_CAN_UTILS
 	bool "can-utils"
-	depends on BR2_USE_MMU # fork()
 	help
 	  SocketCAN is a set of open source CAN drivers and a
 	  networking stack.
Signature · 6 lines
2.32.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH 3/4 package/libmnl: add rtnl-link-can example

In reply to Dario Binacchi

The iproute2 package requires MMU support, and the BusyBox "ip link" command does not handle CAN interfaces. The rtnl-link-can application, added by applying the upstream patch, allows for the use of CAN devices even on such systems.

---
 .../0001-examples-add-rtnl-link-can.patch     | 504 ++++++++++++++++++
 package/libmnl/libmnl.mk                      |   4 +-
 2 files changed, 507 insertions(+), 1 deletion(-)
 create mode 100644 package/libmnl/0001-examples-add-rtnl-link-can.patch
package/libmnl/0001-examples-add-rtnl-link-can.patch new file +504 -0
new file mode 100644
index 000000000000..6196cb5a32cf
@@ -0,0 +1,504 @@
+From 80442c4e32cde0b27b471c5c9688ee8488f14bec Mon Sep 17 00:00:00 2001
+From: Dario Binacchi <[email protected]>
+Date: Thu, 20 Apr 2023 21:21:15 +0200
+Subject: [PATCH] examples: add rtnl-link-can
+
+I developed this application to test the Linux kernel series referenced below.
+I could not use the iproute2 package since the microcontroller is without MMU.
+
+On suggestion of the Linux CAN subsystem maintainer I decided to upstream it.
+
+Cc: Marc Kleine-Budde <[email protected]>
+Link: https://marc.info/?l=linux-netdev&m=167999323611710&w=2
+Signed-off-by: Dario Binacchi <[email protected]>
+Signed-off-by: Florian Westphal <[email protected]>
+Upstream: 80442c4e32cde0b27b471c5c9688ee8488f14bec
+---
+ examples/rtnl/Makefile.am     |   4 +
+ examples/rtnl/rtnl-link-can.c | 452 ++++++++++++++++++++++++++++++++++
+ 2 files changed, 456 insertions(+)
+ create mode 100644 examples/rtnl/rtnl-link-can.c
+
+diff --git a/examples/rtnl/Makefile.am b/examples/rtnl/Makefile.am
+index dd8a77d914b6..5a28e0965926 100644
+--- a/examples/rtnl/Makefile.am
++++ b/examples/rtnl/Makefile.am
+@@ -2,6 +2,7 @@ include $(top_srcdir)/Make_global.am
+ 
+ check_PROGRAMS = rtnl-addr-add \
+ 		 rtnl-addr-dump \
++		 rtnl-link-can \
+ 		 rtnl-link-dump rtnl-link-dump2 rtnl-link-dump3 \
+ 		 rtnl-link-event \
+ 		 rtnl-link-set \
+@@ -13,6 +14,9 @@ check_PROGRAMS = rtnl-addr-add \
+ rtnl_addr_add_SOURCES = rtnl-addr-add.c
+ rtnl_addr_add_LDADD = ../../src/libmnl.la
+ 
++rtnl_link_can_SOURCES = rtnl-link-can.c
++rtnl_link_can_LDADD = ../../src/libmnl.la
++
+ rtnl_addr_dump_SOURCES = rtnl-addr-dump.c
+ rtnl_addr_dump_LDADD = ../../src/libmnl.la
+ 
+diff --git a/examples/rtnl/rtnl-link-can.c b/examples/rtnl/rtnl-link-can.c
+new file mode 100644
+index 000000000000..8ed70d141475
+--- /dev/null
++++ b/examples/rtnl/rtnl-link-can.c
+@@ -0,0 +1,452 @@
++/* This example is placed in the public domain. */
++#include <errno.h>
++#include <limits.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <unistd.h>
++#include <time.h>
++
++#include <libmnl/libmnl.h>
++#include <linux/can/netlink.h>
++#include <linux/if.h>
++#include <linux/if_link.h>
++#include <linux/rtnetlink.h>
++
++static void incomplete_command(void) __attribute__((noreturn));
++
++#define NEXT_ARG()				\
++	do { \
++		if (argc <= 0) incomplete_command();	\
++		argv++; \
++		argc--; \
++	} while (0)
++
++static void duparg2(const char *key, const char *arg)
++{
++	fprintf(stderr,
++		"Error: either \"%s\" is duplicate, or \"%s\" is a garbage.\n",
++		key, arg);
++	exit(-1);
++}
++
++static void incomplete_command(void)
++{
++	fprintf(stderr, "Command line is not complete. Try option \"help\"\n");
++	exit(EXIT_FAILURE);
++}
++
++/* Returns false if 'prefix' is a not empty prefix of 'string'.
++ */
++static bool matches(const char *prefix, const char *string)
++{
++	if (!*prefix)
++		return true;
++
++	while (*string && *prefix == *string) {
++		prefix++;
++		string++;
++	}
++
++	return !!*prefix;
++}
++
++static int get_u16(__u16 *val, const char *arg, int base)
++{
++	unsigned long res;
++	char *ptr;
++
++	if (!arg || !*arg)
++		return -1;
++
++	res = strtoul(arg, &ptr, base);
++
++	/* empty string or trailing non-digits */
++	if (!ptr || ptr == arg || *ptr)
++		return -1;
++
++	/* overflow */
++	if (res == ULONG_MAX && errno == ERANGE)
++		return -1;
++
++	if (res > 0xFFFFUL)
++		return -1;
++
++	*val = res;
++	return 0;
++}
++
++static int get_u32(__u32 *val, const char *arg, int base)
++{
++	unsigned long res;
++	char *ptr;
++
++	if (!arg || !*arg)
++		return -1;
++
++	res = strtoul(arg, &ptr, base);
++
++	/* empty string or trailing non-digits */
++	if (!ptr || ptr == arg || *ptr)
++		return -1;
++
++	/* overflow */
++	if (res == ULONG_MAX && errno == ERANGE)
++		return -1;
++
++	/* in case UL > 32 bits */
++	if (res > 0xFFFFFFFFUL)
++		return -1;
++
++	*val = res;
++	return 0;
++}
++
++static int get_float(float *val, const char *arg)
++{
++	float res;
++	char *ptr;
++
++	if (!arg || !*arg)
++		return -1;
++
++	res = strtof(arg, &ptr);
++	if (!ptr || ptr == arg || *ptr)
++		return -1;
++
++	*val = res;
++	return 0;
++}
++
++static void set_ctrlmode(char *name, char *arg,
++			 struct can_ctrlmode *cm, __u32 flags)
++{
++	if (strcmp(arg, "on") == 0) {
++		cm->flags |= flags;
++	} else if (strcmp(arg, "off") != 0) {
++		fprintf(stderr,
++			"Error: argument of \"%s\" must be \"on\" or \"off\", not \"%s\"\n",
++			name, arg);
++		exit(EXIT_FAILURE);
++	}
++
++	cm->mask |= flags;
++}
++
++static void invarg(const char *msg, const char *arg)
++{
++	fprintf(stderr, "Error: argument \"%s\" is wrong: %s\n", arg, msg);
++	exit(-1);
++}
++
++static void print_usage(FILE *f)
++{
++	fprintf(f,
++		"Usage: ip link set DEVICE type can\n"
++		"\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |\n"
++		"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n \t  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
++		"\n"
++		"\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |\n"
++		"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n \t  dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
++		"\n"
++		"\t[ loopback { on | off } ]\n"
++		"\t[ listen-only { on | off } ]\n"
++		"\t[ triple-sampling { on | off } ]\n"
++		"\t[ one-shot { on | off } ]\n"
++		"\t[ berr-reporting { on | off } ]\n"
++		"\t[ fd { on | off } ]\n"
++		"\t[ fd-non-iso { on | off } ]\n"
++		"\t[ presume-ack { on | off } ]\n"
++		"\t[ cc-len8-dlc { on | off } ]\n"
++		"\n"
++		"\t[ restart-ms TIME-MS ]\n"
++		"\t[ restart ]\n"
++		"\n"
++		"\t[ termination { 0..65535 } ]\n"
++		"\n"
++		"\tWhere: BITRATE	:= { 1..1000000 }\n"
++		"\t	  SAMPLE-POINT	:= { 0.000..0.999 }\n"
++		"\t	  TQ		:= { NUMBER }\n"
++		"\t	  PROP-SEG	:= { 1..8 }\n"
++		"\t	  PHASE-SEG1	:= { 1..8 }\n"
++		"\t	  PHASE-SEG2	:= { 1..8 }\n"
++		"\t	  SJW		:= { 1..4 }\n"
++		"\t	  RESTART-MS	:= { 0 | NUMBER }\n"
++		);
++}
++
++static void usage(void)
++{
++	print_usage(stderr);
++}
++
++static int iplink_set_can_parse(int argc, char **argv, struct nlmsghdr *nlh)
++{
++	struct can_bittiming bt = {}, dbt = {};
++	struct can_ctrlmode cm = {};
++
++	while (argc > 0) {
++		if (matches(*argv, "bitrate") == 0) {
++			NEXT_ARG();
++			if (get_u32(&bt.bitrate, *argv, 0))
++				invarg("invalid \"bitrate\" value\n", *argv);
++		} else if (matches(*argv, "sample-point") == 0) {
++			float sp;
++
++			NEXT_ARG();
++			if (get_float(&sp, *argv))
++				invarg("invalid \"sample-point\" value\n",
++				       *argv);
++
++			bt.sample_point = (__u32)(sp * 1000);
++		} else if (matches(*argv, "tq") == 0) {
++			NEXT_ARG();
++			if (get_u32(&bt.tq, *argv, 0))
++				invarg("invalid \"tq\" value\n", *argv);
++		} else if (matches(*argv, "prop-seg") == 0) {
++			NEXT_ARG();
++			if (get_u32(&bt.prop_seg, *argv, 0))
++				invarg("invalid \"prop-seg\" value\n", *argv);
++		} else if (matches(*argv, "phase-seg1") == 0) {
++			NEXT_ARG();
++			if (get_u32(&bt.phase_seg1, *argv, 0))
++				invarg("invalid \"phase-seg1\" value\n", *argv);
++		} else if (matches(*argv, "phase-seg2") == 0) {
++			NEXT_ARG();
++			if (get_u32(&bt.phase_seg2, *argv, 0))
++				invarg("invalid \"phase-seg2\" value\n", *argv);
++		} else if (matches(*argv, "sjw") == 0) {
++			NEXT_ARG();
++			if (get_u32(&bt.sjw, *argv, 0))
++				invarg("invalid \"sjw\" value\n", *argv);
++		} else if (matches(*argv, "dbitrate") == 0) {
++			NEXT_ARG();
++			if (get_u32(&dbt.bitrate, *argv, 0))
++				invarg("invalid \"dbitrate\" value\n", *argv);
++		} else if (matches(*argv, "dsample-point") == 0) {
++			float sp;
++
++			NEXT_ARG();
++			if (get_float(&sp, *argv))
++				invarg("invalid \"dsample-point\" value\n", *argv);
++			dbt.sample_point = (__u32)(sp * 1000);
++		} else if (matches(*argv, "dtq") == 0) {
++			NEXT_ARG();
++			if (get_u32(&dbt.tq, *argv, 0))
++				invarg("invalid \"dtq\" value\n", *argv);
++		} else if (matches(*argv, "dprop-seg") == 0) {
++			NEXT_ARG();
++			if (get_u32(&dbt.prop_seg, *argv, 0))
++				invarg("invalid \"dprop-seg\" value\n", *argv);
++		} else if (matches(*argv, "dphase-seg1") == 0) {
++			NEXT_ARG();
++			if (get_u32(&dbt.phase_seg1, *argv, 0))
++				invarg("invalid \"dphase-seg1\" value\n", *argv);
++		} else if (matches(*argv, "dphase-seg2") == 0) {
++			NEXT_ARG();
++			if (get_u32(&dbt.phase_seg2, *argv, 0))
++				invarg("invalid \"dphase-seg2\" value\n", *argv);
++		} else if (matches(*argv, "dsjw") == 0) {
++			NEXT_ARG();
++			if (get_u32(&dbt.sjw, *argv, 0))
++				invarg("invalid \"dsjw\" value\n", *argv);
++		} else if (matches(*argv, "loopback") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("loopback", *argv, &cm,
++				     CAN_CTRLMODE_LOOPBACK);
++		} else if (matches(*argv, "listen-only") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("listen-only", *argv, &cm,
++				     CAN_CTRLMODE_LISTENONLY);
++		} else if (matches(*argv, "triple-sampling") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("triple-sampling", *argv, &cm,
++				     CAN_CTRLMODE_3_SAMPLES);
++		} else if (matches(*argv, "one-shot") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("one-shot", *argv, &cm,
++				     CAN_CTRLMODE_ONE_SHOT);
++		} else if (matches(*argv, "berr-reporting") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("berr-reporting", *argv, &cm,
++				     CAN_CTRLMODE_BERR_REPORTING);
++		} else if (matches(*argv, "fd") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("fd", *argv, &cm,
++				     CAN_CTRLMODE_FD);
++		} else if (matches(*argv, "fd-non-iso") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("fd-non-iso", *argv, &cm,
++				     CAN_CTRLMODE_FD_NON_ISO);
++		} else if (matches(*argv, "presume-ack") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("presume-ack", *argv, &cm,
++				     CAN_CTRLMODE_PRESUME_ACK);
++#if defined(CAN_CTRLMODE_CC_LEN8_DLC)
++		} else if (matches(*argv, "cc-len8-dlc") == 0) {
++			NEXT_ARG();
++			set_ctrlmode("cc-len8-dlc", *argv, &cm,
++				     CAN_CTRLMODE_CC_LEN8_DLC);
++#endif
++		} else if (matches(*argv, "restart") == 0) {
++			__u32 val = 1;
++
++			mnl_attr_put(nlh, IFLA_CAN_RESTART, sizeof(val), &val);
++		} else if (matches(*argv, "restart-ms") == 0) {
++			__u32 val;
++
++			NEXT_ARG();
++			if (get_u32(&val, *argv, 0))
++				invarg("invalid \"restart-ms\" value\n", *argv);
++
++			mnl_attr_put(nlh, IFLA_CAN_RESTART_MS, sizeof(val), &val);
++		} else if (matches(*argv, "termination") == 0) {
++			__u16 val;
++
++			NEXT_ARG();
++			if (get_u16(&val, *argv, 0))
++				invarg("invalid \"termination\" value\n",
++				       *argv);
++
++			mnl_attr_put(nlh, IFLA_CAN_TERMINATION, sizeof(val), &val);
++		} else {
++			fprintf(stderr, "unknown option \"%s\"\n", *argv);
++			usage();
++			return -1;
++		}
++
++		NEXT_ARG();
++	}
++
++	if (bt.bitrate || bt.tq)
++		mnl_attr_put(nlh, IFLA_CAN_BITTIMING, sizeof(bt), &bt);
++
++	if (cm.mask)
++		mnl_attr_put(nlh, IFLA_CAN_CTRLMODE, sizeof(cm), &cm);
++
++	return 0;
++}
++
++int main(int argc, char *argv[])
++{
++	char buf[MNL_SOCKET_BUFFER_SIZE];
++	struct mnl_socket *nl;
++	struct nlmsghdr *nlh;
++	struct ifinfomsg *ifm;
++	int ret;
++	unsigned int seq, portid;
++	struct nlattr *linkinfo, *data;
++	const char *signatures[] = {
++		"ip", "link", "set", ""
++	};
++	char *type = NULL;
++	char *dev = NULL;
++	int i;
++
++	NEXT_ARG();
++	for (i = 0; argc > 0 && signatures[i][0];) {
++		if (matches(*argv, signatures[i]))
++			incomplete_command();
++
++		NEXT_ARG();
++		i++;
++	}
++
++	if (argc == 0)
++		incomplete_command();
++
++	nlh = mnl_nlmsg_put_header(buf);
++	nlh->nlmsg_type	= RTM_NEWLINK;
++	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
++	nlh->nlmsg_seq = seq = time(NULL);
++	ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm));
++	ifm->ifi_family = AF_UNSPEC;
++	ifm->ifi_change = 0;
++	ifm->ifi_flags = 0;
++
++	while (argc > 0) {
++		if (matches(*argv, "up") == 0) {
++			ifm->ifi_change |= IFF_UP;
++			ifm->ifi_flags |= IFF_UP;
++		} else if (matches(*argv, "down") == 0) {
++			ifm->ifi_change |= IFF_UP;
++			ifm->ifi_flags &= ~IFF_UP;
++		} else if (matches(*argv, "type") == 0) {
++			NEXT_ARG();
++			type = *argv;
++			NEXT_ARG();
++			break;
++		} else if (matches(*argv, "help") == 0) {
++			usage();
++			exit(EXIT_FAILURE);
++		} else {
++			if (matches(*argv, "dev") == 0)
++				NEXT_ARG();
++
++			if (dev)
++				duparg2("dev", *argv);
++
++			dev = *argv;
++		}
++
++		NEXT_ARG();
++	}
++
++	if (dev)
++		mnl_attr_put_str(nlh, IFLA_IFNAME, dev);
++
++	if (type) {
++		if (matches(type, "can")) {
++			fprintf(stderr, "unknown type \"%s\"\n", type);
++			usage();
++			exit(EXIT_FAILURE);
++		}
++
++		linkinfo = mnl_attr_nest_start(nlh, IFLA_LINKINFO);
++		mnl_attr_put_str(nlh, IFLA_INFO_KIND, "can");
++		data = mnl_attr_nest_start(nlh, IFLA_INFO_DATA);
++
++		if (iplink_set_can_parse(argc, argv, nlh))
++			return -1;
++
++		mnl_attr_nest_end(nlh, data);
++		mnl_attr_nest_end(nlh, linkinfo);
++	}
++
++	nl = mnl_socket_open(NETLINK_ROUTE);
++	if (nl == NULL) {
++		perror("mnl_socket_open");
++		exit(EXIT_FAILURE);
++	}
++
++	if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
++		perror("mnl_socket_bind");
++		exit(EXIT_FAILURE);
++	}
++
++	portid = mnl_socket_get_portid(nl);
++
++	mnl_nlmsg_fprintf(stdout, nlh, nlh->nlmsg_len,
++			  sizeof(struct ifinfomsg));
++
++	if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
++		perror("mnl_socket_sendto");
++		exit(EXIT_FAILURE);
++	}
++
++	ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
++	if (ret == -1) {
++		perror("mnl_socket_recvfrom");
++		exit(EXIT_FAILURE);
++	}
++
++	ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
++	if (ret == -1) {
++		perror("mnl_cb_run");
++		exit(EXIT_FAILURE);
++	}
++
++	mnl_socket_close(nl);
++
++	return 0;
++}
+-- 
+2.32.0
+
package/libmnl/libmnl.mk +3 -1
index d9b1fbabe703..7c48196d7529 100644
@@ -11,6 +11,8 @@ LIBMNL_INSTALL_STAGING = YES
 LIBMNL_LICENSE = LGPL-2.1+
 LIBMNL_LICENSE_FILES = COPYING
 LIBMNL_CPE_ID_VENDOR = netfilter
+# 0001-examples-add-rtnl-link-can.patch patches Makefile.am
+LIBMNL_AUTORECONF = YES
 
 ifeq ($(BR2_PACKAGE_LIBMNL_EXAMPLES),y)
 define LIBMNL_EXAMPLES_BUILD_CMDS
@@ -28,7 +30,7 @@ LIBMNL_EXAMPLES_INSTALL_TARGETS += \
 		nf-queue)
 LIBMNL_EXAMPLES_INSTALL_TARGETS += \
 	$(addprefix examples/rtnl/, rtnl-addr-add rtnl-addr-dump \
-		rtnl-link-dump rtnl-link-dump2 rtnl-link-dump3 \
+		rtnl-link-can rtnl-link-dump rtnl-link-dump2 rtnl-link-dump3 \
 		rtnl-link-event rtnl-link-set rtnl-neigh-dump \
 		rtnl-route-add rtnl-route-dump rtnl-route-event)
 
Signature · 6 lines
2.32.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

PATCH 4/4 package/libmnl: simplify LIBMNL_EXAMPLES_INSTALL_TARGETS setting

In reply to Dario Binacchi

Simplify the setting of LIBMNL_EXAMPLES_INSTALL_TARGETS as suggested by Arnout Vandecappelle in [1].

[1] https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

---
 package/libmnl/libmnl.mk | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
package/libmnl/libmnl.mk +4 -7
index 7c48196d7529..cea528422ea8 100644
@@ -20,15 +20,12 @@ define LIBMNL_EXAMPLES_BUILD_CMDS
 endef
 LIBMNL_POST_BUILD_HOOKS += LIBMNL_EXAMPLES_BUILD_CMDS
 
-LIBMNL_EXAMPLES_INSTALL_TARGETS += \
-	$(addprefix examples/genl/, genl-family-get genl-group-events)
-LIBMNL_EXAMPLES_INSTALL_TARGETS += \
-	$(addprefix examples/kobject/, kobject-event)
-LIBMNL_EXAMPLES_INSTALL_TARGETS += \
+LIBMNL_EXAMPLES_INSTALL_TARGETS = \
+	$(addprefix examples/genl/, genl-family-get genl-group-events) \
+	$(addprefix examples/kobject/, kobject-event) \
 	$(addprefix examples/netfilter/, nfct-create-batch \
 		nfct-daemon nfct-dump nfct-event nf-log \
-		nf-queue)
-LIBMNL_EXAMPLES_INSTALL_TARGETS += \
+		nf-queue) \
 	$(addprefix examples/rtnl/, rtnl-addr-add rtnl-addr-dump \
 		rtnl-link-can rtnl-link-dump rtnl-link-dump2 rtnl-link-dump3 \
 		rtnl-link-event rtnl-link-set rtnl-neigh-dump \
Signature · 6 lines
2.32.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw
In reply to Dario Binacchi

Dario, All,

On 2023-05-09 22:11 +0200, Dario Binacchi spake thusly:

Quoted 15 lines

This series is the result of the work done to add support for the bxCAN controller to the Linux kernel ([1], [2]). Since these are MMU-less systems, I had to apply some patches to the userspace tools required to test the driver. I also submitted a patch to busybox ([3]), but it has not been accepted yet, and I don't know if it will be in the future. In the meantime, the rtnl-link-can application can be used.

This series allows the use of CAN devices on MMU-less systems before it is possible to bump can-utils and libmnl to the new versions containing these patches.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] http://lists.busybox.net/pipermail/busybox/2023-April/090294.html

Quoted 5 lines

Dario Binacchi (4):
package/can-utils: bump to version 2023.03 package/can-utils: enable compilation on MMU-less systems package/libmnl: add rtnl-link-can example package/libmnl: simplify LIBMNL_EXAMPLES_INSTALL_TARGETS setting

All 4 patches applied to master, thanks.

I just tweaked the Upstream: tag for the libmnl patch, to point to the actual URL instead of just the sha1:

    https://git.netfilter.org/libmnl/commit/?id=80442c4e32cde0b27b471c5c9688ee8488f14bec

Regards,
Yann E. MORIN.

Quoted 17 lines
 ...ograms-using-fork-on-MMU-less-system.patch | 257 +++++++++
 package/can-utils/Config.in                   |   1 -
 package/can-utils/can-utils.hash              |   2 +-
 package/can-utils/can-utils.mk                |   2 +-
 .../0001-examples-add-rtnl-link-can.patch     | 504 ++++++++++++++++++
 package/libmnl/libmnl.mk                      |  15 +-
 6 files changed, 770 insertions(+), 11 deletions(-)
 create mode 100644 package/can-utils/0001-Don-t-compile-programs-using-fork-on-MMU-less-system.patch
 create mode 100644 package/libmnl/0001-examples-add-rtnl-link-can.patch
Signature · 6 lines
2.32.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot