Zerocat Chipflasher  v0.4.10-182-333b622f
Flash free firmware to BIOS chips, kick the Management Engine.
Makefile File Reference

Operate the Chipflasher, handle ROM Data. More...

Detailed Description

Code

##>! @file
##>!
##>! @brief Operate the Chipflasher, handle ROM Data.
##>!
##>! # Copyright
##>!
##>! Zerocat Chipflasher --- Flash free firmware to BIOS chips,
##>!                         kick the Management Engine.
##>!
##>! Copyright (C) 2020, 2021 Kai Mertens <kmx@posteo.net>
##>!
##>! The Zerocat Chipflasher is free software: you can redistribute it
##>! and/or modify it under the terms of the GNU General Public License
##>! as published by the Free Software Foundation, either version 3 of
##>! the License, or (at your option) any later version.
##>!
##>! The Zerocat Chipflasher is distributed in the hope that it will be
##>! useful, but WITHOUT ANY WARRANTY; without even the implied warranty
##>! of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##>! GNU General Public License for more details.
##>!
##>! You should have received a copy of the GNU General Public License
##>! along with this program.  If not, see <http://www.gnu.org/licenses/>.
##>!
##>! This file is part of the Zerocat Chipflasher.
##>!
##>! # “In file” Documentation
##>!
##>! ## Usage
##>!
##>! To get an overview of targets, type:
##>!
##>!     $ make help
##>!
##>! To start `connect`, type:
##>!
##>!     $ make start
##>!
##>! To load `kick` into RAM and start `connect`, type:
##>!
##>!     $ make startram
##>!
##>! To load `kick` into EEPROM and start `connect`, type:
##>!
##>!     $ make startrom
##>!
##>! ### Workflow Chip Read
##>!
##>! 1.  Attach clip to chip.
##>! 2.  Perform a successful “detect chip” operation.
##>! 3.  Perform a “read chip” operation and obtain `chip2file.txt`.
##>! 4.  `make txt2srec`
##>! 5.  Again, perform a “read chip” operation and obtain `chip2file.txt`.
##>! 6.  `make diff`
##>! 7.  `make srec2bin[2|4|8|16]`
##>! 8.  `make name`
##>! 9.  `make clean`
##>! 10. Detach clip.
##>!
##>! ### Workflow Chip Write
##>!
##>! 1.  Copy `file2chip.bin` into folder.
##>! 2.  `make bin2txt`
##>! 3.  Attach clip to chip.
##>! 4.  Perform a successful “detect chip” operation.
##>! 5.  Perform a “show register values” operation and check protection bits.
##>! 6.  Perform a “erase chip” operation.
##>! 7.  Perform a “flash file” operation and send `file2chip.txt` to chip.
##>! 8.  Perform a “read chip” operation and obtain `chip2file.txt`.
##>! 9.  `make verify`
##>! 10. `make clean`
##>! 11. Detach clip.
##>!
##>! ### Workflow Virtual 12M Chip Read
##>!
##>! 1.  Attach clip to chip#1 (bottom 8M).
##>! 2.  Perform a successful “detect chip” operation.
##>! 3.  Perform a “read chip” operation and obtain `chip2file.txt`.
##>! 4.  `make txt2srec`
##>! 5.  Again, perform a “read chip” operation and obtain `chip2file.txt`.
##>! 6.  `make diff`
##>! 7.  `make srec2binbottom`
##>! 8.  Attach clip to chip#2 (top 4M).
##>! 9.  Perform a successful “detect chip” operation.
##>! 10. Perform a “read chip” operation and obtain `chip2file.txt`.
##>! 11. `make txt2srec`
##>! 12. Again, perform a “read chip” operation and obtain `chip2file.txt`.
##>! 13. `make diff`
##>! 14. `make srec2bintop`
##>! 15. `make merge12`
##>! 16. `make name`
##>! 17. `make clean`
##>! 18. Detach clip.
##>!
##>! ### Workflow Virtual 12M Chip Write
##>!
##>! 1.  Copy `file2chip.bin` into folder, size must be 12M.
##>! 2.  `make split12`
##>! 3.  `make binbottom2txt`
##>! 4.  Attach clip to chip#1 (bottom 8M).
##>! 5.  Perform a successful “detect chip” operation.
##>! 6.  Perform a “show register values” operation and check protection bits.
##>! 7.  Perform a “erase chip” operation.
##>! 8.  Perform a “flash file” operation and send `file2chip.txt` to chip.
##>! 9.  Perform a “read chip” operation and obtain `chip2file.txt`.
##>! 10. `make verify`
##>! 11. `make bintop2txt`
##>! 12. Attach clip to chip#2 (top 4M).
##>! 13. Perform a successful “detect chip” operation.
##>! 14. Perform a “show register values” operation and check protection bits.
##>! 15. Perform a “erase chip” operation.
##>! 16. Perform a “flash file” operation and send `file2chip.txt` to chip.
##>! 17. Perform a “read chip” operation and obtain `chip2file.txt`.
##>! 18. `make verify`
##>! 19. `make clean`
##>! 20. Detach clip.
##>!
##>! @cond
#

