Home | Projects | Notes > Linux Device Drivers > Project Setup
Install necessary packages on the host:
xxxxxxxxxx
11sudo apt update
xxxxxxxxxx
11sudo apt install build-essential lzop u-boot-tools net-tools bison flex libssl-dev libncurses5-dev libncursesw5-dev unzip chrpath xz-utils minicom
Setup the workspace:
custom_drivers/
downloads/
patches/
source/
Download boot images and root filesystem
Boot images - pre-built-images.zip
am335x-boneblack.dtb
- Device tree binary of BBB
MLO
- Primary boot loader (Memory LOader)
u-boot
- U-boot bootloader image
uEnv.txt
- U-boot commands and environment settings
uImage
- Kernel image
Debian root filesystem - bone-debian-9.9-iot-armhf-2019-08-03-4gb.img.xz
(https://beagleboard.org/)
Prepare
Partition 1 - BOOT / FAT16 / Stores boot images (e.g., MLO, U-boot, kernel image) / 512MB
Partition 2 - ROOTFS / EXT4 / Stores Debian root filesystem / Rest of the
Download cross-compiler and toolchain
To cross-compile the Linux kernel, Linux application, and kernel modules to ARM Cortex-Ax architecture, cross-compiler is necessary.
The SoC AM335x from TI is based on ARM Cortex-A8 processor of ARMv7 architecture.
Download the cross-compiler - gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
(https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/)
Older versions: https://releases.linaro.org/components/toolchain/binaries/
Newer versions: https://snapshots.linaro.org/gnu-toolchain/
Add the toochain binary path to the PATH variable (.bashrc
in home directory)
Go do the home directory
Open .bashrc
file using an editor
Add the following command to the .bashrc
file
xxxxxxxxxx
11export PATH=$PATH:<path_to_toolchain_binaries>
e.g.,
export PATH=$PATH:/home/klee/linux-device-drivers/workspace/downloads/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin
Or simply do
xxxxxxxxxx
11echo "export PATH=$PATH:<path_to_toolchain_binaries>" > ~/.bashrc
In the terminal, type arm
and hit tab
to see if the system recognizes the binaries.
Pin mapping
USB-to-Serial TTL Cable Pins | BBB J1 Header Pin Outs |
---|---|
Pin 1 - GND (Black) | Pin1 - GND |
Pin 4 - RXD (Oragne) | Pin 5 - TXD |
Pin 5 - TXD (Yellow) | Pin 4 - RXD |
Make sure to cross-connect TXDs and RXDs!
Internet over USB
BBB board can communicate with the Internet over the USB cable by sharing the host PC's internet connection.
A separate Ethernet cable is not necessary for the BBB board's internet connection.
The required drivers are enabled by default in the kernel and loaded when Linux boots on the BBB board.
But, you need to enable the internet sharing feature on your host PC to use this service.
First run ifconfig
and see if your system recognizes usb0
interface.
If usb0
interface does not show up, reboot the board and check again.
If it still does not show up, execute the following commands and check again:
xxxxxxxxxx
31sudo modprobe g_ether
2sudo ifconfig usb0 192.168.7.2 up
3ifconfig
At this point you'll be able to ping 192.168.7.1
(to host), but not ping www.google.com
(to the Internet).
Add name server address in /etc/resolv.conf
:
xxxxxxxxxx
21nameserver 8.8.8.8
2nameserver 8.8.4.4
Add name server address in /etc/network/interfaces
xxxxxxxxxx
71iface usb0 inet static
2 address 192.168.7.2
3 netmask 255.255.255.252
4 network 192.168.7.0
5 gateway 192.168.7.1
6 dns-nameservers 8.8.8.8 <-- add this
7 dns-nameservers 8.8.4.4 <-- add this
Add default gateway address by running the following command:
xxxxxxxxxx
11sudo route add default gw 192.168.7.1
We are using the host PC as the default gateway.
Whenever rebooting the board, you need to run this command to get Internet connection. For simple SSH connection to the host PC, running this command is not required.
Run the following commands:
xxxxxxxxxx
11sudo iptables --table nat --append POSTROUTING --out-interface <network_interface_name> -j MASQUERADE
<network_interface_name>
- Your primary connection to the network could be wireless or wired. You must use the name as listed by the commandifconfig
. (In my casewlp61s0
)
xxxxxxxxxx
11sudo iptables --append FORWARD --in-interface <network_interface_name> -j ACCEPT
xxxxxxxxxx
21sudo -s
2echo 1 > /proc/sys/net/ipv4/ip_forward
Simply running
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
won't work!
Whenever rebooting the board, you need to run these commands. So, may be a good idea to create a short script and execute it on every reboot. For example:
xxxxxxxxxx
71#!/bin/bash
2##To run this script do
3##1. chmod +x usbnet.sh
4##2. ./usbnet.sh
5iptables --table nat --append POSTROUTING --out-interface <network_interface_name> -j MASQUERADE
6iptables --append FORWARD --in-interface <network_interface_name> -j ACCEPT
7echo 1 > /proc/sys/net/ipv4/ip_forward
Make sure th replace
<network_interface_name>
with a real name.