**********************************************
Kvaser linuxcan
**********************************************

Frequently Asked Questions - FAQ

(Also check ReleaseNotes for information about known problems.)


--------------------------------------------------------------------------------
Q1
    How to build and install linuxcan?

A1
    $ cd linuxcan
    $ make
    $ sudo make install

    For more information, see README.

--------------------------------------------------------------------------------
Q2
    What version of CANlib is installed?

A2
    CANlib version is printed in the listChannels example.

    $ /usr/doc/canlib/examples/listChannels

--------------------------------------------------------------------------------
Q3
    How to upgrade/reinstall linuxcan?

A3
    Close all running applications that are using CANlib. Unplug all Kvaser USB
    interfaces. Then execute:

    $ sudo make uninstall
    $ make
    $ sudo make install

--------------------------------------------------------------------------------
Q4
    When executing make you get an error like:

    make: *** /lib/modules/'4.10.0-26-generic/build': No such file or directory.
    Stop.

A4
    This probably means that the kernel source either is not installed or that
    the path to the kernel source does not match /lib/modules/`uname -r`/build.
    Make sure you have installed the kernel source. If your kernel source is
    located in a different directory, set the variable KDIR to this path. i.e.

    $ export KDIR=/home/kvaser/kernel_4.10.11

--------------------------------------------------------------------------------
Q5
    When executing make you get an error like:

    make[2]: Entering directory '/usr/src/linux-headers-4.4.38-tegra'
      CC [M]  /home/nvidia/linuxcan/linuxcan/common/VCanOsIf.o
    scripts/basic/fixdep: 1: scripts/basic/fixdep: Syntax error: "(" unexpected

A5
    This probably means that the kernel build system has to be prepared using
    the following command:

    $ cd /lib/modules/`uname -r`/build
    $ sudo make modules_prepare

--------------------------------------------------------------------------------
Q6
    Compilation succeeded but install failed. You get an error like:

    Permission denied

A6
    You need root permissions to install linuxcan. Use 'sudo' or log in as root.

--------------------------------------------------------------------------------
Q7
    I have compiled and installed everything but I still cannot get the drivers
    to work.

A7.1
    Check the kernel log for errors using 'dmesg'. For Kvaser USB interfaces you
    typically see something like this when plugged in:

    $ dmesg
    [32.09107] usb 1-2: new high-speed USB device number 4 using ehci-pci
    [32.30202] usb 1-2: New USB device found, idVendor=0bfd, idProduct=0104
    [32.30207] usb 1-2: Product: Kvaser Memorator Pro 5xHS
    [32.30212] usb 1-2: Manufacturer: Kvaser AB
    [35.42160] usbcore: registered new interface driver mhydra

A7.2
    Make sure the modules are loaded. The following command should print
    kvcommon and at least one more module:

    $ lsmod | grep 'kvcommon\|mhydra\|leaf\|usbcanII\|kvpciefd\|kvpcican\|kvpcicanII\|kvvirutalcan'
    mhydra                 53248  0
    kvcommon               45056  1 mhydra

--------------------------------------------------------------------------------
Q8
    When I execute 'sudo make install' I get a warning like this in the output
    from make:

    ***********************************************************************
    WARNING: kvcommon is already loaded! It is advised to unplug Kvaser USB
             devices and call 'sudo make uninstall' before doing a new
             installation. Or do a reboot after installation.
    ***********************************************************************

A8
    Make sure you execute 'sudo make uninstall' before you install linuxcan.

--------------------------------------------------------------------------------
Q9
    I have unplugged all Kvaser USB interfaces but the module (mhydra, leaf or
    usbcanII) is still loaded?

A9
    Usually this is caused by a running application using CANlib. Make sure you
    close all applications that are using CANlib.

--------------------------------------------------------------------------------
Q10
    I get warnings like this in the kernel log:

    [ 266.950566] mhydra: disagrees about version of symbol vCanInit
    [ 266.950570] mhydra: Unknown symbol vCanInit (err -22)
    ...

