[常見問與答] 如何看 Raspbian 的版本資訊?

自從 Raspbian 從 Wheezy 升級到 Jessie 以後,許多系統性的設計都有所不同。那要如何看 Raspbian 的版本資訊呢?

1. uname -a 查詢 kernel 版本。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux
# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.1.17-v7+ #834 SMP Mon Feb 1 15:17:54 GMT 2016 armv7l GNU/Linux

 

2. /opt/vc/bin/vcgencmd version 查詢 firmware 版本。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ /opt/vc/bin/vcgencmd version
Apr 21 2015 14:42:19 
Copyright (c) 2012 Broadcom
version 2d5ad04b63af4233440c3f7c8587108223201102 (clean) (release)
# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd version
Feb  1 2016 17:51:17 
Copyright (c) 2012 Broadcom
version b3dc56931507f355d503ea69397778643f7a3dc3 (clean) (release)

 

3. strings /boot/start.elf | grep VC_BUILD_ID 查詢 firmware 版本。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ strings /boot/start.elf | grep VC_BUILD_ID
VC_BUILD_ID_USER: dc4
VC_BUILD_ID_TIME: 14:42:19
VC_BUILD_ID_BRANCH: master
VC_BUILD_ID_TIME: Apr 21 2015
VC_BUILD_ID_HOSTNAME: dc4-XPS13-9333
VC_BUILD_ID_PLATFORM: raspberrypi_linux
VC_BUILD_ID_VERSION: 2d5ad04b63af4233440c3f7c8587108223201102 (clean)
# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ strings /boot/start.elf | grep VC_BUILD_ID
VC_BUILD_ID_USER: dc4
VC_BUILD_ID_TIME: 17:51:17
VC_BUILD_ID_BRANCH: master
VC_BUILD_ID_TIME: Feb  1 2016
VC_BUILD_ID_HOSTNAME: dc4-XPS13-9333
VC_BUILD_ID_PLATFORM: raspberrypi_linux
VC_BUILD_ID_VERSION: b3dc56931507f355d503ea69397778643f7a3dc3 (clean)

 

4. cat /proc/version 查詢更完整的 kernel 資料。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ cat /proc/version
Linux version 3.18.11-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015
# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ cat /proc/version
Linux version 4.1.17-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #834 SMP Mon Feb 1 15:17:54 GMT 2016

 

5. cat /etc/os-release 查詢 OS 版本資訊。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
NAME="Raspbian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=raspbian
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

 

6. cat /etc/issue 查詢 Linux distro 版本。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ cat /etc/issue
Raspbian GNU/Linux 7 \n \l

# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ cat /etc/issue
Raspbian GNU/Linux 8 \n \l

 

7. cat /etc/debian_version 查詢 Debian 版本編號。

# 2015-05-05-raspbian-wheezy 
pi@raspberrypi ~ $ cat /etc/debian_version
7.8
# 2016-02-03-raspbian-jessie
pi@raspberrypi:~ $ cat /etc/debian_version
8.0

[進階] 編譯 Raspberry Pi 的核心

本文前言來自鳥哥的私房菜中的第二十六章、Linux 核心編譯與管理

核心是什麼?

其實核心就是系統上面的一個檔案而已,這個檔案包含了驅動主機各項硬體的偵測程式與驅動模組。

為什麼要編譯核心?

新功能的需求、原本核心太過臃腫、與硬體搭配的穩定性、其他需求(如嵌入式系統)。

 

這裡簡介編譯安裝 Raspberry Pi 的流程,未來我們還會常常回來看這篇。

1. 在個人電腦建構交叉編譯的環境,步驟可參考這裡

2. 查詢目前 Pi 的核心版本(以安裝2014-01-07-wheezy-raspbian.img 的映像檔為例,使用的核心版本為 3.10.25)。

pi@raspberrypi:~$ uname -a
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux

3. 取得 Pi 的核心設定。

pi@raspberrypi:~$ zcat /proc/config.gz > .config

4. 在個人電腦下載核心原始碼。

