2021年3月1日星期一

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>/

2017年6月11日星期日

Display the raw FAT32 file structure

Display the raw FAT32 file structure
Only show valid content (Skip zero-filled sector)

const TCHAR devicePath[] = TEXT("\\\\.\\K:");  //Specific the devicePath.
const DWORD addrBegin = 0;                              //Specific the addrBegin. (512 byte aligned)
const DWORD addrEnd = 128*1024*1024;        //Specific the addrEnd (512 byte aligned)

Tested on removable disk only.
Might not work or require administrator right if it is a non-removable disk.

Press 'x' to break the scan progress.



2017年3月10日星期五

Frequency Used GDB commands


set args set arguments
show args show arguments
Run
(or gdb –args <program> <args...>)
run with argument(if previous was set by "set args")


load load the program
attach process-id
(or gdb –pid <pid>)
debug an already running process
detach release the previous attached process


symbol-file filename Read symbol table information from file filename
i threads Display thread
i share Print the names of the shared libraries which are currently loaded


c continue
b add breakpoint
w add watchpoint
s step
n next
si step instruction


info all-registers show all registers
i r same as info registers
i r rax display register rax value (HEX)


p/x $rax display register rax value (HEX)
p/d $rax display register rax value (signed DEC)
p/u $rax display register rax value (unsigned DEC)
p/t $rax display register rax value (BIN)
p/f $rax display register rax value (Floating point number)
p/c $rax display register rax value (CHAR)


p/a $rip display register rip value (ADDRESS)
x /i $pc print next instruction to be executed


p *array@len display array content
p/x (short[2])0x12345678 display array content
x /256xb mem examine memory, 256=repeat count, x=hex, {b=byte, h=2bytes,w=4bytes,g=8bytes}
set *((int *) mem) = value set memory content (char, short, int, long, long long)
set *((char *) reg) = *((char *) reg) | 0x80 set peripheral register bit
set *((char *) reg) = *((char *) reg) & (~0x80) clear peripheral register bit


l filename:function list the source in the filename:function
l function list the source in function
l + list more
l - list less


bt backtrace
f n select frame number n


set $f00=*object_ptr set convenience variable
show convenience show convenience variable
source gdbscriptFile load GDB script file
define print_vars
p var1
p var2
end
create GDB function


disas view disassemble