Raspbian のアップデート

Raspbian jessieをインストールしたときのカーネルのバージョンは 4.1.7-v7+ でした。

以前、Raspbian wheezyを使っていたときに、sudo apt-get update; sudo apt-get upgrade としたらカーネルもバージョンアップされたのですが、起動できなくなってしまったことがありました。
どうやら正しくはrpi-updateコマンドを使うようです。

$ sudo rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10206  100 10206    0     0  20977      0 --:--:-- --:--:-- --:--:-- 20956
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 4.1.7-v7+
#############################################################
This update bumps to rpi-4.1.y linux tree
Be aware there could be compatibility issues with some drivers
Discussion here:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=113753
##############################################################
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168    0   168    0     0    212      0 --:--:-- --:--:-- --:--:--   212
100 48.2M  100 48.2M    0     0   567k      0  0:01:27  0:01:27 --:--:--  498k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.1.10-v7+
 *** depmod 4.1.10+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to 260bc9c7589b3359485fc02fed8f56d4c5eaad9a
 *** A reboot is needed to activate the new firmware
pi@raspberrypi:~$ 

rebootしてからカーネルバージョンを確認すると、4.1.10 に上がっていました。

$ cat /proc/version
Linux version 4.1.10-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #821 SMP PREEMPT Sat Oct 10 00:16:28 BST 2015

Raspberry Pi 2でWiFiドングル PLANEX GW-450Dを使う

Raspbian jessi, kernel 4.1.10-v7+ を使っています。

neuralassemblyのメモ: Raspberry Pi + kernel 4.1 / 4.4 / 4.9 / 4.14 系列で5GHz対応WifiドングルGW-450D/GW-450D2/Archer T1U/WI-U2-433DMを動かした を参考にさせていただき、同じソースコード、同じパッチを使いました。
ただしセルフビルドでなくクロスビルドのために以下の変更をしました。

$ diff -u Makefile.org Makefile
--- Makefile.org	2013-09-16 23:03:08.000000000 +0900
+++ Makefile	2015-10-18 16:59:23.386655463 +0900
@@ -32,7 +32,7 @@
 RTMP_SRC_DIR = $(RT28xx_DIR)/RT$(MODULE)
 
 #PLATFORM: Target platform
-PLATFORM = PC
+#PLATFORM = PC
 #PLATFORM = 5VT
 #PLATFORM = IKANOS_V160
 #PLATFORM = IKANOS_V180
@@ -68,6 +68,7 @@
 #PLATFORM = RALINK_3352
 #PLATFORM = UBICOM_IPX8
 #PLATFORM = INTELP6
+PLATFORM = RASPBERRY_PI
 
 #APSOC
 ifeq ($(MODULE),3050)
@@ -105,6 +106,13 @@
 export MODULE
 endif
 
+ifeq ($(PLATFORM),RASPBERRY_PI)
+LINUX_SRC = $(HOME)/work/raspi/linux
+ARCH = arm
+export ARCH
+CROSS_COMPILE = arm-linux-gnueabihf-
+endif
+
 ifeq ($(PLATFORM),5VT)
 LINUX_SRC = /home/ralink-2860-sdk-5vt-distribution/linux-2.6.17
 CROSS_COMPILE = /opt/crosstool/uClibc_v5te_le_gcc_4_1_1/bin/arm-linux-
$ diff -u os/linux/config.mk.org os/linux/config.mk
--- os/linux/config.mk.org	2015-10-18 15:20:30.000000000 +0900
+++ os/linux/config.mk	2015-10-18 17:08:20.186201077 +0900
@@ -941,6 +941,10 @@
 WFLAGS += -DST
 endif
 
+ifeq ($(PLATFORM),RASPBERRY_PI)
+EXTRA_CFLAGS := $(WFLAGS)
+endif
+
 #kernel build options for 2.4
 # move to Makefile outside LINUX_SRC := /opt/star/kernel/linux-2.4.27-star

できたos/linux/mt7650u_sta.koをRaspberry Pi 2 の/lib/modules/4.1.10-v7+/ にコピーし、

$ sudo depmod

