Setup Development Environment on Phicomm T1

2 minute read

Basic Setup

# change apt source
sed -i s/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list
sed -i s/apt.armbian.com/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list.d/armbian.list

sudo apt install file -y
sudo apt install adb fastboot -y

# ejct usb drive
sudo apt install eject

# for ripgrep building
sudo apt install cargo -y

# rg
sudo apt install ripgrep

#fd
sudo apt install fd-find

# python
sudo apt install python3-pip -y
sudo apt install python3-usb

# kernel menuconfig
sudo apt install libncurses5-dev -y

# errno
sudo apt install moreutils -y

sudo apt install tio
sudo apt install telnet

# docker
sudo apt install docker.io -y
sudo apt install docker-compose -y

sudo apt install strace
sudo apt install trace-cmd
sudo apt install bpfcc-tools -y

ssh

scp ~/.ssh/id_rsa.pub 192.168.1.21:~/.ssh/authorized_keys

hosts

echo '151.101.56.133 raw.githubusercontent.com' >> /etc/hosts

v2ray

# wget -c https://install.direct/go.sh
# wget -c https://gh.api.99988866.xyz/github.com/v2fly/v2ray-core/releases/download/v4.26.0/v2ray-linux-arm64.zip
sudo bash go.sh -l /opt/ubuntu/v2ray-linux-arm64.zip
export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

oh-my-zsh

sudo apt install zsh -y
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git config --global oh-my-zsh.hide-status 1

fzf

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

git config

git config --global url."https://gh.api.99988866.xyz/github.com/".insteadof https://github.com

install git

The git installed by default has issue

# remove git
sudo apt install git-
Removing git (1:2.27.0-1) ...

# build from source
wget -c https://github.com/git/git/archive/v2.27.0.tar.gz
tar xvf v2.27.0.tar.gz
sudo apt install libz-dev
sudo apt install libcurl4-gnutls-dev -y
sudo apt install libexpat1-dev
sudo apt install tclsh
sudo apt install gettext -y
sudo make prefix=/usr/local install -j9

rg

git clone --depth=1 https://github.com/BurntSushi/ripgrep
cd ripgrep
cargo build --release
./target/release/rg --version
ripgrep cp ./target/release/rg ~/.local/bin```

vim

curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh
cd $HOME/.spf13-vim-3
git pull
vim +BundleInstall! +BundleClean +q

cat << EOT >>  ~/.vimrc.local
" Quik close and save
map <leader>q :q<cr>
map <leader>a :qa<cr>
map <leader>x :x<cr>
map <leader>w :w<cr>

map <leader>tn :tabnew
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>to :tabonly<cr>
map <leader>tf :tabfirst<cr>

" Disable scrolloff, whichwrap etc
set whichwrap=
set scrolloff=0
set scrolljump=0
EOT

cat << EOT >>  ~/.vimrc.before.local
" Do not switch to the current file directory
let g:spf13_no_autochdir = 1
EOT

udev rule for phicomm box in fastboot mode:

cat << EOT >>  /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="18d1", ATTR{idProduct}=="0d02", MODE:="0666"
EOT
sudo udevadm control -R

oom

# for some memory hungry jobs
sudo dd if=/dev/zero of=/opt/swapfile bs=1024 count=2M
sudo mkswap /opt/swapfile
sudo swapon /opt/swapfile

Build kernel

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j9 lineageos_rpi3b_kcov_defconfig

syzkaller

wget -c https://dl.google.com/go/go1.14.6.linux-arm64.tar.gz
tar -xf go1.14.6.linux-arm64.tar.gz
mkdir -p $HOME/go/gopath
mv go $HOME/go/goroot

export GOPATH=$HOME/go/gopath
export GOROOT=$HOME/go/goroot
export PATH=$GOPATH/bin:$PATH
export PATH=$GOROOT/bin:$PATH

go get -u -d github.com/google/syzkaller/prog
cd $GOPATH/src/github.com/google/syzkaller/
make TARGETOS=linux TARGETARCH=arm64

cat << EOT >> android.cfg
{
	"target": "linux/arm64",
	"http": "192.168.1.21:56789",
	"workdir": "/home/fdbai/go/gopath/src/github.com/google/syzkaller/workdir",
	"kernel_obj": "/opt/kernel/kernel_rpi/",
	"syzkaller": "/home/fdbai/go/gopath/src/github.com/google/syzkaller",
	"sandbox": "none",
	"procs": 8,
	"type": "adb",
	"cover": true,
	"vm": {
		"devices": ["192.168.1.7:5555"],
		"timeout": 120,
		"battery_check": false
	}
}
EOT

# happy kernel fuzzing
./bin/syz-manager -config=android.cfg -debug

minicom

sudo apt install minicom

cat << EOT >> .minirc.dfl
pu port             /dev/ttyUSB0
EOT

# CTRL a, x to exit minicom
minicom -D /dev/ttyUSB0

Rotate journal logs

sudo journalctl --rotate --vacuum-size=30M

agent-proxy

git clone --depth 1 https://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
cp agent-proxy ~/.local/bin
agent-proxy 4440^4441 0 /dev/ttyUSB0,115200

GNU screen

cat << EOT >> .screenrc
# Turn off that annoying start up message
startup_message off

# scrolling with mouse
termcapinfo xterm* ti@:te@

hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
EOT

Configure pip to use mirror

mkdir $HOME/.pip
cat << EOT >> $HOME/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
EOT