alexmohr / usb-can

USB-CAN Analyzer Linux Support
GNU General Public License v2.0
36 stars 13 forks source link

Build error #18

Closed nopnop2002 closed 4 years ago

nopnop2002 commented 4 years ago

Thank you for a great job.

I can't build.

My environment:

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

My USB-CAN Adapter:

$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 005: ID 1507:2814
Bus 001 Device 007: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Build:

$ ./build.sh
Building module
make -C /lib/modules/4.15.0-109-generic/build/ M=/home/nop/usb-can/src/module modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-109-generic'
scripts/Makefile.build:50: *** CFLAGS was changed in "/home/nop/usb-can/src/module/Makefile". Fix it to use ccflags-y.  Stop.
Makefile:1582: recipe for target '_module_/home/nop/usb-can/src/module' failed
make[1]: *** [_module_/home/nop/usb-can/src/module] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-109-generic'
Makefile:11: recipe for target 'all' failed
make: *** [all] Error 2
Building userpace tools
make: Nothing to be done for 'all'.

Do you have any advice?

alexmohr commented 4 years ago

I've added a new branch bugfix/makefile which should fix the issue for you. Otherwise run

export KBUILD_NOPEDANTIC=1
./build.sh
nopnop2002 commented 4 years ago

Thank you quick response. I made build. It is ok.

$ export KBUILD_NOPEDANTIC=1
$ ./build.sh
Building module
make -C /lib/modules/4.15.0-109-generic/build/ M=/home/nop/usb-can/src/module modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-109-generic'
  CC [M]  /home/nop/usb-can/src/module/hlcan.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/nop/usb-can/src/module/hlcan.mod.o
  LD [M]  /home/nop/usb-can/src/module/hlcan.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-109-generic'
Building userpace tools
make: Nothing to be done for 'all'.

But i got error to install.

$ sudo ./build.sh install
Building module
cp hlcan.ko /usr/lib/modules/4.15.0-109-generic/kernel/drivers/net/can
cp: cannot create regular file '/usr/lib/modules/4.15.0-109-generic/kernel/drivers/net/can': No such file or directory
Makefile:15: recipe for target 'install' failed
make: *** [install] Error 1
Building userpace tools
mkdir -p /usr/local/bin
cp -f hlcand  /usr/local/bin
nopnop2002 commented 4 years ago

I got new branch bugfix/makefile. But same error.

$ git clone -b bugfix/makefile https://github.com/alexmohr/usb-can
Cloning into 'usb-can'...
remote: Enumerating objects: 272, done.
remote: Counting objects: 100% (272/272), done.
remote: Compressing objects: 100% (177/177), done.
remote: Total 371 (delta 164), reused 189 (delta 92), pack-reused 99
Receiving objects: 100% (371/371), 356.14 KiB | 719.00 KiB/s, done.
Resolving deltas: 100% (207/207), done.

$ cd usb-can

$ ./build.sh
Building module
make -C /lib/modules/4.15.0-109-generic/build/ M=/home/nop/usb-can/src/module modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-109-generic'
  CC [M]  /home/nop/usb-can/src/module/hlcan.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/nop/usb-can/src/module/hlcan.mod.o
  LD [M]  /home/nop/usb-can/src/module/hlcan.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-109-generic'
Building userpace tools
cc  -D_GNU_SOURCE   hlcand.c   -o hlcand

$ sudo ./build.sh install
Building module
cp hlcan.ko /usr/lib/modules/4.15.0-109-generic/kernel/drivers/net/can
cp: cannot create regular file '/usr/lib/modules/4.15.0-109-generic/kernel/drivers/net/can': No such file or directory
Makefile:15: recipe for target 'install' failed
make: *** [install] Error 1
Building userpace tools
mkdir -p /usr/local/bin
cp -f hlcand  /usr/local/bin
alexmohr commented 4 years ago

