<<

Title: Setting up the TS7300 boards Author: Craig Duffy 5/10/08, 22/11/10 Module: System on Chip Awards: CSE3, BENG, Robotics 3, MENG. Prerequisites: TSboard, SD cards

The purpose of this worksheet it to show how the TS7300 board boots up and how to install Linux on it. We will also look how to configure the Linux installation on the boards.

The TS7300 startup

The TS7300 has a rather different startup routine from many embedded boards. Like on most boards the CPU, the ARM9, looks for a device to boot from. Rather than using on board FLASH chips the system boots to a small EEPROM on the board. This contains a very small boot strap program, < 2K bytes, this boot strap has a few functions, some to do a basic board initialisation, some to handle the screen and serial ports and a routine to load the boot sector of the first SD card. If there are problems with the SD card the watchdog timer on the board is set up on system initialisation and will force a reboot. If the EEPROM is corrupted then the board is pretty much dead! The EEPROM code should give the message,

>> TS-SDBOOT - built Jul 6 2006 >> Copyright (c) 2006, Technologic Systems . . .

The dots (.) represent disk read activity, if there is no disk the system will keep restarting itself every 8 seconds.

If there is a SD card in the first slot, the one nearest the ARM CPU, and it has had a boot sector correctly installed, then the system may be able to boot into Linux. The boot sector is a very small program, written in ARM Thumb 16 bit instructions, that will load into memory the first 2 partitions of the SD card. These 2 partitions contain the Linux kernel in partition 1 and an initial RAM disk (initrd) in partition 2. The kernel is loaded in address 0x218000 in RAM and the initrd is loaded at address 0x1000000. The final thing the boot sector program does is to jump to the of the kernel to execute it. You should then see the initial kernel message,

Booting Linux...

It is possible that it might go into fastboot mode, in which case you will see the message,

Finished in 1.66 seconds Type '' for full boot - remove JP6 to make this the default $ exit

1 If you in exit at this point then the system should boot up into Linux, and see something like this,

>> Booting Linux... INIT: version 2.86 booting Creating extra device nodes...done. Started device management daemon v1.3.25 for /dev symbol: "fixscsigenericperms" not found in /lib/devfsd/scsigenericperms.so umount: /initrd: device is busy Checking root file system... fsck 1.37 (21-Mar-2005) e2fsck 1.37 (21-Mar-2005) /dev/sdcard0/disc0/part3: clean, 15437/60000 files, 244038/244224 blocks Cleaning up ifupdown...done. Loading modules: usbcore zd pcipool usb-ohci usb-ohci-ep93xx af_packet Checking all file systems... fsck 1.37 (21-Mar-2005) e2fsck 1.37 (21-Mar-2005) /dev/sdcard0/disc0/part4: clean, 11/93888 files, 2959/187712 blocks ... done. /dev/sdcard0/disc0/part4 on /mnt/part4 type ext2 (rw,noatime) Setting up networking...done. Starting hotplug subsystem: usb isapnp ide scsi. Starting portmap daemon: portmap. Starting portmapper...Mounting remote filesystems... mount: RPC: Remote system error - Network is unreachable Recovering nvi editor sessions... done. INIT: Entering runlevel: 2 Starting internet superserver: inetd. Starting OpenBSD Secure server: sshdCould not load host key: /etc/ssh/sshy Could not load host key: /etc/ssh/ssh_host_dsa_key Disabling protocol version 2. Could not load host key sshd: no hostkeys available -- exiting. Starting NFS common utilities: statd. Starting periodic command scheduler: cron.

Debian GNU/Linux 3.1 ts7000 ttyAM0

ts7000 login:

If the system requests a password then try logging in with user id root without a password.

2 Go through the output above and try to figure out what the systems is doing – note that there are error messages! Your system may well differ from the above output.

Talking to the TS7300

