ECE 472/572 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
Buildroot configuration?
- 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 sfdisk ?
- What is the use of files /etc/password and /etc/shadow ?
- 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 ?
Activity (40 pts.)
Customizing and Building ucLinux for BeagleBone
- You will need to keep this project and the SD card until the end of the semester.
- You need about 12GB of free space on the top of your operating system to complete the task.
You will also need a 2GB - 32GB micro SD card.
(Actually, you will need only 512MB but such cards may be hard to find.)
- The first run of main compilation of the ucLinux kernel may take a long time
due to numerous downloads of various source files and then compiling them.
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.- Open a terminal window without root privileges.
- Lab 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 libssl-dev zlib1g-dev
- sudo apt-get install git-core # subversion
- sudo apt-get install putty minicom
- Create a folder to contain the project
- mkdir buildroot
- cd buildroot
- Download the prepared buildroot tool for BeagleBone.
- Configure the installation
- In case you are restarting the process to start over with a
different target microcontroller clean up both the configuration
settings and all compiled files by executing
make distclean. It is almost like you
deleted everything and unpacked the buildroot source code again.
- In case you are restarting the process clean 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:
- Now set your destination microcontroller board, type:
- ls -l configs | grep bone
- make beaglebone_defconfig
- 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 source code first (which is optional),
and then start compiling them. However, running
make busybox-menuconfig requires source code to be pre-downloaded.
- Now inspect the basic configuration for your development board and
make a few small changes as requested:
- This brings up the Configuration Menu
- Select "Build options" and then
- select Enable compiler cache
- Select "Toolchain" and then
- Select "Enable WCHAR support" if the option is available
- Select "Enable C++ support"
If you skip this selection the library file libstdc++ will not be added to the image. This lab will still work but you will run into trouble in later assignments. You might have
copy the missing library from a colleague's system or redo this lab in order to rectify the situation.
- Select "System configuration"
- Change the "System Banner" to "Welcome to
inert-your-name-here Buildroot"
- Set "Root Password" to "ee00" without ""s (or anything else of your choice as long as it is not empty)
- Select "remount root filesystem read-write during boot"
Comment: if you plan not to change the embedded system frequently
then it may be better to leave the file system as read-only
and change it to read-write only temporarily when you want to apply changes to the live image.
Keeping it read-only decreases chances that something goes wrong
when the system is not properly shut down.
However, chances if something going wrong are rather small to start with.
- Set "Network interface to configure through DHCP" to "eth0" without ""s
Note: this is the place where you could release the serial port from being an extra console.
You might want to do so if you need the UART to communicate with further devices.
However, you can also do it later by editing initialization configuration files on the working board.
- Select "Kernel"
- Select "Install kernel image to /boot in target"
Comment: this copies the file called uImage or zImage into rootfs.tar
and can be done by hand instead here. We will revisit that later.
- Select "Needs host OpenSSL"
- Select "Target packages"
- Make sure that "BusyBox" is selected
- Select "Install the watchdog daemon startup script"
Comment: this is not needed for our exercises in this lab but is
a must for any commercial level application. It will allow your
program to activate watchdog and restart the system if your
program fails.
- Select "Filesystem and flash utilities"
- Don't panic if you don't see your favorite file system
support as it may be already included in the kernel
- Select "Interpreter languages and scripting"
- Consider "micropython"
- Consider "micropython-lib"
- Select "Networking Applications"
- Select "dropbear" (find out what dropbear is!)
- Select "netplug" (find out what netplugd is!)
- Select "ntp" (find out what ntp client is!)
- Consider a lightweight Web server for your future projects - CivetWeb
- Select "lrzsz"- file transfer over UART
- Select "lynx"- a text mode Web browser
- Select "mosquitto" and its broker - MQTTT support for IoT
- Select "nmap" - a network diagnostic utility suite
- Select "install nmap" - a network scanning utility
- Select "install nping" - a network diagnostic utility
- Select "rsync"- a utility to keep directories synchronized over network
- Select "tcpdump" - a network diagnostic utility
- Select "Shell and Utilities"
- Select "screen"
- Select "sudo"
- Select "System tools"
- Select "cpuload"
- Select "htop"
- Select "Text editors and viewers"
- Select "nano" or "joe"
that is unless you will follow the instructor who uses vi
Select "Filesystem images"
- Select "tar the root filesystem"
- Optionally select compression method to "(gzip)"
but compressing it does not save space as the plain tar file
will be created first anyway.
- Make sure that "ext2/3/4 root file system" was checked
- select "ext4" as ext2/3/4 variant of the above
- These two options "waste" 100MB of your hard drive but
they make post-image script "happy"
- If exact size is lower than 128M set it to at least 128M.
If it is set to higher size, do not lower it.
(Technically 100MB would be an absolute minimum for this board.)
Actually, the disk image size for the build with all add-ons
(including those that are only suggested) is 89M, where 1M=1024K=1024*1024.
- Make sure that any other file system than the two mentioned
above are unchecked to prevent wasting more hard drive space.
Select Exit and Yes to save.
Now let's bring the source up to date by downloading additional components that we selected:
Now inspect the core of the available Linux commands:
This brings up the Configuration Menu
- Select "Archival Utilities"
- Select "Make tar, rpm, modprobe etc understand .xz data"
- Select "Make tar, rpm, modprobe etc understand .bz2 data"
- Select "Make tar, rpm, modprobe etc understand .gz data"
- Select "bzip2"
- Select "Networking Utilities"
- Select "ifplugd"
or you will not get IP address when you plug in Ethernet cable
- Deselect "httpd" Web server (only if you chose to select another web server)
- Select "Process Utilities"
- Select Exit and Yes to save.
Now let's bring the source up to date by downloading additional components that we selected:
Now inspect the settings of the Linux Kernel:
Note: if you are in a hurry skip this step for now.
This brings up the configuration menu for the Linux kernel.
- Select "Device Drivers"
- Select "GPIO Support"
- Make sure that "/sys/class/gpio/... (sysfs interface)" is selected.
Otherwise, you will have to redo this lab later in order to complete lab 10.
- Go to networking support, observe that wireless support if off at this time.
- If we did not make any changes, just browsed around - exit.
(Otherwise, save the configuration file.)
Now let's bring the source up to date by downloading additional components that we selected:
If you do not want to create the entire self contained operating system
at the moment but you need only to compile the compilers in order to create
your own programs to run on the board type:
Note: if you are in hurry skip this intermediate step!
Now it is time to start the actual compilation.
- make all
- There should be no errors. However, be prepared to manually re-download any archive files
(tar/gzip/bz2/xz) 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.,
save to replace the damaged file, and restart by running make all.
- In case you run out of space in the image file
Redo the step where you set the image size and enter the larger size.
Restart compilation (it will be fast this time) by running make all
- In case you are experimenting and selected some extra options that caused build to fail
- run the appropriate make menu-xxxconfig again and uncheck the offending option
- run make again
- if error persists then
- make clean
- this will erase all compilation results
but will keep the downloaded source files and your settings.
- make all
- the entire compilation will start over.
- if error persists then
- make clean
- make beaglebone_defconfig
- make menuconfig
- and customize settings again from their default values
- make source
- make all
- You probably never should have a need to delete the entire folder
and unpack the downloaded buildroot.tgz file again.
However, that would be the last resort action to try.
Preparing and inspecting SD Card with Buildroot
- 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.
Also, make sure that it does not mount again automatically on Ubuntu.
- OPTION 1
Note: if OPTION 1 does not produce an image that is bootable on your microcontroller, OPTION 2 will work for sure.
- sudo systemctl stop udisks2.service
- sudo umount /dev/sdx?
- sudo dd if=/dev/zero of=/dev/sdx bs=1024 count=1024 status=progress
- do one of the two alternative ways to interact with the program to partition the SD card:
- sudo sfdisk /dev/sdx
Read the instruction printed by the program and type the following text line by line.
label: dos
1,16M,0x0E,*
,512M,,-
,,,-
write
- Type all the lines until "EOF" and then answer yes
sudo sfdisk /dev/sdx << EOF
label: dos
1,16M,0x0E,*
,512M,,-
,,,-
EOF
y<enter>
- sudo fdisk -l /dev/sdx
- lsblk
- sudo umount /dev/sdx?
- sudo mkfs.vfat -F 16 -n "BOOT" /dev/sdx1
- sudo mkfs -t ext4 -L "rootfs" /dev/sdx2
- sudo mkfs -t ext4 -L "data" /dev/sdx3
- We do not desire to mount the SD card partitions manually each time.
Restart the automount service:
sudo systemctl start udisks2.service
- 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 later) mount the partitions under
the account user name. Verify that and adjust this lab script accordingly.
- mount | grep /dev/sd.
- 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 "Buildroot"
(actually, any name would do), 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 all operations are completed.
Running sync should help with that. Note
that you can see files already in the new disk but they are, in facxt,
only in memory chache until sync is
completed.
- cd output/images/
- ls -l
- sudo cp MLO u-boot.img uEnv.txt zImage *.dtb /media/youruserid/BOOT/
- ls -l /media/youruserid/BOOT/
- sudo tar -xf rootfs.tar -C /media/youruserid/rootfs/
- sudo ls -l /media/youruserid/rootfs
- sync
- cd ../../
OPTION 2
- sudo systemctl stop udisks2.service
- sudo umount /dev/sdx?
- sudo dd if=output/images/sdcard.img of=/dev/sdx bs=1024 status=progress
- sudo resize2fs /dev/sdx2
- lsblk
- sudo fdisk -l /dev/sdx
- sudo fdisk /dev/sdx
- Add the third partition of Linuc ext2/3/4 type that utilizes the
reminder of the disk. If you do not do it now, you will have to do
it in Lab 7. The following sequence of commands should accomplish
that:
m p n p 3
default default p w
- lsblk
- sudo fdisk -l /dev/sdx
- lsblk
- sudo mkfs -t ext4 -L "data" /dev/sdx3
- We do not desire to mount the SD card partitions manually each time.
Restart the automount service:
sudo systemctl start udisks2.service
- 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 later) mount the partitions under
the account user name. Verify that and adjust this lab script
accordingly.
BACK TO THE COMMON INSTRUCTION
Now it is time to learn more about the Linux file system and some of its essential configuration files.
- sudo ls -l /media/youruserid/rootfs
- sudo gedit /media/youruserid/rootfs/etc/fstab &
and Inspect contents of the file. You will edit it in Lab 7.
- sudo gedit /media/youruserid/rootfs/etc/shadow &
- Check if root has password set to "ee00". Otherwise, you may grab your Ubuntu account password from the
/etc/shadow and paste it there.
- If the root has no password then you would not be able to log in
to the root account remotely, i.e. in any other way than using
attached serial UART cable.
- 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.
Note: your system may encode the password using different parameters
which results in different sequence of characters. You do not have
to copy the sequence below.
root:$5$H9khTMdxKDqZQN$obRPKgcTSZDabpUJVWSiP7AaQVTie4qH0PKWe41sJP2:::::::
daemon:*:::::::
bin:*:::::::
sys:*:::::::
sync:*:::::::
mail:*:::::::
www-data:*:::::::
operator:*:::::::
nobody:*:::::::
mosquitto:*:::::::
- sudo cat /media/youruserid/rootfs/etc/shadow
- sudo gedit /media/youruserid/rootfs/etc/network/interfaces &
- add the configuration for the Ethernet port eth0 to be enabled and to be configured using a DHCP client
# Configure Loopback
auto lo
iface lo inet loopback
# Configure Ethernet0
auto eth0
iface eth0 inet dhcp
pre-up
/etc/network/nfs_check
wait-delay 15
hostname $(hostname)
- sudo cat /media/youruserid/rootfs/etc/network/interfaces
- Unmount the SD card now or you risk loosing your changes without any warning. Alternatively "eject" the card
- In fact, in case you had to redo this build with different option
later on and put it again on the SD card you would have to perform the
same edit again. We could rectify that situation by editing directly the
version of this file in the skeleton folders. Let's do it now as an
exercise. Note that not all files are available there. The image file
will be updated next time you run make.
- cd
- cd buildroot/buildroot-date_n_version-bbone
- gedit system/skeleton/etc/network/interfaces &
- gedit system/skeleton/etc/inittab &
Lab submission:
- type exit
- save file hw6bb.txt for future submission.
Submit it together with the screenshot requested later in this instruction.
Make sure that you did un-mounted the SD card! Remove it from the card reader.
Installing the SD Card in the Microcontroller
- Make sure that the target board (BeagleBone) 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.
- 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
- putty
- In Serial Port Setup:
- Set serial device to (use correct capitalization!) /dev/ttyUSB0
- Set Speed (baud rate) to 115200
- Set Data bits to eight
- Set Stop bits to one
- Set Parity to None
- Set Hardware Flow Control to None (important!)
- verify transmission parameters: 115200 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
Power it up and observe the boot sequence using the PUTTY hyper terminal.
- 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 welcome message with your initials and upon your login the response to uname -a command.
In case you take a photo using a camera instead of the screen capture - to ensure full credit make sure that captured the image shows
clearly the build date and your initials or name above the login prompt.
- 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!
Backup your work and Restore
(but do 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/Buildroot
- sudo tar czf ~/Desktop/backup_bpi_rootfs.tgz *
- cd /media/youruserid/boot
- tar czf ~/Desktop/backup_bpi_boot.tgz *
- sudo umount /media/youruserid/Buildroot
- sudo umount /media/youruserid/boot
- remove the SD card
- To restore your work from the backup
- insert the card into the SD card reader and delete the contents of
both partitions:
- sudo rm -rf /media/youruserid/Buildroot/*
- sudo rm -rf /media/youruserid/boot/*
- alternatively create a new partition table and reformat the
partitions if the damage is suspected or new SD card used.
- remove and reinsert the SD card
- sudo tar xzf ~/Desktop/backup_bpi_rootfs.tgz -C
/media/youruserid/Buildroot/
- sudo tar xzf ~/Desktop/backup_bpi_boot.tgz -C
/media/youruserid/boot/
- sync
- sudo umount /media/youruserid/Buildroot
- sudo umount /media/youruserid/boot
- remove the SD card and verify if it does boot correctly
- Cleanup temporary files:
- rm -rf ~/.buildroot-ccache
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.
Submission
Submit the aforementioned screen capture along with tar-gzipped script or scripts showing your lab effort
in the corresponding assignment drop box on Canvas. To ensure full credit verify that the screen capture shows
the welcome screen with your name or initials and the build date obtained from the uname -a
command.
Do not pack the screenshot together. Submit the two files at the same time.
Thank you.