ECE472/572 (UCLX) Assignment 6
Prepare for the lab
Answer these questions while doing this lab – they will help you understand the procedure and better prepare for the tests.
- What is a cross-compiler? Is one used in this project? Do we have a C compiler that can be run on the target board when using the default
- What is UCLIBC project?
- What is Das U-boot project?
- What is the difference between uImage and zImage?
- What is the relation between Das U-boot and uImage/zImage? What is
loaded first, what second? What happens afterward?
- What is the Buildroot project?
- What is BusyBox project?
- Find the command to power off BusyBox system safely
- What is the difference between a package and a package that usually starts with the same name but has -dev appended to its name?
- Why there are two console programs that offer almost the same
functionality: fdisk and
- What is the use of files /etc/password and
- What is the use of file /etc/fstab ?
- What is the use of file /etc/inittab ?
- What is the use of files /etc/network/interfaces
and /etc/init.d/S40network ?
Customizing and Building ucLinux for AVR32
- This procedure was tested under Ubuntu Linux 10.04 and buildroot-avr-v3.0.0. The older buildroot-avr-v2.3.0 was tested under Ubuntu 8.04, 9.04, and 10.04. Changes may be required if a different version of Ubuntu is used.
- You need about 4GB of free space on the top of your operating system to complete the task. You will also need an SD card. The SD card must be at least 32MB and must not be larger than 2GB, and should be from a reputable source. The community of AVR32 users recommends using a card of well-known brand. You will need to keep this project for a longer time as much of the future homework and the final project will rely on its development environment. The first run of main compilation of the ucLinux kernel may take a long time due to numerous downloads of various source files. Kernel is just one of the downloads. Pay attention to any errors. Attend to any errors before attempting to proceed with further steps. Before proceeding check the instruction for this homework submission. You may have to collect some information while doing the exercise as a proof of your work.
- Open a terminal window without root privileges.
- Homework submission - type:
- Use the following commands to update package database and install kernel and common Linux tools development packages. The packages listed below are split into two groups out of convenience. The second group relates to packages that contain a source code for the program compilation rather than a precompiled program. These steps were already applied to the persistent virtual machine in the Networked Embedded Systems lab.
- sudo apt-get update
- sudo apt-get install autoconf automake binutils bison flex g++ gcc gettext libtool make patch sed texinfo
- sudo apt-get install libacl1-dev liblzo2-dev libncurses5-dev zlib1g-dev
- sudo apt-get install subversion # needed only for v3.0.0 or later
- sudo apt-get install putty minicom
- Unpatched old buildroot v.2.3.0 on Ubuntu 9 or later:
Check the version of your compilers package. For example Run gcc --version. In case the version number is later than 4.2... you may need to downgrade to the older version of complier for which the process was prepared and edit the main Make file to point to a particular version of the compiler.
- sudo apt-get remove gcc
- sudo apt-get install gcc-4.2
- Create a folder to contain the project
- mkdir buildroot
- cd buildroot
- Download the prepared buildroot tool for AVR32.
- Configure the installation
- In case you are restarting the process clan up the compiled files by executing make clean. Otherwise, start with the next step. Note that the "clean" rule does not delete downloaded source code. It only removes configuration files, intermediate temporary files, and the compiled binary files.
- If you wander about available targets in this particular buildroot setup type
- Set your destination microcontroller board
- Download all necessary source files and then compile building the ucLinux for the target board. This will take a while as source code for the kernel, BusyBox, Das U-boot and many other items would have to be downloaded and then compiled. The repositories with the source code may be busy at certain times during the day. If the build fails due to download failure there is high chance that it will restart from the place it failed and go further upon its restart a few minutes later. In order to prevent surprises we can download all needed soruce code first (which is optional), and then start compiling them. However, running
make busybox-menuconfig requires source code to be pre-downloaded.
- make busybox-menuconfig
This brings up the Configuration Menu
- Select "Archival Utilities" and then select "dpkg". If you do not do that then you might have problems with doing an extra credit homework at later time.
- Select Exit and Yes to save.
- make uclibc-menuconfig
This brings up the configuration menu for the C library that will be used by all C program that you compile to run under uC Linux on that board.
- We do not need to make any changes. Just browse around and exit.
- make linux26-menuconfig
This brings up the configuration menu for the Linux kernel.
- We do not need to make any changes. Just browse around and exit.
- make menuconfig
This brings up the Configuration Menu
- Select "Package selection for the target"
- uncheck "avr32-viki-docs"
- select "Shell and utilities" and then check "sudo"
- Select "Toolchain", select "Build/install c++ compiler and libstdc++" (this was selected by default in older buildroot!)
If you skip the selection of libstdc++ this lab will still work but you will run into trouble in later assignments. You might even will have to redo this work.
- Select "Target file system"Select "Target file system"
- unselect "jffs2 file system" (It could be used to program
the on-board flash memory instead of the SD card.)
- unselect any other file system that might be checked
- select "tar the root file system" if not selected already
- You can make any configuration changes at this point. Be warned – this could damage your installation. In worst case you have to remember what you did and uncheck that/these options.
- Select Exit and Yes to save. If you were not asked whether to save the configuration then run
make menuconfig again and check if the changes were saved.
- Again, although this time it's really optional, let us download all source files first. This time it will take really only a few minutes to download items that you checked in the configuration step.
- make source
- Now it is time to start the compilation
- There should be no errors. However, be prepared to manually re-download any archive files (tar/gzip/bz2) that are reported corrupt. In such cases note the name and location of each such file, and re-download a new file from kernel.org, busybox.org, or buildroot.org, etc., and save to replace the damaged file, and restart
- Unpatched old buildroot v2.3.0 on Ubuntu 9 or later:
- In case you get the error "conflicting types for 'getline' in unidef.c " edit file "toolchain_build_avr32/linux.../scripts/unidef.c) and rename getline to parseline (three occurrences) and run make again.
- In case you get the error "conflicting types for 'getline' in unidef.c " edit file "toolchain_build_avr32/uClibc-.../extra/scripts/unidef.c) and rename getline to parseline (three occurrences) and run make again
- Now it is time to prepare the SD card. In case you use Ubuntu without root access, or you do not have access to a SD card reader take the tar.bz2 file on a USB drive to a computer in the networked embedded systems lab and use virtual machine with live Ubuntu to complete the following steps.
- Unmount the SD card if necessary.
Do not "eject" the card as this would deactivate access to it.
- This step is actually optional but performing it solves problems created by using SD cards previously formatted in exotic ways. First we will erase some sections of the SD cards by filling it with zero byte pattern. This step turned out to solve certain problems caused by incorrectly formatted SD cards. Partition editors frequently read certain parameters from the master boot sector and write them back with the new partition table instead of generating an entirely new data set. Provided data count is in 512 byte blocks.
- sudo dd if=/dev/zero of=/dev/sdx count=32768
- Use fdisk to create a new partition table (option o) and then create a new first partition of ext2/Linux/83 type. Write the new partition table and exit
- sudo fdisk /dev/sdx
- Create a new partition table (option o) .
- Add one new primary partition of ext2
type (type 83) in the first entry of the partition table. The size should be at least 32MB.
- The partition should have at least 32MB but it can be as large as the capacity of the entire SD card. High density SD cards (larger than 2GB) are not supported by uboot at this time.
- Remember to write the partition table before exiting the program.
- Let us check the outcome (option: dash lowercase L).
- sudo fdisk -l /dev/sdx
- Let us format it and label sdcard. Currently the bootloader does not support newer ext2 file systems with 256 byte inodes. Option -I 128
(dash capital i) prevents use of longer inodes otherwise used by recent
- sudo mkfs -t ext2 -I 128 -L sdcard /dev/sdx1
- Remove and reinsert the SD card. Your OS should mount it automatically under the folder
/media . Please check if that happened before proceeding further.
Some systems (e.g. Ubuntu 14.04 and latrer) mount the partitions under
the account user name. Verify that and adjust this lab script
- ls -l /media
- ls -l /media/youruserid
In case you do not see folders with the names assigned to the partitions during formatting start the GUI file explorer (MENU:Places/Computer) and double click on the icon labeled "Angstrom", go back and then click again on "boot". That should do the trick and is sufficient way around at this learning level. Repeat the command above to verify that both partitions are mounted.
- Now it is time to copy the ucLinux to the SD card. Mount the SD card again or alternatively remove and reinsert it into the card reader. make sure that you do not remove the card before formatting is completed.
- cd buildroot/buildroot-avr32-v3.0.0/output/images/
- ls -l
Observe that the file system has been assembled in several formats (depending on options that you left checked in menuconfig) possibly including one in which it is split into two partitions each less than 8MB. Unpack the complete file system to the card and perform certain modifications before booting it for the first time. Depending on the build version, the tar file is either gz-ipped or bz2-ed. (Actually the settings both the file name and the compression software can be changed from their defaults in the menuconfig.) Depending on the build version, uImage may have already been included inside the main tar-file.
- sudo tar xzf rootfs.tar.gz -C /media/youruserid/sdcard/
- sudo cp uImage /media/youruserid/sdcard/boot/
- ls -l /media/youruserid/sdcard/boot
- sudo gedit /media/youruserid/sdcard/etc/fstab &
- Enter the following text. Delete or comment out with '#' any other mounted file systems.
Use TAB instead of spaces, you may enter multiple TABs to keep columns in line.
########## Start of /etc/fstab ##########
/dev/mmcblk0p1 / ext2 defaults 0 0
- cat /media/youruserid/sdcard/etc/fstab
- sudo gedit /media/sdcard/etc/shadow &
- Modify the root password: remove it, later on log in to the board as root.
- root has an unknown password that we are going to remove and then replace with a different one. You may grab your Ubuntu account password from the
/etc/shadow and paste
- Most of other users have direct login and password blocked by means of replacing it with "*" or "!". That does not mean that those accounts are not used. Operating system can run programs with access privileges of these users. Nobody can log in using these accounts though.
- Default account has no password. Remove any password or direct login block if found.
- There are two files: passwd and
shadow. Typically passwd file does not contain any password information. Instead it is moved to
shadow that also contains several other password-related parameters. Originally Linux/Unix had password encoded in the
passwd file but that approach was deemed insecure as the file needs to be readable by many system utility programs and thus by all users of the system.
- sudo cat /media/youruserid/sdcard/etc/shadow
- sudo gedit /media/youruserid/sdcard/etc/network/interfaces &
No modifications are required. Inspect the configuration file that defines what happens with each network interface. AVR NGW100 has two physical network cards. One is running as a DHCP client that obtains configuration from a DHCP server located up link, while the other serves as a DHCP server and Network Address Translation Firewall to potential clients. Can you see that?
- sudo gedit /media/youruserid/sdcard/etc/inittab &
No modifications are required. Inspect the configuration file,
especially the line that contains the command
- sudo chmod u+w /media/sdcard/etc/sudoers
- sudo gedit /media/sdcard/etc/sudoers &
- Add capability to poweroff,
halt the board by any user without need to
provide root password
user ALL=NOPASSWD: /sbin/shutdown,/sbin/reboot,/sbin/halt
- sudo chmod u-w /media/youruserid/sdcard/etc/sudoers
- sudo ls -l /media/youruserid/sdcard/etc/sudoers
- sudo cat /media/youruserid/sdcard/etc/sudoers
- Unmount the SD card now or you risk loosing your changes without any warning. Alternatively "eject" the card.
- Homework submission:
Make sure that you did un-mounted the SD card! Remove it from the card reader.
- type exit
- save file hw6ngw.txt for future homework submission
- Make sure that the target board (AVR32 NGW100) is powered down. Insert into the SD card slot on the target board.
- Make sure that the board is connected to the Internet using WAN port as the initial boot of the ucLinux requires use of current time (from Internet) to initialize SSL configuration correctly.
- Make sure you have the device driver for your Linux
for the UART to USB adaptor. If not, then do the following using Windows
instead of Linux.
- Connect the HyperTerminal to the serial port so that you can observe the boot up sequence.
Power it up and observe the boot sequence using the PUTTY hyper terminal.
- In Ubuntu GUI in Menu / System / Administration / Users and Groups
- Select the current user
- Click Advanced Settings (administrator access verification)
- Select User Privileges tab
- Enable Connect to Internet using a modem and Use modems which together enables serial port access for that particular account.
- open a terminal
- start putty
- In Serial Port Setup:
- Set serial device to (use correct capitalization!)
- for computer lab: /dev/ttyS0
- for your laptop with USB to Serial:
Use a different port number if you are using several USB to Serial converters at the same time.
- Set Speed (baud rate) to
- Set Data bits to
- Set Stop bits to
- Set Parity to
- Set Hardware Flow Control to
- verify transmission parameters: 115000 bits per second, 8-bit, no parity, 1 stop bit,
no flow control
- In Session
- Select Serial
- Consider saving the settings so far using the Set
Saved sessions future.
- Open the connection
- Watch for any failed services.
- When the sequence is completed successfully you will see a console prompt.
- Log in as root if asked for a user ID
- Set a new password using passwd command. Set it to "ee00" (certainly, without ""s).
- Note: it was originally an empty password in case you haven't changed it yet by editing
- Type uname -a
- Homework submission: capture the screen of the serial
communication terminal showing the response to uname -a command.
In case you take a photo using a camera instead of the screen
capture - make sure that the image is crisp.
- You may want to reboot again to verify that all installation is complete (faster boot at the second time).
- Shut the system down and then disconnect the power from the board. Warning: Before powering the board off and removing your SD card do find out how to shut it down safely from the console. I will be able to check if you did do so!
- The SD card with the fully installed ucLinux will be graded.
- Homework submission: secure the SD card for future inspection by the instructor.
Backup your work and Restore (but boot at least once or twice from the SD card first!)
- To back up the card with your work
- insert the card into the SD card reader
- cd /media/youruserid/sdcard
- sudo tar czf ~/Desktop/backup_ngw_sd.tgz *
- sudo umount /media/youruserid/sdcard
- remove the SD card
- To restore your work from the backup
- insert the card into the SD card reader and erase contents of the file
- rm -rf /media/youruserid/sdcard/*
- reformat the partition if the damage is suspected or new SD card used
- sudo umount /media/youruserid/sdcard
sudo mkfs -t ext2 -I 128 -L sdcard /dev/sdx1
- remove and reinsert the SD card
- sudo tar xzf ~/Desktop/backup_ngw_sd.tgz -C /media/youruserid/sdcard/
- sudo umount /media/youruserid/sdcard
- remove the SD card and verify if it does boot correctly
Cleanup (only after the semester is over!)
Just remove the buildroot folder. However, you will need this folder and its contents again very soon for the later assignments. If you do not want to remove it but are short on space run make clean instead. This will erase all target files and your customized configuration but it will keep all downloaded files.
Use tar and then gzip
or bz2 to combine all script files required for the
lab submission into one file. A "convenience fee" may be charged for use of
other kinds of compression.
Drop the tar-gzipped files with the information collected during the exercise as instructed in the corresponding assignment drop box on Sakai.
Drop the SD card with the file system for your embedded Linux in the instructor's office for verification when more homework
accumulates as discussed in the lectures.