myorbit / pynq-mods

Examples on how to modify or enhance PYNQ
2 stars 0 forks source link

Compile CAN kernel module - building fails #1

Open basimon opened 5 years ago

basimon commented 5 years ago

If we follow the guide in the jupyter notebook (slcan_demo.ipynb) as indicated the build will fail. I have compiled the modules with the folowing steps:

Start from:

sudo -i

Starting with PYNQ v2.4 the kernel source is shipped as tar. So from the top directory extract the tar and cd into the directory:

cd /
tar xzf kernel.tgz
cd /usr/src/kernel

Then invoke the config commands:

make xilinx_zynq_defconfig
make menuconfig

The ARCH=arm is not needed since we are compiling on the arm platform. In menuconfig select the modules as described. BUT: make sure to select them as modules (with M, not Y). This makes sure the modules are compiled as loadable modules and not kernel built-in modules (a built-in module needs to be compiled with the kernel and we don't want to build the whole kernel).

grafik

Save and exit. You can check the build flag for the modules in the config:

cat .config | grep SLCAN

This should output:

CONFIG_CAN_SLCAN=m

This should read "m" not "y" so that it is built as loadable module.

Now, in order to prepare the headers and configuration files as well as build scripts to build the modules run:

make modules_prepare

Then build the modules with:

make SUBDIRS=drivers/net/can modules

And copy the build modules to the module directory:

cp drivers/net/can/*.ko /lib/modules/4.14.0-xilinx-v2018.3/kernel/net/can/

The rebuild the module dependency list:

depmod -ae

And load the module:

modprobe slcan
basimon commented 4 years ago

For the Ultra96 Board from AVNet (with PYNQ Ultra96 port) there are minor deviations:

The config has to be generated via (as referenced here: xilinx kernel build guide):

make xilinx_zynqmp_defconfig
make menuconfig

Now, before preparing the module build, we need to define the extraversion, so the module string matches (as described in the arch wiki):

uname -r

The string between the third kernel version number and -ARCH is our extraversion, e.g.: -xilinx-v2018.3

Now use modules_prepare like so:

make EXTRAVERSION=-xilinx-v2018.3 modules_prepare

The other steps should be the same.

basimon commented 4 years ago

In PYNQ version 2.5 this does not work anymore since the kernel tarball got stripped down (last known working PYNQ version is 2.3).

One work around is to manually copy the default configs from an older image.

The following files are needed:

braziper commented 2 years ago

Hello,

I followed your instruction for PYNQ-Z2 image V2.7 . Everything work perfectly before make SUBDIRS=drivers/net/can modules command. I receive error below:

root@pynq:/usr/src/kernel# make SUBDIRS=drivers/net/can modules make[1]: *** No rule to make target 'crypto/crypto_engine.o', needed by '__build'. Stop. make: *** [Makefile:1652: crypto] Error 2

I added manually crypto_engine.c and internal.h files to /kernel/crypto/ directory.

when I run the make command I receive following errors:

root@pynq:/usr/src/kernel# make SUBDIRS=drivers/net/can modules
  CC [M]  crypto/crypto_engine.o
In file included from crypto/crypto_engine.c:15:
crypto/internal.h:33:2: error: redeclaration of enumerator ‘CRYPTOA_UNSPEC’
   33 |  CRYPTOA_UNSPEC,
      |  ^~~~~~~~~~~~~~
In file included from ./include/crypto/engine.h:10,
                 from crypto/crypto_engine.c:13:
./include/linux/crypto.h:800:2: note: previous definition of ‘CRYPTOA_UNSPEC’ was here
  800 |  CRYPTOA_UNSPEC,
      |  ^~~~~~~~~~~~~~
In file included from crypto/crypto_engine.c:15:
crypto/internal.h:34:2: error: redeclaration of enumerator ‘CRYPTOA_ALG’
   34 |  CRYPTOA_ALG,
      |  ^~~~~~~~~~~
In file included from ./include/crypto/engine.h:10,
                 from crypto/crypto_engine.c:13:
./include/linux/crypto.h:801:2: note: previous definition of ‘CRYPTOA_ALG’ was here
  801 |  CRYPTOA_ALG,
      |  ^~~~~~~~~~~
In file included from crypto/crypto_engine.c:15:
crypto/internal.h:35:2: error: redeclaration of enumerator ‘CRYPTOA_TYPE’
   35 |  CRYPTOA_TYPE,
      |  ^~~~~~~~~~~~
In file included from ./include/crypto/engine.h:10,
                 from crypto/crypto_engine.c:13:
./include/linux/crypto.h:802:2: note: previous definition of ‘CRYPTOA_TYPE’ was here
  802 |  CRYPTOA_TYPE,
      |  ^~~~~~~~~~~~
In file included from crypto/crypto_engine.c:15:
crypto/internal.h:36:2: error: redeclaration of enumerator ‘__CRYPTOA_MAX’
   36 |  __CRYPTOA_MAX,
      |  ^~~~~~~~~~~~~
In file included from ./include/crypto/engine.h:10,
                 from crypto/crypto_engine.c:13:
./include/linux/crypto.h:804:2: note: previous definition of ‘__CRYPTOA_MAX’ was here
  804 |  __CRYPTOA_MAX,
      |  ^~~~~~~~~~~~~
In file included from crypto/crypto_engine.c:15:
crypto/internal.h:153:20: error: redefinition of ‘crypto_yield’
  153 | static inline void crypto_yield(u32 flags)
      |                    ^~~~~~~~~~~~
In file included from ./include/crypto/engine.h:14,
                 from crypto/crypto_engine.c:13:
./include/crypto/algapi.h:410:20: note: previous definition of ‘crypto_yield’ was here
  410 | static inline void crypto_yield(u32 flags)
      |                    ^~~~~~~~~~~~
crypto/crypto_engine.c: In function ‘crypto_finalize_request’:
crypto/crypto_engine.c:38:13: error: ‘struct crypto_engine’ has no member named ‘retry_support’
   38 |  if (!engine->retry_support) {
      |             ^~
crypto/crypto_engine.c:47:28: error: ‘struct crypto_engine’ has no member named ‘retry_support’
   47 |  if (finalize_req || engine->retry_support) {
      |                            ^~
crypto/crypto_engine.c: In function ‘crypto_pump_requests’:
crypto/crypto_engine.c:82:13: error: ‘struct crypto_engine’ has no member named ‘retry_support’
   82 |  if (!engine->retry_support && engine->cur_req)
      |             ^~
crypto/crypto_engine.c:128:13: error: ‘struct crypto_engine’ has no member named ‘retry_support’
  128 |  if (!engine->retry_support)
      |             ^~
crypto/crypto_engine.c:175:14: error: ‘struct crypto_engine’ has no member named ‘retry_support’
  175 |   if (!engine->retry_support ||
      |              ^~
crypto/crypto_engine.c:200:3: error: implicit declaration of function ‘crypto_enqueue_request_head’; did you mean ‘crypto_enqueue_request’? [-Werror=implicit-function-declaration]
  200 |   crypto_enqueue_request_head(&engine->queue, async_req);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |   crypto_enqueue_request
crypto/crypto_engine.c:220:12: error: ‘struct crypto_engine’ has no member named ‘retry_support’
  220 |  if (engine->retry_support) {
      |            ^~
crypto/crypto_engine.c:233:12: error: ‘struct crypto_engine’ has no member named ‘do_batch_requests’
  233 |  if (engine->do_batch_requests) {
      |            ^~
crypto/crypto_engine.c:234:15: error: ‘struct crypto_engine’ has no member named ‘do_batch_requests’
  234 |   ret = engine->do_batch_requests(engine);
      |               ^~
crypto/crypto_engine.c: In function ‘crypto_engine_alloc_init_and_set’:
crypto/crypto_engine.c:500:8: error: ‘struct crypto_engine’ has no member named ‘retry_support’
  500 |  engine->retry_support = retry_support;
      |        ^~
crypto/crypto_engine.c:506:8: error: ‘struct crypto_engine’ has no member named ‘do_batch_requests’
  506 |  engine->do_batch_requests = retry_support ? cbk_do_batch : NULL;
      |        ^~
crypto/crypto_engine.c:523:3: error: implicit declaration of function ‘sched_set_fifo’ [-Werror=implicit-function-declaration]
  523 |   sched_set_fifo(engine->kworker->task);
      |   ^~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[1]: *** [scripts/Makefile.build:266: crypto/crypto_engine.o] Error 1
make: *** [Makefile:1652: crypto] Error 2

I do appreciate if you can help me to solve this problem and access CAN in my PYNQ-Z2. Regards, BPe

basimon commented 2 years ago

Sorry for the late reply. As of now, I think the way to go is compiling your own SD card image for the PYNQ board incorporating the missing modules. You may also try an old image, build the module from there and copy the *.ko files over to your new install. I haven't confirmed this works yet though.

braziper commented 1 year ago

I just downloaded an old version of PYNQ image and followed your instruction. It worked. Thank you.