sosorry@ubuntu:~$ cd rpi
sosorry@ubuntu:~/rpi$ git clone https://github.com/raspberrypi/linux.git
Initialized empty Git repository in /home/sosorry/linux/.git/
remote: Counting objects: 3512060, done.
remote: Compressing objects: 100% (586452/586452), done.
Receiving objects: 100% (3512060/3512060), 957.40 MiB | 3.18 MiB/s, done.
remote: Total 3512060 (delta 2897634), reused 3510306 (delta 2896207)
Resolving deltas: 100% (2897634/2897634), done.
Checking out files: 100% (43371/43371), done.

5. 切到目標分支。

sosorry@ubuntu:~/rpi$ cd linux
sosorry@ubuntu:~/rpi/linux$ git checkout rpi-3.10.y

6. 讀取目前 Pi 的核心設定,假設 Pi 的 IP 為 192.168.1.2。

sosorry@ubuntu:~/rpi/linux$ make mrproper
  CLEAN   scripts/basic
  CLEAN   scripts/kconfig
  CLEAN   include/config include/generated

sosorry@ubuntu:~/rpi/linux$ scp pi@192.168.1.2:/home/pi/.config .

sosorry@ubuntu:~/rpi/linux$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- oldconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --oldconfig Kconfig
*
* Restart config...
*
*
* ALSA for SoC audio support
*
ALSA for SoC audio support (SND_SOC) [M/n/?] m
  SoC Audio for the Atmel System-on-Chip (SND_ATMEL_SOC) [N/m/?] n
  SoC Audio support for the Broadcom BCM2708 I2S module (SND_BCM2708_SOC_I2S) [M/n/?] m
    Support for HifiBerry DAC (SND_BCM2708_SOC_HIFIBERRY_DAC) [M/n/?] m
    Support for HifiBerry Digi (SND_BCM2708_SOC_HIFIBERRY_DIGI) [N/m/?] (NEW) 
    Support for RPi-DAC (SND_BCM2708_SOC_RPI_DAC) [M/n/?] m
    Support for IQaudIO-DAC (SND_BCM2708_SOC_IQAUDIO_DAC) [N/m/?] (NEW) 
  Synopsys I2S Device Driver (SND_DESIGNWARE_I2S) [N/m/?] n
  Build all ASoC CODEC drivers (SND_SOC_ALL_CODECS) [N/m/?] n
  ASoC Simple sound card support (SND_SIMPLE_CARD) [N/m/?] n
#
# configuration written to .config
#

7. 以選單方式選取所需要的功能。

sosorry@ubuntu:~/rpi/linux$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

raspberry_pi_kernel_configuration

8. 編譯核心(k, –keep-going)。

sosorry@ubuntu:~/rpi/linux$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -k V=1

9. 安裝核心模組。

sosorry@ubuntu:~/rpi/linux$ mkdir ../modules
sosorry@ubuntu:~/rpi/linux$ make modules_install ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../modules/

10. 使用內建的工具產生出 Raspberry Pi 的核心(kernel.img)。

sosorry@ubuntu:~/rip/linux$ cd ~/tools/mkimage
sosorry@ubuntu:~/rpi/tools/mkimage$ ./imagetool-uncompressed.py ~/rpi/linux/arch/arm/boot/zImage"

11. 將 kernel、firmware、lib 安裝到 Pi 上(假設 SD 卡已經 mount 在 ~/sdb1 和 ~/sdb2)。

sosorry@ubuntu:~/rpi/tools/mkimage$ sudo cp -Rf ~/rpi/modules/lib/firmware/ ~/sdb2/lib/
sosorry@ubuntu:~/rpi/tools/mkimage$ sudo cp -Rf ~/rpi/modules/lib/modules/ ~/sdb2/lib/

12. 移除 SD 卡,重新啟動 Pi,查詢核心版本,可以看到我們從 3.10.25 升級到 3.10.37。

pi@raspberrypi:~$ uname -a
Linux raspberrypi 3.10.37+ #1 PREEMPT Wed Apr 16 03:12:08 CST 2014 armv6l GNU/Linux

常見問與答:

1. 如果沒有 /proc/config.gz 怎麼辦?
請先執行 pi@raspberrypi:~$ sudo modprobe configs 就可以了
(感謝 Jimmy Chen 的貢獻)

RASPBERRY.ORG參考資料:
* KERNEL BUILDING
* CONFIGURING THE KERNEL
* PATCHING THE KERNEL