A10
    A old version of kvcommon is already loaded. You probably reinstalled
    linuxcan and the drivers, but forgot to execute 'sudo make uninstall' before
    you executed 'sudo make install'.

--------------------------------------------------------------------------------
Q11
    I get warnings like this in the kernel log:

    [ 321.875210] kvcommon: disagrees about version of symbol module_layout

A11
    You probably built the modules against a different kernel version than what
    your system is running. Make sure your kernel source version is equal to
    what 'uname -r' reports.

--------------------------------------------------------------------------------
Q12
    I get errors when trying to load Kvaser modules:
    $ sudo modprobe leaf
    modprobe: ERROR: could not insert 'leaf': Operation not permitted

    And get warnings like this in the kernel log:
    [ 28.467002] Lockdown: modprobe: unsigned module loading is restricted; see man kernel_lockdown.7

A12
    Your kernel is probably configured to only allow loading of validly signed
    modules. There are at least two different kernel configurations causing this
    error, CONFIG_EFI_SECURE_BOOT_SIG_ENFORCE and CONFIG_MODULE_SIG_FORCE.

    Usually this is caused by CONFIG_EFI_SECURE_BOOT_SIG_ENFORCE, on some common
    Linux distributions such as Ubuntu and Fedora. If UEFI secure boot is
    enabled on your computer, the kernel will only load validly signed modules.
    To avoid the problem either disable secure boot in UEFI or sign the compiled
    module with a trusted certificate. More information can be found at
    https://www.rodsbooks.com/efi-bootloaders/secureboot.html
    How to apply this on Kvaser linuxcan modules can be found in the
    Developer Blog section at https://www.kvaser.com

    It is also possible to get this error if the kernel was built with
    CONFIG_MODULE_SIG_FORCE set. Then you will have to sign the modules with a
    trusted certificate. More information can be found at
    https://static.lwn.net/kerneldoc/admin-guide/module-signing.html

--------------------------------------------------------------------------------
Q13
    When and how are the modules loaded/unloaded?

A13
    For Kvaser USB interfaces the corresponding module is loaded when the
    interface is plugged in. This is handled by the kernel.
    To unload Kvaser USB modules use modprobe -r <module name>.

    For PCI(E) based interfaces and virtual devices, the modules needs to be
    loaded/unloaded manually with modprobe/modprobe -r.
    It is also possible to have the modules loaded at boot. To achieve this
    execute 'sudo make load' instead of 'sudo make install', when you install
    linuxcan. This will create a config file in /etc/modules-load.d, on the
    format kvaser-<module name>.conf.

--------------------------------------------------------------------------------
Q14
    I have compiled and installed everything but the Kvaser interface is not
    listed when I execute '/usr/doc/canlib/examples/listChannels'.

A14
    Make sure you have connected the Kvaser interface and verify that the
    SocketCAN module does not pick up any CAN interfaces by executing 'ip -d a'.
    Here is an example of what the output could look like:
    4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN group default qlen 10
        link/can  promiscuity 0
        can state STOPPED restart-ms 0
        kvaser_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
        clock 8000000

    This tells us that a SocketCAN module is loaded and not the linuxcan module.
    It is the result of a faulty blacklisting of the SocketCAN module. Try to
    reinstall linuxcan. If it still does not work, try rebooting the machine.

    In very rare cases the SocketCAN modules are built into the kernel,
    CONFIG_CAN_KVASER_USB=y or CONFIG_CAN_KVASER_PCI=y. If so is the case it is
    not possible to prevent the SocketCAN modules from being used. You will
    have to rebuild your kernel with these modules disabled (or as loadable
    modules).

--------------------------------------------------------------------------------
Q15
    What is SocketCAN and how can I use it?

A15
    SocketCAN is a set of open source CAN drivers and a networking stack, that
    is part of the Linux kernel. Many Kvaser CAN interfaces are supported by
    SocketCAN, including Leaf, USBcan and PCI cards. SocketCAN is not maintained
    or developed by Kvaser. To start using SocketCAN you will have to uninstall
    linuxcan by executing 'sudo make uninstall', since linuxcan will blacklist
    the SocketCAN modules. More information regarding SocketCAN can be found at
    https://elinux.org/CAN_Bus

