Skip to content

Setup Development Environment

Antonio Vivace edited this page Apr 13, 2018 · 27 revisions

In this tutorial you'll be guided step by step in the building and setup of CoderBot, from ground up to the fully working evironment, directly from source.

It is composed in four "macro-steps": Preparation of the Machine, Preparation of the Environment, Installation of the Core and Configuration. The first macro-step is composed in two mutually exclusive options: Preparation of the Virtual Machine (qemu) and Preparation of the Physical Machine (Raspberry Pi).

Note: The VM option is for testing and development purposes only.

Preparation of the Machine

Preparation of the Virtual Machine (qemu)

Requirements

Packages:

  • qemu-system-arm (>= 2.11)

Recommended distros:

  • Ubuntu 18.04 or higher
  • Debian 10 Buster or higher

Install qemu

On Debian and Debian-based distros:

sudo apt install qemu-system-arm

Install the Virtual Machine

Create the directories that will host our virtual machine's files:

mkdir ~/rasp-qemu && mkdir ~/rasp-qemu/qemu-rpi-kernel

Move into qemu-rpi-kernel folder and download the patched kernel and its .dtb:

cd ~/rasp-qemu/qemu-rpi-kernel
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.9.59-stretch
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb.dtb

Move to the parent folder, download and unzip Raspbian's image:

cd ..
wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-03-14/2018-03-13-raspbian-stretch-lite.zip
unzip 2018-03-13-raspbian-stretch-lite.zip && rm 2018-03-13-raspbian-stretch-lite.zip

Create an executable file and give execution permission:

echo "qemu-system-arm -kernel ./qemu-rpi-kernel/kernel-qemu-4.9.59-stretch \
                   -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' \
                   -hda 2018-03-13-raspbian-stretch-lite.img \
                   -cpu arm1176 \
                   -m 256 \
                   -machine versatilepb \
                   -no-reboot \
                   -serial stdio \
                   -dtb ./qemu-rpi-kernel/versatile-pb.dtb \
                   -net nic -net user,hostfwd=tcp::2222-:22" > coderbot.sh && chmod +x coderbot.sh

Execute the .sh file, et voilà!

./coderbot.sh

Enable SSH

In order to enable SSH permanently from the first boot, we'll have to create an empty file named "ssh" (without extension) into the boot partition.

Now we'll have to mount the boot partition. The problem is that the .img files are raw images of a whole disk. That means they start with a bootloader and a partition table. We have to find out the offset of the partition in bytes and mount it with the offset option of mount.

fdisk -l 2018-03-13-raspbian-stretch-lite.img

This will show us the sector size of the disk and the start sector of the boot partition (the one with FAT filesystem).

Disk 2018-03-13-raspbian-stretch-lite.img: 1,7 GiB, 1858076672 bytes, 3629056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa8fe70f4

Device                                Boot Start     End Sectors  Size Id Type
2018-03-13-raspbian-stretch-lite.img1       8192   93802   85611 41,8M  c W95 FAT32 (LBA)
2018-03-13-raspbian-stretch-lite.img2      98304 3629055 3530752  1,7G 83 Linux

We can use these data to calculate the offset in bytes with this formula:

sector size in bytes * start sector offset = offset in bytes

In my case:

512 bytes of sector size * 8192 start sector = 4194304 bytes of offset

Now that we have the offset we can mount our partition in a temporary folder:

mkdir tmp && sudo mount -o loop,offset=4194304 2018-03-13-raspbian-stretch-lite.img tmp

We create an empty file named "boot" inside the boot partition:

sudo touch tmp/ssh

Now we umount the partition and delete the temporary folder:

sudo umount tmp
rm -d tmp

Enable SSH Key-Based Authentication

Create the keys in keys folder:

mkdir keys && ssh-keygen -t rsa -b 2048 -q -f keys/rpi_key -P ""

Pass the public key to the Raspberry trough SSH:

ssh-copy-id pi@localhost -i keys/rpi_key.pub -p 2222

Now we should be able to login:

ssh pi@localhost -p 2222 -i ~/rasp-qemu/keys/rpi_key

Preparation of the Physical Machine (Raspberry Pi)

Stuff...

Preparation of the Environment

Stuff...

Clone this wiki locally