User avatar
chronodekar
Posts: 13
Joined: Sat Jun 22, 2013 3:49 pm

How to compile my own .IMG from scratch?

Sat Jun 22, 2013 4:05 pm

A lot of the tutorials I'm finding on this forum deal with creating applications to run on top of one of the existing OS's available for the Pi. But does anyone know how I could cross-compile the linux image myself?

I just finished torrenting the official 'archlinux-hf-2013-06-06.img' file. Are there instructions available that tell me how to create this file on my own?

Also; is this forum the only public online resource we have? I'm hoping there's a wiki somewhere that I missed.

-chronodekar

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: How to compile my own .IMG from scratch?

Sat Jun 22, 2013 5:46 pm

There is this
http://archlinuxarm.org/forum/index.php
There is a later image
http://www.raspberrypi.org/phpBB3/viewt ... 53&t=47476
Don't know why download page isn't done.

Will write how to make the image perhaps tomorrow, or tonight, grandson hogging laptop

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: How to compile my own .IMG from scratch?

Sat Jun 22, 2013 7:10 pm

Ok, image is you want it, all updated with pacman -Syu
Assumes you haven't resized the rootfs partition, or partitioning is the same as the download

Code: Select all

pacman -Scc #answer y to both, clears pkg cache
pacman -Syy
localepurge #can save up to 50Mb
sync
poweroff
Next assumes you plug card into another linux, and it is detected as /dev/sdb

Code: Select all

fsck.ext4 -y -f /dev/sdb2
mkdir /media/1
mkdir /media/2
mount /dev/sdb1 /media/1
mount /dev/sdb2 /media/2
rm /etc/ssh/ssh_host*
rm /etc/machine-id
rm /etc/*.pacnew
rm /etc/*.pacsave
rm /root/*
rm /var/log/*
dd if=/dev/zero of=/media/1/fill bs=1M
dd if=/dev/zero of=/media/2/fill bs=1M
sync
sync
sync
rm /media/1/fill bs=1M #makes empty space compress well, will fill up partition
rm /media/2/fill bs=1M #makes empty space compress well, will fill up partition
sync
sync
sync
umount /dev/sdb1
umount /dev/sdb1
dd if=/dev/sdb of=myarch.img bs=1M count=1870
#If you resized card leave out count=1870, an 8Gb card will create a file 8Gb in size
sync
zip -9 myarch.img.zip myarch.img
sync
#remove card 
#new card burned with
dd of=/dev/sdb if=myarch.img bs=1M
sync

User avatar
chronodekar
Posts: 13
Joined: Sat Jun 22, 2013 3:49 pm

Re: How to compile my own .IMG from scratch?

Sun Jun 23, 2013 11:43 am

I'll check out the Arch Linux ARM forum linked.

But when I asked about compiling my own image, I meant from source. To over-simplify things;

Code: Select all

cd /directory-with-sources-mostly-C-program-files
gcc sources
I've done embedded development before, and know that we usually use Makefiles, but hope I've expressed what I'm looking for?

-chronodekar

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: How to compile my own .IMG from scratch?

Sun Jun 23, 2013 1:54 pm

Click developers here http://archlinuxarm.org/
Basically, abs is for packages that build without modifying, and GitHub for those that don't.
If package is in both places, the git is the one to use

User avatar
chronodekar
Posts: 13
Joined: Sat Jun 22, 2013 3:49 pm

Re: How to compile my own .IMG from scratch?

Sun Jun 23, 2013 4:32 pm

I think I'm running around in circles. First off here is what I'm trying to accomplish - to get linux source codes, cross-compile (targeting ARMv6 (the raspberry pi one)) running off an x86 host, generate a .img file, mount the file on an SD card and boot my pi off it.

I spent some time under the 'developer' section of http://archlinuxarm.org and following the links, eventually found myself on wiki.archlinux.org. It was a rude shock when the FAQ mentioned that the information was only meant for x86 or 64-x86 systems! Figured things out soon enough; so no worries there.

I might need to review my linux kernel knowhow, but intuitively this is what I feel needs to be done (host is an x86 virtualbox system running ubuntu server 13.04, chosen for the lack of GUI);

1. setup the arm cross-compiler toolchain on my host
Some instructions are available here (http://archlinuxarm.org/developers/dist ... -compiling) and I think I saw something elsewhere too, but can't find the link now. It was a blog and I remember reading that it would take about an hour to just compile everything needed. I remember it demonstrating how to cross-compile a simple 'hello world' application on an x86 host and copy it over to the ARM system to run.

2. configure the kernel sources to use the cross-compiler instead of the default one and create an image.
I'm going to assume that the output of this step will be the .img file I need to load on the SD card. Problem is; I'm lost on how to configure things to use the cross-compiler created in the earlier step. At the moment, I'm searching the internet for answers.

Any hints on where I should look would be appreciated. Also; I understand that the Raspberry Pi isn't fully open-source and that some sections of the main chip (such as the GPU) are closed-source and only available in binary blobs (I think). I don't mind linking those in as extra modules, but I really want to compile as much of the final .IMG as I can from raw source code.

-chronodekar

pepedog
Posts: 1043
Joined: Fri Oct 07, 2011 9:55 am

Re: How to compile my own .IMG from scratch?

Sun Jun 23, 2013 5:42 pm

When you say image, I interpret as a whole thing, kernel just a part. No one on Archlinuxarm has compiled solely on an x86, but has used distcc on them. I myself have an odroid U2 with rpi rootfs + odroid kernel. Could understand if you wanted to create rootfs from already compiled packages. Everything from scratch is no mean task, maybe you should look at buildroot as used by noobs.

limpens
Posts: 38
Joined: Thu Sep 13, 2012 1:15 pm

Re: How to compile my own .IMG from scratch?

Sun Jun 23, 2013 6:11 pm

I'm building all stuff from scratch using buildroot. Only dependency is a working internet connection and (64bit) Ubuntu.
The supplied (cross) compilers are 64bit versions, hence the 64bit dependency. But you could always build your own using crosstool-NG.

You can use busybox to replace lots of standard tools or use the full-blown version of the actual tools.

Checkout http://bsquask.com/ for more information.

Typical build times on a core i7 vary from 30 minutes to an hour, depending on how full-blown you want your image to be.

Return to “Arch”