Skip to content

Commit

Permalink
Merge remote-tracking branch 'assignments-base/assignment3-part-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
moschiel committed Dec 13, 2024
2 parents 09b9dff + e8431ef commit 4c02e8f
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 10 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,3 @@ jobs:
run : git submodule update --init --recursive
- name: Run unit test
run: ./unit-test.sh
full-test:
container: cuaesd/aesd-autotest:24-assignment2
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Checkout submodules
run : git submodule update --init --recursive
- name: Run full test
run: ./full-test.sh
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ project(aesd-assignments)
set(AUTOTEST_SOURCES
test/assignment1/Test_hello.c
test/assignment1/Test_assignment_validate.c
test/assignment3/Test_systemcalls.c
)
# A list of all files containing test code that is used for assignment validation
set(TESTED_SOURCE
../examples/autotest-validate/autotest-validate.c
../examples/systemcalls/systemcalls.c
)
add_subdirectory(assignment-autotest)
2 changes: 1 addition & 1 deletion conf/assignment.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assignment2
assignment3
99 changes: 99 additions & 0 deletions examples/systemcalls/systemcalls.c
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;
}
9 changes: 9 additions & 0 deletions examples/systemcalls/systemcalls.h
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, ...);
12 changes: 12 additions & 0 deletions finder-app/autorun-qemu.sh
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
8 changes: 8 additions & 0 deletions finder-app/dependencies.sh
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
80 changes: 80 additions & 0 deletions finder-app/manual-linux.sh
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
38 changes: 38 additions & 0 deletions finder-app/start-qemu-app.sh
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}
32 changes: 32 additions & 0 deletions finder-app/start-qemu-terminal.sh
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}

0 comments on commit 4c02e8f

Please sign in to comment.