# Shell
SHELL                         := /bin/sh

# White Space
EMPTY                         :=
SPACE                         := $(EMPTY) $(EMPTY)
COMMA                         := ,
M5                            := uuuuu

# Suffixes
.SUFFIXES :
.SUFFIXES : .srec .txt .rom .bin

# Root Paths
ROOT_HOST_START               := $(EMPTY)
ROOT_HOST_SRC                 := ../src/
ROOT_HOST_IO                  := $(ROOT_HOST_START)
ROOT_FIRMWARE_START           := ../../firmware/start/

# Utilities
CP                            := $(shell command -v cp)
CPFLAGS                       :=
$(if $(strip $(CP)),,         $(error Cannot find cp utility))

LS                            := $(shell command -v ls)
LSFLAGS                       :=
$(if $(strip $(LS)),,         $(error Cannot find ls utility))

DD                            := $(shell command -v dd)
DDFLAGS                       :=
$(if $(strip $(DD)),,         $(error Cannot find dd utility))

MV                            := $(shell command -v mv)
MVFLAGS                       :=
$(if $(strip $(MV)),,         $(error Cannot find mv utility))

RM                            := $(shell command -v rm)
RMFLAGS                       :=
$(if $(strip $(RM)),,         $(error Cannot find rm utility))

CAT                           := $(shell command -v cat)
CATFLAGS                      :=
$(if $(strip $(CAT)),,        $(error Cannot find cat utility))

CUT                           := $(shell command -v cut)
CUTFLAGS                      :=
$(if $(strip $(CUT)),,        $(error Cannot find cut utility))

SED                           := $(shell command -v sed)
SEDFLAGS                      := -r
$(if $(strip $(SED)),,        $(error Cannot find sed utility))

ECHO                          := $(shell command -v echo)
ECHOFLAGS                     := -e
$(if $(strip $(ECHO)),,       $(error Cannot find echo utility))

DIFF                          := $(shell command -v diff)
DIFFFLAGS                     :=
$(if $(strip $(DIFF)),,       $(error Cannot find diff utility))

READ                          := $(shell command -v read)
READFLAGS                     :=
$(if $(strip $(READ)),,       $(error Cannot find read utility))

MKTEMP                        := $(shell command -v mktemp)
MKTEMPFLAGS                   :=
$(if $(strip $(MKTEMP)),,     $(error Cannot find mktemp utility))

CONNECT                       := $(ROOT_HOST_SRC)connect
CONNECTFLAGS                  :=
$(if $(strip $(CONNECT)),,    $(error Cannot find connect utility))

SHA512SUM                     := $(shell command -v sha512sum)
SHA512SUMFLAGS                :=
$(if $(strip $(SHA512SUM)),,  $(error Cannot find sha512sum utility))

SREC_CAT                      := $(shell command -v srec_cat)
SREC_CAT_FLAGS                :=
$(if $(strip $(SREC_CAT)),,   $(error Cannot find srec_cat utility))

SREC_CMP                      := $(shell command -v srec_cmp)
SREC_CMP_FLAGS                :=
$(if $(strip $(SREC_CMP)),,   $(error Cannot find srec_cmp utility))

SREC_INFO                     := $(shell command -v srec_info)
SREC_INFO_FLAGS               :=
$(if $(strip $(SREC_INFO)),,  $(error Cannot find srec_info utility))

# Files
CHIP2FILE                     := $(ROOT_HOST_IO)chip2file.txt
CHIP2FILE_SREC                := $(addsuffix .srec,$(basename $(CHIP2FILE)))
CHIP2FILE_BIN                 := $(addsuffix .bin,$(basename $(CHIP2FILE)))
CHIP2FILE_BIN_TOP             := $(addsuffix .bin.top,$(basename $(CHIP2FILE)))
CHIP2FILE_BIN_BOTTOM          := $(addsuffix .bin.bottom,$(basename $(CHIP2FILE)))
FILE2CHIP                     := $(ROOT_HOST_IO)file2chip.txt
FILE2CHIP_SREC                := $(addsuffix .srec,$(basename $(FILE2CHIP)))
FILE2CHIP_BIN                 := $(addsuffix .bin,$(basename $(FILE2CHIP)))
FILE2CHIP_BIN_TOP             := $(addsuffix .bin.top,$(basename $(FILE2CHIP)))
FILE2CHIP_BIN_BOTTOM          := $(addsuffix .bin.bottom,$(basename $(FILE2CHIP)))
FILES_CHIP2FILE               := \
	$(CHIP2FILE) \
	$(CHIP2FILE_SREC) \
	$(CHIP2FILE_BIN) \
	$(CHIP2FILE_BIN_TOP) \
	$(CHIP2FILE_BIN_BOTTOM)
