2021年3月1日星期一

List Device Tree in Linux (embedded system)

The device tree is located at

cd /proc/device-tree/

lrwxrwxrwx   device-tree -> /sys/firmware/devicetree/base


Install tree package to view the device tree hierarchy


further investigate the content

plain text file: cat (file)

hex file: hexdump -C (file)

Acts as client(WiFi STA) in OpenWRT, connect and download the package when luci haven't installed

Quick config device
wifi config

Enable wlan0
In /etc/config/wireless,
option disabled '0'

Turn on wlan0
wifi up

Turn off wlan0
wifi down

Scan AP
iw wlan0 scan

Connect to AP
In /etc/config/wireless,
config wifi-iface 'wifinet0'
option ssid 'my_ap'
option device 'radio0'
option mode 'sta'
option network 'my_wlan'
option key 'my_password'
option encryption 'psk2' #AP encryption mode

In /etc/config/network,
config interface 'my_wlan'
option proto 'dhcp'
service network restart

Add devmem in OpenWRT

make menuconfig

1) Select Global build settings

2) Select Kernel build options

3) Select [*] /dev/mem virtual device support

4) Return to main menu

5) select Base System

6) select <*> busybox

7) select <*>Customize busybox options

8) select Miscellaneous Utilities

9) select <*> devmem (2.5 kb)


Usage: devmem ADDRESS [WIDTH [VALUE]]

Read/write from physical address

    ADDRESS Address to act upon, for example 0x????????
    WIDTH   Width (8/16/...)
    VALUE   Data to be written, for example 0x????????


read 32bit register: devmem address

read 16bit register: devmem address 16

read 8bit register: devmem address 8

write 32bit register: devmem address 32 value

write 16bit register: devmem address 16 value

write 8bit register: devmem address 8 value


alias grep

alias grepc='grep --include=\*{h,c,cpp}'

alias grepdts='grep --include=\*{dts,dtsi}'

 

List board information in Linux

#!/bin/bash

RED='\033[0;31m'
NC='\033[0m'    # No Color

echo -e "${RED}====uanme====${NC}"
uname -a

for info in cpuinfo meminfo devices interrupts dma filesystems ioports
do
    echo -e "${RED}===='$info'=====${NC}"
    cat /proc/$info
done

echo -e "${RED}====lsmod====${NC}"
lsmod



2021年2月26日星期五

OpenWRT basic configuration

Enable HDMI in rpi 2:

In target/linux/brcm2708/image/config.txt, hdmi_safe=1


During first start, the device is set to 'static IP mode' (192.168.1.1)

Recommend to change the DHCP network IP pool, range starts from 192.168.1.20


Config gateway and DNS to download the package:

In vi /etc/config/network (default static IP),

#router gateway IP

option gateway '192.168.1.XXX'

#config DNS

list dns '8.8.8.8'

or change to use dhcp client instead of static IP to download / update the opkg package.


Check network connection:

ping 8.8.8.8 to check whether the gateway is config properly.

ping www.openwrt.org to check whether the DNS is setup properly.


2017年8月13日星期日

tmux shortcut key

General Operation:
ctrl-b ? List combination key, press q to quit
ctrl-b x Exit curent panel / window

Panel Operation:
ctrl-b % Split panel (horziontal)
ctrl-b “ Split panel (vertical)
ctrl-b (arrow key) Switch panel
ctrl-b ctrl-(arrow key) Adjust panel size per 1 unit
ctrl-b alt-(arrow key) Adjust panel size per 5 unit
ctrl-b z Maximize current panel (restore to original panel size if issue this key again)
ctrl-b (page up | page down) Scroll up / scroll down
ctrl-b alt-o Rotate panel clockwise
ctrl-b ctrl-o Rotate panel anti-clockwise

Window Operation:
ctrl-b c Create window
ctrl-b , Rename window
ctrl-b . Rename window ID
ctrl-b (num key) Switch window according to window ID
ctrl-b p Switch to previous window
ctrl-b n Switch to next window

apt-get install is locked

https://askubuntu.com/questions/15433/unable-to-lock-the-administration-directory-var-lib-dpkg-is-another-process 
 
sudo apt-get install ???
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
 
Issue below command to solve the problem: 
$sudo rm /var/lib/apt/lists/lock

2017年8月8日星期二

Build Android from Source

1) Establish build environment
https://source.android.com/source/initializing

Ubuntu-16.04 64bit in VirtualBox
Increase swap size if system memory is small (e.g.: 3GB system memory with 18GB swap)
Recommend 180GB or above disk space

$sudo apt-get update
$sudo apt-get install openjdk-8-jdk

$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 lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip

[ Optional ] Install openjdk-7 for old ver AOSP (e.g. 5.x - lollipop)
$sudo add-apt-repository ppa:openjdk-r/ppa
$sudo apt-get update
$sudo apt-get install openjdk-7-jdk
$sudo update-java-alternatives -l
##set jname
$sudo update-java-alternatives -s java-1.7.0-openjdk-amd64

2) Download the source
https://source.android.com/source/downloading

$mkdir ~/bin
$PATH=~/bin:$PATH

$curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$chmod a+x ~/bin/repo 

$mkdir -p android
$cd android
$git config --global user.name "Your Name"
$git config --global user.email "you@example.com"
$repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r27
$repo sync

[ Remark] Please ignore the following error message:
*curl: (22) The requested URL returned error: 404* *Server does not provide clone.bundle; ignoring.*

3) Preparing to Build
https://source.android.com/source/building

$. build/envsetup.sh

[ Remark ] Increase heap size to avoid the following error message.
Cannot connect to jack-server / heap size is small.
$export PATH=$PATH:~/.jack-server
$export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
$./prebuilts/sdk/tools/jack-admin kill-server
$./prebuilts/sdk/tools/jack-admin start-server


[ Remark ] Apply the patch first if using lolllipop version:
https://stackoverflow.com/questions/36048358/building-android-from-sources-unsupported-reloc-43/36073635

[Remark] Remember to clean the project after the makefile (*.mk) or configuration is changed
$make clean

$lunch
$make -j4


[ Remark ] Since pre-built libwebviewchromium.so module does NOT exist in the lollipop or previous version, it takes long time to build this module.

After success, the img can be found at:
<aosp>/out/target/product/<target>/