Wednesday, 26 December 2018

Tinkering OpenWRT (17) : trouble shooting (build source code) target 'world' failed problem

I am trying to compile openwrt and got the following error:

include/toplevel.mk:216: recipe for target 'world' failed

I tried using 15.05 and checked out 18.06 (yes the head master is not newest 18.06) and I got the similar problem. Only the line number is sometimes different. After googling a loooooot, I found the simple solution.

$ make distclean
$ make clean

maybe also make defconfig

And $ make V=99

After over night...I found the image in bin/targets.


ref:
https://www.right.com.cn/forum/thread-186603-1-1.html
https://www.gargoyle-router.com/phpbb/viewtopic.php?t=8011&start=10

Tuesday, 25 December 2018

Tinkering OpenWRT (16) : openwrt Chaos Calmer Build dependency: Please install Git (git-core) >= 1.6.5


For some reason, I'd like to build my openwrt from 15.05 Chaos Calmer. But I ran into the following problem:

~/workspace/chaos_calmer$ make menuconfig 
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'gcc'... ok.
Checking 'working-gcc'... ok.
Checking 'g++'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'zlib'... ok.
Checking 'libssl'... ok.
Checking 'tar'... ok.
Checking 'find'... ok.
Checking 'bash'... ok.
Checking 'patch'... ok.
Checking 'diff'... ok.
Checking 'cp'... ok.
Checking 'seq'... ok.
Checking 'awk'... ok.
Checking 'grep'... ok.
Checking 'getopt'... ok.
Checking 'stat'... ok.
Checking 'md5sum'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'wget'... ok.
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'svn'... ok.
Checking 'git'... failed.
Checking 'file'... ok.
Checking 'openssl'... ok.
Checking 'ldconfig-stub'... ok.

Build dependency: Please install Git (git-core) >= 1.6.5

/home/boris/workspace/openWRT_build/openwrt_RPi/chaos_calmer/include/prereq.mk:12: recipe for target 'prereq' failed
Prerequisite check failed. Use FORCE=1 to override.
/home/boris/workspace/openWRT_build/openwrt_RPi/chaos_calmer/include/toplevel.mk:140: recipe for target 'staging_dir/host/.prereq-build' failed
make: *** [staging_dir/host/.prereq-build] Error 1

##########################################################################

Solution:

Step 1: Download the patch from here:
https://gitlab.labs.nic.cz/turris/openwrt/uploads/0673001b14ab1d1769604ff0ce7d8781/git-version-check-fix.patch

Step 2: put the patch file under the chaos calmer source code

Step 3: patch it
git apply git-version-check-fix.patch


ref:
https://forum.openwrt.org/t/solved-how-to-compile-15-05-release-build-dependency-please-install-git-git-core-1-6-5-message/11623/3
https://gitlab.labs.nic.cz/turris/openwrt/issues/56
https://github.com/spack/spack/issues/5329

Tuesday, 27 November 2018

Tinkering GStreamer (0) : See myself from PC Camera


$ gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! ximagesink
Looks pretty clear: source is /dev/video0

ref:
https://github.com/umlaeute/v4l2loopback/issues/174
https://stackoverflow.com/questions/23354041/gstreamer-video-stream-error-and-breaks-dev-video-source

Saturday, 17 November 2018

Develop Micropython Firmware -- 01: Pure Python Based Driver

Micropython is almost like a mini operating system on a MCU and I'd like to build my own project standing on its shoulder.

Step 1: Setting up the environment
Just follow:
or

The awesome thing is that all the environment is in a virtual machine. Your host is safe. So finish configure the vagrant virtual box first and then compile ESP-toochain and Micropython source code in it.

pitfall 1: 
Depending on what kind of error you might run into, the following commands might help:

- vagrant box update
- vagrant box add ubuntu/trusty32 https://atlas.hashicorp.com/ubuntu/boxes/
vagrant provision

Step 2: coding the hello driver
Going into ~/micropython/drivers/, I found there are modules with C codes based and pure python based. In this tutorial, we focus on the pure python based drivers. For example, onewire and display.

