Nexus 5を有線LAN接続するため、USB-Ethernet LANアダプタを購入。

接続しただけだと使えなかったためLinux向けのドライバソースコードからビルドしてみる。

現状

lsusbでは認識されるものの、nmcliでは認識しない

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 0b95:7720 ASIX Electronics Corp. AX88772
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ nmcli device
DEVICE   TYPE      STATE        CONNECTION
wlan0    wifi      connected    xxxxxxxxxx
ril_0    gsm       unavailable  --
ip6tnl0  ip6tnl    unmanaged    --
sit0     iptunnel  unmanaged    --
lo       loopback  unmanaged    --

手順

$はホストPC
#はDocker環境
%はNexus 5のshellを表す

AX88772C_772B_772A_760_772_178_LINUX_DRIVER_v4.13.0_Source.tar.bz2をダウンロード
チップセット名が同じならある程度互換性があるらしい
https://oss.sony.net/Products/Linux/B2B/PXW-X500.html

環境構築

$ docker run -it --name hoge kajindowsxp/ubp-build-hammerhead

zipを転送

$ docker cp AX88772C_772B_772A_760_772_178_LINUX_DRIVER_v4.13.0_Source.tar.bz2 hoge:/tmp

展開

# cd /tmp
# tar xvf AX88772C_772B_772A_760_772_178_LINUX_DRIVER_v4.13.0_Source.tar.bz2
# cd AX88772C_772B_772A_760_772_178_LINUX_DRIVER_v4.13.0_Source

Makefileを編集する
KDIRDESTのところを変更する
Before <> After

CURRENT = $(shell uname -r)
TARGET  = asix
OBJS    = asix.o
MDIR    = drivers/net/usb
KDIR    = /lib/modules/$(CURRENT)/build
SUBLEVEL= $(shell uname -r | cut -d '.' -f 3 | cut -d '.' -f 1 | cut -d '-' -f 1 | cut -d '_' -f 1)

ifneq (,$(filter $(SUBLEVEL),14 15 16 17 18 19 20 21))
MDIR = drivers/usb/net
endif

EXTRA_CFLAGS = -DEXPORT_SYMTAB
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)

obj-m      := $(TARGET).o

default:
        make -C $(KDIR) SUBDIRS=$(PWD) modules

$(TARGET).o: $(OBJS)
        $(LD) $(LD_RFLAG) -r -o $@ $(OBJS)

install:
        su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"

clean:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean

.PHONY: modules clean

-include $(KDIR)/Rules.make
CURRENT = $(shell uname -r)
TARGET  = asix
OBJS    = asix.o
MDIR    = drivers/net/usb
KDIR    = /work/ubp-5.1/kernel/lge/hammerhead/
SUBLEVEL= $(shell uname -r | cut -d '.' -f 3 | cut -d '.' -f 1 | cut -d '-' -f 1 | cut -d '_' -f 1)

ifneq (,$(filter $(SUBLEVEL),14 15 16 17 18 19 20 21))
MDIR = drivers/usb/net
endif

EXTRA_CFLAGS = -DEXPORT_SYMTAB
PWD = $(shell pwd)
DEST = ./

obj-m      := $(TARGET).o

default:
        make -C $(KDIR) SUBDIRS=$(PWD) modules

$(TARGET).o: $(OBJS)
        $(LD) $(LD_RFLAG) -r -o $@ $(OBJS)

install:
        su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"

clean:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean

.PHONY: modules clean

-include $(KDIR)/Rules.make

環境変数を設定

# export ARCH=arm
# export CROSS_COMPILE="/work/ubp-5.1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-"

必要に応じてvarmagicに-dirtyをつける

echo " " >> /work/ubp-5.1/kernel/lge/hammerhead/arch/arm/configs/cyanogenmod_hammerhead_defconfig

事前準備

# make -C /work/ubp-5.1/kernel/lge/hammerhead/ cyanogenmod_hammerhead_defconfig
# make -C /work/ubp-5.1/kernel/lge/hammerhead/ oldconfig
# make -C /work/ubp-5.1/kernel/lge/hammerhead/ prepare
# make -C /work/ubp-5.1/kernel/lge/hammerhead/ modules

ドライバビルド

# make

ホストに成果物をコピー

$ docker cp hoge:/tmp/AX88772C_772B_772A_760_772_178_LINUX_DRIVER_v4.13.0_Source/asix.ko ./

