move justfiles to scripts/
This commit is contained in:
134
scripts/fail.just
Normal file
134
scripts/fail.just
Normal file
@ -0,0 +1,134 @@
|
||||
[doc("Trace a golden run using FAIL*")]
|
||||
[group("4: fail")]
|
||||
trace module:
|
||||
{{ BOCHS_RUNNER }} \
|
||||
-V {{ FAIL_SHARE }}/vgabios.bin \
|
||||
-b {{ FAIL_SHARE }}/BIOS-bochs-latest \
|
||||
-1 \
|
||||
-f {{ FAIL_TRACE }} \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf \
|
||||
-i {{ BUILD_DIR }}-{{ module }}/system.iso \
|
||||
-- \
|
||||
-Wf,--start-symbol=fail_start_trace \
|
||||
-Wf,--save-symbol=fail_start_trace \
|
||||
-Wf,--end-symbol=fail_stop_trace \
|
||||
-Wf,--state-file={{ BUILD_DIR }}-{{ module }}/state \
|
||||
-Wf,--trace-file={{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-Wf,--elf-file={{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
@echo "Next step: \"just import {{ module }}\""
|
||||
|
||||
# [doc("Dump a FAIL* golden run trace")]
|
||||
# [group("fail")]
|
||||
# dump module:
|
||||
# {{ FAIL_DUMP }} {{ BUILD_DIR }}-{{ module }}/trace.pb
|
||||
|
||||
[doc("Import a FAIL* golden run trace")]
|
||||
[group("4: fail")]
|
||||
import module:
|
||||
{{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-i MemoryImporter \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b mem
|
||||
{{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-i RegisterImporter \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b regs --flags
|
||||
{{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-i RegisterImporter \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b ip --no-gp --ip
|
||||
|
||||
{{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-i ElfImporter --objdump objdump \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b ip
|
||||
{{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-i ElfImporter --objdump objdump \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b mem
|
||||
{{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
-i ElfImporter --objdump objdump \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b regs
|
||||
|
||||
# {{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
# -i ElfImporter --objdump objdump \
|
||||
# -e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b ip --sources
|
||||
# {{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
# -i ElfImporter --objdump objdump \
|
||||
# -e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b mem --sources
|
||||
# {{ FAIL_IMPORT }} --database-option-file ./db.conf -t {{ BUILD_DIR }}-{{ module }}/trace.pb \
|
||||
# -i ElfImporter --objdump objdump \
|
||||
# -e {{ BUILD_DIR }}-{{ module }}/system.elf -v {{ module }} -b regs --sources
|
||||
|
||||
{{ FAIL_PRUNE }} --database-option-file ./db.conf -v {{ module }} -b %% --overwrite
|
||||
@echo "Next step: \"just server {{ module }}\""
|
||||
|
||||
[doc("Start the FAIL* campaign server")]
|
||||
[group("4: fail")]
|
||||
server module:
|
||||
{{ FAIL_SERVER }} \
|
||||
--port {{ FAIL_SERVER_PORT }} \
|
||||
--database-option-file ./db.conf \
|
||||
-v {{ module }} \
|
||||
-b % \
|
||||
--inject-single-bit \
|
||||
--inject-registers \
|
||||
&
|
||||
@echo "Next step: \"just client {{ module }}\""
|
||||
|
||||
[doc("Stop the FAIL* campaign server")]
|
||||
[group("4: fail")]
|
||||
stop-server:
|
||||
pkill -f {{ FAIL_SERVER }}
|
||||
|
||||
[doc("Start a FAIL* campaign client")]
|
||||
[group("4: fail")]
|
||||
client module:
|
||||
# -Wf,--catch-write-textsegment
|
||||
# -Wf,--catch-outerspace
|
||||
{{ BOCHS_RUNNER }} \
|
||||
-V {{ FAIL_SHARE }}/vgabios.bin \
|
||||
-b {{ FAIL_SHARE }}/BIOS-bochs-latest \
|
||||
-f {{ FAIL_INJECT }} \
|
||||
-e {{ BUILD_DIR }}-{{ module }}/system.elf \
|
||||
-i {{ BUILD_DIR }}-{{ module }}/system.iso \
|
||||
-j {{ num_cpus() }} \
|
||||
-- \
|
||||
-Wf,--server-port={{ FAIL_SERVER_PORT }} \
|
||||
-Wf,--state-dir={{ BUILD_DIR }}-{{ module }}/state \
|
||||
-Wf,--trap \
|
||||
-Wf,--catch-outerspace \
|
||||
-Wf,--timeout=500000 \
|
||||
-Wf,--ok-marker=fail_marker_positive \
|
||||
-Wf,--fail-marker=fail_marker_negative \
|
||||
-Wf,--detected-marker=fail_marker_detected \
|
||||
> /dev/null
|
||||
@echo "Next step: \"just result {{ module }}\" or \"just resultbrowser\""
|
||||
|
||||
[doc("Query FAIL* marker statistics from the database")]
|
||||
[group("4: fail")]
|
||||
result module:
|
||||
@echo "select variant, benchmark, resulttype, sum(t.time2 - t.time1 + 1) as faults \
|
||||
FROM variant v \
|
||||
JOIN trace t ON v.id = t.variant_id \
|
||||
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address \
|
||||
JOIN result_GenericExperimentMessage r ON r.pilot_id = g.pilot_id \
|
||||
JOIN fsppilot p ON r.pilot_id = p.id \
|
||||
WHERE v.variant = \"{{ module }}\" \
|
||||
GROUP BY v.id, resulttype \
|
||||
ORDER BY variant, benchmark, resulttype;" | mariadb --defaults-file=./db.conf -t
|
||||
|
||||
[doc("Dump FAIL* markers to CSV")]
|
||||
[group("4: fail")]
|
||||
result-csv module:
|
||||
@echo "SELECT \
|
||||
CONCAT(\"0x\", HEX(p.injection_instr_absolute)) AS fault_address, \
|
||||
SUM(t.time2 - t.time1 + 1) AS total_fail_markers \
|
||||
FROM trace t \
|
||||
JOIN variant v ON v.id = t.variant_id \
|
||||
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address \
|
||||
JOIN result_GenericExperimentMessage r ON r.pilot_id = g.pilot_id \
|
||||
JOIN fsppilot p ON p.id = r.pilot_id \
|
||||
WHERE v.variant = \"{{ module }}\" AND r.resulttype = \"FAIL_MARKER\" \
|
||||
GROUP BY p.injection_instr_absolute \
|
||||
ORDER BY SUM(t.time2 - t.time1 + 1) DESC;" | mariadb --defaults-file=./db.conf --batch --raw | sed 's/\t/,/g'
|
||||
|
||||
[doc("Start the FAIL* resultbrowser")]
|
||||
[group("4: fail")]
|
||||
resultbrowser:
|
||||
{{ RESULT_BROWSER }} -c ./db.conf --host=0.0.0.0 --port={{ RESULTBROWSER_PORT }}
|
||||
35
scripts/mars.just
Normal file
35
scripts/mars.just
Normal file
@ -0,0 +1,35 @@
|
||||
import "fail.just"
|
||||
|
||||
BUILD_DIR := "build"
|
||||
|
||||
# FAIL* variables
|
||||
|
||||
FAIL_SERVER_PORT := "22941"
|
||||
RESULTBROWSER_PORT := "22941"
|
||||
FAIL_BIN := "fail/bin"
|
||||
FAIL_SHARE := "fail/share"
|
||||
BOCHS_RUNNER := f"{{FAIL_BIN}}/bochs-experiment-runner.py"
|
||||
FAIL_TRACE := f"{{FAIL_BIN}}/fail-x86-tracing"
|
||||
FAIL_DUMP := f"{{FAIL_BIN}}/dump-trace"
|
||||
FAIL_IMPORT := f"{{FAIL_BIN}}/import-trace"
|
||||
FAIL_PRUNE := f"{{FAIL_BIN}}/prune-trace"
|
||||
FAIL_SERVER := f"{{FAIL_BIN}}/generic-experiment-server"
|
||||
FAIL_INJECT := f"{{FAIL_BIN}}/generic-experiment-client"
|
||||
RESULT_BROWSER := f"{{FAIL_BIN}}/resultbrowser.py"
|
||||
|
||||
# =================================================================================================================== #
|
||||
# Helper recipes
|
||||
# =================================================================================================================== #
|
||||
|
||||
[default]
|
||||
[private]
|
||||
list:
|
||||
@./just --list --unsorted
|
||||
|
||||
# Create a database:
|
||||
# - mysql -u smchurla -p
|
||||
# - CREATE DATABASE database_name;
|
||||
# - SHOW DATABASES;
|
||||
|
||||
procs:
|
||||
ps -u smchurla
|
||||
229
scripts/nixos.just
Normal file
229
scripts/nixos.just
Normal file
@ -0,0 +1,229 @@
|
||||
import "wasm.just"
|
||||
import "fail.just"
|
||||
|
||||
BUILD_DIR := "build"
|
||||
|
||||
# Load environment variables set by "nix develop"-shell
|
||||
|
||||
FAIL_SHARE := env("FAIL_SHARE")
|
||||
WASI_ROOT := env("WASI_ROOT")
|
||||
WAMR_ROOT := env("WAMR_ROOT")
|
||||
LIBIWASM_DEBUG := env("LIBIWASM_DEBUG")
|
||||
LIBIWASM_RELEASE := env("LIBIWASM_RELEASE")
|
||||
LIBIWASM_LINUX_DEBUG := env("LIBIWASM_LINUX_DEBUG")
|
||||
LIBIWASM_LINUX_RELEASE := env("LIBIWASM_LINUX_RELEASE")
|
||||
CROSS_CC := env("CROSS_CC")
|
||||
LINUX_CC := env("LINUX_CC")
|
||||
|
||||
# FAIL* variables
|
||||
|
||||
FAIL_SERVER_PORT := "1111"
|
||||
RESULTBROWSER_PORT := "5000"
|
||||
BOCHS_RUNNER := "bochs-experiment-runner.py"
|
||||
FAIL_TRACE := "fail-x86-tracing"
|
||||
FAIL_DUMP := "dump-trace"
|
||||
FAIL_IMPORT := "import-trace"
|
||||
FAIL_PRUNE := "prune-trace"
|
||||
FAIL_SERVER := "generic-experiment-server"
|
||||
FAIL_INJECT := "generic-experiment-client"
|
||||
RESULT_BROWSER := "resultbrowser.py"
|
||||
|
||||
# =================================================================================================================== #
|
||||
# Helper recipes
|
||||
# =================================================================================================================== #
|
||||
|
||||
[default]
|
||||
[private]
|
||||
list:
|
||||
@just --list
|
||||
|
||||
[private]
|
||||
create-build-dir module:
|
||||
mkdir -p {{ BUILD_DIR }}-{{ module }}
|
||||
|
||||
[doc("Delete the build directory")]
|
||||
clean module:
|
||||
rm -rf {{ BUILD_DIR }}-{{ module }}
|
||||
|
||||
# =================================================================================================================== #
|
||||
# MySQL recipes
|
||||
# =================================================================================================================== #
|
||||
|
||||
[doc("Start MySQL container to receive FAIL* trace/campaign results")]
|
||||
[group("3: fail db")]
|
||||
start-db:
|
||||
docker run -d \
|
||||
--name fail-db \
|
||||
-e MYSQL_ROOT_PASSWORD=fail \
|
||||
-e MYSQL_USER=fail \
|
||||
-e MYSQL_PASSWORD=fail \
|
||||
-e MYSQL_DATABASE=fail \
|
||||
-p 3306:3306 \
|
||||
mysql
|
||||
|
||||
[doc("Connect to MySQL database using DBeaver")]
|
||||
[group("3: fail db")]
|
||||
connect-db:
|
||||
dbeaver -con "name=fail|driver=mysql|host=localhost|port=3306|database=fail|user=fail|password=fail"
|
||||
|
||||
[doc("Stop MySQL container")]
|
||||
[group("3: fail db")]
|
||||
stop-db:
|
||||
docker stop fail-db
|
||||
|
||||
[doc("Remove MySQL container")]
|
||||
[group("3: fail db")]
|
||||
remove-db:
|
||||
docker container rm fail-db
|
||||
|
||||
# =================================================================================================================== #
|
||||
# Debugging recipes
|
||||
# =================================================================================================================== #
|
||||
|
||||
[doc("Launch gdb")]
|
||||
[group("debug")]
|
||||
gdb module:
|
||||
gdb --tui {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
# [doc("Launch radare2 at address and disassemble")]
|
||||
# [group("debug")]
|
||||
# r2 module addr="dbg.os_main":
|
||||
# # -e asm.section=true
|
||||
# # -e asm.bytes=true
|
||||
# radare2 -AA \
|
||||
# -c "f TARGET @ {{ addr }}; s {{ addr }}; pd-- 30" \
|
||||
# -e asm.syntax=intel \
|
||||
# -e asm.lines=false \
|
||||
# -e asm.xrefs=true \
|
||||
# -e asm.flags=true \
|
||||
# -e asm.comments=true \
|
||||
# -e asm.functions=true \
|
||||
# -e asm.var=true \
|
||||
# -e asm.cmt.right=true \
|
||||
# -e asm.dwarf=true \
|
||||
# -e asm.pseudo=false \
|
||||
# -e asm.describe=false \
|
||||
# -e bin.relocs.apply=true \
|
||||
# {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[doc("Launch radare2 at address (interactive)")]
|
||||
[group("debug")]
|
||||
r2i module addr="dbg.os_main":
|
||||
# -e asm.section=true
|
||||
# -e asm.bytes=true
|
||||
radare2 -AA \
|
||||
-c "s {{ addr }}" \
|
||||
-e scr.color=3 \
|
||||
-e scr.scrollbar=0 \
|
||||
-e scr.responsive=true \
|
||||
-e scr.interactive=true \
|
||||
-e scr.utf8=true \
|
||||
-e scr.utf8.curvy=true \
|
||||
-e asm.syntax=intel \
|
||||
-e asm.lines=false \
|
||||
-e asm.xrefs=true \
|
||||
-e asm.flags=true \
|
||||
-e asm.comments=true \
|
||||
-e asm.functions=true \
|
||||
-e asm.var=true \
|
||||
-e asm.cmt.right=true \
|
||||
-e asm.dwarf=true \
|
||||
-e asm.pseudo=false \
|
||||
-e asm.describe=false \
|
||||
-e bin.relocs.apply=true \
|
||||
{{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
# =================================================================================================================== #
|
||||
# Just do it
|
||||
# =================================================================================================================== #
|
||||
|
||||
[arg("mode", pattern="c|aot|interp", help="Which WASM mode to use")]
|
||||
[arg("target", pattern="fail|linux|linux-baremetal", help="Which platform to compile for")]
|
||||
[doc("Perform all steps for a fail/linux/linux-bm build with aot/interp WASM")]
|
||||
[group("5: just do it")]
|
||||
build module="__help" target="fail" mode="aot":
|
||||
#!/usr/bin/env sh
|
||||
|
||||
if [ "{{ module }}" = "__help" ]; then
|
||||
just --usage build
|
||||
exit 0
|
||||
fi
|
||||
|
||||
just clean {{ module }}
|
||||
just create-build-dir {{ module }}
|
||||
just copy-c-module {{ module }}
|
||||
|
||||
if [ "{{ mode }}" = "aot" ]; then
|
||||
just build-wasm-module {{ module }}
|
||||
just build-wasm-aot {{ module }}
|
||||
just build-wasm-aot-array {{ module }}
|
||||
|
||||
just prepare-aot-host {{ module }}
|
||||
just build-wasm-host {{ module }} {{ target }}
|
||||
|
||||
just build-system-startup {{ module }} {{ target }}
|
||||
just build-system-syscalls {{ module }} {{ target }}
|
||||
just link-system {{ module }} {{ target }}
|
||||
elif [ "{{ mode }}" = "interp" ]; then
|
||||
just build-wasm-module {{ module }}
|
||||
just build-wasm-interp-array {{ module }}
|
||||
|
||||
just prepare-interp-host {{ module }}
|
||||
just build-wasm-host {{ module }} {{ target }}
|
||||
|
||||
just build-system-startup {{ module }} {{ target }}
|
||||
just build-system-syscalls {{ module }} {{ target }}
|
||||
just link-system {{ module }} {{ target }}
|
||||
elif [ "{{ mode }}" = "c" ]; then
|
||||
just build-c-module {{ module }} {{ target }}
|
||||
|
||||
just build-c-host {{ module }} {{ target }}
|
||||
|
||||
just build-system-startup {{ module }} {{ target }}
|
||||
just link-c-system {{ module }} {{ target }}
|
||||
else
|
||||
echo "unknown mode: {{ mode }}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
just build-iso {{ module }}
|
||||
|
||||
[doc("Run binary")]
|
||||
[group("5: just do it")]
|
||||
run module:
|
||||
@echo "Running {{ module }}:"
|
||||
@{{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[arg("mode", pattern="c|aot|interp", help="Which WASM mode to use")]
|
||||
[arg("target", pattern="fail|linux|linux-baremetal", help="Which platform to compile for")]
|
||||
[doc("Perform all steps for a fail/linux/linux-bm build with aot/interp WASM")]
|
||||
[group("5: just do it")]
|
||||
build-run module="__help" target="fail" mode="aot": (build module target mode) (run module)
|
||||
|
||||
[doc("Send binaries to mars")]
|
||||
[group("5: just do it")]
|
||||
upload module:
|
||||
scp -r {{ BUILD_DIR }}-{{ module }} mars:~/Documents/failnix/{{ BUILD_DIR }}-{{ module }}
|
||||
|
||||
[doc("Send markers to local")]
|
||||
[group("5: just do it")]
|
||||
download-markers:
|
||||
scp mars:~/Documents/failnix/markers.csv ./markers.csv
|
||||
|
||||
[doc("Perform all steps for a FAIL* campaign")]
|
||||
[group("5: just do it")]
|
||||
inject module:
|
||||
just start-db
|
||||
@echo "Waiting for database..."
|
||||
sleep 20
|
||||
|
||||
just trace {{ module }}
|
||||
just import {{ module }}
|
||||
just server {{ module }}
|
||||
just client {{ module }}
|
||||
just result {{ module }}
|
||||
|
||||
[doc("Copy build directory to injections/ with timestamp")]
|
||||
[group("5: just do it")]
|
||||
archive module suffix:
|
||||
cp -rv {{ BUILD_DIR }}-{{ module }} ./injections/`date +%Y-%m-%d_%H-%M`_{{ module }}_"{{ suffix }}"
|
||||
356
scripts/wasm.just
Normal file
356
scripts/wasm.just
Normal file
@ -0,0 +1,356 @@
|
||||
# =================================================================================================================== #
|
||||
# Build WASM module recipes
|
||||
# =================================================================================================================== #
|
||||
|
||||
WASI_CC := f"{{WASI_ROOT}}/bin/clang"
|
||||
WASI_CFLAGS := "\
|
||||
--target=wasm32 \
|
||||
--sysroot={{WASI_ROOT}}/share/wasi-sysroot \
|
||||
-z stack-size=4096 \
|
||||
-O0 \
|
||||
-nostdlib \
|
||||
-Wl,--no-entry \
|
||||
-Wl,--export=wasm_module \
|
||||
-Wl,--no-gc-sections \
|
||||
-Wl,--initial-memory=65536 \
|
||||
-Wl,--export=__heap_base \
|
||||
-Wl,--export=__data_end \
|
||||
-Wl,--allow-undefined \
|
||||
"
|
||||
CROSS_CFLAGS_NOWASM := "\
|
||||
-O0 \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-ffreestanding \
|
||||
-fpermissive \
|
||||
-ggdb3 \
|
||||
"
|
||||
CROSS_LDFLAGS_NOWASM := "\
|
||||
-Wl,--build-id=none \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m32 \
|
||||
-lc \
|
||||
-lgcc \
|
||||
-lm \
|
||||
"
|
||||
LINUX_CFLAGS_NOWASM := "\
|
||||
-O0 \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-fpermissive \
|
||||
-ggdb3 \
|
||||
"
|
||||
LINUX_LDFLAGS_NOWASM := "\
|
||||
-Wl,--build-id=none \
|
||||
-m32 \
|
||||
-lm \
|
||||
"
|
||||
WAMRC := "wamrc"
|
||||
WAMRCFLAGS := "\
|
||||
--target=i386 \
|
||||
--cpu=generic \
|
||||
--opt-level=0 \
|
||||
--enable-indirect-mode \
|
||||
--disable-llvm-intrinsics \
|
||||
"
|
||||
XXD := "xxd"
|
||||
|
||||
[doc("C -> WASM: Compile a C function to a WASM module using WASI-SDK")]
|
||||
[group("1: build module")]
|
||||
build-wasm-module module:
|
||||
{{ WASI_CC }} {{ WASI_CFLAGS }} targets/wasm-module/{{ module }}.cpp -o {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm
|
||||
|
||||
[doc("WASM -> AOT: Compile a WASM module ahead-of-time using WAMR")]
|
||||
[group("1: build module")]
|
||||
build-wasm-aot module:
|
||||
{{ WAMRC }} {{ WAMRCFLAGS }} -o {{ BUILD_DIR }}-{{ module }}/wasm_module.aot {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm
|
||||
|
||||
[doc("AOT -> C-Array: Dump a WASM module compiled ahead-of-time to a binary array")]
|
||||
[group("1: build module")]
|
||||
build-wasm-aot-array module:
|
||||
{{ XXD }} -i {{ BUILD_DIR }}-{{ module }}/wasm_module.aot > {{ BUILD_DIR }}-{{ module }}/wasm_aot_array.c
|
||||
|
||||
[doc("WASM -> C-Array: Dump a WASM module to a binary array")]
|
||||
[group("1: build module")]
|
||||
build-wasm-interp-array module:
|
||||
{{ XXD }} -i {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm > {{ BUILD_DIR }}-{{ module }}/wasm_interp_array.c
|
||||
|
||||
[private]
|
||||
build-c-module-fail module:
|
||||
{{ CROSS_CC }} {{ CROSS_CFLAGS_NOWASM }} \
|
||||
-c targets/wasm-module/{{ module }}.cpp \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/c_module.o
|
||||
|
||||
[private]
|
||||
build-c-module-linux module:
|
||||
{{ LINUX_CC }} {{ LINUX_CFLAGS_NOWASM }} \
|
||||
-c targets/wasm-module/{{ module }}.cpp \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/c_module.o
|
||||
|
||||
[doc("C -> Object: Compile a C function (no WASM)")]
|
||||
[group("1: build module")]
|
||||
build-c-module module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just build-c-module-fail "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux" ]; then
|
||||
just build-c-module-linux "{{ module }}"
|
||||
else
|
||||
echo "unknown target: {{ target }}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[private]
|
||||
copy-c-module module:
|
||||
cp targets/wasm-module/{{ module }}.cpp {{ BUILD_DIR }}-{{ module }}/wasm-module.cpp
|
||||
|
||||
# =================================================================================================================== #
|
||||
# Host program recipes
|
||||
# =================================================================================================================== #
|
||||
# FAIL*
|
||||
|
||||
CROSS_CFLAGS := f"-I./targets/wasm-host {{CROSS_CFLAGS_NOWASM}}"
|
||||
CROSS_LDFLAGS := f"-L{{LIBIWASM_DEBUG}} -liwasm {{CROSS_LDFLAGS_NOWASM}}"
|
||||
CROSS_INCLUDES := f"\
|
||||
-I{{WAMR_ROOT}}/core/iwasm/include \
|
||||
-I{{WAMR_ROOT}}/core/shared/utils \
|
||||
-I{{WAMR_ROOT}}/core/shared/platform/baremetal \
|
||||
"
|
||||
|
||||
# LINUX-POSIX
|
||||
|
||||
LINUX_CFLAGS := f"-I./targets/wasm-host {{LINUX_CFLAGS_NOWASM}}"
|
||||
LINUX_LDFLAGS := f"-Wl,-rpath,{{LIBIWASM_LINUX_DEBUG}} -L{{LIBIWASM_LINUX_DEBUG}} -liwasm {{LINUX_LDFLAGS_NOWASM}}"
|
||||
LINUX_INCLUDES := f"\
|
||||
-I{{WAMR_ROOT}}/core/iwasm/include \
|
||||
-I{{WAMR_ROOT}}/core/shared/utils \
|
||||
-I{{WAMR_ROOT}}/core/shared/platform/linux \
|
||||
"
|
||||
|
||||
# LINUX-Baremetal
|
||||
|
||||
LINUX_BAREMETAL_CFLAGS := "\
|
||||
-I./targets/wasm-host \
|
||||
-O0 \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-ffreestanding \
|
||||
-ggdb3 \
|
||||
"
|
||||
LINUX_BAREMETAL_LDFLAGS := f"\
|
||||
-Wl,--build-id=none \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m32 \
|
||||
-L{{LIBIWASM_DEBUG}} \
|
||||
-liwasm \
|
||||
-lc \
|
||||
-lgcc \
|
||||
-lm \
|
||||
--entry main \
|
||||
"
|
||||
LINUX_BAREMETAL_INCLUDES := f"\
|
||||
-I{{WAMR_ROOT}}/core/iwasm/include \
|
||||
-I{{WAMR_ROOT}}/core/shared/utils \
|
||||
-I{{WAMR_ROOT}}/core/shared/platform/baremetal \
|
||||
"
|
||||
|
||||
[doc("Insert the AOT array into the host program")]
|
||||
[group("2: build host")]
|
||||
prepare-aot-host module:
|
||||
cp targets/wasm-host/wasm_host.c {{ BUILD_DIR }}-{{ module }}/module_host.c
|
||||
sed -i \
|
||||
-e "s/__WASM_ARRAY_FILE__/wasm_aot_array.c/g" \
|
||||
-e "s/__WASM_ARRAY__/build_{{ module }}_wasm_module_aot/g" \
|
||||
-e "s/__WASM_ARRAY_LEN__/build_{{ module }}_wasm_module_aot_len/g" \
|
||||
{{ BUILD_DIR }}-{{ module }}/module_host.c
|
||||
|
||||
[doc("Insert the WASM array into the host program")]
|
||||
[group("2: build host")]
|
||||
prepare-interp-host module:
|
||||
cp targets/wasm-host/wasm_host.c {{ BUILD_DIR }}-{{ module }}/module_host.c
|
||||
sed -i \
|
||||
-e "s/__WASM_ARRAY_FILE__/wasm_interp_array.c/g" \
|
||||
-e "s/__WASM_ARRAY__/build_{{ module }}_wasm_module_wasm/g" \
|
||||
-e "s/__WASM_ARRAY_LEN__/build_{{ module }}_wasm_module_wasm_len/g" \
|
||||
{{ BUILD_DIR }}-{{ module }}/module_host.c
|
||||
|
||||
[private]
|
||||
build-wasm-host-fail module:
|
||||
{{ CROSS_CC }} {{ CROSS_CFLAGS }} {{ CROSS_INCLUDES }} \
|
||||
-DTARGET_FAIL \
|
||||
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
||||
|
||||
[private]
|
||||
build-wasm-host-linux module:
|
||||
{{ LINUX_CC }} {{ LINUX_CFLAGS }} {{ LINUX_INCLUDES }} \
|
||||
-DTARGET_LINUX \
|
||||
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
||||
|
||||
[private]
|
||||
build-wasm-host-linux-baremetal module:
|
||||
{{ CROSS_CC }} {{ LINUX_BAREMETAL_CFLAGS }} {{ LINUX_BAREMETAL_INCLUDES }} \
|
||||
-DTARGET_LINUX_BAREMETAL \
|
||||
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
||||
|
||||
[doc("Compile C-Host: The host uses WAMR to load the WASM/AOT module")]
|
||||
[group("2: build host")]
|
||||
build-wasm-host module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just build-wasm-host-fail "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux" ]; then
|
||||
just build-wasm-host-linux "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux-baremetal" ]; then
|
||||
just build-wasm-host-linux-baremetal "{{ module }}"
|
||||
else
|
||||
echo "unknown target: {{ target }}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[private]
|
||||
build-c-host-fail module:
|
||||
{{ CROSS_CC }} {{ CROSS_CFLAGS_NOWASM }} \
|
||||
-DTARGET_FAIL \
|
||||
-c targets/c-host/c_host.c \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/c_host.o
|
||||
|
||||
[private]
|
||||
build-c-host-linux module:
|
||||
{{ LINUX_CC }} {{ LINUX_CFLAGS_NOWASM }} \
|
||||
-DTARGET_LINUX \
|
||||
-c targets/c-host/c_host.c \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/c_host.o
|
||||
|
||||
[doc("Insert the C function into the host program (no WASM)")]
|
||||
[group("2: build host")]
|
||||
build-c-host module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just build-c-host-fail "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux" ]; then
|
||||
just build-c-host-linux "{{ module }}"
|
||||
else
|
||||
echo "unknown target: {{ target }}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[private]
|
||||
build-system-startup-fail module:
|
||||
{{ CROSS_CC }} targets/startup.s {{ CROSS_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/startup.o
|
||||
|
||||
[doc("Compile bootloader")]
|
||||
[group("2: build host")]
|
||||
build-system-startup module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just build-system-startup-fail "{{ module }}"
|
||||
else
|
||||
echo "{{ target }} doesn't need bootloader"
|
||||
fi
|
||||
|
||||
[private]
|
||||
build-system-syscalls-fail module:
|
||||
{{ CROSS_CC }} targets/syscalls.c {{ CROSS_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/syscalls.o
|
||||
|
||||
[private]
|
||||
build-system-syscalls-linux-baremetal module:
|
||||
{{ CROSS_CC }} targets/syscalls.c {{ LINUX_BAREMETAL_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/syscalls.o
|
||||
|
||||
[doc("Compile newlib syscall stubs")]
|
||||
[group("2: build host")]
|
||||
build-system-syscalls module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just build-system-syscalls-fail "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux-baremetal" ]; then
|
||||
just build-system-syscalls-linux-baremetal "{{ module }}"
|
||||
else
|
||||
echo "{{ target }} doesn't require syscall stubs"
|
||||
fi
|
||||
|
||||
[private]
|
||||
link-system-fail module:
|
||||
{{ CROSS_CC }} \
|
||||
-Wl,-T targets/linker.ld \
|
||||
{{ BUILD_DIR }}-{{ module }}/system.o \
|
||||
{{ BUILD_DIR }}-{{ module }}/startup.o \
|
||||
{{ BUILD_DIR }}-{{ module }}/syscalls.o \
|
||||
{{ CROSS_LDFLAGS }} \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[private]
|
||||
link-system-linux module:
|
||||
{{ LINUX_CC }} \
|
||||
{{ BUILD_DIR }}-{{ module }}/system.o \
|
||||
{{ LINUX_LDFLAGS }} \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[private]
|
||||
link-system-linux-baremetal module:
|
||||
{{ CROSS_CC }} \
|
||||
{{ BUILD_DIR }}-{{ module }}/system.o \
|
||||
{{ BUILD_DIR }}-{{ module }}/syscalls.o \
|
||||
{{ LINUX_BAREMETAL_LDFLAGS }} \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[doc("Link C-Host, syscall stubs and bootloader")]
|
||||
[group("2: build host")]
|
||||
link-system module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just link-system-fail "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux" ]; then
|
||||
just link-system-linux "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux-baremetal" ]; then
|
||||
just link-system-linux-baremetal "{{ module }}"
|
||||
else
|
||||
echo "unknown target: {{ target }}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[private]
|
||||
link-c-system-fail module:
|
||||
{{ CROSS_CC }} \
|
||||
-Wl,-T targets/linker.ld \
|
||||
{{ BUILD_DIR }}-{{ module }}/c_host.o \
|
||||
{{ BUILD_DIR }}-{{ module }}/startup.o \
|
||||
{{ BUILD_DIR }}-{{ module }}/c_module.o \
|
||||
{{ CROSS_LDFLAGS_NOWASM }} \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[private]
|
||||
link-c-system-linux module:
|
||||
{{ LINUX_CC }} \
|
||||
{{ BUILD_DIR }}-{{ module }}/c_host.o \
|
||||
{{ BUILD_DIR }}-{{ module }}/c_module.o \
|
||||
{{ LINUX_LDFLAGS_NOWASM }} \
|
||||
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||
|
||||
[doc("Link C-Host, C-function and bootloader")]
|
||||
[group("2: build host")]
|
||||
link-c-system module target="fail":
|
||||
#!/usr/bin/env sh
|
||||
if [ "{{ target }}" = "fail" ]; then
|
||||
just link-c-system-fail "{{ module }}"
|
||||
elif [ "{{ target }}" = "linux" ]; then
|
||||
just link-c-system-linux "{{ module }}"
|
||||
else
|
||||
echo "unknown target: {{ target }}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[doc("Create bootdisk")]
|
||||
[group("2: build host")]
|
||||
build-iso module:
|
||||
mkdir -p {{ BUILD_DIR }}-{{ module }}/grub/boot/grub
|
||||
cp targets/grub.cfg {{ BUILD_DIR }}-{{ module }}/grub/boot/grub/
|
||||
cp {{ BUILD_DIR }}-{{ module }}/system.elf {{ BUILD_DIR }}-{{ module }}/grub/boot/
|
||||
grub-mkrescue -o {{ BUILD_DIR }}-{{ module }}/system.iso {{ BUILD_DIR }}-{{ module }}/grub
|
||||
Reference in New Issue
Block a user