Linuxカーネルデバッグ その1(概要)
BeagleBoneBlackの魅力として、JTAG用のコネクタが実装されていることがあげられる。これを使ってLinuxカーネルのデバッグを行う。
PCとの接続は以下のとおり。
エミュレータは簡単に手に入って安いTMS320-XDS100-V3を使用する。
(マルツで1万円程度で購入可能 https://www.marutsu.co.jp/pc/i/27247491/)
BeagleBoneBlackのJTAGコネクタのピッチは1.27mmなので直接エミュレータに接続できない。そのため、冶具を使って接続する。
BeagleBoneBlackで動作させるターゲットOSはdebian,
ホストPC上で使用するデバッグ環境はTIのCodeComposerStudio v8.1.0(CCS)。
BeagleBone用ケース
秋月で売っていたので、買ってみる。
BeagleBoneBlack用ケース: マイコン関連 秋月電子通商 電子部品 ネット通販
全体はこんな感じ。
ネジレスではめ込む。カバーは一度つけると少しはずしにくい。
はずすコツは、カバーの側面を抑えること。
裏側はネジなどに掛けられるようになっている。
USB側。
電源側。
カバーはちょっと高さがあるので、低いケープならばつけたままカバーを閉められると思われる。
ubuntuカーネルのリビルド
カーネルのリビルドをしてみる。手順は、
https://elinux.org/BeagleBoardUbuntu
を参考にする。
1.適当にディレクトリ作成
mkdir bbb
2. cloneする
git clone https://github.com/RobertCNelson/ti-linux-kernel-dev.git
3. buildする
cd ti-linux-kernel-dev/
git checkout origin/ti-linux-4.14.y -b tmp
./build_kernel.sh
ツールのダウンロード後、KERNELディレクトリにソースがクローンされてビルドが始まる。
途中でmenuconfigの画面になるが、Esc Escで終了する。
Script Complete
eewiki.net: [user@localhost:~$ export kernel_version=4.14.37-ti-r46]
みたいなメッセージが出てきて完了する。deployフォルダにイメージができている。
4.14.37-ti-r46-dtbs.tar.gz
4.14.37-ti-r46-modules.tar.gz
4.14.37-ti-r46.zImage
config-4.14.37-ti-r46
disk
4.インストールする
シェルスクリプトを実行する。
sudo ./tools/install_kernel.sh
初回時は、「system.shの設定がねーよ」、といってエラーになる。
-----------------------------
lsblk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 14.9G 0 disk
└─sdb1 8:17 1 14.9G 0 part /media/ubuntu/rootfs
sda 8:0 0 931.5G 0 disk
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda1 8:1 0 929.6G 0 part /
-----------------------------
ERROR: MMC is not defined in system.sh
system.shの設定をPCに合わせて修正する。変更したのは、
CORES=4
↓
CORES=2
MMC=/dev/sde
↓
MMC=/dev/sdb
一応、全部貼り付けておく。
#!/bin/sh
#copy as "system.sh" and tweak for your systemARCH=$(uname -m)
#ARM Native gcc compiler (running gcc on arm target)
if [ "x${ARCH}" = "xarmv7l" ] ; then
#Native arm gcc compiler
CC=
fi###REQUIRED:
#ARM GCC CROSS Compiler:
#if CC is not set, a known working linaro based gcc compiler will be downloaded and utilized.
#CC=<enter full path>/bin/arm-none-eabi-
#CC=<enter full path>/bin/arm-linux-gnueabi-
#CC=<enter full path>/bin/arm-linux-gnueabihf-###OPTIONAL:
###OPTIONAL: CORES: number of CPU cores to use for compilation
#CORES=4
CORES=2###OPTIONAL: LINUX_GIT: specify location of locally cloned git tree.
#
#LINUX_GIT=/home/user/linux-stable/###OPTIONAL: MMC: (REQUIRED FOR RUNNING: tools/install_kernel.sh)
#Note: This operates on raw disks, NOT PARTITIONS..
#
#WRONG: MMC=/dev/mmcblk0p1
#CORRECT: MMC=/dev/mmcblk0
#
#WRONG: MMC=/dev/sde1
#CORRECT: MMC=/dev/sde
#
#MMC=/dev/sde
MMC=/dev/sdb###ADVANCED: RUN_BISECT: used with ./scripts/bisect.sh
#
#RUN_BISECT=1###ADVANCED: AUTO_BUILD: Easier integration with Jenkins/Buildbot/etc..
#
#AUTO_BUILD=1
system.shを設定後、改めてシェルスクリプトを実行する。
sudo ./tools/install_kernel.sh
ごにょごにょされる。
I see...
fdisk -l:
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram3: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram4: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram5: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram6: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram7: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram8: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram9: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram10: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram11: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram12: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram13: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram14: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/ram15: 64 MiB, 67108864 bytes, 131072 sectors
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk /dev/sdb: 14.9 GiB, 15980298240 bytes, 31211520 sectorslsblk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 14.9G 0 disk
└─sdb1 8:17 1 14.9G 0 part /media/ubuntu/rootfs
sda 8:0 0 931.5G 0 disk
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda1 8:1 0 929.6G 0 part /
-----------------------------
Are you 100% sure, on selecting [/dev/sdb] (y/n)? yDebug: Existing Partition on drive:
-----------------------------
Disk /dev/sdb: 14.9 GiB, 15980298240 bytes, 31211520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb73b7f50Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 8192 31211519 31203328 14.9G 83 LinuxUnmounting Partitions
-----------------------------
Starting Partition Search
-----------------------------
Trying: [/dev/sdb1]
Partition: [/dev/sdb1] trying: [vfat], [ext4], [btrfs]
Partition: [extX]
found: /boot/uEnv.txt
info: 4.14.24-ti-r37 was installed
Installing 4.14.37-ti-r46 to /dev/sdb1
'/home/ubuntu/bbb/ti-linux-kernel-dev/deploy/4.14.37-ti-r46.zImage' -> '/home/ubuntu/bbb/ti-linux-kernel-dev/deploy/disk/boot/vmlinuz-4.14.37-ti-r46'
Installing 4.14.37-ti-r46-dtbs.tar.gz to /dev/sdb1
info: /boot/uEnv.txt: uname_r=4.14.37-ti-r46
found: /etc/fstab
Installing 4.14.37-ti-r46-modules.tar.gz to /dev/sdb1
'/home/ubuntu/bbb/ti-linux-kernel-dev/deploy/config-4.14.37-ti-r46' -> '/home/ubuntu/bbb/ti-linux-kernel-dev/deploy/disk/boot/config-4.14.37-ti-r46'
info: [4.14.37-ti-r46] now installed...
/home/ubuntu/bbb/ti-linux-kernel-dev
-----------------------------
This script has finished...
For verification, always test this media with your end device...
SDカードのカーネルイメージが更新される。SDブートして、unameでタイムスタンプが更新されていればOK。
ubuntu環境
Linux実験環境としてUbuntuを使うことにする。環境構築に使用するホストPC側はUbuntu 16.04。
まずは、SDカードを作成する。以下のページを参考にする。
BeagleBoardUbuntu - eLinux.org
ダウンロードして、解凍する。
wget https://rcn-ee.com/rootfs/2018-03-09/elinux/ubuntu-16.04.4-console-armhf-2018-03-09.tar.xz
tar ubuntu-16.04.4-console-armhf-2018-03-09.tar.xz
SDカードリーダにSDを挿入して、ホストPCと接続する。
ホストPCからSDカードは/dev/sdbとして認識された。
解凍してできたフォルダの中に、スクリプトが入っている。それを実行する。
cd ubuntu-16.04.4-console-armhf-2018-03-09
sudo ./setup_sdcard.sh --mmc /dev/sdb --dtb beaglebone
しばらくすると、
setup_sdcard.sh script complete
と表示され、処理が完了する。
作成されたSDカードをBeagleBoneBlackに挿入し、電源を投入するとUbuntuが起動する。
起動時に、ネットワークをチェックするので、スタンドアロンで動作させる場合にはネットワークを無効にする。
sudo systemctl disable networking.service
なお、LinuxPCでシリアルコンソールを接続する場合にはscreenコマンドを使う。
sudo screen /dev/ttyUSB0 115200
/dev/ttyUSB0がデバイスファイル、115200がボーレート
カーネルパラメータ
カーネルパラメータをカーネルコンフィグで指定していたのに、デバイスツリーに追加したところ、そちらが優先された。
調べると、どうもそうらしい。
A Tutorial on the Device Tree (Zynq) -- Part II | xillybus.com
here are three sources for the kernel boot command line in general:
- Those given as CONFIG_CMDLINE in the kernel configuration
- Those passed on by the boot loader (typically U-boot on ARM processors, LILO or GRUB on x86)
- Those included in the device tree, under chosen/bootargs (see listing above)
Which one is used depends on kernel configuration parameters. In Xillinux, the device tree’s chosen/bootargs is used.
知ってるようで知らないデバイスツリー。
このサイトも詳しい解説がある
Device Tree Usage - eLinux.org