を実行して、モジュールの依存関係を更新します。
また、設定ファイルもRaspberry Pi 2にコピーします。

$ sudo mkdir -p /etc/Wireless/RT2870STA
$ sudo cp RT2870STA.dat /etc/Wireless/RT2870STA/RT2870STA.dat

/etc/network/interface に以下の行を追加します。

auto ra0
allow-hotplug ra0
iface ra0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

WiFiアクセスポイントの登録はRaspberry Pi 2でWiFiを使う - 組み込みの人。の通り。

これでPLANEX GW-450Dを挿したときのカーネルログは以下。

[  291.872361] usb 1-1.5: new high-speed USB device number 4 using dwc_otg
[  291.988871] usb 1-1.5: New USB device found, idVendor=2019, idProduct=ab31
[  291.988899] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  291.988917] usb 1-1.5: Product: GW-450D
[  291.988933] usb 1-1.5: Manufacturer: Planex
[  291.988949] usb 1-1.5: SerialNumber: 1.0
[  294.903179] rtusb init rt2870 --->
[  294.904227] 

=== pAd = bd282000, size = 857568 ===

[  294.904301] <-- RTMPAllocTxRxRingMemory, Status=0
[  294.904821] <-- RTMPAllocAdapterBlock, Status=0
[  294.905048] ==>RT65xx_WLAN_ChipOnOff(): OnOff:1, Reset= 0, pAd->WlanFunCtrl:0x0, Reg-WlanFunCtrl=0xff000002
[  294.906147] MCUType = 2
[  294.906396] NVM is EFUSE
[  294.906406] Endpoint(8) is for In-band Command
[  294.906415] Endpoint(4) is for WMM0 AC0
[  294.906422] Endpoint(5) is for WMM0 AC1
[  294.906430] Endpoint(6) is for WMM0 AC2
[  294.906437] Endpoint(7) is for WMM0 AC3
[  294.906444] Endpoint(9) is for WMM1 AC0
[  294.906451] Endpoint(84) is for Data-In
[  294.906459] Endpoint(85) is for Command Rsp
[  294.907663] usbcore: registered new interface driver rt2870
[  295.045978] -->RTUSBVenderReset
[  295.046095] <--RTUSBVenderReset
[  295.051116] fw version:0.1.00 build:7640
[  295.051135] build time:201308221655____
[  295.051180] ilm length = 68780(bytes)
[  295.051189] dlm length = 11476(bytes)
[  295.072423] #
[  295.080056] loading fw......
[  295.152448] #
[  295.371566] RTMP_TimerListAdd: add timer obj bd300b84!
[  295.371595] RTMP_TimerListAdd: add timer obj bd300bcc!
[  295.371605] RTMP_TimerListAdd: add timer obj bd300c14!
[  295.371614] RTMP_TimerListAdd: add timer obj bd300b3c!
[  295.371627] RTMP_TimerListAdd: add timer obj bd300a64!
[  295.371636] RTMP_TimerListAdd: add timer obj bd300aac!
[  295.371649] RTMP_TimerListAdd: add timer obj bd294c2c!
[  295.371659] RTMP_TimerListAdd: add timer obj bd28403c!
[  295.371668] RTMP_TimerListAdd: add timer obj bd284088!
[  295.371678] RTMP_TimerListAdd: add timer obj bd294d14!
[  295.371691] RTMP_TimerListAdd: add timer obj bd294b9c!
[  295.371707] RTMP_TimerListAdd: add timer obj bd294ccc!
[  295.382926] cfg_mode=5
[  295.382950] wmode_band_equal(): Band Not Equal!
[  295.383529] Key1Str is Invalid key length(0) or Type(0)
[  295.383591] Key2Str is Invalid key length(0) or Type(0)
[  295.383652] Key3Str is Invalid key length(0) or Type(0)
[  295.383715] Key4Str is Invalid key length(0) or Type(0)
[  295.384919] 1. Phy Mode = 31
[  295.384928] 2. Phy Mode = 31
[  295.384938] NVM is Efuse and its size =1d[1e0-1fc] 
[  295.396012] /home/koba/work/raspi/gw-450d_driver_linux_v3002/mt7610u_wifi_sta_v3002_dpo_20130916/os/linux/../../chips/mt76x0.c:2114 assert (pAd->TxPower[choffset].Channel == 36)failed
[  295.406380] ERROR!!! E2PROM: WRONG VERSION 0x2, should be 1
[  295.410472] mt76x0_read_tx_alc_info_from_eeprom: EEPROM_MT76x0_TEMPERATURE_OFFSET (0xD1) = 0xf8
[  295.410483] mt76x0_read_tx_alc_info_from_eeprom: TemperatureOffset = 0xfffffff8
[  295.410491] Temperature Tx ALC not enabled
[  295.427483] 3. Phy Mode = 31
[  295.427499] AntCfgInit: primary/secondary ant 0/1
[  295.432937] RTMPSetPhyMode: channel is out of range, use first channel=1 
[  295.434454] MCS Set = ff 00 00 00 01
[  295.444494] <==== rt28xx_init, Status=0
[  295.445463] 0x1300 = 00064300
[  295.445474] RTMPDrvSTAOpen(1):Check if PDMA is idle!
[  295.445795] RTMPDrvSTAOpen(2):Check if PDMA is idle!
[  295.449133] IOCTL::unknown IOCTL's cmd = 0x00008947
[  296.126395] /home/koba/work/raspi/gw-450d_driver_linux_v3002/mt7610u_wifi_sta_v3002_dpo_20130916/os/linux/../../common/cmm_asic.c:2112 assert KeyIdx < 4failed
[  296.126825] /home/koba/work/raspi/gw-450d_driver_linux_v3002/mt7610u_wifi_sta_v3002_dpo_20130916/os/linux/../../common/cmm_asic.c:2112 assert KeyIdx < 4failed
[  299.749434] ===>rt_ioctl_giwscan. 6(6) BSS returned, data->length = 957
[  299.750764] ==>rt_ioctl_siwfreq::SIOCSIWFREQ(Channel=8)
[  299.878216] PeerBeaconAtJoinAction(): HT-CtrlChannel=8, CentralChannel=>8
[  299.878236] PeerBeaconAtJoinAction(): Set CentralChannel=8
[  299.878253] AdjustChannelRelatedValue(): Input BW=0, rf_channel=8, vht_bw=1, Channel=8, vht_cent_ch=0!
[  300.149464] Rcv Wcid(1) AddBAReq
[  300.149486] Start Seq = 00000000
[  300.149502] RTMP_TimerListAdd: add timer obj bd34df0c!
[  300.222457] RTMP_TimerListAdd: add timer obj bd34b2f8!
[  305.672520] RTMP_TimerListAdd: add timer obj bd34b350!

