Software, electronics and anything else

Installing a custom kernel onto the CHIP

CHIP

I have this C.H.I.P. from NextThingsCo lying around. It was a $9 computer, and more or less equivalent to a Raspberry Pi Zero, although it has built in flash storage and WiFi. For the price, it’s not bad.

Problem is, the company went bankrupt quite a while ago now and I still haven’t done anything with it. So, I decided I would try and set up a PPS GPS time server on it. Probably not the best idea over WiFi, but what else am I going to do with the thing? It’s not even really powerful enough to stream a webcam!

I should mention that getting a PPS GPS source working – as long as you have a compatible GPS itself – is quite easy on a Raspberry Pi, as all the hard work has been done for you. On this thing…not so much.

First order of business was updating it. I followed this guide, ignoring the parts applicable to the PocketCHIP GUI as I only have a normal headless one. And yes, I experienced both of the potential errors they mention, but the solutions worked. I also believe there is an error in the last section “Stretch to Buster” where all except the top apt source are commented out. As far as I know, all are valid and thus should not be commented out.

For building the kernel, I followed two guides: this and this.

I don’t have time to cover everything step-by-step, but the important parts are:

  1. Define some convenience variables, like below for cross compiling the ARM kernel on an x86 system:
MAKE="make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-"
  1. Clone the kernel. I used the one from the original repository at https://github.com/nextthingco/linux, and checked out the branch ntc-stable-mlc-4.4.y as that appears to be the latest branch available and my CHIP uses the mlc kernel normally. Other C.H.I.P.S may be different. The links and branches in the guide are outdated. I will also note that while the linux repository on the old company’s github is still up, a lot of others have been deleted for whatever reason including those for the WiFi drivers. As of now, a complete copy of everything is available here. There were also copies available here, but they no longer seem to work.
  2. Get your current kernel config. I downloaded mine from the CHIP (included in the tar at the end of this post) and saved it as .config in the linux repo folder.
  1. Run $MAKE oldconfig and then $MAKE menuconfig to first load the original configuration and then make any modifications you need. I enabled the PPS kernel options that I need:
  1. Build the kernel (e.g. $MAKE) and all modules. Install them to a directory.
  2. Download the WiFi drivers and apply some patches:
	git clone --single-branch --branch debian https://github.com/ntc-chip-revived/RTL8723BS.git 
	cd RTL8723BS
	for f in debian/patches/0*; do echo "Applying ${f}"; patch -p 1 < $f; done
  1. Fix the WiFi driver to stop flooding the logs with endless debug messages by modifying the file autoconf.h in the include folder and commenting the main debug line CONFIG_DEBUG. This will remove most messages; there are still a few occasional ones left which could probably also be removed if some other debug-related lines are commented but I didn’t test.
//#define CONFIG_DEBUG
  1. Build and install the drivers.
  2. Package the kernel and modules into a tar file and copy it to the C.H.I.P.
  3. On the C.H.I.P, extract the tar file and copy the new kernel over. There should be two folders in it: /boot and /lib if you followed this guide. This other guide covers the actual installation process at the end, but there are some errors in the commands. Basically, you want these files from the tar file to be copied in your /boot directory:
    • vmlinuz-4.4.66+
    • System.map-4.4.66+
    • sun5i-r8-chip.dtb
    • dtbs/4.4.66+/sun5i-r8-chip.dtb
    • config-4.4.66+
  4. I added these symlinks to point to some of these files so that they are used on boot:
    • zImage -> vmlinuz-4.4.66+
    • System.map -> System.map-4.4.66+
    • .config -> config-4.4.66+
    • dtb -> dtbs/4.4.66+/sun5i-r8-chip.dtb
  5. Copy over the contents of the lib directory from the tar file to /lib. This contains all the kernel modules.
  6. Generate a new initramdisk (update-initramfs -c -k “4.4.66+”). It threw some errors at me but seemed to work.

My final /boot folder ended up like this:

chip@chip:/boot$ ls -lah
total 39M
drwxr-xr-x  3 root root 1.5K May  1 20:34 .
drwxr-xr-x 22 root root 1.5K May  1 19:54 ..
lrwxrwxrwx  1 root root   14 May  1 20:32 .config -> config-4.4.66+
-rw-r--r--  1 root root 169K Dec  6  2016 config-4.4.13-ntc-mlc
-rw-r--r--  1 root root 169K May  1 20:31 config-4.4.66+
lrwxrwxrwx  1 root root   30 May  1 20:32 dtb -> dtbs/4.4.66+/sun5i-r8-chip.dtb
lrwxrwxrwx  1 root root   39 May  1 00:54 dtb-4.4.13-ntc-mlc -> dtbs/4.4.13-ntc-mlc/./sun5i-r8-chip.dtb
drwxr-xr-x  4 root root  296 May  1 20:31 dtbs
-rw-r--r--  1 root root 5.6M May  1 00:53 initrd.img-4.4.13-ntc-mlc
-rw-r--r--  1 root root 5.7M May  1 20:34 initrd.img-4.4.66+
-rw-r--r--  1 root root  40K Apr 30 22:24 sun5i-r8-chip.dtb
-rw-r--r--  1 root root  40K Apr 30 21:57 sun5i-r8-chip.dtb.bak
lrwxrwxrwx  1 root root   18 May  1 20:31 System.map -> System.map-4.4.66+
-rw-r--r--  1 root root 3.3M Dec  6  2016 System.map-4.4.13-ntc-mlc
-rw-r--r--  1 root root 3.3M May  1 20:31 System.map-4.4.66+
-rwxr-xr-x  1 root root 6.8M Dec  6  2016 vmlinuz-4.4.13-ntc-mlc
-rwxr-xr-x  1 root root 6.8M May  1 20:31 vmlinuz-4.4.66+
lrwxrwxrwx  1 root root   15 May  1 20:31 zImage -> vmlinuz-4.4.66+
-rwxr-xr-x  1 root root 6.8M Apr 30 21:57 zImage.bak
  1. Reboot your C.H.I.P. (mine had to be unplugged, the reboot command puts it into some sort of zombie state) and your new kernel should be loaded!
chip@chip:~$ uname -a
Linux chip 4.4.66+ #1 SMP Sun May 1 18:56:38 UTC 2022 armv7l GNU/Linux

In case some of the original guides I followed disappear (as has a lot of C.H.I.P. related stuff), I’m posting copies of some of the scripts I followed or borrowed parts of below. I’m also including a copy of the kernel I compiled with PPS support enabled (and no other changes), if you trust downloading it from random strangers on the internet. I compiled it using gcc 7.5.0 on Ubuntu 18.04.6 LTS.

In a future post I’ll cover modifying the Device Tree Binary to actually activate the PPS function – assuming I get it working!

One thought on “Installing a custom kernel onto the CHIP

  1. Thanks friend! I have two C.H.I.P. Pros (chippies) I got just before the NTC implosion and I’ve been thinking of using one as an ADS-B (airplane traffic) receiver, especially since Raspberry Pis are pretty hard to find these days.

Leave a Reply

Your email address will not be published. Required fields are marked *