Difference between revisions of "Debian Init Update (PVT)"

From Studio Kousagi Wiki
Jump to: navigation, search
(Configure your machine type)
(Copy a u-boot onto the card)
 
(17 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
==Make partitions==
 
==Make partitions==
  
Build two partitions. Partition 1 should be 32M in size and of type W95 FAT32 and holds the kernel and device tree. Partition 2 should fill the rest of the disk and should be type Linux.
+
Build two partitions. Partition 1 should be 32M in size and of type W95 FAT32 and holds the kernel and device tree. Partition 2 should be a small swap partition, and partition 3 should fill the rest of the disk and should be type Linux.  The card signature should be 'NovM' for an MMC card, and 'NovS' for an SSD.
  
 
<pre>
 
<pre>
Disk /dev/mmcblk1: 3965 MB, 3965190144 bytes
+
xobs@xobs-novena-laptop:~/Code/kernels/linux-dev$ sudo fdisk /dev/mmcblk0
1 heads, 16 sectors/track, 484032 cylinders, total 7744512 sectors
+
 
Units = sectors of 1 * 512 = 512 bytes
+
Welcome to fdisk (util-linux 2.25.2).
 +
Changes will remain in memory only, until you decide to write them.
 +
Be careful before using the write command.
 +
 
 +
Command (m for help): x
 +
Expert command (m for help): i
 +
 
 +
Enter the new disk identifier: 0x4e6f764d
 +
 
 +
Disk identifier changed from 0x00000000 to 0x4e6f764d.
 +
 
 +
Expert command (m for help): r
 +
 
 +
Command (m for help): p
 +
Disk /dev/mmcblk0: 3.7 GiB, 3965190144 bytes, 7744512 sectors
 +
Units: sectors of 1 * 512 = 512 bytes
 
Sector size (logical/physical): 512 bytes / 512 bytes
 
Sector size (logical/physical): 512 bytes / 512 bytes
 
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
+
Disklabel type: dos
 +
Disk identifier: 0x4e6f764d
 +
 
 +
Device        Boot  Start    End Sectors  Size Id Type
 +
/dev/mmcblk0p1        2048  67583  65536  32M  b W95 FAT32
 +
/dev/mmcblk0p2      67584  133119  65536  32M 82 Linux swap / Solaris
 +
/dev/mmcblk0p3      133120 7744511 7611392  3.6G 83 Linux
 +
 
 +
Command (m for help): w
  
        Device Boot      Start        End      Blocks  Id  System
 
/dev/mmcblk1p1            2048      67583      32768    b  W95 FAT32
 
/dev/mmcblk1p2          67584    7744511    3838464  83  Linux
 
 
</pre>
 
</pre>
  
 
==Build filesystems==
 
==Build filesystems==
  
  sudo mkfs.ext4 /dev/mmcblk1p2 # make ext4 filesystem on the larger partition
+
  sudo mkfs.ext4 /dev/mmcblk1p3 # make ext4 filesystem on the larger partition
 +
sudo mkswap    /dev/mmcblk1p2 # make small swap partition
 
  sudo mkfs.vfat /dev/mmcblk1p1 # make FAT filesystem on the boot partition
 
  sudo mkfs.vfat /dev/mmcblk1p1 # make FAT filesystem on the boot partition
  
 
==Mount and bootstrap the filesystem==
 
==Mount and bootstrap the filesystem==
  
  sudo mount /dev/mmcblk1p2 /mnt
+
  sudo mount /dev/mmcblk1p3 /mnt
 
+
sudo mkdir /mnt/boot
  sudo debootstrap wheezy ~/mnt http://bunniefoo.com/debian  # replace URL with your favorite mirror
+
sudo mount /dev/mmcblk1p1 /mnt/boot
 +
  sudo debootstrap wheezy /mnt http://bunniefoo.com/debian  # replace URL with your favorite mirror
  
 
Several minutes pass. You become sleepy.
 
Several minutes pass. You become sleepy.
Line 48: Line 70:
 
  sudo cp ./sources.list /mnt/etc/apt/
 
  sudo cp ./sources.list /mnt/etc/apt/
 
  sudo cp ./trusted.gpg /mnt/etc/apt/
 
  sudo cp ./trusted.gpg /mnt/etc/apt/
 +
 +
If you need to add keys, run this:
 +
wget -q http://ftp-master.debian.org/keys/archive-key-7.0.asc -O- | sudo apt-key add -
  
 
Now run an update to grab the new packages, but in a chroot environment:
 
Now run an update to grab the new packages, but in a chroot environment:
Line 66: Line 91:
 
  chmod a+x novena-eeprom
 
  chmod a+x novena-eeprom
  
  sudo cp novena--eeprom /mnt/usr/sbin/
+
  sudo cp novena-eeprom /mnt/usr/sbin/
  
 
==Add SDMA firmware==
 
==Add SDMA firmware==
Line 89: Line 114:
 
  allow-hotplug eth0
 
  allow-hotplug eth0
 
  iface eth0 inet dhcp
 
  iface eth0 inet dhcp
 +
 +
Edit /mnt/etc/udev/rules.d/70-persistent-net.rules and add the following lines:
 +
 +
# Unknown net device (/devices/soc0/soc.0/2100000.aips-bus/2188000.ethernet/net/eth0) (fec)
 +
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:22:c6:87:72:06", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
  
 
==Copy a kernel and device tree onto the card==
 
==Copy a kernel and device tree onto the card==
Line 98: Line 128:
 
==Copy a u-boot onto the card==
 
==Copy a u-boot onto the card==
  
You'll need a u-boot. You can build source from this link: http://www.kosagi.com/w/index.php?title=Building_novena_firmware#Getting_and_building_u-boot
+
You'll need a u-boot. You can [[U-boot-novena|build from source]]
 
 
Once you have u-boot built, you need to place it at the right sector in the card for loading with this command:
 
 
 
sudo dd if=u-boot.imx of=/dev/mmcblk1 seek=2
 
 
 
==Setup the u-boot script to point to the right filesystem==
 
Make sure the kernel args point to the right location for the filesystem you want to use.
 
 
 
/dev/mmcblk0p2 if you're sourcing from the internal microSD card
 
/dev/sda2 if you're going from an external SATA drive
 
 
 
Also note that due to a bug in the pfuze driver boot is more reliable if you turn of early printk.
 
 
 
If you want console output also specify console=ttymxc1,115200 in the bootargs.
 
  
The command to generate the u-boot script (just to jog my memory) is
+
Once you have u-boot built, you need to place the SPL file at the right sector in the card.  You also need to copy the actual U-Boot image file to the first partition, which should be FAT-formatted.  Do this by running:
  
  mkimage -T script -C none -n 'Novena Boot Script' -d <scriptname.txt> boot.scr
+
  sudo dd if=SPL of=/dev/mmcblk1 seek=2
 +
sudo cp u-boot.img /mnt/boot
  
 
==Boot into the native environment==
 
==Boot into the native environment==
Line 133: Line 150:
 
Then, run  
 
Then, run  
  
  sudo chroot /mnt tasksel
+
  tasksel
  
 
to configure the machine beyond the basic debian minimum.
 
to configure the machine beyond the basic debian minimum.
Line 141: Line 158:
 
Here's some recommended packages:
 
Here's some recommended packages:
  
  sudo apt-get install build-essential openssh-server systemd
+
  sudo apt-get install build-essential openssh-server
  
 
You'll want systemd so login prompt comes faster (e.g. scripts are blocking the console login). You'll want SSH so you can log into your machine via net. build-essential will be needed for you to compile stuff.
 
You'll want systemd so login prompt comes faster (e.g. scripts are blocking the console login). You'll want SSH so you can log into your machine via net. build-essential will be needed for you to compile stuff.

Latest revision as of 09:09, 25 March 2015

Bootstrapping Debian

Assumes you are initializing a single SD card for booting. You can also do SD card + SATA SSD, the procedure is similar except the boot partition is on the SD card and the data partition on the SSD. It's recommended to still keep the VFAT boot partition on the SSD even though it's not used at the moment, for forward compatibility reasons.

Assumes you have a debian host (in particular, another Novena...) to bootstrap a new card first.

Make partitions

Build two partitions. Partition 1 should be 32M in size and of type W95 FAT32 and holds the kernel and device tree. Partition 2 should be a small swap partition, and partition 3 should fill the rest of the disk and should be type Linux. The card signature should be 'NovM' for an MMC card, and 'NovS' for an SSD.

xobs@xobs-novena-laptop:~/Code/kernels/linux-dev$ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): x
Expert command (m for help): i