assertionのfailed がいくつか出ていて気持ち悪いですが、とりあえず接続して使用可能です。

関連
Raspberry Pi 2でWiFiを使う - 組み込みの人。
Raspberry Pi 2のカーネルをビルドしてみた - 組み込みの人。

Raspberry Pi 2でWiFiドングル BUFFALO WI-U2-433DMを使う

Raspbian jessi, kernel 4.1.10-v7+ を使っています。

WI-U2-433DM エアステーション 11ac/n/a/g/b 433/150Mbps USB2.0用 無線LAN子機 : Wi-Fiアダプター | バッファロー
このWiFiドングルのチップはrtl8811auで、そのドライバは以下のサイトから入手できます。
https://github.com/gnab/rtl8812au

$ git clone https://github.com/gnab/rtl8812au.git
$ cd rtl8812au

ロスコンパイルするために以下のようにMakefileを変更します。

diff --git a/Makefile b/Makefile
index b79a7d8..564efd8 100644
--- a/Makefile
+++ b/Makefile
@@ -49,13 +49,14 @@ CONFIG_EXT_CLK = n
 CONFIG_FTP_PROTECT = n
 CONFIG_WOWLAN = n
 
-CONFIG_PLATFORM_I386_PC = y
+CONFIG_PLATFORM_I386_PC = n
 CONFIG_PLATFORM_ANDROID_X86 = n
 CONFIG_PLATFORM_JB_X86 = n
 CONFIG_PLATFORM_ARM_S3C2K4 = n
 CONFIG_PLATFORM_ARM_PXA2XX = n
 CONFIG_PLATFORM_ARM_S3C6K4 = n
 CONFIG_PLATFORM_ARM_RPI = n
