Quantcast
Channel: 懒得折腾
Viewing all articles
Browse latest Browse all 764

CHIP GSM and GPS – a Cheap Linux Mobile Platform

$
0
0

CHIP GSM and GPS – a Cheap Linux Mobile Platform

http://rabarar.github.io/blog/2016/08/06/chip-gsm-and-gps-a-cheap-linux-mobile-platform/

AUG 6TH, 2016 5:40 PM | COMMENTS

Configuring C.H.I.P. to go Mobile!

I recently received my $9 NTC CHIPs and decided a cool use of the tiny server would be to mate it up with the Adafruit FONA 3G Cellular Breakout and Adafruit FONA 2G Cellular and GPS Breakout to test using both GPS and GSM GPRS via ppp on the CHIP.

Turns out you can’t use the ppp out of the box on the CHIP as it’s not part of the kernel. Depending on which flash you use, you might not even have USB-Serial support (via PL2303 or FTDI USB-to-Serial cables).

So, roll up your sleeves and let’s build us a new kernel! At first blush, this sounds far more daunting than it should. Having been a Unix kernel hacker for far too many years than I’d care to admit, today’s modern kernel build environment takes a lot of the sting out of configuring and building your custom kernel.

Kernel hacking

We need to start by setting up an environment and pulling a code base to allow us to configure and build our kernel

– Build environment:

The build environment will consist of setting up a vagrant environment for the CHIP-SDK. There are great directions for doing so on the CHIP Documentation site. Take a look at these instructions on setting up the CHIP-SDK vagrant vm.

Before you grab the source, you might need a few tools to make your vm ready to rock and roll. Specifically, add the following with your favorate package manager:

1
2
3
apt-get install git build-essential \
 fakeroot kernel-package zlib1g-dev \
 libncurses5-dev lzop

and

1
2
apt-get install gcc-arm-linux-gnueabihf \
binutils-arm-linux-gnueabihf

Once the vagrant machine is setup, clone the CHIP-linux source onto the machine into a working directory, say CHIP-linux

1
2
cd /home/vagrant
git clone https://github.com/NextThingCo/CHIP-linux.git

Next, check out the debian NTC release…

1
2
cd CHIP-linux
git checkout -b debian/4.3.0-ntc-4 origin/debian/4.3.0-ntc-4

Now you have the source, and the tools, and are ready to roll. But before you start the build process, we might want to start with our baseline config from our existing CHIP. This isn’t a requirement, but it will allow you to either add to or subtract from a known kernel configuration.

To grab your config file, simply:

1
scp root@chip.local:/boot/config-4.3.0 .

You might run into problem or two here depending on your CHIP Linux configuration. One, you may not have a root password! You might need to set that. Secondly, you might not have configured sshd to allow root login. Be sure you’ve remedied both of these issues as we’ll use root login throughout the kernel build process.

– Configuring the kernel

To configure our kernel, we simply invoke the makefile with the following:

1
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- menuconfig

This will bring up an easy to use menu-driven application that allows you to select or delete items that you wish to have in your kernel.

Remember that config file that we copied over from the CHIP? Let’s load that as our starting point.

Now make the modifications that you wish to your kernel. In this kernel, I want to add ppp support as well as ppp async-serial support. I select both of those, and then save my configuration file as .config.

Before we actually save the configuration, it’s a good idea to mark your Kernel so you can easily verify you’re running the kernel that you built. To do that we add a Local Version marking to the kernel release. Under the following Menu item: – General setup – ( ) Local version – append to kernel release

Add a tag that marks your kernel. I use rb-2016-08-01.0 for example.

Now I’m ready to actually compile the kernel that represents the configuration that I just selected. To do so, simply run make as follows:

1
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -j n

where n is the number of cores that you have on your box.

Once the compilation successfully completes, you’ll next need to install the modules into a directory that we’ll use later to place them onto the CHIP.

1
2
mkdir /tmp/lib
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- INSTALL_MOD_PATH=/tmp/lib modules_install

Add the RTL8723BS: This is not part of the CHIP-linux source tree.

1
2
cd /home/vagrant/CHIP-linux
git clone https://github.com/NextThingCo/RTL8723BS.git

And build it…

1
2
3
4
5
6
7
8
9
10
11
cd RTL8723BS

## Check out the Debian branch...
git checkout -b debian origin/debian

## Patch it...
for i in debian/patches/0*; do  echo $i; patch -p 1 <$i ; done

## build it...
make -j 8 CONFIG_PLATFORM_ARM_SUNxI=y ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -C /home/vagrant/CHIP-linux/ M=$PWD CONFIG_RTL8723BS=m  INSTALL_MOD_PATH=/tmp/lib
make -j 8 CONFIG_PLATFORM_ARM_SUNxI=y ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -C /home/vagrant/CHIP-linux/ M=$PWD CONFIG_RTL8723BS=m  INSTALL_MOD_PATH=/tmp/lib modules_install

