diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2022-09-21 11:39:23 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2022-09-21 11:39:23 +0200 |
commit | 1cc07e990736b57ee577dd42c8f8540d58b13c4c (patch) | |
tree | 241b8a7da0611555b8bde6829e7d6be5bc6179d1 /examples | |
parent | 3a78298e6dee2032a943204f139c597062c00162 (diff) |
add busybox example script
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/busybox.sh | 100 |
1 files changed, 100 insertions, 0 deletions
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__ |