Customizing BBB Angstrom Kernel?

Hi friends,

Total newbie here, so forgive me.

I’m trying to add functionality to iptables so I can use the BBB as a ad-hoc “router”, sharing it’s Ethernet connection with others.

From what I’ve gleamed so far I need to add that functionality by recompiling the kernel.

So following the links at http://www.angstrom-distribution.org/ i cloned the setup-scripts.

MACHINE=beaglebone ./oebb.sh config beaglebone

MACHINE=beagleboard ./oebb.sh update

. environment-angstrom-v2013.06

bitbake -c menuconfig virtual/kernel

I then change the options I need, but when I built it made a zImage file… Which confuses me.

Now what I don’t understand is that the image I want should be based off the regular systemd image.

  • bitbake systemd-image
    

How do I update the kernel configuration from the systemd image without just building the regular image?

A step-by-step explanation would be awesome, cause I’ve never customized/built the linux kernel before.
I also do not have a serial cable yet. Is this necessary for running a custom kernel? Do options in u-boot need to be changed?

I’m sure I’m asking all the wrong questions, but would really appreciate some help!

Here are the options that I need:

Networking  ---->
 Networking options  ---->
  Network packet filtering framework (Netfilter)--->
   Core Netfilter Configuration ---->
    <*> Netfilter connection tracking support
    <*> Netfilter Xtables support (required for ip_tables)
    <*>   "NFLOG" target support
    <*>   "conntrack" connection tracking match support
    <*>   "state" match support
   IP: Netfilter Configuration --->
    <*> IPv4 connection tracking support (required for NAT)
    <*> IP tables support (required for filtering/masq/NAT)
    <*>   Packet Filtering
    <*>     REJECT target support
    <*>   Full NAT
    <*>     MASQUERADE target support
    <*> Packet mangling

Do you need iptables? When I last had to deal with routing stuff I ran the gated routing daemon, although
this was on a Sun server that had a bunch of ethernet interfaces on it. Sun Solaris didn’t have iptables back then.

Thanks for the response!

I have just been following various tutorials online that use the following command.

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Maybe even the following

iptables -A FORWARD -i eth0 -o wlan0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Allowing the packets coming in via the ad-hoc wlan to be forwarded onward via ethernet.

I’ve seen this in several tutorials of sharing internet whether via usb or wlan.

However, if I run that command on the beaglebone I get an error saying iptables needs to be updated.