step 2.1
mkdir hello_mpy

step 2.2
code hello_mpy.py:

def my_hello_mpy():
  print('This is my first micropython module.')

step 2.3
link it to esp8266 port.

cd ~/micropython/ports/esp8266/modules
ln -s ../../../drivers/hello_mpy/hello_mpy.py hello_mpy.py
ls -l
total 40
-rw-rw-r-- 1 vagrant vagrant  470 Nov 15 04:12 apa102.py
-rw-rw-r-- 1 vagrant vagrant  219 Nov 15 04:12 _boot.py
lrwxrwxrwx 1 vagrant vagrant   27 Nov 15 04:12 dht.py -> ../../../drivers/dht/dht.py
lrwxrwxrwx 1 vagrant vagrant   35 Nov 15 04:12 ds18x20.py -> ../../../drivers/onewire/ds18x20.py
-rw-rw-r-- 1 vagrant vagrant 1110 Nov 15 04:12 flashbdev.py
lrwxrwxrwx 1 vagrant vagrant   39 Nov 17 04:03 hello_mpy.py -> ../../../drivers/hello_mpy/hello_mpy.py
-rw-rw-r-- 1 vagrant vagrant 1425 Nov 15 04:12 inisetup.py
-rw-rw-r-- 1 vagrant vagrant  836 Nov 15 04:12 neopixel.py
-rw-rw-r-- 1 vagrant vagrant  850 Nov 15 04:12 ntptime.py
lrwxrwxrwx 1 vagrant vagrant   35 Nov 15 04:12 onewire.py -> ../../../drivers/onewire/onewire.py
-rw-rw-r-- 1 vagrant vagrant 1094 Nov 15 04:12 port_diag.py
lrwxrwxrwx 1 vagrant vagrant   22 Nov 15 04:12 upip.py -> ../../../tools/upip.py
lrwxrwxrwx 1 vagrant vagrant   31 Nov 15 04:12 upip_utarfile.py -> ../../../tools/upip_utarfile.py
-rw-rw-r-- 1 vagrant vagrant 2118 Nov 15 04:12 webrepl.py
-rw-rw-r-- 1 vagrant vagrant 2748 Nov 15 04:12 webrepl_setup.py
-rw-rw-r-- 1 vagrant vagrant 1624 Nov 15 04:12 websocket_helper.py

step 2.4 compile again
make axtls
make

step 2.5 
Get the .bin file out of vm.

pitfall 2:
I wasn't able to get my compiled firmware-combined.bin out from vm to host.
I eventually used vagrant-scp tool and it worked.
            https://github.com/invernizzi/vagrant-scp
It works both way, host to vm or vm to host.


Step 3: flash the new firmware
esptool.py -p /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 firmware-combined.bin

Step 4: use it
>>>import hello_mpy
>>>hello_mpy.my_hello_mpy()
This is my first micropython module.









Thursday, 15 November 2018

vagrant up issue

Ran in to problem when running:
$vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: aws_default_1449506528859_
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Specific bridge 'en0' not found. You may be asked to s
==> default: which network to bridge to.
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 => 2200 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minut
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in th
'poweroff' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve
For example, if you're using VirtualBox, run vagrant up while the
VirtualBox GUI is open.
The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.
#######################################################
You simply need to turn on the virtualization setting in your BIOS.



Friday, 5 October 2018

Tinkering OpenWRT (15) : Use I2C Bus



Step 1: Do as the official document says

# opkg update 
# opkg install kmod-i2c-gpio-custom kmod-i2c-core 
# insmod i2c-dev 
# insmod i2c-gpio-custom bus0=0,26,12 
# dmesg | grep gpio 
Mar 23 09:01:23 openwrt kern.info kernel: [ 52.910000] Custom GPIO-based I2C driver version 0.1.1 
Mar 23 09:01:23 openwrt kern.info kernel: [ 52.910000] i2c-gpio i2c-gpio.0: using pins 26 (SDA) and 12 (SCL)
Im using my AR9331 board, and Im using GPIO 26 and 12 as my SDA and SCL repectively.
And then what? The official doc just stops here?

