2018年12月3日星期一

Dump QEMU virt machine dts

 Commands:

qemu-system-aarch64 -machine virt,dumpdtb=/tmp/virt.dtb
dtc -I dtb -O dts /tmp/virt.dtb >/tmp/virt.dts 

Example:

/dts-v1/;

/ {
interrupt-parent = <0x8001>;
#size-cells = <0x2>;
#address-cells = <0x2>;
compatible = "linux,dummy-virt";

platform@c000000 {
interrupt-parent = <0x8001>;
ranges = <0x0 0x0 0xc000000 0x2000000>;
#address-cells = <0x1>;
#size-cells = <0x1>;
compatible = "qemu,platform", "simple-bus";
};

2018年10月25日星期四

binutils nm


"A"
The symbol's value is absolute, and will not be changed by further linking.
"B"
"b"
The symbol is in the uninitialized data section (known as BSS ).
"C"
The symbol is common. Common symbols are uninitialized data. When linking, multiple common symbols may appear with the same name. If the symbol is defined anywhere, the common symbols are treated as undefined references.
"D"
"d"
The symbol is in the initialized data section.
"G"
"g"
The symbol is in an initialized data section for small objects. Some object file formats permit more efficient access to small data objects, such as a global int variable as opposed to a large global array.
"i"
For PE format files this indicates that the symbol is in a section specific to the implementation of DLLs. For ELF format files this indicates that the symbol is an indirect function. This is a GNU extension to the standard set of ELF symbol types. It indicates a symbol which if referenced by a relocation does not evaluate to its address, but instead must be invoked at runtime. The runtime execution will then return the value to be used in the relocation.
"N"
The symbol is a debugging symbol.
"p"
The symbols is in a stack unwind section.
"R"
"r"
The symbol is in a read only data section.
"S"
"s"
The symbol is in an uninitialized data section for small objects.
"T"
"t"
The symbol is in the text (code) section.
"U"
The symbol is undefined.
"u"
The symbol is a unique global symbol. This is a GNU extension to the standard set of ELF symbol bindings. For such a symbol the dynamic linker will make sure that in the entire process there is just one symbol with this name and type in use.
"V"
"v"
The symbol is a weak object. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error. On some systems, uppercase indicates that a default value has been specified.
"W"
"w"
The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the symbol is determined in a system-specific manner without error. On some systems, uppercase indicates that a default value has been specified.
"-"
The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the stabs desc field, and the stab type. Stabs symbols are used to hold debugging information.
"?"
The symbol type is unknown, or object file format specific.

2018年10月18日星期四

在Vive Focus上安装2D App

Vive Focus作为一款一体机VR设备,质感还不错。不过由于生态的问题,可用的内容并不多。
如果能引入Android生态中的2D应用感觉会好一些。
但是,截至到目前,消费者版的Vive Focus还不支持2D应用。
具体表现为:可以通过adb install安装APK,但是在home中并没有相应的图标。这样也就无法启动了。当然,可以通过adb shell am start来进行启动,但是每次都要借助PC,还要记包名,就比较痛苦了。
思来想去,决定采用一个比较迂回的方式来解决。
先寻找一个比较简单的2d launcher。
然后通过一个AndroidManifest中包含<category android:name="com.htc.intent.category.VRAPP" />的应用来发送Intent启动之前安装的2d launcher。
实际弄了之后,效果还不错。

Launcher实在github上面找到的一个非常简洁实用的优秀开源项目:
https://github.com/arnabc/simplelauncher
如果想要自己编译的话,可能需要稍微修改一下androidmanifest
<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <!-- The following two intent-filters are the key to set homescreen    <category android:name="android.intent.category.HOME" />    <category android:name="android.intent.category.DEFAULT" />     -->    <category android:name="android.intent.category.LAUNCHER" />
将主activity的HOME 和 DEFAULT注释掉,添加LAUNCHER。不改可能也行。
感兴趣的同学可以自己试试。
懒得自己编的:https://github.com/SimonTheCoder/simplelauncher/releases/download/init_test/SimpleLauncher-debug.apk

用作启动器的VR应用直接使用了wave vr sdk中的wvr_hellovr。
下载:https://github.com/SimonTheCoder/simplelauncher/releases/download/init_test/app-debug.apk

这个代码稍微有一些改动,就是在hellovr.cpp里面的moveSphereHandler中添加了一个发送intent的反向JNI调用
懒得往git上传了。如果需要的人多的话再说吧。

使用方法:
下载或者编译上面两个apk。
adb install安装之。
启动wvr_hellovr,点击场景中的大球,即可启动simplelauncher。

之后再装个moonlight,工作正常哦!惊不惊喜,意不意外?
https://github.com/moonlight-stream/moonlight-android/releases

2018年10月11日星期四

从命令行手动启动X + xfce4 + fcitx

在更新了ubuntu 18.04之后,由于桌面从unity切回到了gnome。导致window manager也切回了gdm。
之前一直在用xfce4,在更新之后系统直接进入tty0。X Window不启动,自然也就没有桌面环境。
下面是手动启动方法:

准备配置:

进入用户目录:

cd ~

编辑x client启动脚本: 

vi .xinitrc

在脚本中加入如下内容:

export XIM=fcitx
export XIM_PROGRAM=/usr/bin/fcitx
export XIM_ARGS=""
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
export DEPENDS="fcitx"
exec startxfce4
保存并关闭。(vim 命令: “:wq” )

启动X Window:

每次启动后,进入终端,执行startx启动图形系统:
startx

扩展应用:

在Ubuntu中,使用ctrl + alt + F[1-8]来进入tty。使用上面方法可以同时开几个桌面了。同时使用KDE、GNOME、Xfce4是完全可以的。
不过chrome会自动启动到第一个task所在的display。估计需要手动指定display后再启动。

2018年2月10日星期六

WSL tty

优势:
  • 支持中文。默认为utf-8。
  • 支持方向键。
  • 支持vim中方向键。中文也没有问题。
  • 支持颜色。
  • 支持搜索。
  • 支持copy/paste。不过按键是 Ctrl + Ins/Shift + Ins。
  • 速度相当快。
  • .bashrc运行OK。
  • .vimrc运行OK。
  • tmux支持良好。

劣势:
  • 不支持多tab
  • 不支持分屏
  • 快捷键不能更改。
  • 工作时没有ConEmu的那种进度条。

Github
https://github.com/mintty/wsltty



直接在release 中下载最新版,安装即可。目前看来并没有build from source 的需要。

2017年12月26日星期二

Selenium + ChromeDriver + Xvfb run on ubuntu server without X11

Install Chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
apt-get update
apt-get install -f
Install pip
apt-get install python-pip
Install Selenium
export LC_ALL=C
pip install selenium 
Install Xvfb
apt-get install xvfb
Download ChromeDriver
wget https://chromedriver.storage.googleapis.com/2.34/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
 Run Xvfb
Xvfb :22

Test selenium
attention: google chrome will crash if running under root user. Switch user first  if your are root.
export DISPLAY=:22
python
from selenium import webdriver
driver = webdrvier.Chrome("./chromedriver")
driver.get("http://www.baidu.com")

#should return https protocl url
driver.execute_script("return window.location")

#should return an element
driver.execute_script("return document.getElementById('kw')")


2017年7月12日星期三

[FAILED] ubuntu 16.04 上使用 TP-LINK WN725N 免驱版 无线网卡

该网卡使用MTK 7601u芯片。虽然型号也叫WN725N,但是和之前的WN725N根本就不是一个东西。。。是的,除了生产厂家以及都是黑色USB无线网卡以外,二者没有任何共同点。
插到机器上之后,lsusb显示为:
Bus 003 Device 006: ID 148f:2878 Ralink Technology, Corp.

系统将之挂载为一个cdrom。在Windows上,可以直接使用里面的安装程序进行驱动安装。
并将网卡模式切换为无线网卡模式。

在Ubuntu上,为了切换模式,参考了usb_modeswitch的data文件:
# RaLink MT7601U
TargetVendor=0x148f
TargetProduct=0x7601
StandardEject=1

是的,只要进行eject即可。。。
可直接执行:
sudo eject /dev/sr0
或者
sudo usb_modeswitch -v 148f -p 2878 -K

之后lsusb,等待一下,即可观察到:
Bus 003 Device 007: ID 148f:7601 Ralink Technology, Corp. MT7601U Wireless Adapter

其实这个等待的时间,是系统正在使用自带mt7601驱动尝试probe网卡。

[  589.049149] usb 3-11: reset high-speed USB device number 7 using xhci_hcd
[  589.179614] mt7601u 3-11:1.0: ASIC revision: 76010001 MAC revision: 76010500
[  589.180380] mt7601u 3-11:1.0: Firmware Version: 0.1.00 Build: 7640 Build time: 201302052146____
[  592.645071] mt7601u 3-11:1.0: Vendor request req:07 off:09a8 failed:-110
[  595.764998] mt7601u 3-11:1.0: Vendor request req:02 off:09a8 failed:-110
[  598.884833] mt7601u 3-11:1.0: Vendor request req:07 off:0734 failed:-110
[  602.004776] mt7601u 3-11:1.0: Vendor request req:42 off:0230 failed:-110
[  605.124673] mt7601u 3-11:1.0: Vendor request req:07 off:0080 failed:-110
[  608.244542] mt7601u 3-11:1.0: Vendor request req:02 off:0080 failed:-110
[  611.364455] mt7601u 3-11:1.0: Vendor request req:02 off:0080 failed:-110
[  611.364489] mt7601u: probe of 3-11:1.0 failed with error -110
[  611.364526] usbcore: registered new interface driver mt7601u

可以看到,probe最终失败了。应该是网卡驱动(分析代码后发现,也可能是firmware)和该型号网卡不匹配。
参照https://askubuntu.com/questions/457061/ralink-mt7601u-148f7601-wi-fi-adapter-installation
手动安装驱动。
sudo apt-get install linux-headers-generic build-essential git

git clone https://github.com/art567/mt7601usta.git

cd mt7601usta/src

make

sudo make install

sudo mkdir -p /etc/Wireless/RT2870STA/

sudo cp RT2870STA.dat /etc/Wireless/RT2870STA/

sudo modprobe mt7601Usta

注意:考虑到之前的驱动已经加载,在执行modprobe之前,应该考虑先将之前的驱动rmmod掉。(实际尝试后发现然并卵。)
系统默认驱动信息:

modinfo mt7601u
filename:       /lib/modules/4.4.0-81-generic/kernel/drivers/net/wireless/mediatek/mt7601u/mt7601u.ko
license:        GPL
firmware:       mt7601u.bin
srcversion:     C4F802D4D12C5BC2BA7FEB7
alias:          usb:v7392p7710d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v2A5Fp1000d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v2955p1001d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v2955p0001d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v2717p4106d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v2001p3D04d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v148Fp760Dd*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v148Fp760Cd*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v148Fp760Bd*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v148Fp760Ad*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v148Fp7601d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v13D3p3434d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v13D3p3431d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0E8Dp760Bd*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0E8Dp760Ad*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0B05p17D3d*dc*dsc*dp*ic*isc*ip*in*
depends:        mac80211,cfg80211
intree:         Y
vermagic:       4.4.0-81-generic SMP mod_unload modversions


modprobe执行之后,可以查看sudo lshw -C net
  *-network DISABLED
       description: Wireless interface
       physical id: 2
       logical name: ra0
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=RALINK WLAN multicast=yes wireless=Ralink STA

可见系统已经可以识别该网卡,但网络处于disable状态。可能和我机器系统本身有关。在dmesg中可以看到
[ 1108.702033] ModemManager[925]: segfault at 0 ip 0000000000431ab3 sp 00007fffc062e940 error 4 in ModemManager[400000+
103000]

接下来尝试使用ifconfig强行up  ra0

sudo ifconfig ra0 up

命令长时间没有反应

尝试将Ubuntu升级至 17.04,效果依旧。估计要深入分析驱动代码,太浪费时间。同时考虑到未来内核升级也要重新手动修改驱动,用户体验难以接受。决定放弃尝试。

================================================================
最终解决方案:
又购买了普通版本TL-WN725N(更小更便宜),未做任何配置,插在机器上,瞬间完成驱动。
教训:一分钱一分货是不假,但在linux的世界里,性价比才是最安全的标准。