Enter the new disk identifier: 0x4e6f764d

Disk identifier changed from 0x00000000 to 0x4e6f764d.

Expert command (m for help): r

Command (m for help): p
Disk /dev/mmcblk0: 3.7 GiB, 3965190144 bytes, 7744512 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: 0x4e6f764d

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        2048   67583   65536   32M  b W95 FAT32
/dev/mmcblk0p2       67584  133119   65536   32M 82 Linux swap / Solaris
/dev/mmcblk0p3      133120 7744511 7611392  3.6G 83 Linux

Command (m for help): w

Build filesystems

sudo mkfs.ext4 /dev/mmcblk1p3 # make ext4 filesystem on the larger partition
sudo mkswap    /dev/mmcblk1p2 # make small swap partition
sudo mkfs.vfat /dev/mmcblk1p1 # make FAT filesystem on the boot partition

Mount and bootstrap the filesystem

sudo mount /dev/mmcblk1p3 /mnt
sudo mkdir /mnt/boot
sudo mount /dev/mmcblk1p1 /mnt/boot
sudo debootstrap wheezy /mnt http://bunniefoo.com/debian  # replace URL with your favorite mirror

Several minutes pass. You become sleepy.

Add Kosagi package server

While you are waiting, you grab these files:

wget http://bunniefoo.com/novena/debian/sources.list  # contains the bunniefoo mirror for novena local packages
wget http://bunniefoo.com/novena/debian/trusted.gpg   # contains public keys

