Monday 23 July 2018

Tinkering OpenWRT (8) : Connect to WiFi

I just got my new Atheros core board and I'd like to set it up. The first thing of course is just to connect to the wifi and then I can install other things.

Step 1: go to vim /etc/config/wireless
config wifi-iface
        option device   radio0
        option network  lan
        option mode     ap
        option ssid     BorisWRT
        option encryption psk2+tkip+ccmp
        option key 888888

Step 2: Switch WiFi to BorisWRT

Step 3: Figure out the IP address
config interface 'lan'
        option ifname 'eth1'
        option force_link '1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.251'
        option netmask '255.255.255.0'
        option ip6assign '60'

Step 4: go to the above LAN address
We can see the luci gui now.

Step 5: login luci to configure wifi









Step 6:






ref:
https://wiki.openwrt.org/zh-cn/doc/howto/firstlogin
https://blog.csdn.net/killalarm/article/details/74364685


Wednesday 4 July 2018

Linux Kernel Module Helloworld Program


I was following the awesome tutorial The Linux Kernel Module Programming Guide until I compiled it and couldn't get it work. So I will just list the steps I did.

Step 1: coding

/*  
 *  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
 printk(KERN_INFO "Hello world 1.\n");

 /* 
  * A non 0 return means init_module failed; module can't be loaded. 
  */
 return 0;
}

void cleanup_module(void)
{
 printk(KERN_INFO "Goodbye world 1.\n");
}

Step 2: Makefile

obj-m += hello-1.o

all:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


Step 3: compile
$ make
make -C /lib/modules/3.19.0-25-generic/build M=/home/boris/workspace/TheLinuxKernelModuleProgrammingGuide/hello-1 modules
make[1]: Entering directory `/usr/src/linux-headers-3.19.0-25-generic'
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.19.0-25-generic'

Step 4: Insert the module
sudo insmod ./hello-1.ko

Step 5: 
$ cat /proc/modules
hello_1 16384 0 - Live 0x00000000 (POE)    <====== here it is!
cp210x 24576 0 - Live 0x00000000
usbserial 40960 1 cp210x, Live 0x00000000
ctr 16384 1 - Live 0x00000000
ccm 20480 1 - Live 0x00000000
rfcomm 61440 0 - Live 0x00000000
...
...


Step 6: 
$ dmesg
...
...
[ 8741.483837] hello_1: module license 'unspecified' taints kernel.
[ 8741.483841] Disabling lock debugging due to kernel taint
[ 8741.483881] hello_1: module verification failed: signature and/or  required key missing - tainting kernel
[ 8741.484112] Hello world 1.


Step 7:
$ cat /var/log/syslog | grep hello
Jul  4 21:07:34 boris-XYZ kernel: [ 8741.483837] hello_1: module license 'unspecified' taints kernel.
Jul  4 21:07:34 boris-XYZ kernel: [ 8741.483881] hello_1: module verification failed: signature and/or  required key missing - tainting kernel

Step 8:
$ sudo rmmod hello-1
$ dmesg
...
...
[ 8741.483837] hello_1: module license 'unspecified' taints kernel.
[ 8741.483841] Disabling lock debugging due to kernel taint
[ 8741.483881] hello_1: module verification failed: signature and/or  required key missing - tainting kernel
[ 8741.484112] Hello world 1.
[ 9291.123571] Goodbye world 1.


ref:
https://www.tldp.org/LDP/lkmpg/2.6/html/x121.html
https://blog.csdn.net/fantasy_wxe/article/details/12379647
https://blog.csdn.net/zhangyifei216/article/details/49703435