Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from olafurw/8-seu-bit-flip-simulator
Browse files Browse the repository at this point in the history
issue #8 include seu simulation
  • Loading branch information
georgeslabreche authored Jan 9, 2024
2 parents 28521c6 + 8ed3a00 commit ca25a6c
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 80 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.vscode
toGround
toGround/
opssat-doom.map
src/build/
src/bin/
src/output/
output/
output/
lib/
deploy/
backup/
40 changes: 36 additions & 4 deletions build-32.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
source /home/user/poky_sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi;
pushd src;
make;
popd;
#!/bin/bash

# default values
STATIC_FLAG=NO
CLEAN_FLAG=NO

# delete backup folder if it exists because it contains the old build
rm -rf backup

# parse arguments
for arg in "$@"
do
if [[ "$arg" == "static" ]]; then
STATIC_FLAG=YES
elif [[ "$arg" == "clean" ]]; then
CLEAN_FLAG=YES
fi
done

# source the environment setup script
source /home/user/poky_sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi

# change directory to src
pushd src

# clean if requested
if [[ "$CLEAN_FLAG" == "YES" ]]; then
make clean
fi

# build the project
make STATIC=$STATIC_FLAG

# Return to the original directory
popd

36 changes: 33 additions & 3 deletions build-64.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
pushd src;
make;
popd;
#!/bin/bash

# default values
STATIC_FLAG=NO
CLEAN_FLAG=NO

# delete backup folder if it exists because it contains the old build
rm -rf backup

# parse arguments
for arg in "$@"
do
if [[ "$arg" == "static" ]]; then
STATIC_FLAG=YES
elif [[ "$arg" == "clean" ]]; then
CLEAN_FLAG=YES
fi
done

# change directory to src
pushd src

# clean if requested
if [[ "$CLEAN_FLAG" == "YES" ]]; then
make clean
fi

# build the project
make STATIC=$STATIC_FLAG

# Return to the original directory
popd

27 changes: 11 additions & 16 deletions create_ipk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
project_dir=$(pwd)

# The files that will be packaged into the ipk.
bin_doom=${project_dir}/src/chocolate-doom
bin_doom=${project_dir}/src/bin/opssat-doom
seu_simulator=${project_dir}/simulate_seu.py
seu_simulator_test=${project_dir}/test_simulate_seu.py

# Check that the required files exist.
if [ ! -f "$bin_doom" ]; then
Expand Down Expand Up @@ -38,12 +40,11 @@ IPK_FILENAME=""
target_dir=/home/${PKG_NAME}
deploy_dir=${project_dir}/deploy
deploy_exp_dir=${deploy_dir}/${target_dir}
deploy_exp_lib_dir=${deploy_exp_dir}/lib

#deploy_exp_lib_dir=${deploy_exp_dir}/lib

# Clean and initialize the deploy folder.
rm -rf ${deploy_dir}
mkdir -p ${deploy_exp_lib_dir}
mkdir -p ${deploy_exp_dir}

# The project can be packaged for the spacecraft (no bash command options) or for the EM (use the 'em' option).
# This distinction is only necessary in case there are files that are environment specific to the EM vs the spacecraft.
Expand All @@ -58,7 +59,8 @@ elif [ "$1" == "em" ]; then
IPK_FILENAME=${PKG_NAME}_${PKG_VER}_${PKG_ARCH}_em.ipk
echo "Create ${IPK_FILENAME} for the EM"

# TODO (Optional): Copy into ${deploy_exp_dir} any EM specific files.
# Copy into ${deploy_exp_dir} any EM specific files.
cp ${seu_simulator_test} ${deploy_exp_dir}/

else
# If not deploying for spacecraft nor the EM then an invalid parameter was given.
Expand All @@ -67,14 +69,11 @@ else
exit 1
fi

# Copy into ${deploy_exp_lib_dir} the library files.
cp /home/user/poky_sdk/tmp/sysroots/beaglebone/lib/libSDL-1.2.so.0 ${deploy_exp_lib_dir}/
cp /home/user/poky_sdk/tmp/sysroots/beaglebone/lib/libSDL_mixer-1.2.so.0 ${deploy_exp_lib_dir}/
cp /home/user/poky_sdk/tmp/sysroots/beaglebone/lib/libSDL_net-1.2.so.0 ${deploy_exp_lib_dir}/
#cp /home/user/poky_sdk/tmp/sysroots/beaglebone/usr/lib/libpng16.so.16 ${deploy_exp_lib_dir}/

# Copy into ${deploy_exp_dir} core project files that are required for both EM and spacecraft deployments.

# The SEU simulator
cp ${seu_simulator} ${deploy_exp_dir}/

# The executable binary.
mkdir ${deploy_exp_dir}/src
cp ${bin_doom} ${deploy_exp_dir}/src
Expand All @@ -86,10 +85,6 @@ cp -r demos ${deploy_exp_dir}/
cp start_${PKG_NAME}.sh ${deploy_exp_dir}/
cp stop_${PKG_NAME}.sh ${deploy_exp_dir}/