These contain links so you can grab the novena-specific packages, which for now we're serving as we're still in development mode.

Once debian is done initializing the filesystem, install the new sources and key files:

sudo cp ./sources.list /mnt/etc/apt/
sudo cp ./trusted.gpg /mnt/etc/apt/

If you need to add keys, run this:

wget -q http://ftp-master.debian.org/keys/archive-key-7.0.asc -O- | sudo apt-key add -

Now run an update to grab the new packages, but in a chroot environment:

sudo chroot /mnt apt-get update

Set a password

You should probably set a root password on the new image. Make sure you don't forget to chroot or else you'll set it on your own machine!

sudo chroot /mnt/ passwd

FIXME Install novena-eeprom

novena-eeprom is a utility to manipulate the hardware configuration template stored in the on-board EEPROM. As of the writing of this guide, novena-eeprom is not yet a package in debian. That's why this section is a FIXME. It's quite possible by the time you read this, this step will be fixed.

wget http://bunniefoo.com/novena/debian/novena-eeprom
chmod a+x novena-eeprom
sudo cp novena-eeprom /mnt/usr/sbin/

Add SDMA firmware

sudo chroot /mnt/ apt-get install imx-sdma-firmware

You will need this to boot.

Enable login via console

sudo emacs /mnt/etc/inittab # or whatever your favorite editor is

Add this to the end of the file:

T1:2345:respawn:/sbin/getty -L ttymxc1 115200 vt100

Enable eth0 interface

Edit /mnt/etc/network/interfaces and add the following lines:

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

Edit /mnt/etc/udev/rules.d/70-persistent-net.rules and add the following lines:

# Unknown net device (/devices/soc0/soc.0/2100000.aips-bus/2188000.ethernet/net/eth0) (fec)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:22:c6:87:72:06", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Copy a kernel and device tree onto the card

The kernel and device tree are a bit of a moving target at the moment, so no link is provided; but basically, you need a boot.scr, a uImage, and a uImage.dtb file on the win32 partition of the card.

You can build your own kernel by following directions here: http://www.kosagi.com/w/index.php?title=Building_novena_firmware#Making_kernel_changes

Copy a u-boot onto the card

You'll need a u-boot. You can build from source

Once you have u-boot built, you need to place the SPL file at the right sector in the card. You also need to copy the actual U-Boot image file to the first partition, which should be FAT-formatted. Do this by running:

sudo dd if=SPL of=/dev/mmcblk1 seek=2
sudo cp u-boot.img /mnt/boot

Boot into the native environment

Install the initialized card into the target platform, and boot it. It should come up to a shell.

But wait, you're not done yet. Make sure you have a net connection on the target and you'll need to execute the following commands on the *new* machine.

Configure your machine type

Configure the hardware options using novena-eeprom. You will also need to set a MAC address for eth0 if you want to use it, and a serial number.

The recommended options are es8328,retina,pcie,gbit,hdmi

Run tasksel to populate packages

Then, run

tasksel

to configure the machine beyond the basic debian minimum.

Add packages

Here's some recommended packages:

sudo apt-get install build-essential openssh-server

You'll want systemd so login prompt comes faster (e.g. scripts are blocking the console login). You'll want SSH so you can log into your machine via net. build-essential will be needed for you to compile stuff.

You have to install ssh and systemd from the native environment and not a chroot environment.

From there, the machine is pretty much primed and ready for use.