LoginSignup
6
5

More than 3 years have passed since last update.

Raspberry pi zeroでカーネルモジュールコンパイル

Last updated at Posted at 2019-11-10

Raspberry pi zeroでカーネルモジュールコンパイルを行った時にエラーが沢山出て困った記録です。

参照

カーネルアプリコンパイルについては、こちらの記事を参照させていただきました。

カーネルモジュールは、組み込みLinuxデバイスドライバの作り方 (1)に記載のtest.cとMakefileをそのまま使っています。

Raspberry Pi zeroの環境

環境は以前書いたこちらの記事を参照ください。

Raspberry pi Zero で設定したこと

これにプラスして、

sudo apt install raspberrypi-kernel-headers

を行いました。

必要なインストール

あれこれ調べた結果、以下をインストールすることでコンパイルが通りました。

sudo apt install git bison flex libssl-dev libncurses5-dev

遭遇したエラーメッセージ

途中で、linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720 なるカーネルをインストールしたりしたので、あまり参考にはならないかもしれませんが、以下記録を残します。

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.
Makefile:590: include/config/auto.conf: No such file or directory
make[1]: *** [Makefile:641: include/config/auto.conf] Error 1
make[1]: Leaving directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'
make: *** [Makefile:6: all] Error 2
make -C /lib/modules/4.19.75+/build M=/home/pi/test1 modules
make[1]: Entering directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'
  CC [M]  /home/pi/test1/test1.o
In file included from ./include/asm-generic/int-ll64.h:11,
                 from ./arch/arm/include/uapi/asm/types.h:5,
                 from ./include/uapi/linux/types.h:5,
                 from ./include/linux/types.h:6,
                 from ./include/linux/list.h:5,
                 from ./include/linux/module.h:9,
                 from /home/pi/test1.c:1:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: No such file or directory
 #include <asm/bitsperlong.h>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:310: /home/pi/test1.o] Error 1
make[1]: *** [Makefile:1519: _module_/home/pi/test1] Error 2
make[1]: Leaving directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'
make: *** [Makefile:6: all] Error 2
make -C /lib/modules/4.19.75+/build M=/home/pi/test1 modules
make[1]: Entering directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'
  CC [M]  /home/pi/test1.o
/bin/sh: 1: ./scripts/recordmcount: not found
make[2]: *** [scripts/Makefile.build:310: /home/pi/test1.o] Error 127
make[2]: *** Deleting file '/home/pi/test1.o'
make[1]: *** [Makefile:1519: _module_/home/pi/test1] Error 2
make[1]: Leaving directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'
make: *** [Makefile:6: all] Error 2
make -C /lib/modules/4.19.75+/build M=/home/pi/test1 modules
make[1]: Entering directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'
  CC [M]  /home/pi/test1.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "__sanitizer_cov_trace_pc" [/home/pi/test1.ko] undefined!
  CC      /home/pi/test1.mod.o
  LD [M]  /home/pi/test1.ko
make[1]: Leaving directory '/home/pi/linux-6d8bf28fa4b1ca0a35c0cd1dcb267fb216daf720'

コマンド記録

カーネルをコンパイルし、実行するためのコマンドを記録しておきます。

// カーネルのバージョン確認
> pi@raspberrypi:~ $ uname -r
> 4.19.75+
// その時点でロードされているモジュールを一覧表示します。
> lsmod
// 稼動中のカーネルに対してロード可能なモジュールをインストールします。
> sudo insmod xxxx.ko
// 稼動中のカーネルからモジュールをアンロードします。
> rmmod
// カーネルが出力したメッセージを表示します。
> dmesg | tail
> sudo make oldconfig
> sudo make prepare
> sudo make modules-prepare
> make menuconfig
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5