Skip to contentSkip to conversation

Socketcan correct way to bootup...

DISCUSSION Marc Kleine-Budde 3 participants 5 messages Jul 9, 2014 1 message not in the archive CAN network drivers

lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#1 lore raw
In reply to a message not in the archive
Quoted 3 lines · gianluca

I was wondering if there is some "Offical" way to bring-up a socketcan interface during bootup of a Linux System. Actually I write a simple script BEFORE running my application in this way:

Depends on your Distribution/init system.

Quoted 15 lines
# run.sh 125000 75 can0

[ run.sh ]
#!/bin/sh
BITRATE=$1
SAMPLE=".$2"
INTERFACE=$3
ip link set $INTERFACE up type can bitrate ${BITRATE} sample-point ${SAMPLE}
ip -details link show $INTERFACE
while [ true ];
do
./myapplication
done

Quoted 3 lines

Are there some guidelines on how to approach this startup? i.e. I was thinking about similar to ifup /etc/network/interface but with the addendum of the bitrate and sample point...

On recent Debian based Distris you can use ifup/ifdown for CAN interfaces. See the man page of interfaces.

If you use busybox's ifup/ifdown you can fall back to the "inet manual" mode and specify /sbin/ip commands to configure and up/down your interface. On systemd you can add a service that starts CAN and runs before your actual program.

Marc

BTW: you probably want to integrate your application into the automatic startup via an init script or in new designs with systemd...and _not_ start it by hand.

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#2 lore raw
Quoted 34 lines · Marc Kleine-Budde
Quoted 3 lines · gianluca

I was wondering if there is some "Offical" way to bring-up a socketcan interface during bootup of a Linux System. Actually I write a simple script BEFORE running my application in this way:

Depends on your Distribution/init system.

Quoted 15 lines
# run.sh 125000 75 can0

[ run.sh ]
#!/bin/sh
BITRATE=$1
SAMPLE=".$2"
INTERFACE=$3
ip link set $INTERFACE up type can bitrate ${BITRATE} sample-point ${SAMPLE}
ip -details link show $INTERFACE
while [ true ];
do
./myapplication
done

Quoted 3 lines

Are there some guidelines on how to approach this startup? i.e. I was thinking about similar to ifup /etc/network/interface but with the addendum of the bitrate and sample point...

On recent Debian based Distris you can use ifup/ifdown for CAN interfaces. See the man page of interfaces.

If you use busybox's ifup/ifdown you can fall back to the "inet manual" mode and specify /sbin/ip commands to configure and up/down your interface. On systemd you can add a service that starts CAN and runs before your actual program.

Quoted 5 lines

Marc

BTW: you probably want to integrate your application into the automatic startup via an init script or in new designs with systemd...and _not_ start it by hand.

You can also use libsocketcan or libnl to configure CAN interface directly from your application.

Yegor

author maintainer
#3 lore raw
Quoted 6 lines · Yegor Yefremov
Quoted 3 lines

BTW: you probably want to integrate your application into the automatic startup via an init script or in new designs with systemd...and _not_ start it by hand.

You can also use libsocketcan or libnl to configure CAN interface directly from your application.

Good point.

here's libsocketcan's API:

http://git.pengutronix.de/?p=tools/libsocketcan.git;a=blob;f=include/libsocketcan.h;h=dc52053b824d1a8976126b043de4ee5d843c1401;hb=0c91940da1c16e01e8220e9fa18c703852ba6d1b

http://www.pengutronix.de/software/libsocketcan/download/

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#4 lore raw
Quoted 8 lines · Marc Kleine-Budde
Quoted 6 lines · Yegor Yefremov
Quoted 3 lines

BTW: you probably want to integrate your application into the automatic startup via an init script or in new designs with systemd...and _not_ start it by hand.

You can also use libsocketcan or libnl to configure CAN interface directly from your application.

Quoted 7 lines

Good point.

here's libsocketcan's API:

http://git.pengutronix.de/?p=tools/libsocketcan.git;a=blob;f=include/libsocketcan.h;h=dc52053b824d1a8976126b043de4ee5d843c1401;hb=0c91940da1c16e01e8220e9fa18c703852ba6d1b

http://www.pengutronix.de/software/libsocketcan/download/

If you're using Buildroot (http://buildroot.uclibc.org/) or OpenWrt
(https://openwrt.org/) you'll find libsocketcan already being integrated into their repositories. I don't know about OpenEmbedded universe.

Yegor

#5 lore raw

For Debian systems I use this script:

https://gitorious.org/linux-can/can-misc/source/etc/can_if

Just copy can_if to /etc/init.d and say

update-rc.d can_if defaults

Btw. Debian changed to systemd. So far this script still run's with the latest Debian unstable (which used systemd).

Regards,
Oliver

Quoted 28 lines · Yegor Yefremov
Quoted 8 lines · Marc Kleine-Budde
Quoted 6 lines · Yegor Yefremov
Quoted 3 lines

BTW: you probably want to integrate your application into the automatic startup via an init script or in new designs with systemd...and _not_ start it by hand.

You can also use libsocketcan or libnl to configure CAN interface directly from your application.

Quoted 7 lines

Good point.

here's libsocketcan's API:

http://git.pengutronix.de/?p=tools/libsocketcan.git;a=blob;f=include/libsocketcan.h;h=dc52053b824d1a8976126b043de4ee5d843c1401;hb=0c91940da1c16e01e8220e9fa18c703852ba6d1b

http://www.pengutronix.de/software/libsocketcan/download/

If you're using Buildroot (http://buildroot.uclibc.org/) or OpenWrt
(https://openwrt.org/) you'll find libsocketcan already being integrated into their repositories. I don't know about OpenEmbedded universe.

Yegor
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html