---- 继续移植 wifi同屏功能------
准备工作:
scrcpy软件: https://github.com/Genymobile/scrcpy
rtl7823bs wifi模块
一. 安装编译工具 pip3,meson,ninja-build,re2c
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo apt-get install python3-pip
sudo pip3 install --upgrade pip
pip3 install --user meson
apt-get install ninjia-build
或者源码安装
git clone https://github.com/ninja-build/ninja
./configure.py --bootstrap
apt-get install re2c
如果碰到问题就按照出错地方修改。
二. 下载相关库源码,交叉编译scrcpy
ffmpeg,x264,xvid,sdl2
1. xvid
tar zxvf xvidcore-1.3.3.tar.gz
cd xvidcore/build/generic
./configure --prefix=/root/ffmpeg/ --host=arm-linux-gnueabihf --target=arm-linux
make -j 8
make install
2. x264
tar jxvf last_x264.tar.bz2
cd x264-snapshot-20161225-2245
./configure --prefix=/root/ffmpeg/x264_out --host=arm-linux-gnueabihf --enable-shared --disable-asm
修改config.mak
修改内容如下:
CC=gcc 改为 CC=arm-linux-gnueabihf-gcc
LD=gcc -o 改为 LD=arm-linux-gnueabihf-gcc -o
RANLIB=ranlib 改为 RANLIB=arm-linux-gnueabihf-ranlib
STRIP=strip 改为 STRIP=aarm-linux-gnueabihf-strip
3. ffmpeg
tar jxvf ffmpeg-3.0.2.tar.bz2
cd ffmpeg-3.0.2/
./configure --prefix=/root/ffmpeg/out --disable-static --enable-shared --disable-debug --disable-asm --disable-ffplay --disable-ffprobe --disable-ffserver --enable-small --disable-doc --enable-demuxer=rtsp --enable-parser=h264 --enable-cross-compile --enable-libx264 --enable-libxvid --enable-nonfree --enable-gpl --arch=arm --target-os=linux --cross-prefix=arm-linux-gnueabihf- --extra-cflags=-I/root/ffmpeg/out/include --extra-ldflags=-L/root/ffmpeg/out/lib --extra-libs=-lrt
tar -zxvf SDL2-2.0.9.tar.gz
./configure --prefix=/root/scrcpy/sdl2 --host=arm-linux-gnueabihf --build=x86_64 --with-gnu-ld --disable-video-nanox --disable-video-qtopia --disable-pulseaudio --disable-video-photon --disable-video-ggi --disable-video-svga --disable-video-aalib --disable-video-dummy --disable-video-dga --disable-arts --disable-esd --disable-alsa --disable-video-x11 --disable-nasm --enable-joystick --disable-input-tslib --disable-video-fbcon
--留一个坑,后续再修改sdl源码,直接用linux framebuffer来显示图像
4. 进入目录scrcpy-1.16
/root/.local/bin/meson c --buildtype release --strip -Db_lto=true -Dprebuilt_server=../scrcpy-server.jar --cross-file cross_file.txt
cross_file.txt 文件的内容是:
[binaries]
c = 'arm-linux-gnueabihf-gcc'
cpp = 'arm-linux-gnueabihf-g++'
ar = 'arm-linux-gnueabihf-ar'
strip = 'arm-linux-gnueabihf-strip'
pkgconfig = '/root/buildroot-2017.08/output/host/bin/pkg-config'
[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'FP-ARMv7'
endian = 'little'
[build_machine]
system = 'linux'
cpu_family = 'x86_64'
cpu = 'i686'
endian = 'little'
在编译之前首先把ffmpeg 和sdl2的库生成的pkg-config文件拷贝到L/root/buildroot-2017.08/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/lib
一切准备就绪,编译生成scrcpy文件
ninja all
5. 用buildroot勾选adb工具,生成adb文件
二. 板子运行
1. 把adb和所有的用到的lib拷贝到板子。
2. 接上手机,打开usb调试模式(多次点击设置->关于手机->版本号)
Lsusb找到pid号
写入到~/.android/adb_usb.ini文件
Adb devices确认能找到手机设备
配置库路径,先录一个视频看看效果
export LD_LIBRARY_PATH=/mnt/scrcpy/lib:/mnt/ffmpeg/lib
./scrcpy -N -m 800 -b 1M --max-fps 15 --rotation
1 --window-height 480 --window-width 800 -r scr_test.mp4
三. rtl8723bs wifi模块
为了给tf留sdc0的接口,把它焊接到sdc1位置。
按照一般的做法就能正常使用,没有什么需要特别注意的地方
1. linux make menuconfig选择drivers/ staging里面的rtl8723bs
2. buildroot下面的wpa_supplicant工具,
3. 然后make,刷rootfs或者直接拷贝相关文件到sd卡,rtl8723bs_nic.bin到/lib/firmware/rtlwifi/目录下。
4. 愉快地运行起来:
修改wpa_supplicant.conf里面的ssid和psk
insmod /lib/modules/4.13.0-licheepi-zero\+/kernel/drivers/staging/rtl8723bs/r8
723bs.ko
ifconfig wlan0 up
./wpa_supplicant -Dnl80211 -iwlan0 -c /root/rtl8723/wpa_supplicant.conf -B
udhcpc -iwlan0 &
[ 873.649642] RTL8723BS: nolinked power save leave
[ 875.646510] RTL8723BS: rtw_set_802_11_connect(wlan0) fw_state = 0x00000008
# [ 875.960288] RTL8723BS: start auth
[ 876.017289] RTL8723BS: auth success, start assoc
[ 876.052762] RTL8723BS: rtw_cfg80211_indicate_connect(wlan0) BSS not found !!
[ 876.059904] RTL8723BS: assoc success
# [ 877.599630] RTL8723BS: rtw_tkip_decrypt(wlan0) no_gkey_bc_cnt:9, no_gkey_mc_cnt:0
[ 878.170886] RTL8723BS: send eapol packet
[ 878.199958] RTL8723BS: send eapol packet
[ 878.204510] RTL8723BS: set pairwise key camid:4, addr:28:6c:07:6c:b1:3a, kid:0, type:AES
[ 878.217725] RTL8723BS: set group key camid:5, addr:28:6c:07:6c:b1:3a, kid:1, type:TKIP
[ 878.226179] RTL8723BS: rtw_tkip_decrypt(wlan0) gkey installed. no_gkey_bc_cnt:2, no_gkey_mc_cnt:0
# udhcpc: sending discover
udhcpc: sending select for 192.168.31.197
udhcpc: lease of 192.168.31.197 obtained, lease time 43200
deleting routers
adding dns 192.168.31.1
烧录文件:
licheepi zeros,密码用户名:root和licheepi
16M spi flash
800*480屏幕
七.遥控器搞起
玩游戏肯定少不了手柄,本来想用一个有线usb手柄,但是作为一个精益求精的玩家,这个长线是不能接受的,所以决定搞一个无线手柄。
1.在某宝买了一个无线2.4G游戏手柄,在windows下免驱的,
估计在zeros的linux上也有相关驱动,果然,在linux目录能找到相关驱动 ~/linux/drivers/hid/hid-dr.c
小技巧:插入电脑上找到设备管理器,属性,就能看到VID和PID号,查找一下驱动目录就能找到相对于的设备商。我买的遥控器是DragonRise Inc. game
controllers
在~/linux/drivers/hid/hid-core.c 添加PID号 0x181c
#if IS_ENABLED(CONFIG_HID_DRAGONRISE)
{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x181c) },
#endif
2. linux menuconfig
> Device Drivers > Input device support
<*> Joystick interface
[x] Joysticks/Gamepads --->
> Device Drivers > HID support > Special HID drivers
<*> DragonRise Inc. game controller
3. 在InfoNes文件joypad_input.cpp 修改键值
看实际情况,ABXY,左右上下,start,select
/**
* FC手柄 bit 键位对应关系 真实手柄中有一个定时器,处理 连A 连B
* 0 1 2 3 4 5 6 7
* A B Select Start Up Down Left Right
*/
4.烧录完内核后,接上usb转接器,插上无线手柄接收器,愉快的玩起来。
[ 26.946678] usb 2-1: new full-speed USB device number 4 using ohci-platform
[ 27.213391] input: TGZ Controller as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.0/0003:0079:181C.0005/input/input6
[ 27.224832] dragonrise 0003:0079:181C.0005: input: USB HID v1.11 Gamepad [TGZ Controller] on usb-1c1a400.usb-1/input0
[ 27.240256] input: TGZ Controller as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:0079:181C.0006/input/input7
[ 27.316983] dragonrise 0003:0079:181C.0006: input: USB HID v1.11 Device [TGZ Controller] on usb-1c1a400.usb-1/input1
# ls /dev/input/js0
/dev/input/js0
---- 继续 ----
六.声音调试:
1. 下载tinyalsa git clone https://github.com/tinyalsa/tinyalsa.git
修改makefile的交叉编译工具链,make 生成几个文件
拷贝到sd卡,执行命令:
# ./tinymix set 1 63
# ./tinymix set 2 1
# ./tinymix contents
因为只买了核心板,没有耳机孔,根据官方的原理图飞了一个滤波电路.
第1,3,5,7脚分别是HP_COM,HP_COMFB, HP_L, HP_R
./tinyplay SoundTest.wav
插上音响,可以听到清晰的声音。
下一步,将InfoNes的声音补上。
一.硬件准备工作:
1.lichee pi zero主板一块
2.无线手柄2.4g一个
3.屏幕800x480
4.xt25f128b spiflash一块,焊接到板子上。(不用sd启动,看着别扭)
二.软件准备工作:
1.参考各个大神文章,uboot,linux,buildroot
简单说明一下需要修改的地方:
u-boot:
include/configs/sun8i.h
#define CONFIG_BOOTCOMMAND "sf probe 0:0 6000000; " \
"sf read 0x41800000 0x80000 0x4000; " \
"sf read 0x41000000 0x90000 0x470000;" \
"bootz 0x41000000 - 0x41800000;"
#define CONFIG_BOOTARGS "console=ttyS0,115200 earlyprintk panic=5 rootwait
mtdparts=spi32766.0:512k(uboot),64k(dtb)ro,4544k(kernel)ro,-(rootfs) root=/dev/mtdblock3 rw rootfstype=jffs2 init=/linuxrc
vt.global_cursor_default=0"
/u-boot/drivers/mtd/spi/spi_flash_ids.c
{"xt25f128b", INFO(0x0b4018, 0x0, 64 * 1024, 256, RD_FULL | WR_QPP | SECT_4K) },
2. linux:
dts:
&spi0 {
status ="okay";
xt25f128b:xt25f128b@0 {
compatible = "jedec,spi-nor";
reg = <0x0>;
spi-max-frequency = <50000000>;
#address-cells = <1>;
#size-cells = <1>;
};
/linux/drivers/mtd/devies/m25p80.c
搜jedec 在最后增加xt25定义
{"w25q80bl"}, {"w25q128"}, {"w25q256"}, {"xt25f128b"}
3. /linux/drivers/mtd/spi-nor
flash_info spi_nor_ids[]中
{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, 0) },
{ "xt25f128b", INFO(0x0b4018, 0, 64 * 1024, 256, 0) },
menuconfig:
- 加入SPI Flash的支持
Device Drivers --->
<x> Memory Technology Device (MTD) support --->
<x> Command line partition table parsing (用以支持命令行参数 mtdparts=spi0.0:512k(uboot)ro, … )
<x> Caching block device access to MTD devices
<x> SPI-NOR device support --->
[ ] Use small 4096 B erase sectors (取消这个选型,否则jffs2文件系统会报错)
- 加入jffs2文件系统支持
File systems --->
[x] Miscellaneous filesystems --->
<x> Journalling Flash File System v2 (JFFS2) support
(0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
[x] JFFS2 write-buffering support
[ ] Verify JFFS2 write-buffer reads
[ ] JFFS2 summary support
[ ] JFFS2 XATTR support
[ ] Advanced compression options for JFFS2
4.编译:(u-boot,linux)
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j2
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
生成的文件:
$ ls -lh arch/arm/boot/zImage
-rwxrwxr-x 1 xlee xlee 4.2M Apr 23 10:41 arch/arm/boot/zImage
$ ls -lh arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dtb
-rw-rw-r-- 1 xlee xlee 12K Apr 22 23:33 arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dtb
5.build-root
ls -l ~/buildroot-2017.08/output/images/rootfs.tar
tar 解压rootfs.tar到目录rootfs_20200820/
拷贝linux下的lib(包含module)文件夹内容到此目录,也可以添加用同样的编译编译出来的一些程序,比如InfoNes文件等
mkfs.jffs2 -s 0x100 -e 0x10000 --pad=0xAF0000 -d rootfs_20200820/ -o rootfs.jffs2
三:烧录
下载sunxi-fel 编译直接在ubuntu上烧
分区如下:
0~0x80000 uboot
0x80000~ 0x90000 dtb
0x90000~ 0x500000 zImage
0x50000~ 16M rootfs.jffs2
短接板子spi的cs脚和地
烧录命令跑起来:
$sudo ./sunxi-fel -p spiflash-write 0 u-boot-sunxi-with-spl.bin
$sudo ./sunxi-fel -p spiflash-write 0x80000 sun8i-v3s-licheepi-zero-dock.dtb
$sudo ./sunxi-fel -p spiflash-write 0x90000 zImage
$sudo ./sunxi-fel -p spiflash-write 0x500000 rootfs.jffs2
四: 编译InfoNes
下载源码:https://github.com/nejidev/arm-NES-linux
在linux目录下修改Makefile:编译器,alsa(暂时去掉)
编译完的InfoNes拷贝到rootfs_20200820,重新生成rootfs.jffs2,
或者拷贝到sd卡,用挂载mount /dev/mmcblk0p1 /mnt/拷贝文件到板子
再到网上下载nes游戏,拷贝到sd卡
愉快的运行起来。
五: 待解决问题:
1.声音
2.遥控器
按照上面的步骤,添加了驱动,能找到wlan0,就是连不上网络。。。
帮忙看看问题
wlan0: State: DISCONNECTED -> DISCONNECTED
# ifconfig wlan0 up
# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
tunl0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP RUNNING NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr AC:D0:74:D1:E4:38
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
#
# vi /etc/wpa_supplicant.conf
#
# wpa_supplicant -B -i wlan0 -dd -c /etc/wpa_supplicant.conf
wpa_supplicant v2.6
random: Trying to read entropy from /dev/random
Successfully initialized wpa_supplicant
Initializing interface 'wlan0' conf '/etc/wpa_supplicant.conf' driver 'default' ctrl_interface 'N/A' bridge 'N/A'
Configuration file '/etc/wpa_supplicant.conf' -> '/etc/wpa_supplicant.conf'
Reading configuration file '/etc/wpa_supplicant.conf'
ctrl_interface='/var/run/wpa_supplicant'
ap_scan=1
Line: 4 - start of a new network block
ssid - hexdump_ascii(len=5):
45 4c 45 50 4e ELEPN
PSK (ASCII passphrase) - hexdump_ascii(len=12): [REMOVED]
key_mgmt: 0x2
PSK (from passphrase) - hexdump(len=32): [REMOVED]
Priority group 0
id=0 ssid='ELEPN'
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
nl80211: Supported cipher 00-0f-ac:2
nl80211: Supported cipher 00-0f-ac:4
nl80211: Using driver-based off-channel TX
nl80211: Driver-advertised extended capabilities (default) - hexdump(len=8): 00 00 00 00 00 00 00 40
nl80211: Driver-advertised extended capabilities mask (default) - hexdump(len=8): 00 00 00 00 00 00 00 40
nl80211: interface wlan0 in phy phy0
nl80211: Set mode ifindex 4 iftype 2 (STATION)
nl80211: Subscribe to mgmt frames with non-AP handle 0x9eb90
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=06
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=0a07
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=0a11
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=1101
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=1102
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=0505
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x9eb90 match=0500
rfkill: initial event: idx=0 type=1 op=0 soft=0 hard=0
netlink: Operstate: ifindex=4 linkmode=1 (userspace-control), operstate=5 (IF_OPER_DORMANT)
Add interface wlan0 to a new radio phy0
nl80211: Regulatory information - country=00
nl80211: 2402-2472 @ 40 MHz 20 mBm
nl80211: 2457-2482 @ 20 MHz 20 mBm (no IR)
nl80211: 2474-2494 @ 20 MHz 20 mBm (no OFDM) (no IR)
nl80211: 5170-5250 @ 80 MHz 20 mBm (no IR)
nl80211: 5250-5330 @ 80 MHz 20 mBm (DFS) (no IR)
nl80211: 5490-5730 @ 160 MHz 20 mBm (DFS) (no IR)
nl80211: 5735-5835 @ 80 MHz 20 mBm (no IR)
nl80211: 57240-63720 @ 2160 MHz 0 mBm
nl80211: Added 802.11b mode based on 802.11g information
wlan0: Own MAC address: ac:d0:74:d1:e4:38
wpa_driver_nl80211_set_key: ifindex=4 (wlan0) alg=0 addr=(nil) key_idx=0 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=4 (wlan0) alg=0 addr=(nil) key_idx=1 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=4 (wlan0) alg=0 addr=(nil) key_idx=2 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=4 (wlan0) alg=0 addr=(nil) key_idx=3 set_tx=0 seq_len=0 key_len=0
wlan0: RSN: flushing PMKID list in the driver
nl80211: Flush PMKIDs
wlan0: Setting scan request: 0.100000 sec
EAPOL: SUPP_PAE entering state DISCONNECTED
EAPOL: Supplicant port status: Unauthorized
nl80211: Skip set_supp_port(unauthorized) while not associated
EAPOL: KEY_RX entering state NO_KEY_RECEIVE
EAPOL: SUPP_BE entering state INITIALIZE
EAP: EAP entering state DISABLED
wlan0: Added interface wlan0
wlan0: State: DISCONNECTED -> DISCONNECTED
nl80211: Set wlan0 operstate 0->0 (DORMANT)
netlink: Operstate: ifindex=4 linkmode=-1 (no change), operstate=5 (IF_OPER_DORMANT)
Daemonize..
#
#