2021年3月2日星期二

Test devmem in rpi2 by shell script

#!/bin/bash

#Test devmem (Toggle RED LED) in rpi2 by shell script

GPIO_BASE=$((0x3F200000))
LED_GPFSEL=4
LED_GPFBIT=21
LED_GPSET=8
LED_GPCLR=11
LED_GPIO_BIT=3

#addr=$(($GPIO_BASE + $LED_GPFSEL * 4))
#rvalue=$(devmem $(($addr)) 32)

addr=$(($GPIO_BASE + $LED_GPCLR * 4))
devmem $((addr)) 32 $((1 << $LED_GPIO_BIT))

sleep 5

addr=$(($GPIO_BASE + $LED_GPSET * 4))
devmem $((addr)) 32 $((1 << $LED_GPIO_BIT))

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