FILES_FILE2CHIP               := \
	$(FILE2CHIP) \
	$(FILE2CHIP_SREC) \
	$(FILE2CHIP_BIN) \
	$(FILE2CHIP_BIN_TOP) \
	$(FILE2CHIP_BIN_BOTTOM)
FILES                         := \
	$(FILES_CHIP2FILE) \
	$(FILES_FILE2CHIP)
TARGET_FILES                  := \
	$(CHIP2FILE_BIN) \
	$(CHIP2FILE_BIN_TOP) \
	$(CHIP2FILE_BIN_BOTTOM)

# Constants
SIZE_16M                      := 16777216
SIZE_12M                      := 12582912
SIZE_8M                       := 8388608
SIZE_4M                       := 4194304
SIZE_2M                       := 2097152
SIZE_4K                       := 4096
SIZE_64K                      := 65536
PAYLOAD                       := 64
FF_RUNLEN                     := 16

# Start Options (connect)
BOARD_CONFIG                  := $(ROOT_FIRMWARE_START)board.cfg
TTY_PORT                      := $(ROOT_FIRMWARE_START)tty_port_pointer
TTY_BAUDRATE                  := B$(shell $(strip \
	$(CAT) $(CATFLAGS) \
		$(BOARD_CONFIG) | \
	$(SED) $(SEDFLAGS) \
		-e '/^baudrate:/!d; s/^.*\: //;' \
			-; \
	))

