Move full-flashing logic into flash.sh, and fix up build ordering issue.