Step 2 : Wiring

AR9331        Slave
SDA              SDA
SCL               SCL
GND             GND       <= this is very important

Step 3 : install i2c-tools

# opkg update && opkg install i2c-tools

Step 3 : install i2c-tools
# i2cdetect 0 

WARNING! This program can confuse your I2C bus, cause data loss and worse! 
I will probe file /dev/i2c-0. 
I will probe address range 0x03-0x77. Continue? [Y/n] y
       0 1 2 3 4 5 6 7 8 9 a b c d e f 
00: -- -- -- -- -- -- -- -- 08 -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- 
48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

try this...
# i2cget 0 0x48 0 w




ref:
https://wiki.openwrt.org/doc/hardware/port.i2c
https://www.cnblogs.com/fastwave2004/articles/4250604.html     !!!!
http://linux-adm5120.sourceforge.net/openwrt/i2c/

Friday, 14 September 2018

Tinkering OpenWRT (14) : Python MQTT Setup





root@JoySince:~# mosquitto_sub  -t "topic" -v
topic OFF


####################################

Could download directly from openwrt:

root@JoySince:/tmp# wget --no-check-certificate https://pypi.python.org/packages
/source/p/paho-mqtt/paho-mqtt-1.1.tar.gz
wget: not an http or ftp url: https://pypi.python.org/packages/source/p/paho-mqtt/paho-mqtt-1.1.tar.gz

Download to PC and upload it to openwrt:
scp -P 2022 paho-mqtt-1.1.tar.gz root@192.168.0.24:/tmp/

Cannot unzip it...
root@JoySince:/tmp# tar xfz paho-mqtt-1.1.tar.gz
tar: can't open 'z': No such file or directory

Unzip locally on PC and upload to openwrt
scp -P 2022 -r paho-mqtt-1.1/ root@192.168.0.24:/tmp/

cd paho-mqtt-1.1
python setup.py install



ref
https://github.com/relayr/python-sdk/blob/master/docs/manual/openwrt.txt
http://lukse.lt/uzrasai/2015-02-internet-of-things-messaging-mqtt-2-install-python-clients-on-pc-carambola-rpi/
http://www.steves-internet-guide.com/into-mqtt-python-client/
http://www.steves-internet-guide.com/publishing-messages-mqtt-client/




Thursday, 13 September 2018

Tinkering OpenWRT (13) : Setup MQTT




Step 1: Install on openWRT
opkg update 
opkg install mosquitto mosquitto-client libmosquitto
Step 2: Start up
/etc/init.d/mosquitto enable
/etc/init.d/mosquitto restart

Step 3: Install on PC with Ubuntu
Many suggest test on the same machine with localhost. But once the mosquitto_sub will hang the terminal on openwrt, so I installed MQTT on my PC and used it as the client.

$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa 
$ sudo apt-get update 
$ sudo apt-get install mosquitto 
$ sudo apt-get install mosquitto-clients
Step 4: Start the sub on openwrt
root@JoySince:~# mosquitto_sub  -t "topic" -v

Step 5: Ping the openwrt on PC
$ mosquitto_pub -h OPENWRT_IP_ADDRESS -t "topic" -m "test message"
$ mosquitto_pub -h OPENWRT_IP_ADDRESS -t "topic" -m "enjoy"

Result on openwrt:
root@JoySince:~# mosquitto_sub  -t "topic" -v
topic test message
topic enjoy


ref:
https://mosquitto.org/blog/2011/08/mosquitto-on-openwrt/
https://blog.csdn.net/hehexiaoxia/article/details/72834625
https://loralandia.com/mosquitto-mqtt-broker-installation-on-openwrt/
https://blog.csdn.net/xiaoreqing/article/details/77571881

Monday, 3 September 2018