# Canned Command COMPARE
define COMPARE
	temp1=`$(MKTEMP) $(MKTEMPFLAGS)`; \
	temp2=`$(MKTEMP) $(MKTEMPFLAGS)`; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$srec1 \
			-uf 0xff \
		-o $$temp1 \
			-m \
			-data_only; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$srec2 \
			-uf 0xff \
		-o $$temp2 \
			-m \
			-data_only; \
	$(DIFF) $(DIFFFLAGS) \
		-y \
		--brief \
		--left-column \
			$$temp1 $$temp2; \
	if [ $$? -eq 0 ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"Data of files “"$$srec1"” and “"$$srec2"” do NOT differ."; \
	else \
		$(ECHO) $(ECHOFLAGS) \
			"Data of files “"$$srec1"” and “"$$srec2"” differ!"; \
		exit 1; \
	fi; \
	$(RM) $(RMFLAGS) \
		-f \
			$$temp1 $$temp2;
endef

# Canned Command BIN2SREC
define BIN2SREC
	$(ECHO) $(ECHOFLAGS) \
		"Convert binary data into lines of Motorola S-Record."; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$fin \
			-raw \
			-uf 0xff $(FF_RUNLEN) \
		-o $$fout \
			-m \
			-obs $(PAYLOAD) \
			-esa 0x00; \
	if [ $$? -eq 0 ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"File “$$fout” successfully written."; \
	else \
		$(ECHO) $(ECHOFLAGS) \
			"An error occured."; \
	fi;
endef

# Canned Command SREC2BINX
define SREC2BINX
	$(ECHO) $(ECHOFLAGS) \
		"Convert Motorola S-Record data into binary data of $$size_min bytes."; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$fin \
			-fill 0xff 0x000000 $$size_min \
		-o $$fout \
			-raw; \
	if [ $$? -eq 0 ]; then \
		if [ `$(LS) $(LSFLAGS) -l $$fout | $(CUT) $(CUTFLAGS) -d ' ' -f 5` -ne $$size_min ]; \
		then \
			$(ECHO) $(ECHOFLAGS) \
				"Size mismatch! Wrong target?"; \
			$(RM) $(RMFLAGS) \
				-f \
					$$fout; \
			exit 1; \
		else \
			$(ECHO) $(ECHOFLAGS) \
				"File “$$fout” successfully written."; \
		fi; \
	else \
		$(ECHO) $(ECHOFLAGS) \
			"An error occured."; \
	fi;
endef

# Built-in Special Targets
#~ .SECONDARY :                  # Uncomment for debugging
.PHONY : \
	all start startram startrom \
	list info diff verify \
	txt2srec \
	split12 merge12 \
	srec2bin2 srec2bin4 srec2bin8 srec2bin16 \
	sre2bintop srec2binbottom \
	name \
	clean-chip2file clean-file2chip clean-interactive clean \
	workflow-chip-read workflow-chip-write \
	workflow-virtual-chip-read workflow-virtual-chip-write \
	help hello

# Targets
#  all: same as start
all : hello start

#  start connect
start : $(TTY_PORT) $(BOARD_CONFIG) $(CONNECT)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(CONNECT) \
		$(ROOT_HOST_IO)$(CHIP2FILE) \
		$(ROOT_HOST_IO)$(FILE2CHIP) \
		$(TTY_PORT) \
		$(TTY_BAUDRATE);

#  load firmware into RAM and start connect
startram :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(MAKE) \
		-C $(ROOT_FIRMWARE_START) \
			loadram;
	$(MAKE) \
		start;

#  load firmware into EEPROM and start connect
startrom :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	$(MAKE) \
		-C $(ROOT_FIRMWARE_START) loadrom;
	$(MAKE) \
		start;

diff : $(CHIP2FILE_SREC) $(CHIP2FILE)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Comparing files $(CHIP2FILE) and $< ..."; \
	srec1=$(CHIP2FILE); \
	srec2=$<; \
	$(COMPARE) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

verify : $(FILE2CHIP) $(CHIP2FILE)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Comparing files $(CHIP2FILE) and $< ..."; \
	srec1=$(CHIP2FILE); srec2=$<; \
	$(COMPARE) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

srec2bin16 : $(CHIP2FILE_SREC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_BIN) with a size of 16M ..."; \
	fin=$<; \
	fout=$(CHIP2FILE_BIN); \
	size_min=$(SIZE_16M); \
	$(SREC2BINX) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

srec2bin8 : $(CHIP2FILE_SREC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_BIN) with a size of 8M ..."; \
	fin=$<; \
	fout=$(CHIP2FILE_BIN); \
	size_min=$(SIZE_8M); \
	$(SREC2BINX) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

srec2bin4 : $(CHIP2FILE_SREC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_BIN) with a size of 4M ..."; \
	fin=$<; \
	fout=$(CHIP2FILE_BIN); \
	size_min=$(SIZE_4M); \
	$(SREC2BINX) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

srec2bin2 : $(CHIP2FILE_SREC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_BIN) with a size of 2M ..."; \
	fin=$<; \
	fout=$(CHIP2FILE_BIN); \
	size_min=$(SIZE_2M); \
	$(SREC2BINX) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

split12 : $(FILE2CHIP_BIN)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing files $(FILE2CHIP_BIN_TOP) and $(FILE2CHIP_BIN_BOTTOM) ..."; \
	if [ `$(LS) $(LSFLAGS) -l $< | $(CUT) $(CUTFLAGS) -d ' ' -f 5` -eq $(SIZE_12M) ]; \
	then \
		$(DD) $(DDFLAGS) \
			if=$< \
			of=$(FILE2CHIP_BIN_TOP) \
			bs=1M skip=8 count=4 && \
		$(ECHO) $(ECHOFLAGS) \
			"File “$(FILE2CHIP_BIN_TOP)” successfully written."; \
		$(DD) $(DDFLAGS) \
			if=$< \
			of=$(FILE2CHIP_BIN_BOTTOM) \
			bs=1M count=8 && \
		$(ECHO) $(ECHOFLAGS) \
			"File “$(FILE2CHIP_BIN_BOTTOM)” successfully written."; \
	else \
		$(ECHO) $(ECHOFLAGS) \
			"Size of file “$<” is not 12M."; \
	fi; \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

bin2txt : $(FILE2CHIP_BIN)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(FILE2CHIP) ..."; \
	fin=$<; \
	fout=$(FILE2CHIP); \
	$(BIN2SREC) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

bintop2txt : $(FILE2CHIP_BIN_TOP)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(FILE2CHIP) ..."; \
	fin=$<; \
	fout=$(FILE2CHIP); \
	$(BIN2SREC) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

binbottom2txt : $(FILE2CHIP_BIN_BOTTOM)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(FILE2CHIP) ..."; \
	fin=$<; \
	fout=$(FILE2CHIP); \
	$(BIN2SREC) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

txt2srec : $(CHIP2FILE)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_SREC) ..."; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$(CHIP2FILE) \
			-m \
			-uf 0xff $(FF_RUNLEN) \
		-o $(CHIP2FILE_SREC) \
			-m \
			-obs $(PAYLOAD) \
			-esa 0x00; \
	$(ECHO) $(ECHOFLAGS) \
		"... done."

srec2bintop : $(CHIP2FILE_SREC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_BIN_TOP) ..."; \
	fin=$<; \
	fout=$(CHIP2FILE_BIN_TOP); \
	size_min=$(SIZE_4M); \
	$(SREC2BINX) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

srec2binbottom : $(CHIP2FILE_SREC)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing file $(CHIP2FILE_BIN_BOTTOM) ..."; \
	fin=$<; \
	fout=$(CHIP2FILE_BIN_BOTTOM); \
	size_min=$(SIZE_8M); \
	$(SREC2BINX) \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

info : $(CHIP2FILE)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Showing info for file $< ..."; \
	$(SREC_INFO) \
		-esw \
			$<; \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

merge12 : $(CHIP2FILE_BIN_BOTTOM) $(CHIP2FILE_BIN_TOP)
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Writing merged file $(CHIP2FILE_BIN) ..."; \
	fsize1=$(shell $(strip \
		$(LS) $(LSFLAGS) \
			-l \
				$(CHIP2FILE_BIN_TOP) | \
		$(CUT) $(CUTFLAGS) \
			-d ' ' \
			-f 5 \
		)); \
	fsize2=$(shell $(strip \
		$(LS) $(LSFLAGS) \
			-l \
				$(CHIP2FILE_BIN_BOTTOM) | \
		$(CUT) $(CUTFLAGS) \
			-d ' ' \
			-f 5 \
		)); \
	if [ $$fsize1 -eq $(SIZE_4M) -a $$fsize2 -eq $(SIZE_8M) ]; \
	then \
		$(CP) $(CPFLAGS) \
			$(CHIP2FILE_BIN_BOTTOM) $(CHIP2FILE_BIN); \
		$(CAT) $(CATFLAGS) \
			$(CHIP2FILE_BIN_TOP) >> $(CHIP2FILE_BIN); \
	else \
		$(ECHO) $(ECHOFLAGS) \
			"Size mismatch."; \
	fi; \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

list :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-@$(LS) $(LSFLAGS) \
		-lht \
			$(FILES);

name :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Renaming files $(TARGET_FILES) ..."; \
	$(READ) $(READFLAGS) \
		-p "Enter title: " \
		-r title; \
	for n in $(TARGET_FILES); \
	do \
		if [ -e $$n ]; then \
			suffix=$${n#*.}; \
			dest=$$title$${suffix:+.}$${suffix}; \
			$(ECHO) $(ECHOFLAGS) \
				"$(MV) $(MVFLAGS) $$n $$dest"; \
			$(MV) $(MVFLAGS) \
				$$n $$dest; \
			files="$${files}$${files:+ }$$dest"; \
		fi; \
	done; \
	$(ECHO) $(ECHOFLAGS) \
		"... done."; \
	if [ "$$files" != '' ]; then \
		$(ECHO) $(ECHOFLAGS) \
			"Writing checksum file $$title.sha512sum ..."; \
		$(SHA512SUM) $(SHA512SUMFLAGS) \
			$$files > $$title.sha512sum; \
		$(ECHO) $(ECHOFLAGS) \
			"... done."; \
	fi;

crop :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Cropping a random range from $(FILE2CHIP) ..."; \
	$(ECHO) $(ECHOFLAGS) \
		"Addresses are starting from zero." \
	$(READ) $(READFLAGS) \
		-p "Enter first address of range: " \
		-r first; \
	$(READ) $(READFLAGS) \
		-p "Enter last address of range: " \
		-r last; \
	first=$$((first)); \
	last=$$((last)); \
	$(ECHO) $(ECHOFLAGS) \
		"Range to keep is: $$first-$$last"; \
	tempfile=`$(MKTEMP) $(MKTEMPFLAGS)`; \
	$(CP) $(CPFLAGS) \
		$(FILE2CHIP) $$tempfile; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$tempfile \
			-uf 0xff $(FF_RUNLEN) \
			-crop $$first $$last \
			-obs $(PAYLOAD) \
			-esa 0x00 \
				> $(FILE2CHIP); \
	$(RM) $(RMFLAGS) \
		$$tempfile; \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

crop4K :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Cropping a range of 4K-sectors from $(FILE2CHIP) ..."; \
	$(ECHO) $(ECHOFLAGS) \
		"Sector numbers start from zero."; \
	$(READ) $(READFLAGS) \
		-p "Enter first sector number: " \
		-r first; \
	$(READ) $(READFLAGS) \
		-p "Enter last sector number: " \
		-r last; \
	first=$$((first*0x1000)); \
	last=$$((last*0x1000+0x1000-0x01)); \
	$(ECHO) $(ECHOFLAGS) \
		"Range to keep is: $$first-$$last"; \
	tempfile=`$(MKTEMP) $(MKTEMPFLAGS)`; \
	$(CP) $(CPFLAGS) \
		$(FILE2CHIP) $$tempfile; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$tempfile \
			-uf 0xff $(FF_RUNLEN) \
			-crop $$first $$last \
			-obs $(PAYLOAD) \
			-esa 0x00 \
				> $(FILE2CHIP); \
	$(RM) $(RMFLAGS) \
		$$tempfile; \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

crop64K :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"Cropping a range of 64K-blocks from $(FILE2CHIP) ..."; \
	$(ECHO) $(ECHOFLAGS) \
		"Block numbers start from zero."; \
	$(READ) $(READFLAGS) \
		-p "Enter first block number: " \
		-r first; \
	$(READ) $(READFLAGS) \
		-p "Enter last block number: " \
		-r last; \
	first=$$((first*0x10000)); \
	last=$$((last*0x10000+0x10000-0x01)); \
	$(ECHO) $(ECHOFLAGS) \
		"Range to keep is: $$first-$$last"; \
	tempfile=`$(MKTEMP) $(MKTEMPFLAGS)`; \
	$(CP) $(CPFLAGS) \
		$(FILE2CHIP) $$tempfile; \
	$(SREC_CAT) $(SREC_CAT_FLAGS) \
		$$tempfile \
			-uf 0xff $(FF_RUNLEN) \
			-crop $$first $$last \
			-obs $(PAYLOAD) \
			-esa 0x00 \
				> $(FILE2CHIP); \
	$(RM) $(RMFLAGS) \
		$$tempfile; \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

clean-chip2file : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-@$(ECHO) $(ECHOFLAGS) \
		"Removing files $(FILES_CHIP2FILE) ..."; \
	$(RM) $(RMFLAGS) \
		-f \
			$(FILES_CHIP2FILE); \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

clean-file2chip : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-@$(ECHO) $(ECHOFLAGS) \
		"Removing files $(FILES_FILE2CHIP) ..."; \
	$(RM) $(RMFLAGS) \
		-f \
			$(FILES_FILE2CHIP); \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

clean-interactive : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@for n in $(FILES); do \
		if [ -e $$n ]; then \
			$(ECHO) $(ECHOFLAGS) \
				"Going to delete “$$n” ..."; \
			$(READ) $(READFLAGS) \
				-p "Continue (yes|no)? " \
				-r reply && \
			if [ "$$reply" = 'yes' ]; then \
				$(RM) $(RMFLAGS) \
					$$n; \
				$(ECHO) $(ECHOFLAGS) \
					"... done."; \
			fi; \
		fi; \
	done;

clean : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	-@$(ECHO) $(ECHOFLAGS) \
		"Removing files $(FILES) ..."; \
	$(RM) $(RMFLAGS) \
		-f \
			$(FILES); \
	$(ECHO) $(ECHOFLAGS) \
		"... done.";

#  display help information
help : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nUsage"\
		"\n====="\
		"\n"\
		"\nUse this Makefile with two terminal windows in parallel."\
		"\nTerminal#1: Start “connect” and operate the Chipflasher’s Menu"\
		"\nTerminal#2: Handle incoming/outgoing ROM Data"\
		"\n"\
		"\nList of Targets (Terminal#1)"\
		"\n----------------------------"\
		"\n"\
		"\nStart Connect:"\
		"\n  all\r\t\tsame as start"\
		"\n  start\r\t\tstart “connect”, the host utility, which will talk to “kick” stored in EEPROM"\
		"\n  startram\r\t\tload firmware “kick” into Propeller RAM and start “connect”"\
		"\n  startrom\r\t\tload firmware “kick” into EEPROM and start “connect”"\
		"\n"\
		"\nList of Targets (Terminal#2)"\
		"\n----------------------------"\
		"\n"\
		"\nHelp and Workflow Information:"\
		"\n  help\r\t\t\t\tprovide this overview of targets"\
		"\n  workflow-chip-read\r\t\t\t\thow to read a physical single chip"\
		"\n  workflow-chip-write\r\t\t\t\thow to write a physical single chip"\
		"\n  workflow-virtual-chip-read\r\t\t\t\thow to read a virtual 12M chip (formed by two physical chips)"\
		"\n  workflow-virtual-chip-write\r\t\t\t\thow to write a virtual 12M chip (formed by two physical chips)"\
		"\n"\
		"\nClean Operations:"\
		"\n  clean-chip2file\r\t\t\tremove $(basename $(CHIP2FILE))-Files"\
		"\n  clean-file2chip\r\t\t\tremove $(basename $(FILE2CHIP))-Files"\
		"\n  clean-interactive\r\t\t\tremove files interactively"\
		"\n  clean\r\t\t\tremove files"\
		"\n"\
		"\nVerification:"\
		"\n  list\r\t\t\tlist relevant files if present"\
		"\n  info\r\t\t\tdisplay content info for “$(CHIP2FILE)”"\
		"\n  diff\r\t\t\tcompare “$(CHIP2FILE)” with “$(CHIP2FILE_SREC)”"\
		"\n  verify\r\t\t\tcompare “$(CHIP2FILE)” with “$(FILE2CHIP)”"\
		"\n"\
		"\nPostprocessing File $(CHIP2FILE):"\
		"\n  txt2srec\r\t\t\tconvert “$(CHIP2FILE)” into “$(CHIP2FILE_SREC)”"\
		"\n  srec2bin2\r\t\t\tconvert “$(CHIP2FILE_SREC)” into “$(CHIP2FILE_BIN)” and guarantee a file size of 2MB"\
		"\n  srec2bin4\r\t\t\tconvert “$(CHIP2FILE_SREC)” into “$(CHIP2FILE_BIN)” and guarantee a file size of 4MB"\
		"\n  srec2bin8\r\t\t\tconvert “$(CHIP2FILE_SREC)” into “$(CHIP2FILE_BIN)” and guarantee a file size of 8MB"\
		"\n  srec2bin16\r\t\t\tconvert “$(CHIP2FILE_SREC)” into “$(CHIP2FILE_BIN)” and guarantee a file size of 16MB"\
		"\n  srec2bintop\r\t\t\tconvert “$(CHIP2FILE_SREC)” into “$(CHIP2FILE_BIN_TOP)”"\
		"\n  srec2binbottom\r\t\t\tconvert “$(CHIP2FILE_SREC)” into “$(CHIP2FILE_BIN_BOTTOM)”"\
		"\n  merge12\r\t\t\tconvert and merge “$(CHIP2FILE_BIN_TOP)” and “$(CHIP2FILE_BIN_BOTTOM)” into “$(CHIP2FILE_BIN)”"\
		"\n  name\r\t\t\tEnter title and rename selected chip2file files, thus moving them out of this Makefile’s scope."\
		"\n"\
		"\nPreprocessing File $(FILE2CHIP):"\
		"\n  split12\r\t\t\tsplit 12M “$(FILE2CHIP_BIN)” into 4M “$(FILE2CHIP_BIN_TOP)” and 8M “$(FILE2CHIP_BIN_BOTTOM)”"\
		"\n  bin2txt\r\t\t\tconvert “$(FILE2CHIP_BIN)” into “$(FILE2CHIP)” using Motorola S-Record"\
		"\n  bintop2txt\r\t\t\tconvert “$(FILE2CHIP_BIN_TOP)” into “$(FILE2CHIP)” using Motorola S-Record"\
		"\n  binbottom2txt\r\t\t\tconvert “$(FILE2CHIP_BIN_BOTTOM)” into “$(FILE2CHIP)” using Motorola S-Record"\
		"\n  crop\r\t\t\tcrop a random range of data from “$(FILE2CHIP)”, discard other data"\
		"\n  crop4K\r\t\t\tcrop a range of 4K-Sectors from “$(FILE2CHIP)”, discard other data"\
		"\n  crop64K\r\t\t\tcrop a range of 64K-Blocks from “$(FILE2CHIP)”, discard other data"\
		"\n";

workflow-chip-read : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nWorkflow Single Chip Read"\
		"\n-------------------------"\
		"\n"\
		"\n1.  Attach clip to chip."\
		"\n2.  Perform a successful “detect chip” operation."\
		"\n3.  Perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n4.  make txt2srec"\
		"\n5.  Again, perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n6.  make diff"\
		"\n7.  make srec2bin[2|4|8|16]"\
		"\n8.  make name"\
		"\n9.  make clean"\
		"\n10. Detach clip."\
		"\n";

workflow-chip-write : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nWorkflow Single Chip Write"\
		"\n--------------------------"\
		"\n1.  Copy “file2chip.bin” into folder."\
		"\n2.  make bin2txt"\
		"\n3.  Attach clip to chip."\
		"\n4.  Perform a successful “detect chip” operation."\
		"\n5.  Perform a “show register values” operation and check protection bits."\
		"\n6.  Perform a “erase chip” operation."\
		"\n7.  Perform a “flash file” operation and send “file2chip.txt” to chip."\
		"\n8.  Perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n9.  make verify"\
		"\n10. make clean"\
		"\n11. Detach clip."\
		"\n";

workflow-virtual-chip-read : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nWorkflow Virtual Chip Read"\
		"\n--------------------------"\
		"\n"\
		"\n1.  Attach clip to chip#1 (bottom 8M)."\
		"\n2.  Perform a successful “detect chip” operation."\
		"\n3.  Perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n4.  make txt2srec"\
		"\n5.  Again, perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n6.  make diff"\
		"\n7.  make srec2binbottom"\
		"\n8.  Attach clip to chip#2 (top 4M)."\
		"\n9.  Perform a successful “detect chip” operation."\
		"\n10. Perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n11. make txt2srec"\
		"\n12. Again, perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n13. make diff"\
		"\n14. make srec2bintop"\
		"\n15. make merge12"\
		"\n16. make name"\
		"\n17. make clean"\
		"\n18. Detach clip."\
		"\n";

workflow-virtual-chip-write : hello
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5) Process target “$@” $(M5)$(M5)";
	@$(ECHO) $(ECHOFLAGS) \
		"\nWorkflow Virtual Chip Write"\
		"\n---------------------------"\
		"\n"\
		"\n1.  Copy “file2chip.bin” into folder, size must be 12M."\
		"\n2.  make split12"\
		"\n3.  make binbottom2txt"\
		"\n4.  Attach clip to chip#1 (bottom 8M)."\
		"\n5.  Perform a successful “detect chip” operation."\
		"\n6.  Perform a “show register values” operation and check protection bits."\
		"\n7.  Perform a “erase chip” operation."\
		"\n8.  Perform a “flash file” operation and send “file2chip.txt” to chip."\
		"\n9.  Perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n10. make verify"\
		"\n11. make bintop2txt"\
		"\n12. Attach clip to chip#2 (top 4M)."\
		"\n13. Perform a successful “detect chip” operation."\
		"\n14. Perform a “show register values” operation and check protection bits."\
		"\n15. Perform a “erase chip” operation."\
		"\n16. Perform a “flash file” operation and send “file2chip.txt” to chip."\
		"\n17. Perform a “read chip” operation and obtain “chip2file.txt”."\
		"\n18. make verify"\
		"\n19. make clean"\
		"\n20. Detach clip."\
		"\n";

