This homework is due on Thursday, September 15, at 11:59:59 PM
(Eastern daylight time). You must use submit
to turn in your homework like so:
submit cs421_jtang hw1 greeting.out 0001-your_commit_message.patch platform-driver.txt hw1.c
All of your homework assignments must run under 64-bit Linux, specifically Ubuntu 16.04 LTS ("Xenial Xerus"), and all projects will involve making changes to the Linux kernel. In addition, all later assignments require that you have a working Linux virtual machine. The projects require that you have finished customizing your Linux kernel. In this homework, you will become familiar with the procedures of installing and updating the kernel inside a VM.
If you are unable to customize your kernel for this homework, you will get a zero on the later projects.
This homework is divided into several parts that will help you perform the following objectives:
If you choose to work in the lab, you will need an external USB hard drive or flash drive for development as well as for backups. You will need to have at least 30 GiB of free space on the drive to store your VM image on it, so a 32 GiB or larger drive is highly recommended. Also, you will need to format the drive to filesystems that supports files of size > 4GiB. Many flash drives come pre-formatted as FAT32, which do not support file sizes >= 4GiB. FAT32 will not work for this reason! You should format your drive as either NTFS (if you will be using Windows with the drive as well) or a Linux filesystem such as ext4.
In order to aid development of assignemnts in this course, we will be running the submissions under virtualization. Virtualization allows us to run a virtual machine on an actual physical machine. In this way, we can run a second guest operating system inside the regular host operating system. To do the assignments in this class, we assume you will have access to a relatively modern PC that can run VirtualBox. VirtualBox requires an x86 CPU with a decent amount of RAM, at least 4 GiB. In addition, your host CPU should support the x86 virtualization extensions (VT-x for Intel processors, or AMD-V for AMD processors). For more information about hardware and software requirements for VirtualBox, please consult the VirtualBox website. All assignments are expected to run in 64-bit mode on VirtualBox.
VirtualBox is available on the machines in the ITE 240 lab under both Linux and Windows. You can also download it for free from https://www.virtualbox.org/wiki/Downloads to run under your own Windows, Mac, or even Linux host operating system.
For the purposes of assignments in this course, we will be using the x86 (64-bit) version of the Ubuntu 16.04 Linux distribution. In addition, the custom kernels that are built in this class will be based on the Linux kernel version 4.4 (the latest long-term stable kernel).
Perform the following tasks to create the environment that will be used to complete assignments in this course. These instructions are based upon a WikiHow article.
sudo apt-get update && sudo apt-get upgradeYou will need to enter your password to run the operation as root.
Be aware you may need to reinstall the Guest Additions each time you update the kernel for this class.
Many of the commands that you will be running within the VM will require root privileges. There are a variety of methods to elevate your user privileges on Linux. You can use any of the following methods to do so:
sudo -s (enter your user password when prompted) (perform any commands to execute as root) exitOR
sudo sh (enter your user password when prompted) (perform any commands to execute as root) exitOR
sudo (command to execute as root)
Ubuntu 16.04 ships with a 4.4 Linux kernel. As that this class involves learning how kernels really work, you will recompile the kernel. Follow these steps to obtain the kernel source files:
sudo apt-get install g++ libqt4-dev libncurses5-dev libssl-dev emacs vim git indent
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linuxThis last command fetches the Linux source code repository, via git, and writes the files into the new linux directory. If you are not familiar with the git version control system, you should work through the Interactive Git Tutorial before proceeding.
cd linux git checkout linux-4.4.yFor the rest of this assignment, the sources in the linux directory will be referred to as your working copy of the kernel, or alternatively, Linux kernel repository. If you ever need the original unmodified code, re-run the clone command in a different directory; advanced git users may also want to create their own branches within the repository.
git config --global user.email "gburdell@umbc.edu" git config --global user.name "George Burdell"(Note the above is dash, dash, "global".)
wget http://www.csee.umbc.edu/~jtang/cs421.f16/homework/hw1/0001-x86-irq-Allow-for-software-triggered-IRQ.patch wget http://www.csee.umbc.edu/~jtang/cs421.f16/homework/hw1/0002-x86-Create-kernel-defconfig-for-CS421-VirtualBox-VMs.patch
git am 0001-x86-irq-Allow-for-software-triggered-IRQ.patch git am 0002-x86-Create-kernel-defconfig-for-CS421-VirtualBox-VMs.patch
Next, you will perform a simple modification of the official Linux kernel. At startup, your custom kernel will write a message to the kernel log using your name. If you have followed all of the instructions up to this point, you should have no trouble doing this.
dmesg
dmesg | head
[ 0.000000] Linux version 4.4.17+ (jtang@421vm-VirtualBox) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) ) #2 SMP Sun Aug 14 22:52:16 EDT 2016 [ 0.000000] This is jtang's kernel! [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.4.17+ root=UUID=ecbd668e-8eb0-4f3c-b2b3-3c07ce06b700 ro quiet splashEmphasis added.
printk()
function works.
To begin, you need to compile the kernel and accompanying modules as is.
make mrproper make cs421_defconfig make clean
make -j3 sudo make modules_install install
GRUB_HIDDEN_TIMEOUT
and GRUB_HIDDEN_TIMEOUT_QUIET
. Save and quit, then
run update-grub (again as root) to
update grub's configuration. See
the grub
documentation for details.
uname -a
mkdir -p $HOME/hw1 dmesg | head > $HOME/hw1/greeting.out
Your next objective is to learn about patches and diffs. Since many modifications to the kernel are small (compared to the total kernel source size), such updates are usually distributed in the form of a patch file; those patch files describe differences between the original software and the modified code. If you make minor modifications to the kernel (such as for CS421 projects) you will want to create patches containing the diffs. Later projects may distribute minor kernel changse in the form of patches.
#
will be ignored. Save
and exit.
git format-patch HEAD^1 -o $HOME/hw1
Now that you have a working Linux virtual machine, it is time for some programming. Write a simple program, in C, that takes a single command line argument, an interrupt number. Your program then searches through /proc/interrupts for that interrupt number, then displays the kernel driver or drivers associated with the number. If no drivers have the requested interrupt number, or if the user did not supply a interrupt number, then do not print anything at all. (Yes, you could implement this entirely using awk, but then you would miss out on the joy of compilation.)
Your program must be called hw1.c, and it will be compiled on Ubuntu 16.04 as follows:
gcc --std=c99 -Wall -O2 -o hw1 hw1.cThere must not be any compilation warnings in your submission; warnings will result in grading penalties. In addition, each code file must be properly indented and have a file header comment, as described on the coding conventions page.
Here is a sample output when run in the VM:
$ ./hw1 19 ehci_hcd:usb1, enp0s3 $ ./hw1 0 timer $ ./hw1 999 (no such interrupt, so no output) $ ./hw1 CS421 (not a number, so no output) $ ./hw1 421CS (also not a number, so no output) $ ./hw1 (no argument given, so no output) $ ./hw1 4 21 (more than one argument, so no output)
Sorry, there is no extra credit available for this assignment.