+CONFIG_PLATFORM_ARM_RPI_CROSS = y
 CONFIG_PLATFORM_MIPS_RMI = n
 CONFIG_PLATFORM_RTD2880B = n
 CONFIG_PLATFORM_MIPS_AR9132 = n
@@ -738,6 +739,15 @@ KSRC ?= /lib/modules/$(KVER)/build
 MODDESTDIR := /lib/modules/$(KVER)/kernel/drivers/net/wireless/
 endif
 
+ifeq ($(CONFIG_PLATFORM_ARM_RPI_CROSS), y)
+EXTRA_CFLAGS += -DCONFIG_LITTLE_ENDIAN
+ARCH := arm
+CROSS_COMPILE := arm-linux-gnueabihf-
+KVER  := 4.1.10-v7+
+KSRC ?= $(HOME)/work/raspi/linux
+MODDESTDIR := 
+endif
+
 ifeq ($(CONFIG_PLATFORM_RTD2880B), y)
 EXTRA_CFLAGS += -DCONFIG_BIG_ENDIAN -DCONFIG_PLATFORM_RTD2880B
 ARCH:=

make してできた8812au.ko をRaspberry Pi 2 の /lib/modules/4.1.10-v7+/ にコピーし、

$ sudo depmod

を実行して、モジュールの依存関係を更新します。

WiFiアクセスポイントの登録はRaspberry Pi 2でWiFiを使う - 組み込みの人。の通り。

BUFFALO WI-U2-433DMを挿したときのカーネルログは以下の通り。

[  160.521582] usb 1-1.5: new high-speed USB device number 4 using dwc_otg
[  160.622988] usb 1-1.5: New USB device found, idVendor=0411, idProduct=0242
[  160.623017] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  160.623035] usb 1-1.5: Product: 802.11ac WLAN Adapter 
[  160.623051] usb 1-1.5: Manufacturer: Realtek 
[  160.623068] usb 1-1.5: SerialNumber: 00e04c000001
[  161.213418] usbcore: registered new interface driver rtl8812au
[  161.747741] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[  162.416979] RTL871X: set bssid:00:00:00:00:00:00
[  162.418093] RTL871X: set ssid [g\xffffffc6isQ\xffffffffJ\xffffffec)ͺ\xffffffab\xfffffff2\xfffffffb\xffffffe3F|\xffffffc2T\xfffffff8xffffffe8\xffffffe7\xffffff8dvZ.c3\xffffff9fɚ ] fw_state=0x00000008
[  165.718720] RTL871X: set ssid [0024A52FB295] fw_state=0x00000008
[  165.718911] RTL871X: set bssid:00:24:a5:2f:b2:95
[  165.950915] RTL871X: start auth
[  165.960182] RTL871X: auth success, start assoc
[  165.967813] RTL871X: assoc success
[  165.969984] UpdateHalRAMask8812A => mac_id:0, networkType:0x0b, mask:0x000fffff
	 ==> rssi_level:0, rate_bitmap:0x000ff005
[  165.993282] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[  166.090729] RTL871X: send eapol packet
[  166.149026] RTL871X: send eapol packet
[  166.157988] RTL871X: set pairwise key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4) camid:4
[  166.158044] RTL871X: set group key to hw: alg:2(WEP40-1 WEP104-5 TKIP-2 AES-4) keyid:2
[  171.744734] UpdateHalRAMask8812A => mac_id:0, networkType:0x0b, mask:0x000fffff
	 ==> rssi_level:1, rate_bitmap:0x000f0000

接続して使用可能になりました。

関連
Raspberry Pi 2でWiFiを使う - 組み込みの人。
Raspberry Pi 2のカーネルをビルドしてみた - 組み込みの人。

Raspberry Pi 2でH.264ハードウェアエンコーダを試してみた

Raspberry Pi 1/2 にはH.264のハードウェアエンコーダが載っているとスペックシートには書いてあります。それをどうやって使うのか調べました。

