aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/linksys-image.sh
blob: d251b5da8ee84ee9e2fc023d19214223258f0ec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#
# Copyright (C) 2018 Oceanic Systems (UK) Ltd
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# Maintained by: Ryan Pannell <ryan [at] o s u k l .com> <github.com/Escalion>
#
# Write Linksys signature for factory image
# This is appended to the factory image and is tested by the Linksys Upgrader - as observed in civic.
# The footer is 256 bytes. The format is:
#  .LINKSYS.        This is detected by the Linksys upgrader before continuing with upgrade. (9 bytes)
#  <VERSION>        The version number of upgrade. Not checked so use arbitrary value (8 bytes)
#  <TYPE>           Model of target device, padded (0x20) to (15 bytes)
#  <CRC>      	    CRC checksum of the image to flash (8 byte)
#  <padding>	    Padding ('0' + 0x20 *7) (8 bytes)
#  <signature>	    Signature of signer. Not checked so use arbitrary value (16 bytes)
#  <padding>        Padding (0x00) (192 bytes)

## version history
# * version 1: initial commit

set -e

ME="${0##*/}"

usage() {
	echo "Usage: $ME <type> <in filename>"
	[ "$IMG_OUT" ] && rm -f "$IMG_OUT"
	exit 1
}

[ "$#" -lt 3 ] && usage

TYPE=$1

tmpdir="$( mktemp -d 2> /dev/null )"
if [ -z "$tmpdir" ]; then
	# try OSX signature
	tmpdir="$( mktemp -t 'ubitmp' -d )"
fi

if [ -z "$tmpdir" ]; then
	exit 1
fi

trap "rm -rf $tmpdir" EXIT

IMG_TMP_OUT="${tmpdir}/out"

IMG_IN=$2
IMG_OUT="${IMG_IN}.new"

[ ! -f "$IMG_IN" ] && echo "$ME: Not a valid image: $IMG_IN" && usage

dd if="${IMG_IN}" of="${IMG_TMP_OUT}"
CRC=$(printf "%08X" $(dd if="${IMG_IN}" bs=$(stat -c%s "${IMG_IN}") count=1|cksum| cut -d ' ' -f1))

printf ".LINKSYS.01000409%-15s%-8s%-8s%-16s" "${TYPE}" "${CRC}" "0" "K0000000F0246434" >> "${IMG_TMP_OUT}"

dd if=/dev/zero bs=1 count=192 conv=notrunc >> "${IMG_TMP_OUT}"

cp "${IMG_TMP_OUT}" "${IMG_OUT}"
$(STAGING_DIR) $(BIN_DIR) $(OUTPUT_DIR)/packages/$(ARCH_PACKAGES) $(TOPDIR)/staging_dir/packages clean: _clean rm -rf $(BUILD_LOG_DIR) targetclean: _clean rm -rf $(TOOLCHAIN_DIR) $(BUILD_DIR_BASE)/hostpkg $(BUILD_DIR_TOOLCHAIN) dirclean: targetclean clean rm -rf $(STAGING_DIR_HOST) $(STAGING_DIR_HOSTPKG) $(BUILD_DIR_BASE)/host rm -rf $(TMP_DIR) $(MAKE) -C $(TOPDIR)/scripts/config clean toolchain_rebuild_check: $(SCRIPT_DIR)/check-toolchain-clean.sh cacheclean: ifneq ($(CONFIG_CCACHE),) $(STAGING_DIR_HOST)/bin/ccache -C endif ifndef DUMP_TARGET_DB $(BUILD_DIR)/.prepared: Makefile @mkdir -p $$(dirname $@) @touch $@ tmp/.prereq_packages: .config unset ERROR; \ for package in $(sort $(prereq-y) $(prereq-m)); do \ $(_SINGLE)$(NO_TRACE_MAKE) -s -r -C package/$$package prereq || ERROR=1; \ done; \ if [ -n "$$ERROR" ]; then \ echo "Package prerequisite check failed."; \ false; \ fi touch $@ endif # check prerequisites before starting to build prereq: $(target/stamp-prereq) tmp/.prereq_packages @if [ ! -f "$(INCLUDE_DIR)/site/$(ARCH)" ]; then \ echo 'ERROR: Missing site config for architecture "$(ARCH)" !'; \ echo ' The missing file will cause configure scripts to fail during compilation.'; \ echo ' Please provide a "$(INCLUDE_DIR)/site/$(ARCH)" file and restart the build.'; \ exit 1; \ fi $(BIN_DIR)/profiles.json: FORCE $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \ WORK_DIR=$(BUILD_DIR)/json_info_files \ $(SCRIPT_DIR)/json_overview_image_info.py $@ \ ) json_overview_image_info: $(BIN_DIR)/profiles.json checksum: FORCE $(call sha256sums,$(BIN_DIR),$(CONFIG_BUILDBOT)) buildversion: FORCE $(SCRIPT_DIR)/getver.sh > $(BIN_DIR)/version.buildinfo feedsversion: FORCE $(SCRIPT_DIR)/feeds list -fs > $(BIN_DIR)/feeds.buildinfo diffconfig: FORCE mkdir -p $(BIN_DIR) $(SCRIPT_DIR)/diffconfig.sh > $(BIN_DIR)/config.buildinfo buildinfo: FORCE $(_SINGLE)$(SUBMAKE) -r diffconfig buildversion feedsversion prepare: .config $(tools/stamp-compile) $(toolchain/stamp-compile) $(_SINGLE)$(SUBMAKE) -r buildinfo world: prepare $(target/stamp-compile) $(package/stamp-compile) $(package/stamp-install) $(target/stamp-install) FORCE $(_SINGLE)$(SUBMAKE) -r package/index $(_SINGLE)$(SUBMAKE) -r json_overview_image_info $(_SINGLE)$(SUBMAKE) -r checksum ifneq ($(CONFIG_CCACHE),) $(STAGING_DIR_HOST)/bin/ccache -s endif .PHONY: clean dirclean prereq prepare world package/symlinks package/symlinks-install package/symlinks-clean endif