Wednesday, January 31, 2018

about linux kernel memory map

cat /proc/vmallocinfo

0xbf000000-0xbf007000   28672 module_alloc_update_bounds+0xc/0x5c pages=6 vmalloc
0xbf009000-0xbf011000   32768 module_alloc_update_bounds+0xc/0x5c pages=7 vmalloc
0xbf015000-0xbf052000  249856 module_alloc_update_bounds+0xc/0x5c pages=60 vmalloc
0xbf05b000-0xbf060000   20480 module_alloc_update_bounds+0xc/0x5c pages=4 vmalloc
0xbf062000-0xbf0c7000  413696 module_alloc_update_bounds+0xc/0x5c pages=100 vmalloc
0xbf0d6000-0xbf147000  462848 module_alloc_update_bounds+0xc/0x5c pages=112 vmalloc
0xbf151000-0xbf15d000   49152 module_alloc_update_bounds+0xc/0x5c pages=11 vmalloc
0xbf160000-0xbf1ca000  434176 module_alloc_update_bounds+0xc/0x5c pages=105 vmalloc
0xbf1d1000-0xbf1d8000   28672 module_alloc_update_bounds+0xc/0x5c pages=6 vmalloc
0xbf1db000-0xbf1ff000  147456 module_alloc_update_bounds+0xc/0x5c pages=35 vmalloc
0xbf206000-0xbf211000   45056 module_alloc_update_bounds+0xc/0x5c pages=10 vmalloc
0xbf216000-0xbf241000  176128 module_alloc_update_bounds+0xc/0x5c pages=42 vmalloc
0xbf24a000-0xbf307000  774144 module_alloc_update_bounds+0xc/0x5c pages=188 vmalloc
0xbf328000-0xbf331000   36864 module_alloc_update_bounds+0xc/0x5c pages=8 vmalloc
0xbf334000-0xbf339000   20480 module_alloc_update_bounds+0xc/0x5c pages=4 vmalloc
0xe0800000-0xe0802000    8192 of_iomap+0x2c/0x34 phys=b000000 ioremap
0xe0802000-0xe0804000    8192 of_iomap+0x2c/0x34 phys=b002000 ioremap
0xe0810000-0xe0a11000 2101248 atomic_pool_init+0x0/0x100 phys=9f600000 user
0xe0a12000-0xe0a14000    8192 devm_ioremap_nocache+0x38/0x70 phys=7700000 ioremap
0xe0a14000-0xe0a16000    8192 devm_ioremap+0x38/0x70 phys=78b7000 ioremap
0xe0a16000-0xe0a18000    8192 devm_ioremap+0x38/0x70 phys=78b8000 ioremap
0xe0a18000-0xe0a1a000    8192 devm_ioremap_nocache+0x38/0x70 phys=1948000 ioremap

Friday, January 26, 2018

Thursday, January 25, 2018

tcpdump option and filters

tcpdump -Q in -xxx -ni ap0 port 42424

(ip.src == 192.168.12.2 && ip.dst == 192.168.12.1) && (udp.length < 80) && (frame contains a5:b8:a5:b8:00:38:00:00:40:00)

Wednesday, January 24, 2018

timestamp in linux shell commandline / file operations


touch /root/client-01-$(date +%s)


[ -f /etc/hosts ] && echo "Found" || echo "Not found"


[ ! -f /etc/hosts ] && echo "File does not exist" || echo "File exits"


#!/bin/bash
file="/etc/hosts"
if [ -f "$file" ]
then
echo "$file found."
else
echo "$file not found."
fi


#!/bin/bash
file="/.config/backup.cfg"
if [ ! -f "$file" ]
then
    echo "$0: File '${file}' not found."
fi


File test operators
The following operators returns true if file exists:

if [ operator FileName ]
then
     echo "FileName - Found, take some action here"
else
   echo "FileName - Not found, take some action here"
fi


       -b FILE
              FILE exists and is block special

       -c FILE
              FILE exists and is character special

       -d FILE
              FILE exists and is a directory

       -e FILE
              FILE exists

       -f FILE
              FILE exists and is a regular file

       -g FILE
              FILE exists and is set-group-ID

       -G FILE
              FILE exists and is owned by the effective group ID

       -h FILE
              FILE exists and is a symbolic link (same as -L)

       -k FILE
              FILE exists and has its sticky bit set

       -L FILE
              FILE exists and is a symbolic link (same as -h)

       -O FILE
              FILE exists and is owned by the effective user ID

       -p FILE
              FILE exists and is a named pipe

       -r FILE
              FILE exists and read permission is granted

       -s FILE
              FILE exists and has a size greater than zero

       -S FILE
              FILE exists and is a socket

       -t FD  file descriptor FD is opened on a terminal

       -u FILE
              FILE exists and its set-user-ID bit is set

       -w FILE
              FILE exists and write permission is granted

       -x FILE
              FILE exists and execute (or search) permission is granted

Tuesday, January 16, 2018

write MTD partition on Linux kernel

1. look up the dev name of MTD partition to be written
cat /proc/mtd

2. mtd write xxx.bin /dev/mtdX