Menu

How to create an image

Stefan Fuchs

How to prepare a sd card image with Debian for IOT2000

A virtual machine with Debian 8.x i386 was used to build the kernel and to prepare the sd ard image for the IOT2000.



Prepare build environment

Install required packages
sudo apt-get install debootstrap build-essential binutils git gawk chrpath kernel-package fakeroot libncurses5-dev parted


Prepare the linux kernel

Download the kernel
mkdir ~/dev
cd ~/dev
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git


Download Intel Quark patches

Download 'bsp_sources_and_docs_for_intel_quark_v1.1.0.zip' from here and unzip to '~/dev/quark_patchset'

Download IOT2000 patches
cd ~/dev
git clone https://github.com/siemens/meta-iot2000.git
mkdir ~/dev/iot2000-patchset/
cp ~/dev/meta-iot2000/meta-iot2000-bsp/recipes-kernel/linux/files/* ~/dev/iot2000-patchset


Patch the kernel with Intel Quark patches
cd ~/dev/linux-stable/
git reset --hard 531ec28f9f26f78797124b9efcf2138b89794a1e
git am ~/dev/quark_patchset/*.patch         

Some whitespace warnings appear but that is okay.

Patch the kernel with IOT2000 patches

This has to be done manuelly because patch is not 100% compatible with the kernel version. See patches in ~/dev/iot2000-patchset.

Configure the kernel

The kernel config from Intel Quark patchset can be seen in

~/dev/linux-stable/meta/cfg/kernel-cache/bsp/quark/quark.cfg

You may also have a look at the examples folder, I have uploaded the kernel config which was used for the kernel on the sd card image.

Edit some linux kernel code:

++
in drivers/gpio/Kconfig
Add UIO dependency to GPIO_SCH
config GPIO_SCH
depends on UIO
++


++
in include/linux/serial_core.h
Add the following field in struct uart_port

int                     (*rs485_config)(struct uart_port *, struct serial_rs485 *rs485);

++

Compile the kernel

cd ~/dev/linux-stable/
fakeroot make-kpkg --cross-compile - --arch i386 --initrd --revision 1 kernel_image modules_image

This may take a while depending on your hardware.

Create the sd card image

Setup the image partitions and create a loop device
dd of=~/dev/iot2000.img bs=1 count=0 seek=1G
sudo losetup -f ~/dev/iot2000.img
sudo parted /dev/loop0 mktable gpt
sudo parted /dev/loop0 mkpart primary fat32 1 100MB
sudo parted /dev/loop0 mkpart primary ext3 100MB 1000MB

sudo parted /dev/loop0 set 1 boot on
sudo parted /dev/loop0 set 2 msftdata on

sudo partx -a /dev/loop0
sudo mkfs.vfat -F 16 -I /dev/loop0p1
sudo mkfs.ext3 /dev/loop0p2


Load Debian Wheezy to the image

Mount the second partition of the image and load Debian files
mkdir ~/dev/sd_root
sudo mount /dev/loop0p2 ~/dev/sd_root
sudo debootstrap --arch i386 wheezy ~/dev/sd_root http://http.debian.net/debian


Mount additional directories
sudo mount --bind /dev ~/dev/sd_root/dev/
sudo mount --bind /dev/shm ~/dev/sd_root/dev/shm
sudo mount --bind /dev/pts ~/dev/sd_root/dev/pts
sudo mount --bind /proc ~/dev/sd_root/proc
sudo mount -t sysfs /sys ~/dev/sd_root/sys


Copy previously built IOT2000 kernel to the image:
sudo cp ~/dev/*.deb ~/dev/sd_root/opt/


Prepare Debian on the sd card image

Set root to sd card image and prepare Debian
sudo chroot ~/dev/sd_root/

aptitude install locales
dpkg-reconfigure locales
localedef -i de_DE -c -f UTF-8 en_US.UTF-8 


Install additional packages
apt-get install sudo locales ntp openssh-server initramfs-tools net-tools bash-completion
apt-get install efibootmgr firmware-linux-free gettext-base gnu-fdisk grub-common grub-efi-ia32 grub-efi-ia32-bin grub2-common lockfile-progs os-prober parted ucf zerofree


Prepare serial connection

Add the following lines to file /etc/modules

pch_udc
g_serial



Add the following lines to file /etc/inittab

GS0:23:respawn:/sbin/getty -L 115200 ttyGS0 vt100
T1:23:respawn:/sbin/getty -L 115200 ttyS1 vt100

and comment the following lines in file /etc/inittab

#1:2345:respawn:/sbin/getty 38400 tty1
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6


Set password and create user
passwd
adduser user
addgroup user sudo


Sudo without password
visudo

Change the following line:
%sudo ALL=(ALL:ALL) ALL => %sudo ALL=(ALL) NOPASSWD:ALL

Configure network

Prepare hostname

Add the following line in file /etc/hostname

iot2000

Add the following line in file /etc/hosts

127.0.0.1       localhost iot2000
::1             localhost ip6-localhost ip6-loopback iot2000


Prepare network interfaces

Add the following lines in file /etc/network/interfaces

auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet dhcp


Install the IOT2000 kernel

dpkg -i /opt/*.deb


Fix libpthread bug
for i in `/usr/bin/find /lib -type f -name \*pthread\*so`; do cp ${i} ${i}.bak; sed -i "s/\xf0\x0f\xb1\x8b/\x90\x0f\xb1\x8b/g" ${i}; done


Configure grub bootloader

A valid grub configuration can be seen in examples folder. Copy the example config to /boot/grub/grub.cfg or prepare the configuration on your own.

Create efi bootloader with actual grub configuration
/usr/lib/grub/i386-efi/grub-install


Leave chroot environment

exit


Prepare efi bootloader on sd card

Copy efi loader to first partition of sd card image.

mkdir ~/dev/sd_boot
sudo mount /dev/loop0p1 ~/dev/sd_boot
sudo mkdir -p ~/dev/sd_boot/EFI/BOOT
sudo cp ~/dev/sd_root/boot/grub/boot.efi ~/dev/sd_boot/EFI/BOOT/BOOTIA32.EFI


Clean up

Unmount image
sudo killall ntpd
sudo umount ~/dev/sd_root/dev/pts ~/dev/sd_root/dev/shm ~/dev/sd_root/dev ~/dev/sd_root/proc ~/dev/sd_root/sys ~/dev/sd_root ~/dev/sd_boot
sudo losetup -d /dev/loop0



Now the image is ready and can be used.

Copy image to sd card

sudo dd bs=4M if=~/dev/iot2000.img of=/dev/sdx <check sd card path here>


That's it...


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.