软件包安装
安装 Kernel 及 U-Boot 编译需要依赖的软件包:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl \
zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev \
x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev \
libxml2-utils xsltproc unzip device-tree-compiler p7zip tree liblz4-tool
若编译遇到报错,可以视报错信息,安装对应的软件包。因本文记录安装ubuntu的根文件系统,在此省略了buildroot的编译环境安装。
U-Boot 及 Kernel 使用的编译工具链在 prebuilt/gcc目录下:
prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
下载 SDK
由于 SDK 比较大,Firefly有提供了一个打包好的.git
以供下载:
-
Firefly-RK3308_Linux_SDK
下载完成后解压到相应的工作目录:
mkdir -p /home/dolphin/WORK/Firefly-RK3308
cd /home/dolphin/WORK/Firefly-RK3308
sudo cp -rf Firefly-RK3308_Linux_SDK_git_20181008.7z /home/dolphin/WORK/Firefly-RK3308/
sudo chown dolphin:dolphin Firefly-RK3308_Linux_SDK_git_20181008.7z
7zr x Firefly-RK3308_Linux_SDK_git_20181008.7z
git reset --hard
解压出SDK后,直接从 gitlab 处更新:
git remote -v
git pull gitlab firefly:firefly
查看SDK的目录结构:
dolphin@dolphin-ubuntu:~/WORK$ tree -L 1 Firefly-RK3308
Firefly-RK3308
├── buildroot
├── build.sh -> device/rockchip/common/build.sh
├── device
├── envsetup.sh -> buildroot/build/envsetup.sh
├── external
├── kernel
├── Makefile -> buildroot/build/Makefile
├── mkfirmware.sh -> device/rockchip/rk3308/mkfirmware.sh
├── prebuilts
├── rkbin
├── tools
├── u-boot
└── yocto
9 directories, 4 files
其中:
-
build.sh
为系统编译脚本,执行可进行 SDK 的完整编译 -
device
目录存放板级配置及一些预置文件,开机脚本等 -
kernel
为内核部分源码 -
mkfirmware.sh
脚本可对镜像文件进行打包,并统一拷贝至rockdev/
目录 -
prebuilts
目录存放 U-Boot、Kernel 编译使用的交叉编译工具链 -
rkbin
目录存放 Rockchip 平台一些关键性二进制文件,包括ddr.bin
,miniloader.bin
,bl31.bin
,在 U-Boot 编译过程中会用到 -
rockdev
执行mkfirmware.sh
会把系统编译的生成的镜像,统一拷贝至rockdev/
-
tools
目录存放着 Windows 及 Linux 环境下的开发工具、调试工具、量产工具 -
u-boot
目录存放着 U-Boot 部分的源码
编译 Uboot
编译 Uboot:
cd u-boot/
./make.sh roc-rk3308-cc
编译完会生成 trust.img、rk3308_loader_xxx.bin、uboot.img 三个镜像文件。
编译 Kernel
我们需要kernel能支持ubuntu的文件系统,也需要小板可以挂载U盘和摄像头等外设,所以对config文件作了一些更改:
dolphin@dolphin-ubuntu:~/WORK/Firefly-RK3308/kernel/arch/arm64/configs$ git diff firefly-rk3308_linux_defconfig
diff --git a/kernel/arch/arm64/configs/firefly-rk3308_linux_defconfig b/kernel/arch/arm64/configs/firefly-rk3308_linux_defconfig
index 5015876..3e59241 100644
--- a/kernel/arch/arm64/configs/firefly-rk3308_linux_defconfig
+++ b/kernel/arch/arm64/configs/firefly-rk3308_linux_defconfig
@@ -6,6 +6,16 @@ CONFIG_FHANDLE=y
CONFIG_NO_HZ=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_LOG_BUF_SHIFT=18
+CONFIG_CGROUPS=y
+CONFIG_CGROUP_FREEZER=y
+CONFIG_CGROUP_DEVICE=y
+CONFIG_CPUSETS=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_CFS_BANDWIDTH=y
+CONFIG_NAMESPACES=y
+CONFIG_USER_NS=y
+CONFIG_DEFAULT_USE_ENERGY_AWARE=y
CONFIG_BLK_DEV_INITRD=y
# CONFIG_RD_BZIP2 is not set
# CONFIG_RD_LZMA is not set
@@ -19,8 +29,9 @@ CONFIG_EMBEDDED=y
CONFIG_PROFILING=y
CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y
+CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_MODULE_FORCE_UNLOAD=y
CONFIG_PARTITION_ADVANCED=y
# CONFIG_RK_PARTITION is not set
# CONFIG_IOSCHED_DEADLINE is not set
@@ -65,6 +76,7 @@ CONFIG_ARM_ROCKCHIP_CPUFREQ=y
CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
+CONFIG_XFRM_USER=y
CONFIG_NET_KEY=y
CONFIG_INET=y
CONFIG_SYN_COOKIES=y
@@ -122,7 +134,8 @@ CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_8250_NR_UARTS=5
CONFIG_SERIAL_8250_RUNTIME_UARTS=5
CONFIG_SERIAL_8250_DW=y
-# CONFIG_HW_RANDOM is not set
+CONFIG_HW_RANDOM=y
+CONFIG_HW_RANDOM_ROCKCHIP=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MUX=y
CONFIG_I2C_RK3X=y
@@ -148,6 +161,20 @@ CONFIG_REGULATOR=y
CONFIG_REGULATOR_FIXED_VOLTAGE=y
CONFIG_REGULATOR_GPIO=y
CONFIG_REGULATOR_PWM=y
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_MEDIA_CAMERA_SUPPORT=y
+CONFIG_MEDIA_CONTROLLER=y
+CONFIG_VIDEO_DEV=y
+CONFIG_VIDEO_V4L2_SUBDEV_API=y
+CONFIG_MEDIA_USB_SUPPORT=y
+CONFIG_USB_VIDEO_CLASS=y
+CONFIG_USB_GSPCA=y
+CONFIG_USB_GSPCA_SONIXJ=y
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_SOC_CAMERA=y
+# CONFIG_VIDEO_RK_CIF_ISP10=y
+CONFIG_V4L_MEM2MEM_DRIVERS=y
+CONFIG_VIDEO_ROCKCHIP_RGA=y
CONFIG_DRM=y
CONFIG_DRM_ROCKCHIP=y
CONFIG_ROCKCHIP_RGB=y
@@ -161,8 +188,9 @@ CONFIG_SOUND=y
CONFIG_SND=y
CONFIG_SND_HRTIMER=y
# CONFIG_SND_SUPPORT_OLD_API is not set
-# CONFIG_SND_DRIVERS is not set
+CONFIG_SND_ALOOP=y
# CONFIG_SND_SPI is not set
+CONFIG_SND_USB_AUDIO=y
CONFIG_SND_SOC=y
CONFIG_SND_SOC_ROCKCHIP=y
CONFIG_SND_SOC_ROCKCHIP_I2S=y
@@ -170,10 +198,12 @@ CONFIG_SND_SOC_ROCKCHIP_I2S_TDM=y
CONFIG_SND_SOC_ROCKCHIP_MULTI_DAIS=y
CONFIG_SND_SOC_ROCKCHIP_PDM=y
CONFIG_SND_SOC_ROCKCHIP_SPDIF=y
+CONFIG_SND_SOC_ROCKCHIP_SPDIFRX=y
CONFIG_SND_SOC_ROCKCHIP_VAD=y
CONFIG_SND_SOC_ROCKCHIP_MULTICODECS=y
CONFIG_SND_SOC_DUMMY_CODEC=y
CONFIG_SND_SOC_RK3308=y
+CONFIG_SND_SOC_TAS571X=y
CONFIG_SND_SIMPLE_CARD=y
# CONFIG_HID_GENERIC is not set
CONFIG_USB=y
@@ -182,26 +212,33 @@ CONFIG_USB_EHCI_HCD_PLATFORM=y
CONFIG_USB_OHCI_HCD=y
CONFIG_USB_OHCI_HCD_PLATFORM=y
CONFIG_USB_STORAGE=y
-CONFIG_USB_STORAGE_DATAFAB=y
-CONFIG_USB_STORAGE_FREECOM=y
-CONFIG_USB_STORAGE_ISD200=y
-CONFIG_USB_STORAGE_USBAT=y
-CONFIG_USB_STORAGE_SDDR09=y
-CONFIG_USB_STORAGE_SDDR55=y
-CONFIG_USB_STORAGE_JUMPSHOT=y
-CONFIG_USB_STORAGE_ALAUDA=y
-CONFIG_USB_STORAGE_ONETOUCH=y
-CONFIG_USB_STORAGE_KARMA=y
-CONFIG_USB_STORAGE_CYPRESS_ATACB=y
-CONFIG_USB_STORAGE_ENE_UB6250=y
-CONFIG_USB_UAS=y
+#CONFIG_USB_STORAGE_FREECOM=y
+#CONFIG_USB_STORAGE_ISD200=y
+#CONFIG_USB_STORAGE_USBAT=y
+#CONFIG_USB_STORAGE_SDDR09=y
+#CONFIG_USB_STORAGE_SDDR55=y
+#CONFIG_USB_STORAGE_JUMPSHOT=y
+#CONFIG_USB_STORAGE_ALAUDA=y
+#CONFIG_USB_STORAGE_ONETOUCH=y
+#CONFIG_USB_STORAGE_KARMA=y
+#CONFIG_USB_STORAGE_CYPRESS_ATACB=y
+#CONFIG_USB_STORAGE_ENE_UB6250=y
+#CONFIG_USB_UAS=y
CONFIG_USB_DWC2=y
CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_DEBUG_FILES=y
CONFIG_USB_GADGET_VBUS_DRAW=500
CONFIG_USB_CONFIGFS=y
+CONFIG_USB_CONFIGFS_ACM=y
+CONFIG_USB_CONFIGFS_RNDIS=y
+CONFIG_USB_CONFIGFS_MASS_STORAGE=y
CONFIG_USB_CONFIGFS_F_FS=y
+CONFIG_USB_CONFIGFS_F_MTP=y
+CONFIG_USB_CONFIGFS_F_PTP=y
+CONFIG_USB_CONFIGFS_F_ACC=y
+CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y
CONFIG_USB_CONFIGFS_UEVENT=y
+CONFIG_USB_CONFIGFS_F_MIDI=y
CONFIG_MMC=y
CONFIG_MMC_BLOCK_MINORS=32
# CONFIG_MMC_BLOCK_BOUNCE is not set
@@ -261,24 +298,37 @@ CONFIG_RK_SFC_NAND=y
CONFIG_RK_SFC_NOR=y
CONFIG_ROCKCHIP_SIP=y
CONFIG_EXT2_FS=y
-CONFIG_EXT4_FS=m
+CONFIG_EXT2_FS_XATTR=y
+CONFIG_EXT4_FS=y
+CONFIG_EXT4_FS_POSIX_ACL=y
+CONFIG_EXT4_FS_SECURITY=y
+CONFIG_XFS_FS=y
+CONFIG_BTRFS_FS=y
# CONFIG_DNOTIFY is not set
-CONFIG_MSDOS_FS=y
+CONFIG_FUSE_FS=y
+CONFIG_ISO9660_FS=y
+CONFIG_JOLIET=y
+CONFIG_ZISOFS=y
CONFIG_VFAT_FS=y
CONFIG_FAT_DEFAULT_CODEPAGE=936
CONFIG_FAT_DEFAULT_IOCHARSET="utf8"
-CONFIG_NTFS_FS=y
-CONFIG_NTFS_RW=y
+# CONFIG_NTFS_FS=y
+# CONFIG_NTFS_RW=y
CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
+CONFIG_CONFIGFS_FS=y
CONFIG_SQUASHFS=y
-CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU=y
-CONFIG_SQUASHFS_4K_DEVBLK_SIZE=y
-CONFIG_PSTORE=y
-CONFIG_PSTORE_CONSOLE=y
-CONFIG_PSTORE_RAM=y
-# CONFIG_NETWORK_FILESYSTEMS is not set
+CONFIG_SQUASHFS_LZ4=y
+CONFIG_SQUASHFS_LZO=y
+CONFIG_SQUASHFS_XZ=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+CONFIG_NFS_SWAP=y
CONFIG_NLS_DEFAULT="utf8"
+CONFIG_NLS_CODEPAGE_437=y
CONFIG_NLS_CODEPAGE_936=y
+CONFIG_NLS_ASCII=y
CONFIG_NLS_ISO8859_1=y
CONFIG_NLS_UTF8=y
CONFIG_PRINTK_TIME=y
@@ -299,7 +349,7 @@ CONFIG_RCU_CPU_STALL_TIMEOUT=60
CONFIG_STRICT_DEVMEM=y
CONFIG_DEBUG_SET_MODULE_RONX=y
# CONFIG_CRYPTO_ECHAINIV is not set
-CONFIG_CRYPTO_CRC32C=y
+# CONFIG_CRYPTO_CRC32C is not set
# CONFIG_CRYPTO_HW is not set
CONFIG_ARM64_CRYPTO=y
CONFIG_CRYPTO_SHA1_ARM64_CE=y
其中CGROUP的选项用于开启CPU控制组,ubuntu系统会依赖到这些控制组的挂载,不添加将导致ubuntu文件系统无法挂载。
一些USB相关的选项用于添加对U盘,USB摄像头及其V4L控制等功能。
进入~/WORK/Firefly-RK3308/kernel/arch/arm64/boot/dts/rockchip
,通过vim rk3308-firefly.dtsi
命令修改文件上中的bootargs使kernel支持ext4根文件系统,并获得根文件系统的读写权限:
#include <dt-bindings/input/input.h>
#include "rk3308.dtsi"
/ {
model = "Firefly RK3308";
compatible = "firefly,rk3308-firefly", "firefly,rk3308";
chosen {
bootargs = "earlycon=uart8250,mmio32,0xff0c0000 swiotlb=1 console=ttyFIQ0 rw root=PARTUUID=614e0000-0000";
};
编译 Kernel:
cd ~/WORK/Firefly-RK3308/kernel/
make arch=arm64 firefly-rk3308_linux_defconfig
make arch=arm64 rk3308-roc-cc-dmic-pdm_emmc.img -j8
这里通过编译firefly-rk3308_linux_defconfig
生成.config
的编译选项文件,也可以通过make menuconfig
文件生成.config
,只是要留意,修改后的配置要及时保存,以免被覆盖丢失配置过的选项:
make menuconfig
make savedefconfig
cp defconfig arch/arm64/configs/firefly-rk3308_linux_defconfig
编译 kenrel 的时候可以直接make arch=arm64 dts-name.img
(如rk3308-roc-cc-dmic-pdm_emmc.img
),即可生成对应的 resource.img(包含 dtb 数据)。
最终生成的kernel.img和resource.img将会被打包进boot.img,因此更新内核的时候,只需烧写boot.img即可。
制作根文件系统
安装依赖包:
sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
下载ubuntu core:
wget -c http://cdimage.ubuntu.com/ubuntu-base/releases/18.04/release/ubuntu-base-18.04.1-base-arm64.tar.gz
创建一个大小为 4G 的根文件系统映像文件,将 ubuntu core 解压到该映像中,如果不需要安装过多的软件,可以先设置成 4G ,后期通过resize再调整。
cd /mnt/h/proj
#dd if=/dev/zero of=rootfs.img bs=1M count=0 seek=4000
#sudo mkfs.ext4 -F -L ROOTFS rootfs.img
sudo mkdir ubuntu
#sudo mount rootfs.img mnt/
sudo tar -xpzf ubuntu-base-18.04-base-arm64.tar.gz -C ubuntu/
将 qemu-aarch64-static 放到挂载的 rootfs 的 /usr/bin 中,能在 x86_64 主机系统下 chroot 到该 arm64 文件系统中运行:
sudo cp -a /usr/bin/qemu-aarch64-static mnt/usr/bin/
chroot 命令用来在指定的根目录下运行指令,在使用 chroot 之后,系统的目录结构将以指定的位置作为 “/” 位置。
sudo chroot mnt/
在 rootfs 的 root 用户下设置:
# 这里可以修改设置
USER=dolphin
HOST=dolphin-ubuntu
# 创建用户
useradd -G sudo -m -s /bin/bash dolphin
passwd $USER
# 输入密码
# 设置主机名和以太网
echo $HOST /etc/hostname
echo "127.0.0.1 $HOST" >> /etc/hosts
echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
mkdir /etc/network
mkdir /etc/network/interfaces.d
echo "auto eth0" > /etc/network/interfaces.d/eth0
echo "iface eth0 inet dhcp" >> /etc/network/interfaces.d/eth0
echo "nameserver 127.0.1.1" > /etc/resolv.conf
echo "nameserver 8.8.8.8 " >> /etc/resolv.conf
# 安装包
apt-get update
apt-get upgrade
apt-get install -y udev sudo ssh language-pack-en-base --no-install-recommends
apt-get install systemd --no-install-recommends
#设置timezone
apt-get install tzdata
dpkg-reconfigure tzdata
# 必须安装systemd,否则系统无法挂载
apt-get install -y ifupdown net-tools network-manager ethtool --no-install-recommends
apt-get install -y vim rsyslog bash-completion htop --no-install-recommends
# 无线网络配置工具
apt-get install -y wireless-tools wpasupplicant iputils-ping --no-install-recommends
#安装Display Server
#apt-get install -y --no-install-recommends xserver-xorg --no-install-recommends
#lxde桌面环境
#apt-get install -y lxde --no-install-recommends
systemctl enable rockchip.service
systemctl mask systemd-networkd-wait-online.service
systemctl mask NetworkManager-wait-online.service
#rm /lib/systemd/system/wpa_supplicant@.service
# Ubuntu 16.04.02采用了systemd的init初始化系统,用于提高系统的启动速度。
# 在执行getty.targe时,systemd会自动在/etc/systemd/system/getty.target.wants查找相关的targe执行
# 即实际执行/lib/systemd/system/serial-getty@.service这个串口终端服务。
# ROC-RK3328-CC的UART默认使用1 500 000波特率和TTL电平。
ln -s /lib/systemd/system/serial-getty\@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service
#sudo vim /etc/systemd/system/network-online.target.wants/networking.service
#以下内容:
#[Service]
#Type=oneshot
#EnvironmentFile=-/etc/default/networking
#ExecStartPre=-/bin/sh -c '[ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifqueryy
# --read-environment --list --exclude=lo)" ] && udevadm settle'
#ExecStart=/sbin/ifup -a --read-environment
#ExecStop=/sbin/ifdown -a --read-environment --exclude=lo
#RemainAfterExit=true
#TimeoutStartSec=5min
# 将里面的TimeoutStartSec=5min 修改为TimeoutStartSec=5sec,解决开机无网络需长时间等待的问题。
退出,并制作文件系统:
exit
sudo sync
# <enter user password>
dd if=/dev/zero of=ubuntu.img bs=1M count=4000
sudo mkfs.ext4 ubuntu.img
mkdir ubuntu-mount
sudo mount ubuntu.img ubuntu-mount
sudo cp -rfp ubuntu/* ubuntu-mount/
sudo umount ubuntu-mount
e2fsck -p -f ubuntu.img
resize2fs -M ubuntu.img
如果想要在创建的根文件系统中安装软件,也可以继续chroot
到该文件系统中,安装一些常用的软件,比如 "pip" , "numpy" 等,避免复杂的交叉编译环境设置和加快文件系统的成型。
这样rootfs.img
里就已经有刚才制作的根目录内容了,但这个img
文件大小却是定义的镜像的大小,不是文件系统的实际大小,所以还要经过一些处理才能发布。
检查并查看rootfs.img镜像的文件系统:
dolphin@dolphin-ubuntu:~/proj/rootfs$ e2fsck -p -f rootfs.img
ROOTFS:17032/640848 文件(0.2% 为非连续的), 234632/2560000 块
dolphin@dolphin-ubuntu:~/proj/rootfs$ ls -l rootfs.img
-rw-rw-r-- 1 dolphin dolphin 10485760000 10月 24 22:18 rootfs.img
减小ubuntu.img镜像文件的大小:
dolphin@dolphin-ubuntu:~/proj/rootfs$ resize2fs -M rootfs.img
resize2fs 1.44.1 (24-Mar-2018)
  将 rootfs.img 上的文件系统调整为 305886 个块(每块 4k)。
rootfs.img 上的文件系统现在为 305886 个块(每块 4k)。
dolphin@dolphin-ubuntu:~/proj/rootfs$ ls -l rootfs.img
-rw-rw-r-- 1 dolphin dolphin 1252909056 10月 24 22:19 rootfs.img
烧写镜像文件
创建烧录用的parameter文件如下,将其存储为*.txt
文件,在这个文件中,删除了非必要的分区,同时将rootfs分配成了可增长的分区,避免前期开发多次调整分区大小:
FIRMWARE_VER:8.1
MACHINE_MODEL:RK3308
MACHINE_ID:007
MANUFACTURER: RK3308
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 3308
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT
CMDLINE:mtdparts=rk29xxnand:0x1000@0x2000(uboot),0x1000@0x6000(trust),0x6000@0x8000(boot),-@0x40000(rootfs:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9
打开官方的烧录工具,右键添加项创建如下所示的烧录配置:
烧录配置.png
其中在导入parameter文件时,各项烧录地址也会同步变化。
随后点击路径添加所有的烧录文件,即可以进入ubuntu系统了。
设置使用音频设备
查看音频设置的组成员
grep audio /etc/group
如果没有所建用户,需要添加:
sudo usermod -a -G audio dolphin
dolphin@localhost:~/data$ grep audio /etc/group
audio:x:29:dolphin,root
安装alsa的工具:
sudo apt-get install alsa-base alsa-utils alsa-oss alsa-tools
在修改前先查看小机上的声卡设备:
dolphin@localhost:~/data$ cat /proc/asound/cards
0 [rockchiprk3308v]: rockchip_rk3308 - rockchip,rk3308-vad
rockchip,rk3308-vad
1 [rockchiprk3308p]: rockchip_rk3308 - rockchip,rk3308-pcm
rockchip,rk3308-pcm
7 [Loopback ]: Loopback - Loopback
Loopback 1
dolphin@localhost:~/data$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: rockchiprk3308v [rockchip,rk3308-vad], device 0: dailink-multicodecs multicodec-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: rockchiprk3308p [rockchip,rk3308-pcm], device 0: dailink-multicodecs dummy_codec-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 7: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 7: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
alsa的配置文件位于/usr/share/alsa 目录下,主要配置文件为/usr/share/alsa/alsa.conf 。 在alsa.conf 中,还会引用/etc/asound.conf 和~/.asoundrc 这两个配置文件,这两个文件用于存放个人设置的相关参数。
另外,通常还有/usr/share/alsa/card 和/usr/share/alsa/pcm 两个子目录,用于设置全局的card相关参数,别名以及一些PCM默认设置。
以下修改用于放音或者录音的声卡设备:
sudo vim /etc/asound.conf
在打开的文件中加入以下内容,表示使用声卡0的设备0
defaults.ctl.card 0
defaults.pcm.card 0
defaults.pcm.device 0
设置默认播放音量:
dolphin@localhost:$ alsamixer
出现如图所示的音量调节画面:
通过左、右键选择声道,上、下键设置音量大小,保存为默认设置:
dolphin@localhost:$ sudo alsactl store
dolphin@localhost:$ sudo reboot
安装mplayer并使用mplayer播放音乐:
dolphin@localhost:$ sudo apt-get install mplayer
dolphin@localhost:$ mplayer -version
MPlayer 1.3.0 (Debian), built with gcc-7 (C) 2000-2016 MPlayer Team
dolphin@localhost:~/data$ mplayer 11-Why Do We Fall.mp3
MPlayer 1.3.0 (Debian), built with gcc-7 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing 11 - Why Do We Fall!.mp3.
libavformat version 57.83.100 (external)
Audio only file format detected.
Clip info:
Title: Why Do We Fall?
Artist: Hans Zimmer
Album: The Dark Knight Rises
Year: 2012
Comment:
Track: 11
Genre: Unknown
Load subtitles in ./
==========================================================================
Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III
AUDIO: 44100 Hz, 2 ch, s16le, 320.0 kbit/22.68% (ratio: 40000->176400)
Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III)
==========================================================================
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 7.1 (07.1) of 122.0 (02:02.0) 3.1%
也可以安装sox,用来播放音乐,sox 是同时具备 play 和 rec 功能:
dolphin@localhost:~/data/music/piano$ sudo apt-get install sox libsox-fmt-all
dolphin@localhost:~/data/music/piano$ play *.mp3
Crying In The Party.mp3:
File Size: 5.91M Bit Rate: 190k
Encoding: MPEG audio Info: 2009
Channels: 2 @ 16-bit Track: 9
Samplerate: 44100Hz Album: ä�ÇÙÐÄÇé101 (Disc 3)
Replaygain: off Artist: ¼�Òô�·
Duration: 00:04:08.92 Title: Crying In The Party
In:21.8% 00:00:54.24 [00:03:14.68] Out:2.39M [ =====|=====-] Hd:2.8 Clip:0
网友评论