# Replace relative paths in the test script with full paths in the spacecraft payload computer's file system.
sed -i "s|\./src/chocolate-doom|${target_dir}/src/chocolate-doom|g; s|demos/|${target_dir}/demos/|g; s|toGround/|${target_dir}/toGround/|g" ${deploy_exp_dir}/start_${PKG_NAME}.sh

# Create the toGround directory.
mkdir ${deploy_exp_dir}/toGround

Expand Down Expand Up @@ -119,4 +114,4 @@ rm -f ${deploy_dir}/debian-binary
rm -rf ${deploy_dir}/home

# Done with great success.
echo "Qapla'"
echo "Qapla'"
24 changes: 12 additions & 12 deletions demos/zero-e1m1-long.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
===========================================
E1M1 / MAP01
===========================================
Time: 4:18 (par: 0:30)
Player 1 (Green):
Kills: 22 / 4 (550%)
Items: 30 / 37 (81%)
Secrets: 3 / 3 (100%)
RNG Calls: 70148
===========================================
E1M1 / MAP01
===========================================

Time: 4:18 (par: 0:30)

Player 1 (Green):
Kills: 22 / 4 (550%)
Items: 30 / 37 (81%)
Secrets: 3 / 3 (100%)
RNG Calls: 70148

24 changes: 12 additions & 12 deletions demos/zero-e1m1-run-around.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
===========================================
E1M1 / MAP01
===========================================
Time: 2:44 (par: 0:30)
Player 1 (Green):
Kills: 6 / 6 (100%)
Items: 24 / 37 (64%)
Secrets: 1 / 3 (33%)
RNG Calls: 42696
===========================================
E1M1 / MAP01
===========================================

Time: 2:44 (par: 0:30)

Player 1 (Green):
Kills: 6 / 6 (100%)
Items: 24 / 37 (64%)
Secrets: 1 / 3 (33%)
RNG Calls: 42696

24 changes: 12 additions & 12 deletions demos/zero-e1m1-short.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
===========================================
E1M1 / MAP01
===========================================
Time: 0:37 (par: 0:30)
Player 1 (Green):
Kills: 4 / 4 (100%)
Items: 4 / 37 (10%)
Secrets: 0 / 3 (0%)
RNG Calls: 11492
===========================================
E1M1 / MAP01
===========================================

Time: 0:37 (par: 0:30)

Player 1 (Green):
Kills: 4 / 4 (100%)
Items: 4 / 37 (10%)
Secrets: 0 / 3 (0%)
RNG Calls: 11492

2 changes: 1 addition & 1 deletion sepp_package/CONTROL/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Priority: optional
Maintainer: esoc
Architecture: sepp
Section: Applications
Version: 1.0
Version: 2.0
Description: DOOM is a 1993 first-person shooter. Will it run in space onboard the OPS-SAT-1 satellite computer?
50 changes: 50 additions & 0 deletions simulate_seu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import random
import sys

def flip_bit(byte, bit_position):
"""Flip the specified bit in a byte"""
return byte ^ (1 << bit_position)

def simulate_seu(seu_target_file_path, seu_rate):
"""Simulate SEU on a file given its path and SEU rate"""
if not os.path.exists(seu_target_file_path):
print("ERROR: SEU target file does not exist")
sys.exit(1)

# Read file into memory
with open(seu_target_file_path, "rb") as file:
data = bytearray(file.read())

total_bits = len(data) * 8
num_flips = int(total_bits * seu_rate)

# Randomly select bits to flip
for _ in range(num_flips):
bit_to_flip = random.randint(0, total_bits - 1)
byte_index = bit_to_flip // 8
bit_position = bit_to_flip % 8
data[byte_index] = flip_bit(data[byte_index], bit_position)

# Write data back to file
with open(seu_target_file_path, "wb") as file:
file.write(data)

# Check if the script has the necessary command-line arguments
if len(sys.argv) != 3:
print("Usage: python simulate_seu.py [seu_target_file_path] [seu_rate]")
sys.exit(1)

# Command-line arguments
seu_target_file_path = sys.argv[1]
try:
seu_rate = float(sys.argv[2])
except ValueError:
print("ERROR: SEU rate must be a float")
sys.exit(1)

# Simulate SEU on target file at given rate
simulate_seu(seu_target_file_path, seu_rate)
print("QAPLA': SEU simulation completed")
sys.exit(0)

8 changes: 7 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ ifndef CC
endif

LDFLAGS+=-Wl,--gc-sections
CFLAGS+=-static -ggdb3 -Os -Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM
CFLAGS+=-ggdb3 -Os -Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM

# check if static flag is set to YES
ifeq ($(STATIC),YES)
CFLAGS+=-static
endif

LIBS+=-lm -lc

# subdirectory for objects
Expand Down
Loading

0 comments on commit ca25a6c

Please sign in to comment.