From 1cc07e990736b57ee577dd42c8f8540d58b13c4c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 21 Sep 2022 11:39:23 +0200 Subject: add busybox example script --- README.md | 2 +- examples/busybox.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 examples/busybox.sh diff --git a/README.md b/README.md index 88b1128..9ac52b5 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ To do so, it needs to support the **make**, **make clean**, **make randconfig**, **make nfpkeys** is expected to print a JSON dict with meta-data about those. All of these commands can be changed, see `bin/explore-kconfig.py --help`. -See **examples/kconfig-static** for a simple example project, and [multipass](https://github.com/derf/multipass) and [kratos](https://ess.cs.uos.de/git/software/kratos/kratos) for more complex ones. +See **examples/kconfig-static** for a simple example project, and **examples/busybox.sh** for a more complex one. The `make_benchmark` section of **.gitlab-ci.yml** shows how to run benchmarks and generate a model for the example project. As benchmark generation employs frequent recompilation, using a tmpfs is recommended. diff --git a/examples/busybox.sh b/examples/busybox.sh new file mode 100755 index 0000000..3ad225f --- /dev/null +++ b/examples/busybox.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +set -ex + +wget https://busybox.net/downloads/busybox-1.35.0.tar.bz2 +tar xjf busybox-1.35.0.tar.bz2 +rm busybox-1.35.0.tar.bz2 + +# Generate Config.in files +( cd busybox-1.35.0 ; make gen_build_files ) + +git clone --recursive https://ess.cs.uos.de/git/software/dfatool.git + +dfatool/bin/kconfig-expand-includes busybox-1.35.0/Config.in > busybox-1.35.0/Kconfig + +cat > busybox-1.35.0/Makefile.local << __EOF__ +.PHONY: nfpkeys +nfpkeys: + @echo '{"ELF": {"Size": {"unit": "B", "description": "Binary Size", "minimize": true}, "RAM": {"unit": "B", "description": "static RAM", "minimize": true}}}' + +.PHONY: nfpvalues +nfpvalues: + @scripts/nfpvalues.py size _ data,bss + +__EOF__ + +cat > busybox-1.35.0/scripts/nfpvalues.py << __EOF__ +#!/usr/bin/env python3 + +import json +import re +import subprocess +import sys + + +def main(size_executable, rom_sections, ram_sections): + rom_sections = rom_sections.split(",") + ram_sections = ram_sections.split(",") + + status = subprocess.run( + [size_executable, "-A", "busybox"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + + section_size = dict() + + for line in status.stdout.split("\n"): + match = re.match("[.](\S+)\s+(\d+)", line) + if match: + section = match.group(1) + size = int(match.group(2)) + section_size[section] = size + + status = subprocess.run( + ["stat", "-c", "%s", "busybox"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + binary_size = int(status.stdout) + + total = { + "Size": binary_size, + "RAM": sum(map(lambda section: section_size[section], ram_sections)), + } + + output = {"ELF": total} + + print(json.dumps(output)) + + +if __name__ == "__main__": + main(*sys.argv[1:]) + +__EOF__ + +chmod 755 busybox-1.35.0/scripts/nfpvalues.py + +set +ex + +cat <<__EOF__ + +busybox has been prepared for dfatool data acquisition for NFP model generation. + +Example usage with random sampling (10,000 samples) + +> mkdir data +> cd data +> ../dfatool/bin/explore-kconfig.py --random 10000 ../busybox-1.35.0 + +Alternatively, you can run multiple build processes in parallel. + +> for i in {1..10}; do rsync -a busybox-1.35.0/ busybox-build-\${i}/ ; done +> mkdir data +> cd data +> for i in {1..10}; do ../dfatool/bin/explore-kconfig.py --random 1000 ../busybox-build-\${i} & done + +__EOF__ -- cgit v1.2.3