Creating Emdebian file system for ARM

Information of device properties, device configuration, internal register modification, memory mapping.
Creating, building, loading and executing binary images form RedBoot, including Linux kernel.
Creating, building, loading and executing binary files from Linux user and kernel space.

Creating Emdebian file system for ARM

Postby kakanakov » Tue Jul 19, 2011 5:24 pm

To create a file system for the ARM you can use http://linux.die.net/man/8/debootstrap utility.
First, create a debootstrap directory and change to it:
Code: Select all
$mkdir /opt/debootstrap
$cd /opt/debootstrap

The using the utility as root you can create an initial file system.Note: if you have no debootstrap command, you must install the debootstrap package
Code: Select all
$debootstrap --arch=armel --foreign lenny grip/ http://www.emdebian.org/grip/

The --arch show that the target is ARM.
The --foreign show the utility to do the initial unpack phase of bootstrapping only, for example if the target architecture does not match the host architecture. A copy of debootstrap sufficient for completing the bootstrap process will be installed as /debootstrap/debootstrap in the target filesystem.
The next parameter shows the name of the distro to use (testing/stable/etch/sid/lenny/squeeze).
The grip/ is the directory to download the packages, and final parameter is the URL to get the packages from.

After this step you have successfully downloaded a file system, but is is incomplete.The file system needs to be configured.
Code: Select all
$cd grip/
$echo "proc /proc proc none 0 0" >>etc/fstab
$echo "EP9302" >etc/hostname
$mknod dev/console c 5 1
$mknod dev/ttyAM0 c 204 64
$echo 'http://www.emdebian.org/grip/ lenny main' >>etc/apt/sources.list

In these steps you make sure that the file system will have initial fstab and you create console and ttyAM0 nods in the /dev system to ensure access to console after boot.
Note: creating the serial device depends on your hardware platform - the name of the device and the parameters to configure it.
User avatar
kakanakov
 
Posts: 28
Joined: Fri Mar 06, 2009 4:36 pm
Location: Lab 2204a, campus 2, TU - Plovdiv

Re: Creating Emdebian file system for ARM

Postby kakanakov » Tue Jul 19, 2011 5:39 pm

Now, having a file system, You must select device to put it on.
You can use SD card or USB memory (at least 1GB), or you can use NFS on remote device.
Assuming to use USB (the same will work with SD/MMC cards substituting the device name).
First, you must plug the USB memory to the computer but do not mount it. Then you must open a terminal as root (or su in users terminal).
In the terminal you can use
Code: Select all
$fdisk -l
to see the name of the USB device (/dev/sd?). Make sure which one is it or you can make irreversible changes to the data on your devices such as SATA disks.
Assuming the USB device is /dev/sdc, we must create partition on it and make file sysytem.
Code: Select all
$fdisk /dev/sdc

Command (m for help): o
Building a new DOS disklabel with disk identifier 0xa5017fba.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/sdd: 990 MB, 990904320 bytes
32 heads, 63 sectors/track, 960 cylinders
Units = cylinders of 2016 * 512 = 1032192 bytes
Disk identifier: 0xa5017fba
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-960, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-960, default 960):
Using default value 960
Command (m for help): p
Disk /dev/sdc: 990 MB, 990904320 bytes
32 heads, 63 sectors/track, 960 cylinders
Units = cylinders of 2016 * 512 = 1032192 bytes
Disk identifier: 0xa5017fba
Device Boot Start End Blocks Id System
/dev/sdd1 1 960 967648+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Code: Select all
$mkfs.ext3 /dev/sdc1

mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
60544 inodes, 241912 blocks
12095 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=251658240
8 block groups
32768 blocks per group, 32768 fragments per group
7568 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Then you must mount the newly created partition:
Code: Select all
$mkdir /mnt/arm
$mount /dev/sdc1 /mnt/arm

After that you must copy the created debootstrap file system into USB flash drive. It can be done using dd or with archiving the /opt/debootstrap/grip and extracting it on the /mnt/arm. Using the simple copy can make some problems as long as the debootstrap file system includes special files as /dev/null, dev/zero/, dev/urandom, etc.
Code: Select all
$cd /opt/dbootstrap/grip
$tar jcf ../emdebian-grip.tar.bz2 .
$cd /mnt/arm
$tar jxf /opt/debootstrap/emdebian-grip.tar.bz2
$sync
User avatar
kakanakov
 
Posts: 28
Joined: Fri Mar 06, 2009 4:36 pm
Location: Lab 2204a, campus 2, TU - Plovdiv

dbootstrap second stage

Postby kakanakov » Tue Jul 19, 2011 6:22 pm

The next stage is called second stage.
In this stage you must boot the target system (ARM9 device).
Considering the use of EP9302 or similar with RedBoot, you must prepare an appropriate kernel (see other topics in this forum).
In the RedBoot environment interrupt the bootloader. Using the
Code: Select all
fconfig
command change the boot commands.
For the kernel additional parameters must be used.In my case:
Code: Select all
console=ttyAM0 root=/dev/sda1 init=/bin/sh rootdelay=10

