Armbian on Rock64でドライバを作るときにKernelHeaderをaptで入れたのに使えない件


経緯

とあるデバイスのドライバを入れたいのに、dkmsするとエラーを吐いてしまう。
ログを見たらカーネルヘッダのファイルが不足している模様。

結果

  • aptでカーネルヘッダ入れたときのコンパイルが失敗している
  • make scriptsclassmap.hが無いと怒られる
  • scriptsのMakefileの
    subdir-$(CONFIGS_SECURITY_SELINUX) += selinuxをコメントアウト
  • めでたしめでたし?

ソース

環境

  • ROCK64 4GB
  • Linux rock64 4.4.180-rockchip64 #1 SMP Thu Jun 6 08:08:17 CEST 2019 aarch64 aarch64 aarch64 GNU/Linux

したこと

いつもの手順

$ sudo apt -y install dkms

$ wget https://apt.armbian.com/pool/main/l/linux-4.4.180-rockchip64/linux-headers-rockchip64_5.88_arm64.deb
$ sudo apt install ./linux-headers-rockchip64_5.88_arm64.deb
...
Unpacking linux-headers-rockchip64 (5.88) ...
Setting up linux-headers-rockchip64 (5.88) ...
Compiling headers - please wait ...

$ 

問題の箇所

  • カーネルヘッダのファイルが不足している
$ sudo dkms install px4_drv/0.2.1

Creating symlink /var/lib/dkms/px4_drv/0.2.1/source ->
                 /usr/src/px4_drv-0.2.1

DKMS: add completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
cd ./driver; make KVER=4.4.180-rockchip64 px4_drv.ko....(bad exit status: 2)
Error! Bad return status for module build on kernel: 4.4.180-rockchip64 (aarch64)
Consult /var/lib/dkms/px4_drv/0.2.1/build/make.log for more information.
/var/lib/dkms/px4_drv/0.2.1/build/make.log
DKMS make.log for px4_drv-0.2.1 for kernel 4.4.180-rockchip64 (aarch64)
Sun Jun 23 12:53:32 JST 2019
'revision.h' was updated.
make[1]: Entering directory '/usr/src/linux-headers-4.4.180-rockchip64'
  CC [M]  /var/lib/dkms/px4_drv/0.2.1/build/driver/px4.o
/bin/sh: 1: ./scripts/recordmcount: not found
scripts/Makefile.build:277: recipe for target '/var/lib/dkms/px4_drv/0.2.1/build/driver/px4.o' failed
make[2]: *** [/var/lib/dkms/px4_drv/0.2.1/build/driver/px4.o] Error 127
make[2]: *** Deleting file '/var/lib/dkms/px4_drv/0.2.1/build/driver/px4.o'
Makefile:1485: recipe for target '_module_/var/lib/dkms/px4_drv/0.2.1/build/driver' failed
make[1]: *** [_module_/var/lib/dkms/px4_drv/0.2.1/build/driver] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.4.180-rockchip64'
Makefile:34: recipe for target 'px4_drv.ko' failed
make: *** [px4_drv.ko] Error 2

/usr/src/linux-headers-4.4.180-rockchip64/scripts/recordmcountが無いらしい。

  • ソースファイルがあるけどバイナリがないっぽい
$ pwd
/usr/src/linux-headers-4.4.180-rockchip64/scripts

$ ls recordmcount*
recordmcount.c  recordmcount.h  recordmcount.pl
  • もう一回ここだけmakeしてみるがclassmap.hとは…
$ pwd
/usr/src/linux-headers-4.4.180-rockchip64

$ sudo make scripts
  CHK     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/selinux/genheaders/genheaders
scripts/selinux/genheaders/genheaders.c:13:10: fatal error: classmap.h: No such file or directory
 #include "classmap.h"
          ^~~~~~~~~~~~
compilation terminated.
scripts/Makefile.host:91: recipe for target 'scripts/selinux/genheaders/genheaders' failed
make[3]: *** [scripts/selinux/genheaders/genheaders] Error 1
scripts/Makefile.build:484: recipe for target 'scripts/selinux/genheaders' failed
make[2]: *** [scripts/selinux/genheaders] Error 2
scripts/Makefile.build:484: recipe for target 'scripts/selinux' failed
make[1]: *** [scripts/selinux] Error 2
Makefile:585: recipe for target 'scripts' failed
make: *** [scripts] Error 2

$ sudo find / -name classmap.h
find: '/run/user/1000/gvfs': Permission denied
$ 

ここで必死のgoogling

解決策

/usr/src/linux-headers-4.4.180-rockchip64/scripts$ diff -u Makefile.20190623 Makefile
--- Makefile.20190623   2019-06-23 13:29:18.248584138 +0900
+++ Makefile    2019-06-23 13:29:34.232157372 +0900
@@ -42,7 +42,7 @@

 subdir-$(CONFIG_MODVERSIONS) += genksyms
 subdir-y                     += mod
-subdir-$(CONFIG_SECURITY_SELINUX) += selinux
+# subdir-$(CONFIG_SECURITY_SELINUX) += selinux
 subdir-$(CONFIG_DTC)         += dtc
 subdir-$(CONFIG_GDB_SCRIPTS) += gdb

わぁい

$ sudo make scripts
  CHK     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/recordmcount
  HOSTCC  scripts/resource_tool
  HOSTCC  scripts/mkkrnlimg
  HOSTCC  scripts/sortextable
  HOSTCC  scripts/asn1_compiler
  HOSTCC  scripts/extract-cert

$ sudo dkms install px4_drv/0.2.1
...
DKMS: build completed.
...
depmod...

DKMS: install completed.