summaryrefslogtreecommitdiff
path: root/examples/busybox.sh
diff options
context:
space:
mode:
Diffstat (limited to 'examples/busybox.sh')
-rwxr-xr-xexamples/busybox.sh100
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__