I've updated the MakeFile on master. It now creates the folders needed. The bugfix/makefile branch is not actually building how it's supposed to. Therefore do not use this at the moment.

nopnop2002 commented 4 years ago

I used master.

I got an error with insmod.

$ git clone https://github.com/alexmohr/usb-can
Cloning into 'usb-can'...
remote: Enumerating objects: 271, done.
remote: Counting objects: 100% (271/271), done.
remote: Compressing objects: 100% (175/175), done.
remote: Total 370 (delta 164), reused 189 (delta 93), pack-reused 99
Receiving objects: 100% (370/370), 356.00 KiB | 154.00 KiB/s, done.
Resolving deltas: 100% (207/207), done.

$ cd usb-can

$ ./build.sh
Building module
make -C /lib/modules/4.15.0-109-generic/build/ M=/home/nop/usb-can/src/module modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-109-generic'
  CC [M]  /home/nop/usb-can/src/module/hlcan.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/nop/usb-can/src/module/hlcan.mod.o
  LD [M]  /home/nop/usb-can/src/module/hlcan.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-109-generic'
Building userpace tools
cc -O2 -Wall -Wno-parentheses -D_GNU_SOURCE   hlcand.c   -o hlcand

$ sudo ./build.sh install
Building module
mkdir -p /usr/lib/modules/4.15.0-109-generic/kernel/drivers/net/can
cp hlcan.ko /usr/lib/modules/4.15.0-109-generic/kernel/drivers/net/can
Building userpace tools
mkdir -p /usr/local/bin
cp -f hlcand  /usr/local/bin

$ modprobe can-dev

$ insmod hlcan.ko
insmod: ERROR: could not load module hlcan.ko: No such file or directory

I'm using Bionic Beaver.

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
alexmohr commented 4 years ago

Just load the module with an abosulte path.

 sudo insmod  /usr/lib/modules/$(uname -r)/kernel/drivers/net/can/hlcan.ko
nopnop2002 commented 4 years ago

Just load the module with an abosulte path. But i got this error.

$ sudo insmod  /usr/lib/modules/$(uname -r)/kernel/drivers/net/can/hlcan.ko

$ ip link set can0 up
Cannot find device "can0"

$ lsmod | grep hlcan
hlcan                  16384  0
can_dev                28672  1 hlcan
alexmohr commented 4 years ago

Post the result of ip link

nopnop2002 commented 4 years ago

$ ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether a0:48:1c:9c:49:c6 brd ff:ff:ff:ff:ff:ff 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default link/ether 02:42:fb:5f:49:6d brd ff:ff:ff:ff:ff:ff

nopnop2002 commented 4 years ago

Thank for your support.

I'm going to out.

I can not respond for a while.

alexmohr commented 4 years ago

The order in the readme was wrong. first start userspace tool then set link up :+1:

nopnop2002 commented 4 years ago

I am waiting for you to update the README.

nopnop2002 commented 4 years ago

Terminal 1:

$ hlcand -F -s 500000 /dev/ttyUSB0
[6] starting on TTY device /dev/ttyUSB0
ioctl TIOCSETD: Operation not permitted

$ sudo hlcand -F -s 500000 /dev/ttyUSB0
[6] starting on TTY device /dev/ttyUSB0
[5] attached TTY /dev/ttyUSB0 to netdevice

Terminal 2:

$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether a0:48:1c:9c:49:c6 brd ff:ff:ff:ff:ff:ff
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
    link/ether 02:42:fb:5f:49:6d brd ff:ff:ff:ff:ff:ff
4: can0: <NOARP> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can

$ ip link set can0 up
RTNETLINK answers: Operation not permitted

$ sudo ip link set can0 up

I am sending a CAN frame, but nothing is displayed in Terminal1.

alexmohr commented 4 years ago

hlcand does not show any output except debug informations. You wan't to take a look at the kernel CAN utils. For example run candump can0 to show traffic.

nopnop2002 commented 4 years ago

I understand how USB-CAN works.

Thank you very much.