-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'assignments-base/assignment3-part-1'
- Loading branch information
Showing
10 changed files
with
281 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
assignment2 | ||
assignment3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "systemcalls.h" | ||
|
||
/** | ||
* @param cmd the command to execute with system() | ||
* @return true if the command in @param cmd was executed | ||
* successfully using the system() call, false if an error occurred, | ||
* either in invocation of the system() call, or if a non-zero return | ||
* value was returned by the command issued in @param cmd. | ||
*/ | ||
bool do_system(const char *cmd) | ||
{ | ||
|
||
/* | ||
* TODO add your code here | ||
* Call the system() function with the command set in the cmd | ||
* and return a boolean true if the system() call completed with success | ||
* or false() if it returned a failure | ||
*/ | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param count -The numbers of variables passed to the function. The variables are command to execute. | ||
* followed by arguments to pass to the command | ||
* Since exec() does not perform path expansion, the command to execute needs | ||
* to be an absolute path. | ||
* @param ... - A list of 1 or more arguments after the @param count argument. | ||
* The first is always the full path to the command to execute with execv() | ||
* The remaining arguments are a list of arguments to pass to the command in execv() | ||
* @return true if the command @param ... with arguments @param arguments were executed successfully | ||
* using the execv() call, false if an error occurred, either in invocation of the | ||
* fork, waitpid, or execv() command, or if a non-zero return value was returned | ||
* by the command issued in @param arguments with the specified arguments. | ||
*/ | ||
|
||
bool do_exec(int count, ...) | ||
{ | ||
va_list args; | ||
va_start(args, count); | ||
char * command[count+1]; | ||
int i; | ||
for(i=0; i<count; i++) | ||
{ | ||
command[i] = va_arg(args, char *); | ||
} | ||
command[count] = NULL; | ||
// this line is to avoid a compile warning before your implementation is complete | ||
// and may be removed | ||
command[count] = command[count]; | ||
|
||
/* | ||
* TODO: | ||
* Execute a system command by calling fork, execv(), | ||
* and wait instead of system (see LSP page 161). | ||
* Use the command[0] as the full path to the command to execute | ||
* (first argument to execv), and use the remaining arguments | ||
* as second argument to the execv() command. | ||
* | ||
*/ | ||
|
||
va_end(args); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param outputfile - The full path to the file to write with command output. | ||
* This file will be closed at completion of the function call. | ||
* All other parameters, see do_exec above | ||
*/ | ||
bool do_exec_redirect(const char *outputfile, int count, ...) | ||
{ | ||
va_list args; | ||
va_start(args, count); | ||
char * command[count+1]; | ||
int i; | ||
for(i=0; i<count; i++) | ||
{ | ||
command[i] = va_arg(args, char *); | ||
} | ||
command[count] = NULL; | ||
// this line is to avoid a compile warning before your implementation is complete | ||
// and may be removed | ||
command[count] = command[count]; | ||
|
||
|
||
/* | ||
* TODO | ||
* Call execv, but first using https://stackoverflow.com/a/13784315/1446624 as a refernce, | ||
* redirect standard out to a file specified by outputfile. | ||
* The rest of the behaviour is same as do_exec() | ||
* | ||
*/ | ||
|
||
va_end(args); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <stdarg.h> | ||
|
||
bool do_system(const char *command); | ||
|
||
bool do_exec(int count, ...); | ||
|
||
bool do_exec_redirect(const char *outputfile, int count, ...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
echo "Running test script" | ||
./finder-test.sh | ||
rc=$? | ||
if [ ${rc} -eq 0 ]; then | ||
echo "Completed with success!!" | ||
else | ||
echo "Completed with failure, failed with rc=${rc}" | ||
fi | ||
echo "finder-app execution complete, dropping to terminal" | ||
/bin/sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Dependency installation script for kernel build. | ||
# Author: Siddhant Jajoo. | ||
|
||
|
||
sudo apt-get install -y libssl-dev | ||
sudo apt-get install -y u-boot-tools | ||
sudo apt-get install -y qemu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
# Script outline to install and build kernel. | ||
# Author: Siddhant Jajoo. | ||
|
||
set -e | ||
set -u | ||
|
||
OUTDIR=/tmp/aeld | ||
KERNEL_REPO=git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git | ||
KERNEL_VERSION=v5.1.10 | ||
BUSYBOX_VERSION=1_33_1 | ||
FINDER_APP_DIR=$(realpath $(dirname $0)) | ||
ARCH=arm64 | ||
CROSS_COMPILE=aarch64-none-linux-gnu- | ||
|
||
if [ $# -lt 1 ] | ||
then | ||
echo "Using default directory ${OUTDIR} for output" | ||
else | ||
OUTDIR=$1 | ||
echo "Using passed directory ${OUTDIR} for output" | ||
fi | ||
|
||
mkdir -p ${OUTDIR} | ||
|
||
cd "$OUTDIR" | ||
if [ ! -d "${OUTDIR}/linux-stable" ]; then | ||
#Clone only if the repository does not exist. | ||
echo "CLONING GIT LINUX STABLE VERSION ${KERNEL_VERSION} IN ${OUTDIR}" | ||
git clone ${KERNEL_REPO} --depth 1 --single-branch --branch ${KERNEL_VERSION} | ||
fi | ||
if [ ! -e ${OUTDIR}/linux-stable/arch/${ARCH}/boot/Image ]; then | ||
cd linux-stable | ||
echo "Checking out version ${KERNEL_VERSION}" | ||
git checkout ${KERNEL_VERSION} | ||
|
||
# TODO: Add your kernel build steps here | ||
fi | ||
|
||
echo "Adding the Image in outdir" | ||
|
||
echo "Creating the staging directory for the root filesystem" | ||
cd "$OUTDIR" | ||
if [ -d "${OUTDIR}/rootfs" ] | ||
then | ||
echo "Deleting rootfs directory at ${OUTDIR}/rootfs and starting over" | ||
sudo rm -rf ${OUTDIR}/rootfs | ||
fi | ||
|
||
# TODO: Create necessary base directories | ||
|
||
cd "$OUTDIR" | ||
if [ ! -d "${OUTDIR}/busybox" ] | ||
then | ||
git clone git://busybox.net/busybox.git | ||
cd busybox | ||
git checkout ${BUSYBOX_VERSION} | ||
# TODO: Configure busybox | ||
else | ||
cd busybox | ||
fi | ||
|
||
# TODO: Make and install busybox | ||
|
||
echo "Library dependencies" | ||
${CROSS_COMPILE}readelf -a bin/busybox | grep "program interpreter" | ||
${CROSS_COMPILE}readelf -a bin/busybox | grep "Shared library" | ||
|
||
# TODO: Add library dependencies to rootfs | ||
|
||
# TODO: Make device nodes | ||
|
||
# TODO: Clean and build the writer utility | ||
|
||
# TODO: Copy the finder related scripts and executables to the /home directory | ||
# on the target rootfs | ||
|
||
# TODO: Chown the root directory | ||
|
||
# TODO: Create initramfs.cpio.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# !/bin/bash | ||
# Script to open qemu terminal. | ||
# Author: Siddhant Jajoo. | ||
|
||
set -e | ||
|
||
OUTDIR=$1 | ||
|
||
if [ -z "${OUTDIR}" ]; then | ||
OUTDIR=/tmp/aeld | ||
echo "No outdir specified, using ${OUTDIR}" | ||
fi | ||
|
||
KERNEL_IMAGE=${OUTDIR}/Image | ||
INITRD_IMAGE=${OUTDIR}/initramfs.cpio.gz | ||
|
||
if [ ! -e ${KERNEL_IMAGE} ]; then | ||
echo "Missing kernel image at ${KERNEL_IMAGE}" | ||
exit 1 | ||
fi | ||
if [ ! -e ${INITRD_IMAGE} ]; then | ||
echo "Missing initrd image at ${INITRD_IMAGE}" | ||
exit 1 | ||
fi | ||
|
||
|
||
echo "Booting the kernel" | ||
# See trick at https://superuser.com/a/1412150 to route serial port output to file | ||
qemu-system-aarch64 \ | ||
-m 256M \ | ||
-M virt \ | ||
-cpu cortex-a53 \ | ||
-nographic \ | ||
-smp 1 \ | ||
-kernel ${KERNEL_IMAGE} \ | ||
-chardev stdio,id=char0,mux=on,logfile=${OUTDIR}/serial.log,signal=off \ | ||
-serial chardev:char0 -mon chardev=char0 \ | ||
-append "rdinit=/home/autorun-qemu.sh console=ttyAMA0" -initrd ${INITRD_IMAGE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# !/bin/bash | ||
# Script to open qemu terminal. | ||
# Author: Siddhant Jajoo. | ||
|
||
set -e | ||
|
||
OUTDIR=$1 | ||
|
||
if [ -z "${OUTDIR}" ]; then | ||
OUTDIR=/tmp/aeld | ||
echo "No outdir specified, using ${OUTDIR}" | ||
fi | ||
|
||
KERNEL_IMAGE=${OUTDIR}/Image | ||
INITRD_IMAGE=${OUTDIR}/initramfs.cpio.gz | ||
|
||
if [ ! -e ${KERNEL_IMAGE} ]; then | ||
echo "Missing kernel image at ${KERNEL_IMAGE}" | ||
exit 1 | ||
fi | ||
if [ ! -e ${INITRD_IMAGE} ]; then | ||
echo "Missing initrd image at ${INITRD_IMAGE}" | ||
exit 1 | ||
fi | ||
|
||
|
||
echo "Booting the kernel" | ||
# See trick at https://superuser.com/a/1412150 to route serial port output to file | ||
qemu-system-aarch64 -m 256M -M virt -cpu cortex-a53 -nographic -smp 1 -kernel ${KERNEL_IMAGE} \ | ||
-chardev stdio,id=char0,mux=on,logfile=${OUTDIR}/serial.log,signal=off \ | ||
-serial chardev:char0 -mon chardev=char0\ | ||
-append "rdinit=/bin/sh" -initrd ${INITRD_IMAGE} |