In order to talk to the board the easiest form of connection is through the serial port. You will need a null modem serial cable – there are lots hanging up in the labs. Connect to serial port 1 on the ts7300 – next to the USB port and onto serial port 1 on the desktop PC. The program to manage the connection is called minicom, it is available on most Linux distros, it is installed on the Netlabs Linux. To connect you can type in

%minicom -o pup1

The -o stops minicom sending any modem control signals down the wire, the pup1 is a configuration script for the puppeteer boards. These board have the same settings as the ts7300, so we can use their config files. The setting are (if you want to do it manually – no hardware or software flow control, 115200 baud. If you have connected to the 2nd serial port you need to use the pup2 config file.

%minicom -o pup2

Connect to the board and boot it up – you should see some of the output mentioned above. To get a minicom menu type ^A (control A). You can follow that by another command - ^AZ shows you a menu of commands, ^AQ quits from minicom.

Installing Linux on an SD card

It is quite likely that you will need to install Linux onto an SD card or upgrade your version. If you have a laptop, running Linux, with an SD card reader then it is possible to do the installation without using the TS board.

Before powering up the board, put the Linux bootable SD card into slot 1 and the new card into slot 2. Power up and boot the system. You should that the system on boot has found the cards. You can either look in the systems diagnostic messages, using dmesg | , or by looking in the file /proc/devices. In the dmesg output you should find that it reports the partitions that the disk has,

sdcard0: Technologic Systems SD card controller, address 0x13000000 sdcard0: card size 1999872 sectors Partition check: sdcard0a: p1 p2 p3 ......

3 sdcard1: Technologic Systems SD card controller, address 0x72000020 sdcard1: card size 1999872 sectors sdcard1a: p1 p2 p3 p4

This shows that SD card 0 has 3 sectors and card 1 has 4. It is likely that with a new card that it will have 1 large sector. In order to change this we will need to edit the disk's partition table using the command. The fdisk command, the commands name is lost in the history of MSDOS, is a fairly bruttal program that is used for editing disks' partition tables. The commands only argument is the name of the disk partition, so to look at SD card 0's partition table printing out the disk sizes in sectors rather than cylinders (much more useful), then type

fdisk -lu /dev/discs/disk0/disc

This will output

root@ts7000:root# fdisk -ul /dev/discs/disc0/disc

Disk /dev/discs/disc0/disc: 1023 MB, 1023934464 bytes 4 heads, 16 sectors/track, 31248 cylinders, total 1999872 sectors Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System /dev/discs/disc0/part1 16 9855 4920 da Non-FS data /dev/discs/disc0/part2 9856 17727 3936 da Non-FS data /dev/discs/disc0/part3 17728 1999871 991072 83 Linux

Copying the Boot sector

In order to make an SD card bootable the first sector of the disk must contain some boot loader code as well as the partition. As the boot sector is not part of the mountable file system it is also not available to commands that manipulate those file systems. For example, you can't use a command like cp () to copy the boot sector onto the disc as the boot sector is 'outside' of the file system. Fortunately Linux comes with command that can deal with such situations and the 'raw' disk is made available to developers.

The command that is most commonly used is dd. This command reads data from an input stream and copies, with possible transformations, to an output stream. It doesn't sound too exciting but the important point is that it makes no assumptions about the of the data and isn't restricted where it writes it.

In order to copy the boot sector from one SD disk to the other we need to know where they are and how big they are. Finding the boot sectors is fairly easy, they are at the beginning of the raw drives. So for SD card01 the raw disc is /dev/discs/disc0/disc, for 1 is /dev/discs/disc1/disc.

4 Although the boot sector is only 512 bytes, we can copy across the whole sector 1k (1024 bytes). The command to do this is

dd if=/dev/discs/disc0/disc of=/dev/discs/disc1/disc bs=1k count=1

Read the manual entry for dd – man dd.

Be careful to distinguish between the command name dd and the arguments -l, bs=..,etc, You can use the tab character to automatically complete names, which may .

So we can see that the input and output files are correct, the block size (bs) to be copied is 1 k and the number of blocks is 1. WARNING – if you get the source and destination mixed up then you could end up with an unbootable disc!

You should receive the following (or similar) message on completion,

1+0 records in 1+0 records out 1024 bytes (1.0 kB) copied, 0.0238498 s, 42.9 kB/s

As well as copying the boot loader code it will have also have copied across the partition table for the disc. However it is best to use fdisk manually to edit the new disc and create the partitions that you need.

To edit a disk simply type in – (the output below also shows the output from the p () partition table command)

root@ts7000:root# fdisk /dev/discs/disc1/disc

The number of cylinders for this disk is set to 3906. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/discs/disc1/disc: 1023 MB, 1023934464 bytes 16 heads, 32 sectors/track, 3906 cylinders Units = cylinders of 512 * 512 = 262144 bytes

Device Boot Start End Blocks Id System /dev/discs/disc1/part1 1 6 1520 da Non-FS data

5 /dev/discs/disc1/part2 7 10 1024 da Non-FS data /dev/discs/disc1/part3 20 973 244224 83 Linux /dev/discs/disc1/part4 974 3906 750848 83 Linux

Note that there is a 10 block gap between partition 2 and 3 – this has been left to allow the initrd to expand into the empty space should it need to.

The parameter disc is important, as this is the entire raw disk that is being looked at not the partitions, you will note that the directory /dev/disc/disc1/ will also contain the partitions. Once in fdisk we can start to modify the disk to our own purposes.

Read the fdisk manual – man fdisk.

You should start by deleting all the existing partitions on the disk – be careful that you do this with disc1 not disc0, if you delete disc0 then your system will no longer boot into Linux. The deletion can be done with the d delete command.

Command (m for help): d Partition number (1-4): 4

You then delete each unwanted partition. New partitions are created with the n command. Only create 3 or 4 partitions so that they are all direct ones. When creating them you will need to specify the size of the partitions, below is a table to help create them.

Partition 1 Kernel 5MB Partition 2 Initrd 4MB Partition 3 Root file system 250MB (or the rest of the disc) Partition 4 Other data The rest of the disc (if used)

You can also use the existing, working boot disc as a guideline, although it may be a different size from the disc you are installing onto, you know that the size used on that disc for partitions 1 and 2 should work.

Once the partitions are created then they need to identified. This involves changing, or toggling the partition identification number, this requires the t command. The command l allows you to list all of the possible partition types and as Linux uses lots of different files systems and operating systems it is quite a long list.

Command (m for help): l

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot 1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris 2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT­ 3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT­

6 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT­ 5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx 6 FAT16 42 SFS 86 NTFS volume set da Non­FS data 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT 10 OPUS 55 EZ­Drive a6 OpenBSD ef EFI (FAT­12/16/ 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA­RISC b 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux RAID auto 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT 1c Hidden W95 FAT3 75 PC/IX

The first 2 partitions need to be set to da, non file system data, actually it probably doesn't matter too much what it is set to as these partitions are only read by the EEPROM bootloader. The 3rd partition needs to be set to 83, Linux, for the root file system.

Once the partition have been created and their labels assigned the new partition table can be saved, use the w write command at the fdisk prompt. You may find that the write is done but fdisk complains and says that the new table will be used on reboot. If you look in the devices directory, /dev/discs/disc1 – you may find that the new settings are not reflected. In order to sort this out issue a reboot command,

-r now

Copying the kernel

Partition 1 contains the kernel – which is just a large program in binary form on the disc. As it is read directly from disc into memory and executed by the bootloader code it does not need to be stored in a file system, hence the partition non file system data. As the 2 partitions should be of similar size it is possible to do a complete copy of the partition using dd.

dd if=/dev/discs/disc0/part1 of=/dev/discs/disc1/part1

As this is a small amount of data it shouldn't take too long.

Initial ram disk initrd

The system uses an initial ram disk on boot up. This is a bit of disc that is temporarily loaded up at boot time to allow the kernel to load up modules and run commands at boot time. This is used for 2 reasons. Firstly the kernel may not know until boot time what hardware resources it has until it

7 boots – for example is there a WIFI card plugged into the USB? Do I have a hard drive? The kernel can load these in from the initrd at boot time and therefore does need to be built with them. This means that the kernel can be smaller and only the modules needed can be loaded in. The other reason is to do with the nature of the Linux kernel. The kernel is open source, which means that all the code must be open to be read (and possibly changed). The system also requires access to routines for the SD card, which are controlled by proprietary licenses – being able to load in closed source binary modules from the initrd means that the system can use a full Linux kernel and still access the SD disc.

The initrd is read from memory by the kernel – remember the bootloader loads it into memory at 0x1000000 – but can be read from disc as it is really a file system. So we can look at the initrd by mounting it into a directory.

mount /dev/discs/disc0/part2 /initrd (note the spaces)

Read the mount manual – man mount.

If you then list the directory you should see what is in that partition.

ls /initrd

In order to copy the data across to the new partition we need to do 3 things; format the partition, then mount it and finally copy the data across.

Formatting requires the mkfs command with a specification of what file system is being made – ext2 in this case.

mkfs.ext2 /dev/discs/disc1/part2

Read the mkfs manual – man mkfs. you can accept the defaults for mkfs. Once it has been formatted it can then be mounted.

mount /dev/discs/disc1/part2 / mnt/part2 (note the spaces)

You may need to create a directory /mnt/part2. If you then list the directory you should see that is empty

ls /mnt/part2

We can now copy across all of the data.

cp -a /initrd/* /mnt/part2

The -a option makes sure that all files and links are correctly copied. It would be possible to

8 achieve the same effect with the dd command using

dd if=/dev/discs/disc0/part2 of=/dev/disc/disc1/part2

As the copies are going from one SD card to another the copying can be slow because of the SD write times, so doing whole partition copies is best avoided. In the initrd case the partition is pretty small so it can be done with dd. For the root file system it is a different matter.

Copying the root file system

The root file system is quite large so doing a dd copy would not be wise. The partition will need formatting and then mounting. Then the cp -a command can be used to copy everything from / the root file system on the running system to new partition. As the new file system is mounted into the root file system care has to be take not to start copying the new system back onto itself! (Hint use the -x option with cp – read the cp amn page!) So if the new partition is mounted with

mount /dev/discs/disc1/part3 /mnt the directory /mnt must not be copied across as the system will start recursively copying data. Also some of the pseudo file systems, procfs for example, can cause problems when being copies across. This isn't a problem as procfs is recreated each time the system reboots, and we don't really want to copy it across. Therefore we should unmount it before we do the copy. You may well need to umount usbfs before hand – otherwise proc will be busy as usbfs is mounted on it. Don't do this if you have a flash stick mounted or plugged into you ts board!

umount usbfs umount /proc

Note that some commands (ps for example) may not work when proc is unmounted, so if you wish to use the system after copying, then remounting /proc is a good idea. If you need usb then remount the above file systems in reverse order.

Once the system has been completely copied across then the system can be taken down and rebooted with the new disk in slot 1. Use the

shutdown -h now command to restart the system – the -h means halt. This means that the system will stop and you can change the disks and turn the power off and on again.

Reconfiguring the system

You will notice from the boot banner that quite a few services are started at boot time. In order to make the machine more efficient you should change the services – they are started through scripts in /etc/rcN.d, where N is the run level. The run level is set up through the file /etc/inittab, check it

9 to find out which run level your machine is running at. Once you have found this out you can simply rename the scripts to stop them being called at boot time.

As the TS boards use Debian Linux it is possible to use the apt-get package manager to install new software. Using the site http://www.debian.org/doc/manuals/apt-howto/index.en.html#contents use apt-get to install some new packages – for example hexedit.

10