Now that everything is compiled and built, you’re ready to copy it to your CHIP!

1
2
3
4
5
6
7
scp /home/vagrant/CHIP-linux/arch/arm/boot/zImage root@chip.local:/boot/vmlinuz-4.3.0rb-2016-08-01.1+
scp /home/vagrant/CHIP-linux/.config root@chip.local:/boot/config-4.3.0rb-2016-08-01.1+
scp /home/vagrant/CHIP-linux/System.map root@chip.local:/boot/System.map-4.3.0rb-2016-08-01.1+
cd /tmp/lib/lib/modules
tar cf - 4.3.0rb-2016-08-01.1+ | ssh root@chip.local 'cd /lib/modules; tar xf -'
cd ../firmware/
tar cf - . | ssh root@chip.local 'mkdir /lib/firmware/4.3.0rb-2016-08-01.1+; cd /lib/firmware/4.3.0rd235+; tar xf -'

Now to boot your new kernel, there are two choices.

The Easy Choice:

Simply copy the existing kernel so you have a backup

1
2
sudo cp /boot/zImage /boot/zImage.backup
sudo cp /boot/vmlinuz-4.3.0rb-2016-08-01.1 /boot/zImage

Should something go wrong with the new kernel and you can’t boot, you’re hosed. There’s another way.

The Complicated, But More Better for Ya Choice:

The more complicated, but far more flexible approach is to add a serial USB-to-Serial connector to the chip. You can use a PL2303 and connect it as follows:

1
2
3
PL2303 TX (white wire)      -> CHIP Pin 3
PL2303 RX (grey wire)       -> CHIP Pin 5
PL2303 Gnd (black wire)     -> CHIP Pin 1

And on your computer use screen to access the serial port:

1
screen /dev/ttyUSB0 115200

Keep in mind that the actual device name may change depending on what OS you are using. I use the linux device name. Also, pay attention to the digit at the end, it might be some number other than zero.

Before you connect the serial port, be sure to first copy the orgiginal kernel so you have a backup. And then shut down the CHIP before you connect the serial cable.

Once all connected (both litreally with the USB connector as well as the screen command), type a key to stop the U-Boot booting process and fall into a u-boot shell.

Now you can change the bootcmd and boot the kernel that you copied to the CHIP in the previous section. In this case, if there is a problem booting your new kernel, you can easily boot the backup kernel instead.

Wah Lah! You have successfully booted your new kernel!

If everything went as expected, you should be able to now connect your FONA 2g or 3g Cellular GSM breakout to a PL2303 and connect it to your CHIP. Be sure to use a lipo battery as well as a USB power source for your FONA. Turn it on, and verify that you can access the device.

Here again, I use screen /dev/ttyUSB0 to access the FONA. Verify that the PL2303 is accessable to the CHIP via lsusb and you should see the PL2303 signature. If you don’t see it, you likely didn’t configure your kernel properly to include the USB device.

But if you did read the directions carefully, and have the device, and are able to screen to it, you should be able to communicate with the FONA by sending it AT commands, and receive back from the FONA a response, like OK.

Make sure you’ve added the ppp package.

1
2
sudo apt-get update
sudo apt-get install ppp

If all’s connected, and you’ve successfully added the ppp package, you can now configure the ppp setup.

1
2
3
sudo -i
cd /etc/ppp/peers/
wget https://raw.githubusercontent.com/adafruit/FONA_PPP/master/fona

Now edit the file and change the MUST CHANGE items. There are essentialy two of them

  • The first one is the APN. In my case I am using Ting Wireless. The APN is wholesale
  • The second item to change is the serial device. Make sure the device name that is connected to the FONA is specified in the file. For example, /dev/ttyUSB0.

Save the file, and give it a go! To turn on and off ppp, use pon`` andpoff“` respectivly.

1
sudo pon fona

You can verify that it worked by looking for the interface. A successful ppp session will result in a device shown when you run ifconfig. If you run into problems, take a look at the log files for details on what went wrong. Common problems include forgetting to turn on the FONA device!

take a look at the ppp chat script in the syslog file:

1
cat /var/log/syslog | grep chat

If you successfully create your ppp connection and have verified it via ifconfig, try it out! simply ping a website of your choice.

1
ping yahoo.com

To get a feel for the speed of the connection, grab some data too:

1
wget www.yahoo.com

Once you’re done with your ppp connection, simply turn it off:

1
sudo poff fona


Viewing all articles
Browse latest Browse all 764

Trending Articles