#  display greeting
#   provided with all, clean and help
hello :
	@$(ECHO) $(ECHOFLAGS) \
		"\n$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)"\
		"\n$(M5) Zerocat Chipflasher – Start and Operate"\
		"\n$(M5) This Makefile starts “connect” and processes in- and outgoing data."\
		"\n$(M5) Use two terminal windows in parallel, i.e. Terminal#1 and Terminal#2."\
		"\n$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)$(M5)";

##>! @endcond

Copyright

Zerocat Chipflasher — Flash free firmware to BIOS chips, kick the Management Engine.

Copyright (C) 2020, 2021 Kai Mertens kmx@p.nosp@m.oste.nosp@m.o.net

The Zerocat Chipflasher is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Zerocat Chipflasher is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

This file is part of the Zerocat Chipflasher.

“In file” Documentation

Usage

To get an overview of targets, type:

$ make help

To start connect, type:

$ make start

To load kick into RAM and start connect, type:

$ make startram

To load kick into EEPROM and start connect, type:

$ make startrom

Workflow Chip Read

  1. Attach clip to chip.
  2. Perform a successful “detect chip” operation.
  3. Perform a “read chip” operation and obtain chip2file.txt.
  4. make txt2srec
  5. Again, perform a “read chip” operation and obtain chip2file.txt.
  6. make diff
  7. make srec2bin[2|4|8|16]
  8. make name
  9. make clean
  10. Detach clip.