参考にさせてもらったのは以下のページ
Connecting The Dots: Raspberry Piでgstreamerを使ったh264エンコード
raspbian - Hardware h.264 encoding and decoding on the GPU core - Raspberry Pi Stack Exchange
GStreamer-devel - Stopping a gst-launch-ed pipeline

H.264のハードウェアエンコーダはgstreamerのomxh264encに実装されているということです。

Raspbian jessie では必要なものは以下のコマンド一発で揃います。

$ sudo apt-get install gstreamer1.0-*

以下のコマンドで、USB Webcamの映像をH.264エンコードしてmp4の動画ファイルとして保存することができます。

gst-launch-1.0 -e \
v4l2src device=/dev/video0 ! "video/x-raw,width=640,height=480,framerate=30/1" ! \
omxh264enc ! "video/x-h264,profile=high" ! \
h264parse ! queue max-size-bytes=10000000 ! \
mp4mux ! \
filesink location=test1.mp4

これをcap1.sh に書いておいて実行し、コントロールCで止めます。

$ ./cap1.sh 
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
^Chandling interrupt.
Interrupt: Stopping pipeline ...
EOS on shutdown enabled -- Forcing EOS on the pipeline
Waiting for EOS...
Got EOS from element "pipeline0".
EOS received - stopping pipeline...
Execution ended after 0:01:36.699275713
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

mp4にmuxする場合は、gst-launch-1.0に -eオプションをつけておく必要があります。そうでないとコントロールCで止めたときに中途半端に切れたmp4ファイルができて再生不能になります。

エンコードの最中にtopコマンドでCPUの負荷をみるとidleが90%以上でした。確かにハードウェアでエンコードしていると思われます。

できたtest1.mp4をffprobeで調べると以下の通り。

$ ffprobe test1.mp4 
ffprobe version 2.7.2 Copyright (c) 2007-2015 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2d8bfb0] Invalid timestamps stream=0, pts=-421387831, dts=0, size=4307
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2015-10-11 23:51:53
  Duration: 00:01:36.67, start: -140462.610333, bitrate: 189 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 186 kb/s, 27.69 fps, 29.75 tbr, 3k tbn, 6k tbc (default)
    Metadata:
      creation_time   : 2015-10-11 23:51:53
      handler_name    : VideoHandler

タイプスタンプがおかしい箇所があるようですが、このファイルは普通に再生できました。

続きを書きました。
Raspberry Pi 2 でWebcamの映像音声を録画する - 組み込みの人。

Raspberry Pi 2 でWebcamの映像音声を録画する

前回の続きで、映像だけでなく音声も一緒にmp4ファイルに録画するようにしました。

#!/bin/sh

if [ $# -ne 1 ]; then
  echo "Usage: " $0 " output_file" 1>&2
  echo "Hit ^C to stop." 1>&2
  exit 1
fi
output_file=$1

gst-launch-1.0 -e \
  v4l2src  ! "video/x-raw,width=640,height=480,framerate=30/1" ! \
    omxh264enc target-bitrate=1000000 control-rate=variable ! \
    video/x-h264,profile=high ! h264parse ! queue ! \
    mp4mux name=mux \
  alsasrc device=hw:1 ! audioresample ! audio/x-raw,rate=48000 ! \
    queue ! voaacenc bitrate=32000 ! queue ! mux. \
  mux. ! filesink location=$output_file

使用しているWebcamLogicool c270でその内蔵マイクはモノラルです。
録画したファイルのffprobeの結果。

$ ffprobe out3.mp4 
ffprobe version 2.7.2 Copyright (c) 2007-2015 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x13abfb0] Invalid timestamps stream=0, pts=-421387831, dts=0, size=5601
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2015-10-12 02:57:00
  Duration: 00:00:19.83, start: -140462.610333, bitrate: 1031 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 992 kb/s, 29.81 fps, 29.97 tbr, 3k tbn, 6k tbc (default)
    Metadata:
      creation_time   : 2015-10-12 02:57:00
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 32 kb/s (default)
    Metadata:
      creation_time   : 2015-10-12 02:57:00
      handler_name    : SoundHandler