The first parameter is critical to have a console to reach the target. It depends on the hardware chip of the serial port as stated in the first stage when tuning the file system.
The second provides the kernel with the path to its root file system. It depends on the drive used - USB, SD, MMC, other.
The third parameter is to specify /bin/sh as the init because there is no inittab file and even if you add one you won't be able to login because login/pam are not set up properly.
The last tells the kernel to wait 10 seconds for the root device to be ready. It is usefull for USB device, because there is delay for loading drivers for USB, storage, etc.
Then boot the device.
After booting the device you should see shell sh-3.2#.
If you cannot reach this shell review the kernel parameters depending on the error provided by the kernel.
In the shell you must start the second stage of the dbootstrap:
Code: Select all
sh-3.2# mount /proc /proc -t proc
sh-3.2# export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
sh-3.2# /debootstrap/debootstrap --second-stage

After this you should wait a long time (more than an hour).
Then add this line to inittab
Code: Select all
sh-3.2# printf "T0:123:respawn:/sbin/getty 57600 ttyAM0\n" >>etc/inittab

And change the root password.
Code: Select all
sh-3.2#passwd

And reboot.
After rebooting you must remove the init=/bin/sh parameter from the bootscript.

After login update and upgrade the packets.
Code: Select all
EP9302:~# apt-get update
EP9302:~# apt-get upgrade
User avatar
kakanakov
 
Posts: 28
Joined: Fri Mar 06, 2009 4:36 pm
Location: Lab 2204a, campus 2, TU - Plovdiv

QEMU/debootstrap approach

Postby mshopov » Fri Dec 14, 2012 3:36 pm

  1. Choose the target's architecture and Debian suite (e.g. stable, testing, sid) you want to bootstrap. For this tutorial, we will choose the ARM target architecture and the wheezy (AKA Debian testing) suite.
  2. Choose a (empty) directory where you want the new system to be populated. This directory will reflect the root filesystem of the new system. Note that the host system is not affected in any way, and all modifications are restricted to the directory you have chosen.
    Note: For the purporses of this document, we will use "debian_armel_wheezy" as the target directory. Create this directory, if it does not exist already:
    Code: Select all
    # mkdir debian_armel_wheezy
  3. To bootstrap the new system, run debootstrap. E.g.:
    Code: Select all
    # debootstrap --foreign --arch armel wheezy debian_armel_wheezy http://ftp.debian.org/debian/

    where "debian_armel_wheezy" is the directory you have created and "armel" is the target architecture. See debootstrap(8) manpage for more details about each parameter used above.
    "http://ftp.debian.org/debian/" is the Debian mirror from which the necessary .deb packages will be downloaded. You are free to choose any mirror you like, as long as it has the architecture you are trying to bootstrap. See http://www.debian.org/mirror/list for the list of available Debian mirrors.
  4. The new system is now created. By default, debootstrap creates a very minimal system, so you will probably want to extend it (see below 'Configuring the new system' for some instructions).
  5. Copy 'qemu-arm-static' to the target file system. To be able to chroot into a target file system, the qemu emulator for the target CPU needs to be accessible from inside the chroot jail.
    Code: Select all
    # cp /usr/bin/qemu-arm-static debian_armel_wheezy/usr/bin
  6. Run the second stage debootstrap to unpack all the packages you instralled in step 3.
    Code: Select all
    # DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
     LC_ALL=C LANGUAGE=C LANG=C chroot debian_armel_wheezy /debootstrap/debootstrap --second-stage
  7. Trigger post install scripts
    Code: Select all
    # DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
     LC_ALL=C LANGUAGE=C LANG=C chroot debian_armel_wheezy dpkg --configure -a

If you are using EP930x development board you will also need some extra preparations:

  1. Change root user password:
    Code: Select all
    # DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
     LC_ALL=C LANGUAGE=C LANG=C chroot debian_armel_wheezy echo "root:olimex" | chpasswd
  2. To mount proc filesystem for the initial login
    Code: Select all
    echo "proc /proc proc defaults 0 0" >> etc/fstab
  3. To redirect console to the serial port of the board after init
    Code: Select all
    printf "T0:123:respawn:/sbin/getty 57600 ttyAM0\n" >>etc/inittab

    Comment: It is useful to open and edit /etc/inittab to disable other TTYs
source: http://wiki.debian.org/EmDebian/CrossDebootstrap
Take a method and try it. If it fails, admit it frankly, and try another. But by all means, try something
User avatar
mshopov
 
Posts: 16
Joined: Thu Feb 26, 2009 2:15 pm
Location: Plovdiv


Return to EP9302_Linux

Who is online

Users browsing this forum: No registered users and 3 guests

cron