sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / seed / rung0 / load0.sh
| 1 | #!/bin/sh |
| 2 | # load0.sh <seed0.hex> <out.bin> -- the one outside tool of the seed chain (named in seed/README.md). |
| 3 | # Used once, to turn the hand-written seed0.hex into seed0.bin before any seed program exists. |
| 4 | # POSIX shell and its printf only (no gcc, as, ld, xxd). Strict: after the comment ('#' to end of line) |
| 5 | # is cut, a line is empty or holds exactly one word of 8 hex digits; anything else stops the load. |
| 6 | # Each word goes out lowest byte first (little-endian), as seed0 itself writes it. |
| 7 | set -eu |
| 8 | [ $# -eq 2 ] || { echo "usage: load0.sh <seed0.hex> <out.bin>" >&2; exit 2; } |
| 9 | n=0 |
| 10 | : > "$2" |
| 11 | while IFS= read -r line || [ -n "$line" ]; do |
| 12 | n=$((n + 1)) |
| 13 | w=${line%%#*} |
| 14 | w=$(printf '%s' "$w" | tr -d ' \t\r') |
| 15 | [ -z "$w" ] && continue |
| 16 | case $w in |
| 17 | [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]) ;; |
| 18 | *) echo "load0: line $n: not one 8-digit hex word: '$w'" >&2; exit 1 ;; |
| 19 | esac |
| 20 | v=$((0x$w)) |
| 21 | for s in 0 8 16 24; do |
| 22 | printf "\\$(printf '%03o' $(( (v >> s) & 255 )))" |
| 23 | done >> "$2" |
| 24 | done < "$1" |