Workflow Chip Write

  1. Copy file2chip.bin into folder.
  2. make bin2txt
  3. Attach clip to chip.
  4. Perform a successful “detect chip” operation.
  5. Perform a “show register values” operation and check protection bits.
  6. Perform a “erase chip” operation.
  7. Perform a “flash file” operation and send file2chip.txt to chip.
  8. Perform a “read chip” operation and obtain chip2file.txt.
  9. make verify
  10. make clean
  11. Detach clip.

Workflow Virtual 12M Chip Read

  1. Attach clip to chip#1 (bottom 8M).
  2. Perform a successful “detect chip” operation.
  3. Perform a “read chip” operation and obtain chip2file.txt.
  4. make txt2srec
  5. Again, perform a “read chip” operation and obtain chip2file.txt.
  6. make diff
  7. make srec2binbottom
  8. Attach clip to chip#2 (top 4M).
  9. Perform a successful “detect chip” operation.
  10. Perform a “read chip” operation and obtain chip2file.txt.
  11. make txt2srec
  12. Again, perform a “read chip” operation and obtain chip2file.txt.
  13. make diff
  14. make srec2bintop
  15. make merge12
  16. make name
  17. make clean
  18. Detach clip.

Workflow Virtual 12M Chip Write

  1. Copy file2chip.bin into folder, size must be 12M.
  2. make split12
  3. make binbottom2txt
  4. Attach clip to chip#1 (bottom 8M).
  5. Perform a successful “detect chip” operation.
  6. Perform a “show register values” operation and check protection bits.
  7. Perform a “erase chip” operation.
  8. Perform a “flash file” operation and send file2chip.txt to chip.
  9. Perform a “read chip” operation and obtain chip2file.txt.
  10. make verify
  11. make bintop2txt
  12. Attach clip to chip#2 (top 4M).
  13. Perform a successful “detect chip” operation.
  14. Perform a “show register values” operation and check protection bits.
  15. Perform a “erase chip” operation.
  16. Perform a “flash file” operation and send file2chip.txt to chip.
  17. Perform a “read chip” operation and obtain chip2file.txt.
  18. make verify
  19. make clean
  20. Detach clip.