Tinkering OpenWRT (12) : Cross-Compile the Helloworld Program



Step 1: Download the SDK 

Download
OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2

from

http://archive.openwrt.org/barrier_breaker/14.07/ar71xx/generic/

Two things you need to know. The openWRT version running on your board, in my case, barrier_breaker. The chipset of your board, in my case, ar9331.


Step 2: Create the working structure

cd package
mkdir helloworld
cd helloworld
mkdir src
cd src
touch helloworld.c
touch Makefile

tree:

OpenWrt-SDK-ar71xx-.../package/helloworld
├── Makefile
└── src
    ├── helloworld.c
    └── Makefile
The Makefile in /src/ is just local compiling for checking if there is any coding errors.
The Makefile ourside /src/ is the real cross-compiling makefile.

Step 3: coding

~/helloworld/src/helloworld.c:
#include <stdio.h> int main(void) { printf("Hell! O' world, why won't my code compile?\n\n"); return 0; }

~/helloworld/src/Makefile:
# build helloworld executable when user executes "make" helloworld: helloworld.o $(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: helloworld.c $(CC) $(CFLAGS) -c helloworld.c # remove object files and executable when user executes "make clean" clean: rm *.o helloworld


Step 3: Cross-compiling Makefile


##############################################
# OpenWrt Makefile for helloworld program
#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.
#
##############################################
 
include $(TOPDIR)/rules.mk
 
# Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1
 
 
# This specifies the directory where we're going to build the program. 
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
 
include $(INCLUDE_DIR)/package.mk
 
 
 
# Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/helloworld
 SECTION:=utils
 CATEGORY:=Utilities
 TITLE:=Helloworld -- prints a snarky message
endef
 
 
# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/helloworld/description
        If you can't figure out what this program does, you're probably
        brain-dead and need immediate medical attention.
endef
 
 
 
# Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default.  The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
 mkdir -p $(PKG_BUILD_DIR)
 $(CP) ./src/* $(PKG_BUILD_DIR)/
endef
# We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one
# Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist.  Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
 $(INSTALL_DIR) $(1)/bin
 $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef
# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))

Step 4: Compile

Go to the root directory of the compiler and make:
make V=s

Step 5: Find the .ipk

If the compiling passes, you can find helloworld_1_ar71xx.ipk in

OpenWrt-SDK-ar71xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/bin/ar71xx/packages/base

Step 6: upload the .ipk to the board

scp helloworld_1_ar71xx.ipk root@192.168.0.24:/root/

Step 7: Install the package
opkg install helloworld_1_ar71xx.ipk
Step 8: run the program
just run

$ helloworld

or

$ /bin/helloworld

or

check it with
$ opkg list




ref:
http://archive.openwrt.org/barrier_breaker/14.07/ar71xx/generic/
https://www.gargoyle-router.com/old-openwrt-coding.html
https://blog.csdn.net/luck_good/article/details/23517135
http://www.uubook.net/article/detail/116354.html





Sunday, 2 September 2018

Tinkering OpenWRT (11) : SSH Configuration and Upload Files

Coding is done with cross-compiling. After we pack the compiled package, .pkg file, we need to upload the file to the board and install.

Step 1:
Edit /etc/config/dropbear:
The first option is used if the client is connect to the openwrt AP. The second option is used if both the client and the openwrt board are connected to the router.

config dropbear
        option PasswordAuth 'on'
        option Port '22'
        option Interface 'lan'

config dropbear
        option PasswordAuth 'off'
        option Interface 'wan'
        option Port '2022'
Step 2:
ifconfig  to get the openwrt IP address.
ssh root@192.168.0.24 -p 2022

Enter the password to test the ssh connection.

Step 3:
scp -P 2022 helloworld_1_ar71xx.ipk root@192.168.0.24:/root/

ref:
https://wiki.openwrt.org/doc/uci/dropbear
https://blog.csdn.net/qq_29663071/article/details/79081103
http://blog.51cto.com/lynnteng0/1066795



Friday, 10 August 2018

Hacking Cisco Linksys EA2700


Step 1: taking apart
Note there are three screws to take off.




Step 2: Hook up UART Serial debugger







Step 3:
screen /dev/ttyUSB0 115200


ref:
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=276769&sid=6a27f6c98e93a870f25587ca2236a2f3
https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=989071&sid=48bddfccb6ab58c28bb44fc91b9b9ca7
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=51486
https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=773996


Wednesday, 8 August 2018

Tinkering OpenWRT (10) : WiFi Configuration Again

I don't know why my AS9331 board couldn't even ping 192.168.1.1 and I'm getting the following error:
        pingsendto:Network is unreachable

Step 1:

Updated my /etc/config/wireless and /etc/config/network as shown below.

/etc/config/wireless
config wifi-device 'radio0'
        option type 'mac80211'
        option hwmode '11g'
        option path 'platform/ar933x_wmac'
        option htmode 'HT40'
        #option disabled '0'   #REMOVE THIS LINE TO ENABLE WIFI:
        option channel '1'
        option txpower '30'
        option country 'US'

config wifi-iface
        option network 'wan0'
        option ssid 'FIDO_NETWORK'
        option encryption 'psk2'
        option device 'radio0'
        option mode 'sta'
        option bssid 'B8:4C:3F:F:62:68'
        option key '12345678'

config wifi-iface
        option  device  radio0
        option  network lan
        option  mode    ap
        option  ssid    OpenWrt
        option  encryption none

###############################################

/etc/config/network
config switch 'eth1'
        option reset '0'
        option enable_vlan '0'

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config interface 'lan'
        option ifname 'eth1'
        option proto 'static'
        option ipaddr '192.168.1.1'           # this has to be your router addr
        option netmask '255.255.255.0'

config interface 'wan0'
        option ifname 'wlan0'
        option proto 'dhcp'
        option macaddr '00:CA:01:07:23:96'  # this is the mac addr of the board (router)
        #if mac address not provided, it will take a loooong time (~10min) to connect to the wifi

config interface 'wan1'
        option ifname 'eth0'
        option proto 'dhcp'
        option ifname eth0
        option proto dhcp


Step 2:
/sbin/wifi up

#######################################################

For some reason the above stopped working anymore. There must be some problems. For example, 192.168.1.1 cannot be in lan configuration because this ipaddr indicates the ip address when this AR9931 device acts as the AP for other clients to connect. It has to be something else.

Here are my new configurations and it works!!!

Step 1: Factory Reset
$ firstboot

Step 2:
/etc/config/network

config switch 'eth1'
        option reset '0'
        option enable_vlan '0'

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config interface 'lan'
        option ifname 'eth1'
        option proto 'static'
        option ipaddr '192.168.6.1'
        option netmask '255.255.255.0'

config interface 'wan0'
        option ifname 'wlan0'
        option proto 'dhcp'

config interface 'wan1'
        option ifname 'eth0'
        option proto 'dhcp'
    option ifname eth0
    option proto dhcp


Step 3:
/etc/config/dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'

config dhcp 'wan0'
        option interface 'wan0'
        option ignore '1'

config dhcp 'wan1'
        option interface 'wan1'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'

Step 4:
/etc/config/wireless

config wifi-device  radio0
        option type     mac80211
        option channel  8
        option hwmode   11g
        option path     'platform/ar933x_wmac'
        option htmode   HT40

config wifi-iface
        option device   radio0
        option network  lan
        option mode     ap
        option ssid     JoySince
        option encryption none

config wifi-iface
        option device 'radio0'
        option network 'wan0'
        option mode 'sta'
        option ssid 'wifi ssid name'
        option encryption 'psk2'
        option key 'wifi password'

Step 5:
/etc/init.d/network restart


ref:
https://my.oschina.net/lvsin/blog/392817     !!!!!!
https://my.oschina.net/lvsin/blog/384410
https://blog.csdn.net/gaopeiliang/article/details/40430915


Thursday, 2 August 2018

Tinkering OpenWRT (9) : Boot Loop? Don't Connect the Power Line!

I bought a core board of AR9331 running openWRT and trying to set it up. I simply used a cp2102 TTL to USB converter trying to serial monitoring it just like other CPUs: RX->TX, TX->RX, GND->GND and 3v3->3v3.

However, the problem I'm having is that it stuck in a boot loop forever. After I see the root@UserName:/# it would start from the top all over again and keeps looping.

I actually first had this experience with linkit smart 7688. I had to power it via the USB and only uses UART pins for serial communication. And I found the following in the openWRT document:

WARNING!: Some people reported they fried their router connecting the voltage pins spite it isn't neccesary. NEVER connect voltage pins when using USB adapters unless you know what are you doing. Unless you need to power the device, you don't have to connect the voltage pins. And you usually don't need to power it this way - use the router power supply.

OK so basically, an independent power line? Fine, I could provide 3v3 to the module with an Arduino. So I did the following connection:

AR9331       CP2102       Arduino
GND            GND            --
RX               TX               --
TX               RX               --
3V3              --                 3V3

Now I plugged in the CP2102 USB to my computer and open up the serial com and then I plugged in the Arduino cable to power it on. I got it stop looping once or twice. But when I come back a few days later it still loops.

So here is my working wiring:

AR9331       CP2102       Arduino
GND            --     works now            GND
RX               TX               --
TX               RX               --
3V3              --                 3V3

Basically, power the module from Arduino and only uses the TTL converter as UART.

I plugged in the TTL converter first and the Arduino cable. It almost like powering on an router after setting up the serial com. It does no loop anymore. I can start working.

It might still showing the following:

root@UserName:/# [ 4082.090000] wlan0: authenticate with ax:4y:zf:fd:12:
[ 4082.100000] wlan0: send auth to ax:4y:zf:fd:12:34 (try 1/3)
[ 4082.110000] wlan0: authenticated
[ 4082.120000] wlan0: associate with ax:4y:zf:fd:12:34 (try 1/3)
[ 4082.140000] wlan0: RX AssocResp from ax:4y:zf:fd:12:34 (capab=0x431 status=0 aid=5)
[ 4082.150000] wlan0: associated
[ 4086.150000] wlan0: disassociated from ax:4y:zf:fd:12:34 (Reason: 2)

It just means it tried to connect to the Router (Internet) but timed out. Press enter again it will come back to console.


ref:
https://wiki.openwrt.org/doc/hardware/port.serial.cables
https://openwrt.org/docs/techref/hardware/port.serial.cables
https://openwrt.org/docs/techref/hardware/port.serial

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

Sunday, 17 June 2018

Linkit Getting Started


Step 1: Wiring
I am using a cp2102 ttl to usb converter. And this is the connection from the official website.


Very interestingly, there is no power line listed. So I tried connecting 3.3V from the cp2102 to the 3.3V on Linkit. But the system just keeps booting again and again for some reason.

This is what I did:
    -  keep the above three connections but no power;
    -  use a usb cable to supply power. Connect it to "pwr" port (not "host").

Step 2:
screen /dev/ttyUSB0 57600

Step 3: Blink
python /IoT/examples/blink-gpio44.py

ref:
http://wiki.seeedstudio.com/LinkIt_Smart_7688/

Thursday, 14 June 2018

Nutstore problem: SSL failed to connect

备份并移除老的cacerts
sudo mv /etc/ssl/certs/java/cacerts{,.backup}


生成新的cacerts
sudo keytool -importkeystore -destkeystore /etc/ssl/certs/java/cacerts -deststoretype jks -deststorepass changeit -srckeystore /etc/ssl/certs/java/cacerts.backup -srcstoretype pkcs12 -srcstorepass changeit


询问官方后官方提供的临时解决方案

ref:
http://tieba.baidu.com/p/5680448441
I got the following error when installing matplotlib:

sudo python -mpip install -U matplotlib

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-t_g0M1/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-YcuLqR/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-t_g0M1/subprocess32/

I fixed it by installing python-dev:
sudo apt-get install python-dev

ref:
https://github.com/google/python-subprocess32/issues/38

Wednesday, 23 May 2018

Android Studio: /dev/kvm device permission denied

I installed my Android Studio in my Home directory rather than /. So at first I thought I need to somehow do sudo. Then I tried sudo ./studio.sh but it ask me to install the AS again.

This worked for me:

To check the ownership of /dev/kvm use
ls -al /dev/kvm
The user was root, the group kvm. To check which users are in the kvm group, use
grep kvm /etc/group
This returned
kvm:x:some_number:
on my system: as there is nothing left to the final :, there are no users in the kvm group.
To add the user username to the kvm group, you could use
sudo adduser username kvm
which adds the user to the group, and check once again with grep kvm /etc/group.
Log out and back in (or restart), for the permissions to take effect. If you get the message
adduser: The group kvm does not exist.
On Ubuntu 18.04 you need to additionally sudo apt install qemu-kvm.


ref:
https://stackoverflow.com/questions/37300811/android-studio-dev-kvm-device-permission-denied

Thursday, 10 May 2018

Set a PIN to OPEN DRAIN





digitalWriteOpenDrain(byte pin, bool state)
{
    if (state==LOW)
    {
        pinMode(pin, OUTPUT);
        digitalWrite(pin, LOW);
    }
    else //state==HIGH
    {
        pinMode(pin, INPUT); // Getting HiZ output from this pin
        digitalWrite(pin, LOW);
    }
}


ref:
https://electronics.stackexchange.com/questions/28091/push-pull-open-drain-pull-up-pull-down
https://blog.csdn.net/fengyu09/article/details/50317423
http://www.st.com/content/ccc/resource/technical/document/reference_manual/51/f7/f3/06/cd/b6/46/ec/CD00225773.pdf/files/CD00225773.pdf/jcr:content/translations/en.CD00225773.pdf
http://www.st.com/content/ccc/resource/technical/document/datasheet/bc/21/42/43/b0/f3/4d/d3/CD00237391.pdf/files/CD00237391.pdf/jcr:content/translations/en.CD00237391.pdf
https://github.com/particle-iot/firmware/blob/1a0c5a2c204b312ae8c0435728999d6e3f296ead/hal/src/stm32f2xx/gpio_hal.c#L78
https://community.particle.io/t/electron-open-drain-output-gpio/20196/3
https://electronics.stackexchange.com/questions/156930/stm32-understanding-gpio-settings
https://github.com/DFRobot/STM32/blob/master/cores/blunoM3/wiring_digital.c
https://sites.google.com/site/learningeclipsearm/5-using-stm32-std-lib/b-digital-io-pins
http://m.www.cnblogs.com/luckyalan/p/5154829.html



Tuesday, 8 May 2018

PlatformIO Daily Use Practice


(1) Start a new project
             $ platformio init --board uno --board nanoatmega328

If you need to add new board to the existing project please use platformio init again with all boards included.

(2) compile
Just compile:
             $platformio run
or
             $platformio run -e nanoatmega328

(3) flash/upload
             $platformio run -e nanoatmega328 -t upload
The awesome thing about this is that, even if using a CP2102 TTL to USB, it works perfectly.

(4) more...


ref:
http://docs.platformio.org/en/latest/quickstart.html

Thursday, 26 April 2018

Move a tag on a git Branch to a Different Commit

You might forget to do something before you tag a commit. Then you realize OMG I gotta make that small change or delete something etc. You would have a new commit after the tag you've just made so you want to move the tag to this new commit. Here is how.

  1. Delete the tag on any remote before you push
    git push origin :refs/tags/<tagname>
    
  2. Replace the tag to reference the most recent commit
    git tag -fa <tagname>
    
  3. Push the tag to the remote origin
    git push --tags

ref:
https://stackoverflow.com/questions/8044583/how-can-i-move-a-tag-on-a-git-branch-to-a-different-commit