成果物をNexus 5にコピー

$ scp asix.ko [email protected]:/tmp

インストール

% sudo insmod /tmp/asix.ko

結果

enxc436c0b3523cとして認識できるようになった。

$ nmcli device
DEVICE           TYPE      STATE        CONNECTION
enxc436c0b3523c  ethernet  connected    Wired connection 1
wlan0            wifi      connected    xxxxxxxxxx
ril_0            gsm       unavailable  --
ip6tnl0          ip6tnl    unmanaged    --
sit0             iptunnel  unmanaged    --
lo               loopback  unmanaged    --

番外編 どうやってやり方を導いたかの自分用記録

ソースコードのトップディレクトリ(ubp-5.1)でmkaコマンドを実行すると、config設定やカーネルのビルド、システムのビルドをすべて一発でやってくれる。
しかし、今回はカーネルモジュールのビルドがしたいので、カーネルのビルドするコマンドは何かをまず調べた。

いろいろ弄っていると、makeでdefconfigをするコマンドを知ることができた。

$ make clean
$ mka 2> /dev/null | grep -P '^make'
make: Entering directory '/work/ubp-5.1'
make  -C kernel/lge/hammerhead O=/work/ubp-5.1/out/target/product/hammerhead/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE=" /work/ubp-5.1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-" VARIANT_DEFCONFIG= SELINUX_DEFCONFIG= cyanogenmod_hammerhead_defconfig
...

3行目のコマンドがそれっぽい。
なので不要なオプションを削除して確かめてみる。

$ cd kernel/lge/hammerhead/
$ make ARCH=arm CROSS_COMPILE="/work/ubp-5.1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-" cyanogenmod_hammerhead_defconfig
. . .省略
#
# configuration written to .config
#

正常に.configが作成できたようなので、このままカーネルモジュールをビルドしてみる
いろいろオプション(環境変数)が付いているが、基本的にはどのカーネルもmake modulesはカーネルモジュールをビルドするオプションである。

$ make ARCH=arm CROSS_COMPILE="/work/ubp-5.1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-" modules
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.
  CC      kernel/bounds.s
  GEN     include/generated/bounds.h
  CC      arch/arm/kernel/asm-offsets.s
  GEN     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/util.o
  HOSTLD  scripts/dtc/dtc
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/selinux/genheaders/genheaders
  HOSTCC  scripts/selinux/mdp/mdp
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/bin2c
  HOSTCC  scripts/recordmcount
  CC [M]  drivers/net/wireless/bcmdhd/aiutils.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmsdh_sdmmc_linux.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_linux.o
  CC [M]  drivers/net/wireless/bcmdhd/siutils.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmutils.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_linux_sched.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_pno.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_sdio.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmwifi_channels.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmevent.o
  CC [M]  drivers/net/wireless/bcmdhd/hndpmu.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmsdh.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_cdc.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmsdh_linux.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_common.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_wlfc.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_ip.o
  CC [M]  drivers/net/wireless/bcmdhd/linux_osl.o
  CC [M]  drivers/net/wireless/bcmdhd/bcmsdh_sdmmc.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_custom_gpio.o
  CC [M]  drivers/net/wireless/bcmdhd/sbutils.o
  CC [M]  drivers/net/wireless/bcmdhd/wldev_common.o
  CC [M]  drivers/net/wireless/bcmdhd/wl_android.o
  CC [M]  drivers/net/wireless/bcmdhd/wl_cfg80211.o
  CC [M]  drivers/net/wireless/bcmdhd/wl_cfgp2p.o
  CC [M]  drivers/net/wireless/bcmdhd/wl_linux_mon.o
  CC [M]  drivers/net/wireless/bcmdhd/dhd_cfg80211.o
  CC [M]  drivers/net/wireless/bcmdhd/wl_cfgvendor.o
  LD [M]  drivers/net/wireless/bcmdhd/bcmdhd.o
  CC [M]  drivers/scsi/scsi_wait_scan.o
  Building modules, stage 2.
  MODPOST 2 modules
  CC      drivers/net/wireless/bcmdhd/bcmdhd.mod.o
  LD [M]  drivers/net/wireless/bcmdhd/bcmdhd.ko
  CC      drivers/scsi/scsi_wait_scan.mod.o
  LD [M]  drivers/scsi/scsi_wait_scan.ko

#### make completed successfully (19 seconds) ####

参考