参考にしたページ
Streaming with nginx-rtmp-module: GStreamer and Raspberry Pi

Raspbian jessie でperfコマンドをビルドする

Raspbian jessie ではperfコマンドが含まれる linux-tools パッケージが正しくメンテされていないようで、カーネルのバージョンと食い違ったperf_3.16というコマンドがインストールされてしまいます。

pi@raspberrypi:~/work/kernel/linux$ sudo apt-get install linux-tools
 ...
pi@raspberrypi:~/work/kernel/linux$ which perf
/usr/bin/perf
pi@raspberrypi:~/work/kernel/linux$ perf
/usr/bin/perf: line 24: exec: perf_4.1: not found
E: linux-tools-4.1 is not installed.
pi@raspberrypi:~/work/kernel/linux$ sudo apt-get install linux-tools-4.1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package linux-tools-4.1
E: Couldn't find any package by regex 'linux-tools-4.1'
pi@raspberrypi:~/work/kernel/linux$ ls /usr/bin/perf*
/usr/bin/perf  /usr/bin/perf_3.16

待っていればそのうち解決されるかもしれませんが、自力でperfコマンドをビルドしました。
以前もやったことありましたし。
perfコマンドをソースからビルドする - 組み込みの人。

まず必要なライブラリを用意します。

$ sudo apt-get install  flex bison python pkg-config libaudit-dev \
binutils-dev  libelf-dev python-dev libpython-dev libperl-dev  \
libslang2-dev libdw-dev libiberty-dev libunwind-dev liblzma-dev

カーネルソースを取ってきます。--depth=1 をつけるとリポジトリ全部でなく最新だけになります。

$ mkdir kernel
$ cd kernel/
$ git clone --depth=1 https://github.com/raspberrypi/linux

ビルド

$ cd linux/
$ cd tools/perf/
$ make 2>&1 |tee make.log

インストール

$ make install

自分のホームディレクトリにインストールされます。一度ログアウトしてから再度ログインすると、~/bin にPATHが追加されます。

perfコマンドの試し打ち。

$ which perf
/home/pi/bin/perf
$ perf stat pwd
/home/pi/work/kernel/linux/tools/perf

 Performance counter stats for 'pwd':

          6.080886      task-clock (msec)         #    0.152 CPUs utilized          
                 6      context-switches          #    0.987 K/sec                  
                 0      cpu-migrations            #    0.000 K/sec                  
                56      page-faults               #    0.009 M/sec                  
         3,603,787      cycles                    #    0.593 GHz                    
         stalled-cycles-frontend  
         stalled-cycles-backend   
           964,216      instructions              #    0.27  insns per cycle        
           107,687      branches                  #   17.709 M/sec                  
            27,999      branch-misses             #   26.00% of all branches        

       0.040087712 seconds time elapsed

追記。
最初はインストールとして/usr/bin/perf_4.1 にコピーするようにかきましたが、make install のほうがよさそうなので修正しました。

Raspbian jessieを試してみた

Raspberry Pi用のRaspbianがアップデートされてjessieベースのものになっていたので試してみました。

https://www.raspberrypi.org/downloads/raspbian/ から2015-09-24-raspbian-jessie.zipを取ってきて中身のimgを取り出して、dd でマイクロSDカードに書き込みます。
しかし、4GBのマイクロSDカードを使ったら容量が不足して最後まで書けませんでした。8GBのものではうまくいきました。
Linuxから書き込んだのですが、ddコマンド実行後にマイクロSDカードを抜く前にsyncを忘れて一度失敗しました。

Raspbian jessieのブートログ
カーネルは4.1.7, initはsystemd になっていました。

書き込みに失敗した4GBのマイクロSDカードもbootパーティションは生きているので、bootcmd.txt を書き換えてNFSrootにすれば使えます。
Raspberry PiをNFSrootで起動する - 組み込みの人。
中途半端になっているrootパーティションはfdiskでパーティションを削除して再度作成してから、mkfs -e ext4 /dev/mmcblk0p2 で再利用できます。
(fdiskで再度パーティションを作るときには、パーティションの開始位置が前と同じになるようにします。bootパーティションと重ならないように。)