December 11, 2019, 11:36:49 pm

News:

Have you visited the Allwinner Chipset wiki? - http://linux-sunxi.org/


Building your own disk image

Started by lawrence, January 25, 2013, 11:05:55 pm

Previous topic - Next topic

lawrence

January 25, 2013, 11:05:55 pm Last Edit: January 31, 2013, 09:53:59 am by lawrence
So, you want to make your own disk image?

Its not that hard, and its good to know how to do it, even if you don't need/want to.

We have some pre-req's -

Go grab the nightlies from here -
http://dl.linux-sunxi.org/amery/sunxi-3.0/latest/cubieboard_hwpack.tar.xz  or
http://dl.linux-sunxi.org/amery/testing-3.4/latest/cubieboard_hwpack.tar.xz

(Doesn't matter which, we only want the ipl and spl for now)


You also need an SD card and a card reader (as we're doing this on a desktop or laptop, not on the Cubie). 
Plug it into your system, and note where the card gets mounted.
This is important, if you get that wrong, you can wipe your system.  So please be careful!.
dmesg will usually show you the device name if you plug in a card, so take a look at what just happened with dmesg, and see what device it is.

Also, if its been a dirty dirty card  :o , may be a good idea to clean it.

#MAKE TRIPLE SURE THE of=/dev/XXX is correct for YOU
#wipe our disk
dd if=/dev/zero of=/dev/[yourcard] bs=1M count=1


Now its all clean, we can do stuff to it.
My preference is to make a 64M bootable partition at 1M on the card (our kernel goes in there)
Then use the rest of the card for the rootfs.

The astute will notice that we make the boot partition at a sufficiently large size that we can test other kernels if we need to (kernels are typically <4M in size).

sfdisk is mildly easier to use than fdisk, so lets use that.


#re-read the card in case you wiped it above
sfdisk -R /dev/[yourcard]

#create a partition 64M in size at 1M, then another partition at 66M till end of the disk
sfdisk -uM /dev/[yourcard]
1,64,c
67,,L

#quit sfdisk, and write the partitions out.

#format them appropriately
mkfs.vfat /dev/[yourcard]1
mkfs.ext4 /dev/[yourcard]2

#ensure filesystem is synced
sync
[/quote]

We should now have 2 partitions.
One 64M in vfat format, and another in ext4.

We also need to make this bootable, so lets blat in the IPL and SPL to the SD at the appropriate places.
Files are the ones extracted from the cubieboard_hwpack we downloaded earlier

[code]
#write spl -> 8k on (this is actually an IPL - initial program loader named badly)
dd if=sunxi-spl.bin of=/dev/[yourcard] bs=1024 seek=8

#write uBoot -> 32k on (uBoot is an SPL - secondary program loader)
dd if=u-boot.bin of=/dev/[yourcard] bs=1024 seek=32


Ok, so now we have the correct partitions, and no data.
What next?

Lets mount them!


mkdir /mnt/boot
mkdir /mnt/rootfs

mount -t auto  /dev/[yourcard]1 /mnt/boot
mount -t auto /dev/[yourcard]2 /mnt/rootfs



Our first partition needs some configuration, as the uBoot expects certain things there.


cd /mnt/boot


Create a file called uEnv.txt and stick the following into it:
Quotebootenv=boot.scr
loaduimage=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}
mmcboot=echo Running boot.scr script from mmc ...; source ${loadaddr}


This tells the uBoot that it needs to look for a file called boot.scr
boot.scr is a compiled file, so lets create it, and compile it.

setenv bootargs console=ttyS0,115200 console=tty0 noinitrd init=/init root=/dev/mmcblk0p2 rootfstype=ext4 rootwait panic=10 ${extra}
fatload mmc 0 0x43000000 script.bin
fatload mmc 0 0x48000000 kernel.img
bootm 0x48000000


The first line calls the kernel, and passes parameters onto it. You'll note that I setup 2 consoles, one on tty0 and another on ttyS0.  I like to have both a serial and a display console on kernel bootup.


To compile it do -
mkimage ‐C none ‐A arm ‐T script ‐d boot.cmd boot.scr

Ok, so now we have a boot.scr and the uEnv.txt tells the uBoot to use it.
What about all those things we just wrote in there?
What are script.bin and kernel.img ?

For the A10 SoC, an FEX file is a compiled settings file to configure the CPU GPIO's and other bits and pieces.
Lets not worry about that now, and just use the premade file script.bin from the cubie_hwpack zip.  Copy that into the first partition.

How about the kernel?

Well, you can either compile your own, or try other peoples.  I generally try a few different things before settling onto one solution.

Copy some kernel's into the boot partition, and name one of them kernel.img
I'll put a few test kernels up in the dl.cubieforums.com later.

So, now we have a bootable card, a sufficiently configured boot partition, with a kernel or three, and... no rootfs.

Lets make one!

Download one of the existing rootfs from here  (user space filesystem actually)  -
http://dl.cubieforums.com/loz/rootfs/

get + unpack into /mnt/rootfs


cd /tmp
axel http://dl.cubieforums.com/loz/rootfs/debian-unstable-armhf.tar.bz2
cd /mnt/rootfs
unp /tmp/debian-unstable-armhf.tar.bz2
#if you don't have/use unp or axel, use more standard tools, or apt-get/yum/pactool... install them


You can now finally unmount the SD card, and try it out.


umount /mnt/rootfs
umount /mnt/boot


Give it a go, and let me know how it works for you.
I'll probably make an empty one for people to try with all the correct files in later, and link in.
For now though, go make some filesystems!


ale92_

hi,
first of all thank you very much for this guide i really needed one like this.
second i have a question:
if i got this correct at the end i should have a boot partition with the kernel, the script.bin, boot.src and the uEnv.txt.
why the other images that i download just has the script.bin and the kernel?
did i missed something?

lawrence

The uBoot does have semi sensible defaults.

I prefer to ensure that we state clearly what we need though, so I create the boot instructions.
You can do without them assuming you name things the way it wants them (eg Kernel -> uImage) etc.

I'd strongly suggest provide the relevant info though.

castalla

Sorry I'm confused - which is not unusual.

You reference some files in http://dl.cubieforums.com/loz/rootfs/

For example, the 'wheezy' image - I thought this was a standalone precompiled image that could simply be written to a SD card and used?

Could you clarify, please?


ale92_

January 29, 2013, 01:01:33 pm #4 Last Edit: January 29, 2013, 04:33:07 pm by ale92_
hi,
i can't get this to work and i'am trying to understand where i made a mistake.

i just notice this line in boot.cmd: root=/dev/mmcblk0p2
what is mmcblk0p2? is it the name of the sd partition (for example mine is sdc2)?

and another thing
in the boot.cmd file there are these two lines:
boot/script.bin
boot/kernel.img
are you sure these are correct? (i think it should be without the boot/ folder)

let me know

lawrence

Quote from: castalla on January 29, 2013, 05:01:03 am
Sorry I'm confused - which is not unusual.

You reference some files in http://dl.cubieforums.com/loz/rootfs/

For example, the 'wheezy' image - I thought this was a standalone precompiled image that could simply be written to a SD card and used?

Could you clarify, please?


No, they are not standalone precompiled images, they are filesystems.
Unpack those to partition 2 after you created it.

SD card -
8k , 32k hold the ipl, then uBoot.
Partition 1 holds the Kernel, and uBoot instructions. (vfat any size, I use 64M)
Partition 2 holds your filesystem and user binaries.   (ext4 or any other format supported by your kernel.  I generally use the rest of the card for it.  I don't see the need for a swap partition or other partitions, especially on small media like 4G SD or similar).

lawrence

Quotehi,
i can't get this to work and i'am trying to understand where i made a mistake.

i just notice this line in boot.cmd: root=/dev/mmcblk0p2
what is mmcblk0p2? is it the name of the sd partition (for example mine is sdc2)?

and another thing
in the boot.cmd file there are these two lines:
boot/script.bin
boot/kernel.img
are you sure these are correct? (i think it should be without the boot/ folder)

let me know


The /dev/mmcblk0p2 is what the uBoot mounts the SD card as, so thats what you write.
Its not referring to what your particular computer see's.
As every Cubie is identical, we can guarantee that its most definitely /dev/mmcblk0p2

The /boot is indeed incorrect, its due to me using 2 sets of different board with different setups on each.
I'll correct that.

ale92_

hi,
still me.
i have repeated this guide every day for a week now (even twice a day) and i still can't make this work.
the main problem seems to be that i have no hdmi output. the green led doesn't turn on so i guess i have done the u-boot part correctly.
i tryed several kernel (both compiled by me and other's) and several rootfs (like the linaro precise alip or the quantal server).
Lawrence i need you to do me a favor.
Can you try your guide and tell me if you can make it work?

can you also give me some advice?

castalla

Re-reading this thread, I see that it's necessary to have another linux PC running ... what's the best Live usb linux for this - I assume that a Live version (without persistence) is sufficient to carry out the process you describe?

Presume I only realy need terminal access?

GeorgeIoak


GeorgeIoak

when I ran this step:

Quote#create a partition 64M in size at 1M, then another partition at 66M till end of the disk
sfdisk -uM /dev/[yourcard]
1,64,c
67,,L


I get an error at the 67,,L line saying that it has to start at 68 or greater. If I did that I ran into some other problems. I switched to fdisk and it worked OK.

GeorgeIoak

@castalla I prefer to run a Vm using VirtualBox on my Win7 x64 machine. Some of the instructions say that you need a Ubuntu x64 version so that is what I installed. My daily PC is the Win7 x64 so I prefer the VM since I can treat it like a window and let it run without tying up a machine. I have a fastmachine with 16GB of memory so the VM runs almost as fast as a normal machine.

nich

I'm trying to create eEnv.txt in root. I'm using sudo nano to do so. When I try to write the file, I get an error saying that it's a read only filesystem...

What's the workaround for this... or what am I doing wrong?

patwood

Where is this file?  On your hard drive or on the SD card?  If on the SD card, make sure the partition is mounted read-write and not read-only.  Use the "mount" command to tell you how it's mounted.