--------------------------------------------------------------------------------
Q16
    When I execute 'make' I get warnings like these in the output from make:

    *****************************************************
    WARNING: Secure Boot is enabled on <hostname>!
             When Secure Boot is enabled, driver modules
             need to be signed with a valid private key
             in order to be loaded by the kernel.
    *****************************************************

    or

    *****************************************************
    WARNING: EFI is used on <hostname>!
             It looks like Secure Boot is enabled!
             When Secure Boot is enabled, driver modules
             need to be signed with a valid private key
             in order to be loaded by the kernel.
    *****************************************************

    or

    *****************************************************
    WARNING: EFI is used on <hostname>!
             It looks like Secure Boot is disabled.
             When Secure Boot is enabled, driver modules
             need to be signed with a valid private key
             in order to be loaded by the kernel.
    *****************************************************

    or

    *****************************************************
    WARNING: EFI is used on <hostname>!
             Not able to determine whether Secure Boot is
             enabled or disabled.
             When Secure Boot is enabled, driver modules
             need to be signed with a valid private key
             in order to be loaded by the kernel.
    *****************************************************


A16
    We try to determine if you are using EFI and if secure boot is enabled.
    See A12 in this FAQ for more details.

--------------------------------------------------------------------------------
Q17
    How do I update the firmware on my device?

A17
    It is possible to update the firmware of a device using kv_flash_prog,
    located in linuxcan/kvflash/canlib. Basic usage is covered bellow. For more
    details see linuxcan/kvflash/README.

    Build kv_flash_prog:
    $ cd linuxcan
    $ make kvflash

    Download the "Kvaser Firmware Update Tool" from the downloads section at
    https://www.kvaser.com. It contains the different firmware image
    files (*.img).
    unzip the downloaded FwUpdateTool_xx_yy.zip
    The images are sorted after platform. Locate the image matching your device
    (for instance for Kvaser PCIEcan 4xHS use pcie/pciecan_00683_fpgasys.img).
    kv_flash_prog expects the path to the firmware image. If no other option is
    passed, kv_flash_prog is started in interactive mode. It is possible to
    specify a device with the option --device-index=<index>. Or if you know the
    EAN and serial number of the device, you can use the option
    --device=<EAN>:<S/N>.

    Return an indexed list with supported and available Kvaser devices found on
    the PC:
    $ cd linuxcan/kvflash/canlib
    $ ./kv_flash_prog --list

    Interactive usage:
    $ cd linuxcan/kvflash/canlib
    $ ./kv_flash_prog FwUpdateTool_4_23/pcie/pciecan_00683_fpgasys.img

    Flash device with index 4:
    $ cd linuxcan/kvflash/canlib
    $ ./kv_flash_prog --device-index=4 FirmwareUpdateTool/4_23/pcie/pciecan_00683_fpgasys.img

    Flash device with EAN 73-30130-00683-6 an serial number 11055:
    $ cd linuxcan/kvflash/canlib
    $ ./kv_flash_prog --device=73-30130-00683-6:11055 FirmwareUpdateTool/4_23/pcie/pciecan_00683_fpgasys.img


    It is also possible to do a "dry run", where the image is only verified and
    not actually flashed:
    $ cd linuxcan/kvflash/canlib
    $ ./kv_flash_prog --dryrun --device-index=4 FwUpdateTool_4_23/pcie/pciecan_00683_fpgasys.img

    Note: Currently firmware upgrade is only supported in Linux for devices
          using the pciefd driver (see list in README). If you need to upgrade
          firmware of a different device, please use the
          "Kvaser Firmware Update Tool" in Windows.

--------------------------------------------------------------------------------
Q18
    Why can't CANlib find any devices after a system upgrade?

A18
    If the Linux kernel was upgraded, it is required to rebuild and reinstall
    the CANlib drivers. If the CANlib drivers are installed using DKMS, this is
    done automatically and won't be a problem.