can’t initialize iptables table `nat’: (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

I’ll look into gated a little more. I’m looking for any simple solution that works.

Hi,

What your attempting to do is possible with Angstrom Linux. You just have to work through a number of setup issues.

If you want to use IP forwarding with NAT it is necessary to recompile the kernel. My kernel configuration is:

→ Networking support (NET [=y])
→ Networking options
→ Network packet filtering framework (Netfilter) (NETFILTER [=y])
→ Core Netfilter Configuration
Netfilter connection tracking support
{M} Netfilter Xtables support (required for ip_tables)
*** Xtables combined modules ***
“NFLOG” target support
“conntrack” connection tracking match support
“state” match support
→ IP: Netfilter Configuration
IPv4 connection tracking support (required for NAT)
[*] proc/sysctl compatibility with old connection tracking (NEW)
IP Userspace queueing via NETLINK (OBSOLETE)
IP tables support (required for filtering/masq/NAT)
“ah” match support
“ecn” match support
“rpfilter” reverse path filter match support
“ttl” match support
Packet filtering
REJECT target support
ULOG target support
IPv4 NAT
MASQUERADE target support
NETMAP target support
REDIRECT target support
Packet mangling

Before you start spending time rebuilding the kernel …

Do you want to use DHCP to assign IP addresses to computers attached to the ethernet port?

What about DNS?

Have you considering disabling connman?

Regards
RLYON

Some further comments:

You don’t need to rebuild MLO/u-boot.img
You don’t need a serial cable. It can be helpful for debugging, but thats all.
Have you got the wifi device working correctly on your BBB?

I would recommend you get an micro SD card for testing your new kernel, before you copy it to eMMC.

Regards …

Thanks a lot for clearing some of this up!

So I’m trying to get a mesh network running for a university project using AHCPD/Babel.
The goal would be for a Ethernet connected node (beaglebone) to use DHCP to acquire an IP address, and then it would share it’s internet connection over ad-hoc wlan with it’s peers (also beaglebones).

If I can’t get AHCPD/Babel to run properly, I’ll probably just use a regular ad-hoc network with static IPs. ('m severely time-constrained as this project is due by the end of the semester… and this is only a part of it!)

Yes I have got my wifi module working, I was already able to ping google.com from wireless ad-hoc beaglebones over my laptop’s eth0 which was awesome!
Now I just want to replicate this with only beaglebones, which is why I need the kernel changes for NAT.

I do have a microSD card for testing. I ran into some complications last night trying to format the card properly because the mkcard.sh script was not working for me.
I followed some of the instructions here http://derekmolloy.ie/custom-kernel-and-angstrom-distribution-recipe/.

Do you know of any good guides for testing the kernel? I didn’t know you could test it before flashing it.

I’m also still trying to work through bitbake and just building the custom kernel. It’s been difficult to distinguish how the images get built, since there are lots of defconfigs (ti-linux-psp-3.2 vs. linux-mainline-3.8.0) and I’m unsure how they all get tied together.

Thanks again,
Mark

Wow! I think I got it to work.
I did some stuff that I’m not totally sure is correct, but it appears to have worked!!!

bitbake -c clean virtual/kernel
bitbake -c -f virtual/kernel

this gave uImage and modules.tgz, where modules is lib/ folder

//Make copy of old image
root@beaglebone cp /boot/uImage /boot/uImage.old

//Copy new image
host# scp uImage root@192.168.1.3:/boot/uImage

//Copy modules
host# scp lib root@192.168.1.3:confused: -r

//Install modules a
root@beaglebone depmod -a
root@beaglebone reboot

Now I was able to run my iptable command and it seems to have worked! (It went through, before I’d get an error message)

 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

So the rootfs and the uImage are completely separated? Cause it doesn’t appear that a rootfs was built and I didn’t change it? I’m still a noob at this linux stuff…

Should my process have even worked???

To assign addresses and handle DNS I would recommend dnsmasq. I compiled the source code on the bbb. Have you installed gcc/make/etc on the beaglebone black? I think you can also install it using opkg. 08 - Installing dnsmasq Source Site: File: dnsmasq-2.66.tar.gz Version: 2.66 Compile and Install Extract dnsmasq-2.66.tar.gz into the home directory. cp ~/libconfig-1.4.9/aux-build/install-sh ~/dnsmasq-2.66/install-sh Modify variable in Makefile to INSTALL = ~/dnsmasq-2.66/install-sh Build and install: make make install dnsmasq Service Create a file /lib/systemd/dnsmasq.service which contains: [Unit] Description=A lightweight DHCP and caching DNS server After=networking.service [Service] Type=forking ExecStart=/usr/local/sbin/dnsmasq ExecStop=/usr/bin/killall dnsmasq [Install] WantedBy=multi-user.target Create a link to the dnsmasq service file cd /etc/systemd/system ln -f /lib/systemd/dnsmasq.service dnsmasq.service Start the service: systemctl daemon-reload systemctl enable dnsmasq.service Configuration file Create a configuration file /etc/dnsmasq.conf with the following lines resolv-file=/var/run/ppp/resolv.conf interface=eth0 no-hosts dhcp-range=192.168.0.50,192.168.0.70,12h dhcp-option=252,"\n" dhcp-option=vendor:MSFT,2,1i Restart beagle to allow the dnsmasq service to start. great I don’t use the script. Instead I just use the gnome disk utility. ie Installing on SD card Use the disk utility application to create the partitions on a blank micro SD card and mount them. Create DOS Partition with following: Size: 8.00 MB Type: FAT Name: BEAGLEBONE The edit the DOS partition with the following: Partition Label: Type: W95 FAT32 (LBA) (0x0c) Bootable: Check this tickbox Create a Linux partition to fill the rest of the SD card: Size: 7.940 GB Type: Ext4 Name: Angstrom Take Ownership of filesystem: Not checked Encrypt underlying device: Not checked Then mount both partitions. The dos partition will be mounted at /media/BEAGLEBONE and the Linux partition will be mounted at /media/Angstrom. Copy the Angstrom distribution files to the SD card: cd ~/Projects/angstrom-v2012.12/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/deploy/images/beaglebone sudo cp u-boot-beaglebone-2011.09+git-r30.img /media/BEAGLEBONE/u-boot.img sudo cp MLO-beaglebone-2011.09+git /media/BEAGLEBONE/MLO sudo echo “optargs=quiet” > /media/BEAGLEBONE/uEnv.txt sudo tar zxv -C /media/Angstrom -f Angstrom-console-image-eglibc-ipk-v2012.12-beaglebone.rootfs.tar.gz sudo tar zxv -C /media/Angstrom -f modules-3.8.13-r23a-beaglebone.tgz The SD card now is ready for the Beaglebone. Demount the partitions. Make sure when the system boots for the first time to run: depmod -a That’s what the SD card is used for. Once that is complete you have to build a flasher. But you can complete all software development using the SD card. 01 - Building Angstrom-v2012.12 This guide details the process of building a console image from the Angstrom source on an Xubuntu 12.04.3 32-bit Linux host. Prerequisites Then we need some additional development tools. Enter the following: sudo apt-get install sed wget cvs subversion git-core coreutils unzip texi2html texinfo docbook-utils gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ desktop-file-utils chrpath /bin/sh (ls -l /bin/sh) is symbolically linked to dash. “dash” is a POSIX compliant shell that is much smaller than “bash”. Some broken shell scripts still make use of bash extensions while calling into /bin/sh. To work around this issue call “sudo dpkg-reconfigure dash” and select No when it asks you to install dash as /bin/sh. Download Angstrom Distribution and Build To download the distribution for Beaglebone enter the following commands: cd ~/Projects mkdir angstrom-v2012.12 cd ./angstrom-v2012.12 git clone git://github.com/Angstrom-distribution/setup-scripts.git cd setup-scripts MACHINE=beaglebone ./oebb.sh config beaglebone MACHINE=beaglebone ./oebb.sh update And to compile the console version of the distribution: . ~/.oe/environment-angstromv2012.12 bitbake console-image During these steps the computer must be connected to the Internet. Custom Kernel Delete the contents of the directory /home/rlyon/Projects/angstrom-v2012.12/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/deploy/images/beaglebone Clean distribution with following commands bitbake u-boot-denx -c cleansstate bitbake virtual/kernel -c cleansstate bitbake -c clean console-image Create the boot files MLO and u-boot with the following command: bitbake u-boot-denx Set up the custom kernel we require: bitbake virtual/kernel -c configure cd ~/Projects/angstrom-v2012.12/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-mainline-3.8.13-r23a/git make ARCH=arm menuconfig Disable watchdog shut down: → Device Drivers → Watchdog Timer Support -- WatchDog Timer Driver Core [] Disable watchdog shutdown on close *** Watchdog Device Drivers *** < > Software watchdog < > Synopsys DesignWare watchdog < > MPcore watchdog <> OMAP Watchdog <> TWL4030 Watchdog < > Max63xx watchdog Enable NAT: → Networking support (NET [=y]) → Networking options → Network packet filtering framework (Netfilter) (NETFILTER [=y]) → Core Netfilter Configuration Netfilter connection tracking support {M} Netfilter Xtables support (required for ip_tables) *** Xtables combined modules *** “NFLOG” target support “conntrack” connection tracking match support “state” match support → IP: Netfilter Configuration IPv4 connection tracking support (required for NAT) [*] proc/sysctl compatibility with old connection tracking (NEW) IP Userspace queueing via NETLINK (OBSOLETE) IP tables support (required for filtering/masq/NAT) “ah” match support “ecn” match support “rpfilter” reverse path filter match support “ttl” match support Packet filtering REJECT target support ULOG target support IPv4 NAT MASQUERADE target support NETMAP target support REDIRECT target support Packet mangling Then copy the configuration file: ~/Projects/angstrom-v2012.12/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-mainline-3.8.13-r23a/git/.config to ~/Projects/angstrom-v2012.12/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-mainline-3.8.13-r23a/git/.config.old ~/Projects/angstrom-v2012.12/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-mainline-3.8.13-r23a/git/defconfig ~/Projects/angstrom-v2012.12/setup-scripts/sources/meta-beagleboard/common-bsp/recipes-kernel/linux/linux-mainline-3.8/beaglebone/defconfig ~/Projects/angstrom-v2012.12/setup-scripts/sources/meta-ti/recipes-kernel/linux/linux-ti33x-psp-3.1/beaglebone/defconfig ~/Projects/angstrom-v2012.12/setup-scripts/sources/meta-ti/recipes-kernel/linux/linux-ti33x-psp-3.2/beaglebone/defconfig Then compile: cd ~/Projects/angstrom-v2012.12/setup-scripts bitbake virtual/kernel bitbake console-image Maybe this will give you some ideas.

The kernel image and root files system are separate items. You can upgrade the kernel and copy it to the existing root files system. If you upgrade the kernel it is usual to to upgrade the device modules as well.

Thanks Richard, you really have been an enormous help in this process, and I feel much more comfortable with this. Thank you for helping, I really have already learned a lot more.

Right now I’m trying to tweak the bitbake recipes a bit.
I’d like to remove connman and install networkmanager instead.
Connman apparently does not have ad-hoc wireless support…

All I’m trying to do is get my beagles to autojoin the ad-hoc network on startup.
I initially had some init.d scripts that would use ifconfig and iwconfig to set up the network, but for some reason these would not work totally correctly. The static IP would be correct, but in iwconfig it would not be set up with the ad-hoc network defined…

I also followed this guide, set up the service as was discussed in the link, but it did not function correctly either.
http://octopusprotos.com/?p=37

I tried removing connman with opkg and installing networkmanager, since I noticed I did not have a networking service (/etc/systemd/networking or whatever it is)… (this was a n00b mistake).
I ended up losing ssh access… and now am unable to talk to the board.

I guess if I had a serial cable I could debug the board, but right now it doesn’t get an IP address (I checked the router’s IP tables and it wasn’t there) and the default USB 192.168.7.2 doesn’t work either (I’m assuming connman used to set that up, but that was removed.)

Right now the plan is to edit the bitbake recipes to remove connman and have networkmanager built instead. Then reflash the board. I have a feeling that there may be an easier way…

Thanks again for the help,
Mark

I started to try to debug the board at home, and it actually did show up on my dhcp list. So I do have SSH access!

Here is my /etc/network/interfaces file.

`
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto usb0
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.0

auto wlan0
iface wlan0 inet static
address 10.42.0.1
netmask 255.255.255.0
wireless-essid Capstone
wireless-mode ad-hoc

`

I guess I assumed NetworkManager was tied to /etc/network/interfaces… which I think is wrong…

Hi,

If you want to use /etc/network/interface as a configuration file you start the network services with the command ifup -a. If you can define the wifi interface in /etc/network/interface then it will automatically started as well. ie I am talking about a static configuration, where the network interfaces are configured and started just after boot (using system). It is assumed the wifi dongle remains permanently plugged into the bbb.

Netmanager is useful for dynamic situations. ie You want automatic detection of your wi-fi dongle whenever it is plugged in.

Netmanager will allow you to specify a static IP address for the Ethernet interface. You will need to have a look at the man pages.

Regards …