code:
#!/bin/bash

#
#  helper script: generate the ROM image release archives
#
#	Copyright (C) 2015 Francis Rowe <info@gluglug.org.uk>
#	Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

if [ ! -d bin/ ]; then
	printf "build/release/roms: no bin/ directory exists. (you haven't built any images)\n"
	exit 1
fi

if [ -f "version" ]; then
	# _src release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi
versiondir="release/${version}"
romdir="${versiondir}/rom"
distname="libreboot_${version}"

printf 'Building ROM image release archives for...\n'

cd "bin/"

for payload in *; do

	[ ! -d "../${romdir}/${payload}/" ] && mkdir -p "../${romdir}/${payload}/"

	cd "${payload}/"

	for board in *; do

		archivename="${distname}_${payload}_${board}"

		printf '...%s' "${payload}/${board}"

		# Delete the old archive
		rm -f "../../${romdir}/${payload}/${distname}_${board}.tar.xz"

		cp -R "${board}/" "${archivename}/"

		# Put the version string in the archive.
		printf '%s\n' "${version}" >"${archivename}/version"

		# Create the compressed archive.
		tar -c "${archivename}/" | xz -9e >"../../${romdir}/${payload}/${archivename}.tar.xz"

		rm -Rf "${archivename:?}/"

		printf ' OK\n'

	done

	cd "../"

done

cd "../"

printf 'ROM image release archives are stored in %s/\n' "${romdir}"


code:
#!/bin/bash

#
#  helper script: create sha512sum file for the current snapshot
#
#	Copyright (C) 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

if [ -f "version" ]; then
	# _src release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi
versiondir="release/${version}"
sha512filename="SHA512SUMS"
sha512filepath="${versiondir}/${sha512filename}"

if [ ! -d "${versiondir}/" ]; then

	printf "build/release/sha512sums: directory %s/ does not exist. You haven't generated any archives yet.\n" "${versiondir}"
	exit 1

fi

# delete the old file
rm -f "${sha512filepath}"

# create sha512sum file
printf "Creating list of SHA512 sums in %s...\n" "${sha512filepath}"
(cd "${versiondir}/" && for file in $(find -type f); do sha512sum "${file}" >> "${sha512filename}"; done)
printf "...done.\n"

printf "\n"

repo_name: Amlouden/libreboot

license: mit


code:
#!/bin/bash

#
#  helper script: generate the source release archive
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#	Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

printf 'Building the source release archive\n'

if [ -f "version" ]; then
	# _src release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi
versiondir="release/${version}"
distname="libreboot_${version}_src"
distdir="${versiondir}/${distname}"

printf 'Deleting old source release archives\n'
rm -f "${distdir}.tar.xz"
rm -Rf "${distdir:?}/"

mkdir -p "${distdir}/"

printf 'Copying sources to %s/\n' "${distdir}"
for resource in *; do
	case "${resource}" in
		release | docs);;
		*) cp -R "${resource}" "${distdir}/";;
	esac
done

printf '%s\n' "${version}" >"${distdir}/version"

printf 'Cleaning files in %s/\n' "${distdir}"

# Clean old builds.
(cd "${distdir}/" && ./build clean all)
printf '\n'

# Delete Git repositories and properties and Subversion administrative
# directories and properties.
rm -Rf "${distdir}/bucts/".git*
rm -Rf "${distdir}/flashrom/".git*
rm -Rf "${distdir}/grub/".git*

# Delete useless files.
rm -Rf "${distdir}/TODO/"
rm -f "${distdir}/push"

# Delete the deblob scripts.
# Since the source archive doesn't distribute the download scripts and already
# comes with a deblobbed coreboot, the deblobbing scripts aren't needed at all.
rm -Rf "${distdir}/resources/utilities/coreboot-libre/"

# Download scripts not needed, because the modules already exist
# in the src release archive
rm -f "${distdir}/download"
rm -Rf "${distdir}/resources/scripts/helpers/download/"

# The release archive for _src does not include docs, so it
# is nonsense to include the script for it there
rm -f "${distdir}/resources/scripts/helpers/build/release/docs"

# Patches are not needed, because they are already applied to coreboot sources.
rm -Rf "${distdir}/resources/libreboot/patch/"

# ich9deblob: There are certain files in there that the user most likely does
# not want to share.
rm -f "${distdir}/resources/utilities/ich9deblob/"*.bin
rm -f "${distdir}/resources/utilities/ich9deblob/"*.rom
rm -f "${distdir}/resources/utilities/ich9deblob/mk"*.[ch]
rm -f "${distdir}/mk"*.[ch]
rm -f "${distdir}/"*.bin
rm -f "${distdir}/"*.rom

# Remove any GRUB payload ELF executables that may exist
rm -f "${distdir}/resources/utilities/grub-assemble/grub_txtmode.elf"
rm -f "${distdir}/resources/utilities/grub-assemble/grub_vesafb.elf"

printf 'Creating %s.tar.xz\n' "${distdir}"
(cd "${versiondir}/" && tar -c "${distname}/" | xz -9e >"${distname}.tar.xz")

rm -Rf "${distdir:?}/"

printf 'Source release archive is stored in %s/\n' "${versiondir}"


code:
#!/bin/bash

#  helper: prepare a small source archive for those utils
#  that don't easily cross-compile. Then the tarball can be extracted
#  on those systems with the target architecture, and compiled.
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

if [ -f "version" ]; then
	# _src release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi
versiondir="release/${version}"
distname="libreboot_${version}_tobuild"
distdir="${versiondir}/${distname}"

printf "Creating source archive for flashrom and bucts\n"

# delete the old data
rm -Rf "${distdir:?}/"
rm -f "${distdir}.tar.xz"

# this is where they will go
mkdir -p "${distdir}/"

# flashrom
cp -R "flashrom/" "${distdir}/"
rm -f "${distdir}/flashrom/flashrom_lenovobios_sst"
rm -f "${distdir}/flashrom/flashrom_lenovobios_macronix"
(cd "${distdir}/flashrom/" && make clean)
mkdir -p "${distdir}/resources/flashrom/"
cp -R "resources/flashrom/patch/" "${distdir}/resources/flashrom/"

# bucts
cp -R "bucts/" "${distdir}/"
(cd "${distdir}/bucts/" && make clean)
mkdir -p "${distdir}/resources/bucts/"
cp -R "resources/bucts/patch/" "${distdir}/resources/bucts/"

# the build script will be needed
cp build "${distdir}/"
# needed build scripts (helpers)
mkdir -p "${distdir}/resources/scripts/helpers/build/"
mkdir -p "${distdir}/resources/scripts/helpers/build/module/"
mkdir -p "${distdir}/resources/scripts/helpers/build/clean/"
cp "resources/scripts/helpers/build/clean/bucts" "${distdir}/resources/scripts/helpers/build/clean/"
cp "resources/scripts/helpers/build/clean/flashrom" "${distdir}/resources/scripts/helpers/build/clean/"
cp "resources/scripts/helpers/build/module/bucts" "${distdir}/resources/scripts/helpers/build/module/"
cp "resources/scripts/helpers/build/module/flashrom" "${distdir}/resources/scripts/helpers/build/module/"
cp "resources/scripts/misc/powertop.trisquel7" "${distdir}/"

printf '%s\n' "${version}" >"${distdir}/version"

# that is all. now tar it up
(cd "${versiondir}/" && tar -c "${distname}/" | xz -9e >"${distname}.tar.xz")

# and delete the directory
rm -Rf "${distdir:?}/"

printf "\n"
printf "Tar archive created: %s\n" "${distdir}.tar.xz"
printf "NOTE: don't forget to add ARM binaries for flashrom.\n"
printf "NOTE: don't forget to add i386 binaries for flashrom/bucts.\n"
printf "The archive %s.tar.xz has been created with everything needed to build these utilities.\n\n" "${distname}"


code:
#!/bin/bash

#
#  helper script: generate the release archives
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the current working directory when running
# it is the root directory of the libreboot git repository clone.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

arch="unknown"
if [ "$(uname -i)" = "i686" ] || [ "$(uname -m)" = "i686" ]
	then
		arch="i686"
		echo "Running on i686. ok."
		sleep 2
elif [ "$(uname -i)" = "x86_64" ] || [ "$(uname -m)" = "x86_64" ]
	then
		arch="x86_64"
		echo "Running on x86_64. ok."
		sleep 2
else
	echo "This script must be run on an i686 or x86_64 host. x86_64 is recommended."
	exit 1
fi

if [ -f "version" ]; then
	# _src release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi
versiondir="release/${version}"
distname="libreboot_${version}_util"
distdir="${versiondir}/${distname}"

printf "Creating utility archive (static executables)\n"

# delete the old data
rm -Rf "${distdir:?}/"
rm -f "${distdir}.tar.xz"

# this is where they will go
mkdir -p "${distdir}/"

# include version information
printf '%s\n' "${version}" >"${distdir}/version"

# --------------
# BUC.TS related
# --------------
# X60/T60: BUC.TS utility is needed to flash libreboot while Lenovo BIOS is running
# Include it statically compiled
cp -R "bucts" "bucts_/"
# make it statically compile
./build module bucts static
mkdir -p "${distdir}/bucts/${arch}/"
mv "bucts/bucts" "${distdir}/bucts/${arch}/"
rm -Rf "bucts/"
mv "bucts_/" "bucts/"

# ----------------
# Flashrom related
# ----------------
# Flashrom is used to install libreboot on supported targets
# Include it statically compiled
cp -R "flashrom/" "flashrom_/"
# make it statically compile
./build module flashrom static
mkdir -p "${distdir}/flashrom/${arch}/"
mv "flashrom/flashrom" "${distdir}/flashrom/${arch}/"
mv "flashrom/flashrom_lenovobios_sst" "${distdir}/flashrom/${arch}/"
mv "flashrom/flashrom_lenovobios_macronix" "${distdir}/flashrom/${arch}/"
rm -Rf "flashrom/"
mv "flashrom_/" "flashrom/"

# ----------------
# cbfstool related
# ----------------
# build cbfstool, compiled (statically linked) and include the binary

mkdir -p "${distdir}/cbfstool/${arch}/"

cd "coreboot/util/"
cp -R "cbfstool" "cbfstool_/"
cd "cbfstool/"
make clean
make SHARED=0 CC='gcc -static'

mv "cbfstool" "../../../${distdir}/cbfstool/${arch}/"

if [ "${arch}" = "x86_64" ]
	then
		# Now build 32-bit binaries
		make clean
		make SHARED=0 CC='gcc -static -m32'
		mkdir "../../../${distdir}/cbfstool/i686"
		mv "cbfstool" "../../../${distdir}/cbfstool/i686/"
fi

# cross-compile for ARM
make clean
make SHARED=0 CC='arm-linux-gnueabi-gcc -static'
mkdir "../../../${distdir}/cbfstool/armv7l/"
mv "cbfstool" "../../../${distdir}/cbfstool/armv7l/"

cd ../
rm -Rf "cbfstool/"
mv "cbfstool_/" "cbfstool/"
cd ../../

# ----------------
# ich9deblob related
# ----------------
# build ich9deblob, compiled (statically linked) and include the binary

mkdir -p "${distdir}/ich9deblob/${arch}"

cd "resources/utilities/"
cp -R "ich9deblob" "ich9deblob_/"
cd "ich9deblob/"
make clean
make SHARED=0 CC='gcc -static'

mv "ich9deblob" "../../../${distdir}/ich9deblob/${arch}/"
mv "ich9gen" "../../../${distdir}/ich9deblob/${arch}/"
mv "demefactory" "../../../${distdir}/ich9deblob/${arch}/"

if [ "${arch}" = "x86_64" ]
	then
		# Now build 32-bit binaries
		make clean
		make SHARED=0 CC='gcc -static -m32'
		mkdir "../../../${distdir}/ich9deblob/i686/"
		mv "ich9deblob" "../../../${distdir}/ich9deblob/i686/"
		mv "ich9gen" "../../../${distdir}/ich9deblob/i686/"
		mv "demefactory" "../../../${distdir}/ich9deblob/i686/"
fi

# cross-compile for ARM
make clean
make SHARED=0 CC='arm-linux-gnueabi-gcc -static'
mkdir "../../../${distdir}/ich9deblob/armv7l"
mv "ich9deblob" "../../../${distdir}/ich9deblob/armv7l/"
mv "ich9gen" "../../../${distdir}/ich9deblob/armv7l/"
mv "demefactory" "../../../${distdir}/ich9deblob/armv7l/"

cd "../"
rm -Rf "ich9deblob/"
mv "ich9deblob_/" "ich9deblob/"
cd "../../"

# -----------------
# nvramtool related
# -----------------
# build nvramtool, compiled (statically linked) and include the binary
cd "coreboot/util/"
cp -R "nvramtool/" "nvramtool_/"
cd "nvramtool/"
make clean
make SHARED=0 CC='gcc -static'

mkdir -p "../../../${distdir}/nvramtool/${arch}/"

mv "nvramtool" "../../../${distdir}/nvramtool/${arch}/"

if [ "${arch}" = "x86_64" ]
	then
		# Now build 32-bit binaries
		make clean
		make SHARED=0 CC='gcc -static -m32'
		mkdir "../../../${distdir}/nvramtool/i686/"
		mv "nvramtool" "../../../${distdir}/nvramtool/i686/"
fi

cd "../"
rm -Rf "nvramtool/"
mv "nvramtool_/" "nvramtool/"
cd "../../"

# -------------
# Miscellaneous
# -------------

# Flashing script
cp "flash" "${distdir}/"

# powertop script
cp "resources/scripts/misc/powertop.trisquel7" "${distdir}/"

printf "\n\n"

# ### Create the release tarballs
# ----------------------------------------------------------------------------------------------------------------------------

printf "Compressing %s/ into %s.tar.xz\n" "${distdir}" "${distdir}.tar.xz"
# create lzma compressed util archive
(cd "${versiondir}/" && tar -c "${distname}/" | xz -9e >"${distname}.tar.xz")

printf "done\n\n"

# ### Delete the uncompressed release directories
# ----------------------------------------------------------------------------------------------------------------------------

# The uncompressed archives are no longer needed
rm -Rf "${distdir:?}/"


code:
#!/bin/bash

#
#  helper script: build ROM images with GRUB and put them in ./bin/
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the root
# of libreboot_src or git

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

printf "Building ROM images with the GRUB payload\n"

if [ ! -d "bin/" ]
then
	mkdir "bin/"
fi

# Put GRUB payloads and config files
# in the coreboot directory, ready for next step
cd "coreboot/"
for romtype in txtmode vesafb
do
	cd "../resources/utilities/grub-assemble"
	./gen.sh ${romtype}
	rm -f "../../../coreboot/grub_${romtype}.elf"
	mv "grub_${romtype}.elf" "../../../coreboot/"
	cd "../../../coreboot"

	# GRUB configuration files
	for keylayout in ../resources/utilities/grub-assemble/keymap/original/*
	do
		keymap="${keylayout##*/}"
		cat "../resources/grub/config/extra/common.cfg" > "grub_${keymap}_${romtype}.cfg"
		cat "../resources/grub/config/extra/${romtype}.cfg" >> "grub_${keymap}_${romtype}.cfg"
		printf "keymap %s\n" "${keymap}" >> "grub_${keymap}_${romtype}.cfg"
		cat "../resources/grub/config/menuentries/common.cfg" >> "grub_${keymap}_${romtype}.cfg"
		cat "../resources/grub/config/menuentries/${romtype}.cfg" >> "grub_${keymap}_${romtype}.cfg"
		# grubtest.cfg should be able to switch back to grub.cfg
		sed 's/grubtest.cfg/grub.cfg/' < "grub_${keymap}_${romtype}.cfg" > "grub_${keymap}_${romtype}_test.cfg"
	done
done
cd ../

# Build ROM images for supported boards
buildrom() {
	board="$1"
	if [ -f "resources/libreboot/config/grub/${board}/config" ]; then
		./build roms withgrub_helper "${board}"
	fi
}

if [ $# -gt 0 ]; then
	for board in "${@}"; do
		buildrom "$board"
	done
else
	for board in resources/libreboot/config/grub/*; do
		buildrom "${board##*/}"
	done
fi

# Needed on i945 systems for the bucts/dd trick (documented)
# This enables the ROM to be flashed over the lenovo bios firmware
for i945board in "x60" "t60"
do
	if [ -d "bin/grub/${i945board}/" ]; then
		cd "bin/grub/${i945board}/"
		for i945rom in *
		do
			dd if="${i945rom}" of=top64k.bin bs=1 skip=$[$(stat -c %s "${i945rom}") - 0x10000] count=64k
			dd if=top64k.bin of="${i945rom}" bs=1 seek=$[$(stat -c %s "${i945rom}") - 0x20000] count=64k conv=notrunc
			rm -f top64k.bin
		done
		cd "../../../"
	fi
done

# TEMPORARY HACK: copy t400* to r500*
# (until proper R500 support is added)
if [ -d "bin/grub/" ]; then
	cd "bin/grub/"
	for board in "t400"
	do
		for romsize in "4m" "8m"
		do
			if [ -d "${board}_${romsize}b/" ]; then
				cp -R "${board}_${romsize}b/" "r500_${romsize}b/"
			fi
		done
	done
	cd ../../
fi

# Build the deblobbed descriptor+gbe regions for GM45/ICH9M targets.
# Then put them in the ROM images.
if [ -d "bin/grub/" ]; then
	cd "bin/grub/"
	for board in "x200" "r400" "r500" "t400" "t500"
	do
		for romsize in "4m" "8m"
		do
			if [ -d "${board}_${romsize}b/" ]; then
				cd "${board}_${romsize}b/"
				../../../resources/utilities/ich9deblob/ich9gen
				for rom in *
				do
					if [ "${board}" = "r500" ]; then
						dd if="ich9fdnogbe_${romsize}.bin" of="${rom}" bs=1 count=4k conv=notrunc
					else
						dd if="ich9fdgbe_${romsize}.bin" of="${rom}" bs=1 count=12k conv=notrunc
					fi
				done
				rm -f "ich9fd"*.bin "mk"*.[ch]
				cd "../"
			fi
		done
	done
	cd ../../
fi

# The GRUB files are no longer needed
rm -f "coreboot/grub"*.{elf,cfg}

printf "\n\n"


code:
#!/bin/bash

#  helper script: create ROM images for a given system, with GRUB
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#	Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the root
# of libreboot_src or git

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

if (( $# != 1 )); then
	printf "Usage: ./buildrom-withgrub boardname\n"
	printf "Example: ./buildrom-withgrub x60\n"
	printf "You need to specify exactly 1 argument\n"
	exit 1
fi

boardtarget="${1}"

printf "GRUB Helper script: build ROM images for '%s'\n" "${boardtarget}"

cd "coreboot/"

if [ -f "../version" ]; then
	# _src release archive is being used
	version="$(cat ../version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi
printf '%s\n' "${version}" >"lbversion"

# Build ROM images with text-mode and corebootfb modes.
# ---------------------------------------------------------------------------------------------------------------

if [ "${boardtarget}" = "qemu_i440fx_piix4" ] || [ "${boardtarget}" = "qemu_q35_ich9" ]
then
	# assume that the default config enable framebuffer mode, duplicate and patch for text-mode
	# necessary, otherwise it will ask you to enter the Y/X resolution of the framebuffer at build time
	cp "../resources/libreboot/config/grub/${boardtarget}/config" "config_vesafb"
	sed 's/CONFIG_FRAMEBUFFER_KEEP_VESA_MODE=y/# CONFIG_FRAMEBUFFER_KEEP_VESA_MODE is not set/' < "config_vesafb" > "config_txtmode"
else
	# assume that the default config enables text-mode, duplicate and patch for framebuffer mode
	cp "../resources/libreboot/config/grub/${boardtarget}/config" "config_txtmode"
	sed 's/# CONFIG_FRAMEBUFFER_KEEP_VESA_MODE is not set/CONFIG_FRAMEBUFFER_KEEP_VESA_MODE=y/' < "config_txtmode" > "config_vesafb"
fi

for romtype in txtmode vesafb
do
	if [ "${boardtarget}" = "x200_8mb" ] || [ "${boardtarget}" = "x200_4mb" ] || [ "${boardtarget}" = "r400_8mb" ] || [ "${boardtarget}" = "r400_4mb" ] || [ "${boardtarget}" = "r500_8mb" ] || [ "${boardtarget}" = "r500_4mb" ] || [ "${boardtarget}" = "t400_8mb" ] || [ "${boardtarget}" = "t400_4mb" ] || [ "${boardtarget}" = "t500_8mb" ] || [ "${boardtarget}" = "t500_4mb" ]
		then
			if [ "${romtype}" = "txtmode" ]
				then
					printf "Text mode graphics is currently broken on X200, R400, T400 and T500. Only framebuffer mode works.\n"
					printf "TODO: offending coreboot commit found (see docs/release.html). Fix text-mode graphics initialization.\n"
					continue
			fi
	fi

	# Build coreboot ROM image
	make clean
	mv "config_${romtype}" ".config"
	mv "grub_${romtype}.elf" "grub.elf"
	make -j"$(nproc)"
	mv "grub.elf" "grub_${romtype}.elf"
	mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"
	# .config no longer needed
	rm -f ".config"

	# Add version information to this image
	./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f lbversion -n lbversion -t raw

	# Add the background image
	if [ "$romtype" = "vesafb" ]
	then
		if [ "$1" = "macbook21" ] || [ "$1" = "x200_4mb" ] || [ "$1" = "x200_8mb" ] || [ "$1" = "r400_4mb" ] || [ "$1" = "r400_8mb" ]  || [ "$1" = "r500_4mb" ] || [ "$1" = "r500_8mb" ] || [ "$1" = "t400_4mb" ] || [ "$1" = "t400_8mb" ] || [ "$1" = "t500_4mb" ] || [ "$1" = "t500_8mb" ]
		then
			./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../resources/grub/background/background1280x800.png -n background.png -t raw
		else
			./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../resources/grub/background/background1024x768.png -n background.png -t raw
		fi
	fi

	# Add the correct GRUB configuration file for this image.
	for keylayout in ../resources/utilities/grub-assemble/keymap/original/*
	do
		keymap="${keylayout##*/}"

		# copy the images based on the keymap
		cp "${boardtarget}_${romtype}.rom" "${boardtarget}_${keymap}_${romtype}.rom"

		# Insert grub config into the image
		./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f "grub_${keymap}_${romtype}.cfg" -n grub.cfg -t raw
		# Insert grub test config into the image (for the user to test modifications to before modifying the main one)
		./util/cbfstool/cbfstool "${boardtarget}_${keymap}_${romtype}.rom" add -f "grub_${keymap}_${romtype}_test.cfg" -n grubtest.cfg -t raw
	done

	# This config-less ROM is no longer needed
	rm -f "${boardtarget}_${romtype}.rom"
done

# Now we clean up and prepare the bin directory containing all the images
# ----------------------------------------------------------------------------------------------------------------------------

# prepare directory for new ROM images
rm -Rf "${boardtarget:?}/"
mkdir "${boardtarget}/"
# move the ROM's into the newly created directory
mv "${boardtarget}"*.rom "${boardtarget}/"

# delete the old ROM's from ../bin
rm -Rf "../bin/grub/${boardtarget}/"
# now put the new ROM's in ./bin/grub/
[ ! -d "../bin/grub/" ] && mkdir -p "../bin/grub/"
mv "${boardtarget}/" "../bin/grub/"

# libreboot version file no longer needed
rm -f "lbversion"

# go back to main source directory
cd "../"

printf "\n\n"


code:
#!/bin/bash

#  helper script: downloads bucts and patches it
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the
# root of libreboot_src or libreboot git.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

# Get bucts and checkout last revision used

# Remove the old version that may exist
# ------------------------------------------------------------------------------

printf "Downloading bucts\n"

rm -Rf "bucts/"

# Get bucts
# ------------------------------------------------------------------------------

# download it using git
git clone git://git.stuge.se/bucts.git

# modifications are required
cd "bucts/"

# Reset to the last commit that was tested
# ------------------------------------------------------------------------------

printf "Patching bucts to not require git for building\n"
git reset --hard dc27919d7a66a6e8685ce07c71aefa4f03ef7c07

# Apply patches
# ------------------------------------------------------------------------------

git am "../resources/bucts/patch/0001-Makefile-don-t-use-git.patch"

# we're done
cd "../"

printf "\n\n"


code:
#!/bin/bash

#  helper script: downloads coreboot and patches/deblobs it
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the
# root of libreboot_src or libreboot git.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

printf "Downloading coreboot, patching coreboot and deblobbing coreboot\n"

# This grabs current base used, and applies patches
# This is also used to run the deblob scripts.

# Remove the old version that may exist
# ------------------------------------------------------------------------------

rm -Rf "coreboot/"

# Get latest coreboot:
# ------------------------------------------------------------------------------

# download it using git
git clone http://review.coreboot.org/coreboot

# there are modifications required
cd "coreboot/"

# reset to previously tested revision
git reset --hard 5d5fcdd82b72c1fc621aab9fd6ff88cce9345d8e

# Get patches from review.coreboot.org
# ------------------------------------------------------------------------------

# ----

# check on coreboot mailing list (see "favourites" in mail client):
# [coreboot] macbook21: broken by 10385 (Make DSDT a file in CBFS rather than embedding it into ramstage.)
# -- probably affects the X60 and T60 as well, if this is not already fixed.
# seems to be related to normal/fallback payload mechanism

# KEEP ON EYE ON:
# http://review.coreboot.org/#/c/7549

# ----

printf "southbridge/intel/common/spi: Add Flash lockdown option\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/70/9370/4 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0001-southbridge-intel-common-spi-Add-Flash-lockdown-opti.patch"

# This patch doesn't actually work...
# printf "mainboards/lenovo/t400: Enable serial debug option for use with dock\n"
# printf "NOTE: doesn't actually work at the moment. see docs/tasks.html\n"
# printf "Only including so that .config doesn't have to change\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/17/9317/13 && git cherry-pick FETCH_HEAD
# git am "../resources/libreboot/patch/0002-mainboards-lenovo-t400-Enable-serial-debug-option-fo.patch"

printf "mainboard/lenovo/t400: Add initial hybrid graphics support\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/19/9319/18 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0002-mainboard-lenovo-t400-Add-initial-hybrid-graphics-su.patch"

# not included, but keep an eye on it:
# printf "mainboard/lenovo/t400: Increase backlight frequency to reduce flicker\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/31/9331/14 && git cherry-pick FETCH_HEAD

printf "NOTFORMERGE: lenovo/t400: hard-code enable integrated-only video\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/50/10550/1 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0003-NOTFORMERGE-lenovo-t400-hard-code-enable-integrated-.patch"

# ----

printf "lenovo/x60: use correct BLC_PWM_CTL value\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/24/10624/1 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0004-lenovo-x60-use-correct-BLC_PWM_CTL-value.patch"

printf "Enable T60 native graphics\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/45/5345/10 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0005-lenovo-t60-Enable-native-intel-gfx-init.patch"

printf "lenovo/t60: Enable VESA framebuffer mode (native graphics)\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/51/10551/1 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0006-lenovo-t60-Enable-VESA-framebuffer-mode-native-graph.patch"

printf "lenovo/t60: Enable brightness controls (native graphics)\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/52/10552/1 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0007-lenovo-t60-Enable-brightness-controls-native-graphic.patch"

printf "ec/lenovo/h8: permanently enable wifi/trackpoint/touchpad/bluetooth/wwan\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/58/7058/9 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0008-NOTFORMERGE-ec-lenovo-h8-wlan-trackpoint-touchpad-bl.patch"

# printf "i945: permanently set tft_brightness to 0xff. this fixes the issue with X60 and 'scrolling' backlight\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/61/7561/2 && git cherry-pick FETCH_HEAD
# The patch was accidentally merged in coreboot. See
# http://review.coreboot.org/#/c/8697/ for the revert commit. rebase 7561 and re-include it in
# libreboot, once 8697 is merged in coreboot.

printf "northbridge/gm45/raminit.c: enable GS45 high-perf (i.e. add X200S support to libreboot)\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/86/7786/11 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0009-northbridge-gm45-raminit.c-enable-GS45-high-performa.patch"
# NOTE: 7786 is abandoned. See: http://review.coreboot.org/#/c/11135/ <-- that's the new one

printf "fix uneven backlight on X200 (when setting brightness low)\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/79/7979/2 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0010-gm45-fix-uneven-backlight-native-gfx-init.patch"

printf "ThinkPad R400 support (clone of the T400)\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/93/8393/5 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0011-lenovo-r400-Add-clone-of-Lenovo-T400.patch"

printf "ThinkPad T500 (depends on T400 patch)\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/45/10545/1 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0012-lenovo-t500-Add-clone-of-Lenovo-T400.patch"

# Misc:

printf "ec/lenovo/h8: re-factor handling of power_management_beeps\n"
# git fetch http://review.coreboot.org/coreboot refs/changes/31/10531/8 && git cherry-pick FETCH_HEAD
git am "../resources/libreboot/patch/0013-ec-lenovo-h8-re-factor-handling-of-power_management_.patch"

# Run coreboot-libre deblob scripts
# ------------------------------------------------------------------------------

printf "Deleting .git* in coreboot/ (history inside .git contains the blobs that were deleted)\n"
rm -Rf ".git/"
rm -f ".gitreview"
rm -f ".gitmodules"
rm -f ".gitignore"

# Strictly overkill. libreboot doesn't even checkout this submodule
rm -Rf "3rdparty/"

cd "../"

printf "Deblobbing coreboot\n"
./resources/utilities/coreboot-libre/deblob

printf "\n\n"


code:
#!/bin/bash

#  helper script: downloads flashrom and patches it
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the
# root of libreboot_src or libreboot git.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

# Get flashrom at the last previously tested revision

# Remove the old version that may still exist:
# ------------------------------------------------------------------------------

printf "Downloading flashrom\n"

rm -Rf "flashrom/"

# Get flashrom
# ------------------------------------------------------------------------------

# download it using subversion
git clone https://github.com/stefanct/flashrom.git

cd "flashrom/"

# reset to known revision
git reset --hard 80c9382948afa5e572854d49846a36b7f9d90e03

# Apply patches
# ------------------------------------------------------------------------------

printf "Enabling whitelist for X200S, X200 Tablet, T400, T500 and R400\n"
patch "board_enable.c" < "../resources/flashrom/patch/x200s_x200t_t400_t500_r400_whitelist.diff"

printf "Enabling whitelist for Libiquity Taurinus X200\n"
patch "board_enable.c" < "../resources/flashrom/patch/0001-Add-board-enable-for-Libiquity-Taurinus-X200.patch"

# Remove redundant definitions for the flash chips that
# supported libreboot systems use. This removes the need
# for the user to run with the "-c" argument on these systems
printf "Patching flashchips.c to remove the redundant entries\n"
patch "flashchips.c" < "../resources/flashrom/patch/purged_chips.diff"

cd "../"

printf "\n\n"


code:
#!/bin/bash

#  helper script: Downloads GRUB and patches it.
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the
# root of libreboot_src or libreboot git.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

# Get GRUB, revert to commit last used and apply patches.

# Remove the old version that may still exist
# ------------------------------------------------------------------------------

printf "Downloading GRUB\n"

rm -Rf "grub/"

# Get latest GRUB
# ------------------------------------------------------------------------------

# download it using git
git clone git://git.savannah.gnu.org/grub.git

# modifications are required
cd "grub/"

# Apply patches
# ------------------------------------------------------------------------------

# Replace "GNU GRUB version" in GRUB screen with "FREE AS IN FREEDOM"
git am "../resources/grub/patch/0001-grub-core-normal-main.c-Display-FREE-AS-IN-FREEDOM-n.patch"

cd "../"
printf "\n\n"

path: resources/scripts/helpers/download/grub


code:
#!/bin/bash

#  helper script: Downloads MemTest86+ and patches it
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#	Copyright (C) 2015 Joseph Michael Thompson <jmt@josepht.me>
#	Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
#
#    This program 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.
#
#    This program 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 script assumes that the working directory is the
# root of libreboot_src or libreboot git.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

# Get the last version of MemTest86+ used, apply patches, build it.

# Remove the old version that may exist
# ------------------------------------------------------------------------------

printf "Downloading MemTest86+\n"

rm -Rf "memtest86plus/"

# Get latest memtest86+:
# ------------------------------------------------------------------------------

# download it using wget
wget http://www.memtest.org/download/5.01/memtest86+-5.01.tar.gz

if [ "$(sha512sum memtest86+-5.01.tar.gz | cut -c1-128)" = "d872db35ef733ec8f49094251f2bf6b98cc80eb06d04044be3aecf28d534f24ba293a08b9979b112dbd07cf27368148939a33a32c7010fc9581a3a5b150c94d7" ]; then
	printf "Valid checksum for memtest86plus\n"
else
	rm -f "memtest86+-5.01.tar.gz"
	printf "Invalid checksum for memtest86plus\n"
	exit 1
fi

# extract it
tar -xzf "memtest86+-5.01.tar.gz"

# delete the tar file (no longer needed)
rm -f "memtest86+-5.01.tar.gz"

# make direcotory name consistent
mv "memtest86+-5.01/" "memtest86plus/"

# there are modifications required
cd "memtest86plus/"

# Apply necessary patches
# ------------------------------------------------------------------------------

# place the right config
rm -f "config.h"
cp "../resources/memtest86plus/patch/config.h" .

# place the right Makefile
rm -f "Makefile"
cp "../resources/memtest86plus/patch/Makefile" .

# (diff them with defaults to see what changed)

# we're done
cd "../"

printf "\n\n"


code:
#!/usr/bin/env guile
-*- scheme -*-
!#
;;; check-trailing-newline -- Find files lacking a trailing newline
;;; Use guile 2 (not 1.8)
;;; Copyright (C) 2015  Mark H Weaver <mhw@netris.org>
;;;
;;; This program 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.
;;;
;;; This program 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/>.

(use-modules (ice-9 match)
             (rnrs io ports))

(define (check-file file-name)
  (let ((contents (call-with-input-file file-name get-string-all)))
    (unless (string-suffix? "\n" contents)
      (format (current-error-port)
              "~a: lacks trailing newline\n"
              file-name))))

(match (command-line)
  ((_ file-names ...)
   (for-each check-file file-names)))


code:
#!/bin/bash

#  powertop.trisquel7: automatically sets up powertop --auto-tune on startup in trisquel 7
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

if [ $EUID -ne 0 ]; then
   printf "This script must be run as root\n"
   exit 1
fi

# For Trisquel 7 users.

apt-get -y install powertop

# Remove startup symlink if it exists
update-rc.d powertop remove
# Remove previous file if it exists
rm -Rf "/etc/init.d/powertop"

# write the correct commands there:
printf "#!/bin/sh\n" > "/etc/init.d/powertop"
printf "/usr/sbin/powertop --auto-tune\n" >> "/etc/init.d/powertop"

# make it executable:
chmod +x "/etc/init.d/powertop"

# Add the service to make it run automatically at boot time:
update-rc.d powertop defaults

# Run powertop now and tell the user
powertop --auto-tune
printf "Done. Run 'powertop --auto-tune' now. This will also run automatically at boot time. Run it again at any time, if needed. This has also been done for you just now.\n"


code:
git clone git://git.mtjm.eu/i945-pwm.git
^ is where i945-pwm came from.

The usual git commands apply.


code:
#!/bin/bash

#  DEBLOB script: deblobs the version of coreboot used for this release.
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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 script assumes that the current working directory is the root
# of the libreboot_src/ or git clone.

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

printf "Deleting blobs in coreboot\n"

cd "coreboot/"

# ---------------------
# Intel SoC (broadwell): CPU microcode updates
# ---------------------

# ---------------------
# Intel SoC (baytrail): CPU microcode updates
# ---------------------

# ---------------------
# AMD: CPU microcode updates
# ---------------------

rm -f \
"src/cpu/amd/model_fxx/microcode_rev_e.h" \
"src/cpu/amd/model_fxx/microcode_rev_c.h" \
"src/cpu/amd/model_fxx/microcode_rev_d.h" \
"src/cpu/amd/model_10xxx/mc_patch_010000d9.h" \
"src/cpu/amd/model_10xxx/mc_patch_01000096.h" \
"src/cpu/amd/model_10xxx/mc_patch_010000dc.h" \
"src/cpu/amd/model_10xxx/mc_patch_010000db.h" \
"src/cpu/amd/model_10xxx/mc_patch_01000095.h" \
"src/cpu/amd/model_10xxx/mc_patch_010000c7.h" \
"src/cpu/amd/model_10xxx/mc_patch_010000c8.h"

# ---------------------
# AMD: CPU microcode updates
# ---------------------
rm -f \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch01000085.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c7.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c6.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c8.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000d9.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c5.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/RevE/F10MicrocodePatch010000bf.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x15/OR/F15OrMicrocodePatch06000624_Enc.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x15/OR/F15OrMicrocodePatch0600050D_Enc.c" \
"src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x15/OR/F15OrMicrocodePatch06000425.c" \
"src/vendorcode/amd/agesa/f15tn/Proc/CPU/Family/0x15/TN/F15TnMicrocodePatch0600110F_Enc.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch01000085.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c7.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c6.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c8.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c4.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c5.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/RevE/F10MicrocodePatch010000bf.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x14/F14MicrocodePatch0500000B.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x14/F14MicrocodePatch0500001A.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch01000085.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c6.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c8.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c4.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c5.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevE/F10MicrocodePatch010000bf.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/F12MicrocodePatch03000002.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/F12MicrocodePatch0300000f.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/F12MicrocodePatch0300000e.c" \
"src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000c7.c" \
"src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch01000085.c" \
"src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch010000b6.c" \
"src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch01000098.c" \
"src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/RevC/F10MicrocodePatch01000086.c" \
"src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c4.c" \
"src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/RevD/F10MicrocodePatch010000c5.c" \
"src/vendorcode/amd/agesa/f16kb/Proc/CPU/Family/0x16/KB/F16KbId7001MicrocodePatch.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x14/F14MicrocodePatch05000029.c" \
"src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x14/F14MicrocodePatch05000119.c"

# ---------------------
# VIA (nano): CPU microcode updates
# ---------------------
rm -f \
"src/cpu/via/nano/nano_ucode_blob.c"

# -------------------------------------
# AMD AGESA: SMU firmware
# -------------------------------------
rm -f \
"src/vendorcode/amd/agesa/f12/Proc/GNB/Nb/Family/LN/F12NbSmuFirmware.h" \
"src/vendorcode/amd/agesa/f14/Proc/GNB/Nb/Family/0x14/F14NbSmuFirmware.h" \
"src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbInitKB/GnbSmuFirmwareKB.h" \
"src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/GnbSmuFirmwareTN.h"

# -------------------------------------
# AMD vendorcode: SCS Binary
# -------------------------------------
rm -f \
"src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbInitKB/excel925.h"

# -------------------------------------
# AMD vendorcode: GNB CAC weights table <-- TODO: Is this really a blob? Does it really need to be deleted by libreboot?
# -------------------------------------
rm -f \
"src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/GnbCacWeightsTN.h"

# -------------------------------------
# AMD vendorcode: SAMU firmware
# -------------------------------------
rm -f \
"src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbInitKB/GnbSamuPatchKB.h"

# -------------------------------------
# AMD vendorcode: Hotplug firmware
# -------------------------------------
rm -f \
"src/vendorcode/amd/cimx/rd890/HotplugFirmware.h"

# -------------------------------------
# keyboard controller firmware (8051 assembly)
# for the DMP Vortex86ex SoC
# -------------------------------------
rm -f \
"src/cpu/dmp/vortex86ex/dmp_kbd_fw_part1.inc"

# -------------------------------------
# DSDT/SSDT (pre-coreboot/compiled blobs)
# -------------------------------------
rm -f \
"src/vendorcode/amd/agesa/f14/Proc/GNB/PCIe/Family/0x14/F14PcieAlibSsdt.h" \
"src/vendorcode/amd/agesa/f12/Proc/GNB/PCIe/Family/LN/F12PcieAlibSsdt.h" \
"src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbInitKB/AlibSsdtKB.h" \
"src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/PcieAlibSsdtTNFM2.h" \
"src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/PcieAlibSsdtTNFS1.h"

# ----------------------------------
# Purpose unknown. TODO: investigate
# ----------------------------------

# <Stepan> francis7: util/broadcom/secimage/misc.c is a precalculated crc32 polynome table
# <Stepan> It's just a standard crc32 implementation

rm -f \
"util/broadcom/secimage/misc.c"

printf "\n\n"

cd "../"


code:
#!/bin/bash

#  find blobs in coreboot
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -e -u

# This is used when updating the version of
# coreboot that libreboot uses, to know what
# new blobs have landed in coreboot

# full deblob scripts based on linux-libre
# will replace this script later on. For now,
# this will have to do.

printf "Searching for blobs in coreboot\n"
cp "deblob-check" "../../../coreboot"
cd "../../../coreboot/"

chmod +x "deblob-check"
find -type f | xargs ./deblob-check > "blobs"
rm -f "deblob-check"

rm -f "tocheck"
touch "tocheck"

for file in $(cat blobs)
do
	if ! grep -Fxq "${file}" "../resources/utilities/coreboot-libre/nonblobs"
	then
		 printf "%s\n" "${file}" >> tocheck
	fi
done
rm -f "blobs"

rm -f "../resources/utilities/coreboot-libre/tocheck"
mv "tocheck" "../resources/utilities/coreboot-libre/"

cd "../resources/utilities/coreboot-libre/"

printf "Done! open resources/utilities/coreboot-libre/tocheck in an editor\n"
printf "This will contain the names of the files that you must decide whether they are blobs or not\n\n"


code:
./payloads/libpayload/curses/PDCurses-3.4/demos/worm.c
./payloads/libpayload/curses/PDCurses-3.4/sdl1/deffont.h
./payloads/libpayload/curses/PDCurses-3.4/sdl1/deficon.h
./payloads/libpayload/curses/PDCurses-3.4/win32/pdckbd.c
./payloads/libpayload/curses/PDCurses-3.4/x11/big_icon.xbm
./payloads/libpayload/curses/PDCurses-3.4/x11/little_icon.xbm
./payloads/libpayload/curses/pdcurses-backend/pdcdisp.c
./payloads/libpayload/curses/tinycurses.c
./payloads/libpayload/drivers/keyboard.c
./payloads/libpayload/drivers/usb/usbmsc.c
./payloads/libpayload/tests/cbfs-x86-test.c
./payloads/nvramcui/payload.sh
./src/cpu/allwinner/a10/raminit.c
./src/cpu/amd/geode_gx2/Kconfig
./src/cpu/amd/geode_lx/cpureginit.c
./src/cpu/amd/geode_lx/Kconfig
./src/cpu/amd/model_10xxx/init_cpus.c
./src/cpu/amd/model_10xxx/processor_name.c
./src/cpu/amd/model_fxx/model_fxx_update_microcode.c
./src/cpu/amd/model_fxx/powernow_acpi.c
./src/cpu/intel/fsp_model_206ax/acpi.c
./src/cpu/intel/fsp_model_406dx/acpi.c
./src/cpu/intel/haswell/acpi.c
./src/cpu/intel/microcode/microcode.c
./src/cpu/intel/model_2065x/acpi.c
./src/cpu/intel/model_206ax/acpi.c
./src/cpu/Kconfig
./src/cpu/samsung/exynos5250/update-bl1.sh
./src/cpu/via/nano/update_ucode.c
./src/device/dram/spd_cache.c
./src/device/Kconfig
./src/device/oprom/yabel/interrupt.c
./src/drivers/pc80/mc146818rtc.c
./src/drivers/pc80/vga/vga_palette.c
./src/Kconfig
./src/lib/coreboot_table.c
./src/lib/jpeg.c
./src/mainboard/advansus/a785e-i/mptable.c
./src/mainboard/amd/bimini_fam10/mptable.c
./src/mainboard/amd/dinar/buildOpts.c
./src/mainboard/amd/dinar/Kconfig
./src/mainboard/amd/inagua/Kconfig
./src/mainboard/amd/olivehill/mptable.c
./src/mainboard/amd/olivehillplus/mptable.c
./src/mainboard/amd/parmer/mptable.c
./src/mainboard/amd/persimmon/Kconfig
./src/mainboard/amd/serengeti_cheetah_fam10/get_bus_conf.c
./src/mainboard/amd/south_station/Kconfig
./src/mainboard/amd/south_station/mptable.c
./src/mainboard/amd/thatcher/mptable.c
./src/mainboard/amd/torpedo/Kconfig
./src/mainboard/amd/torpedo/mptable.c
./src/mainboard/amd/union_station/Kconfig
./src/mainboard/amd/union_station/mptable.c
./src/mainboard/asrock/e350m1/mptable.c
./src/mainboard/asrock/imb-a180/mptable.c
./src/mainboard/asus/f2a85-m/mptable.c
./src/mainboard/asus/m5a88-v/mptable.c
./src/mainboard/avalue/eax-785e/mptable.c
./src/mainboard/digitallogic/adl855pc/irq_tables.c
./src/mainboard/gigabyte/ga-b75m-d3h/romstage.c
./src/mainboard/gizmosphere/gizmo2/Micron_MT41J128M16JT.spd.hex
./src/mainboard/gizmosphere/gizmo/mptable.c
./src/mainboard/google/bolt/romstage.c
./src/mainboard/google/butterfly/hda_verb.c
./src/mainboard/google/butterfly/mainboard.c
./src/mainboard/google/falco/romstage.c
./src/mainboard/google/link/hda_verb.c
./src/mainboard/google/link/i915.c
./src/mainboard/google/link/romstage.c
./src/mainboard/google/panther/lan.c
./src/mainboard/google/peach_pit/mainboard.c
./src/mainboard/google/peppy/romstage.c
./src/mainboard/google/rambi/romstage.c
./src/mainboard/google/samus/romstage.c
./src/mainboard/google/slippy/romstage.c
./src/mainboard/hp/dl165_g6_fam10/get_bus_conf.c
./src/mainboard/hp/pavilion_m6_1035dx/mptable.c
./src/mainboard/ibase/mb899/cmos.layout
./src/mainboard/ibase/mb899/superio_hwm.c
./src/mainboard/intel/cougar_canyon2/Kconfig
./src/mainboard/intel/minnowmax/Kconfig
./src/mainboard/intel/mohonpeak/Kconfig
./src/mainboard/intel/wtm2/i915.c
./src/mainboard/jetway/nf81-t56n-lf/Kconfig
./src/mainboard/kontron/986lcd-m/cmos.layout
./src/mainboard/kontron/986lcd-m/mainboard.c
./src/mainboard/lenovo/g505s/mptable.c
./src/mainboard/lippert/frontrunner-af/Kconfig
./src/mainboard/lippert/frontrunner-af/mptable.c
./src/mainboard/lippert/toucan-af/Kconfig
./src/mainboard/lippert/toucan-af/mptable.c
./src/mainboard/msi/ms9652_fam10/get_bus_conf.c
./src/mainboard/packardbell/ms2290/mainboard.c
./src/mainboard/samsung/lumpy/romstage.c
./src/mainboard/siemens/sitemp_g1p1/cmos.layout
./src/mainboard/supermicro/h8dmr_fam10/get_bus_conf.c
./src/mainboard/supermicro/h8qgi/buildOpts.c
./src/mainboard/supermicro/h8qme_fam10/get_bus_conf.c
./src/mainboard/supermicro/h8scm/buildOpts.c
./src/mainboard/tyan/s2912_fam10/get_bus_conf.c
./src/mainboard/tyan/s4880/irq_tables.c
./src/mainboard/tyan/s4882/irq_tables.c
./src/mainboard/tyan/s8226/buildOpts.c
./src/northbridge/amd/agesa/common/common.c
./src/northbridge/amd/amdk8/acpi.c
./src/northbridge/amd/amdk8/coherent_ht.c
./src/northbridge/amd/amdk8/raminit_test.c
./src/northbridge/amd/amdmct/mct_ddr3/mcttmrl.c
./src/northbridge/amd/amdmct/mct/mctardk3.c
./src/northbridge/amd/amdmct/mct/mctardk4.c
./src/northbridge/amd/amdmct/mct/mcttmrl.c
./src/northbridge/amd/gx2/pll_reset.c
./src/northbridge/amd/pi/00730F01/Kconfig
./src/northbridge/intel/fsp_rangeley/fsp/Kconfig
./src/northbridge/intel/fsp_sandybridge/fsp/Kconfig
./src/northbridge/intel/gm45/raminit_rcomp_calibration.c
./src/northbridge/intel/gm45/raminit_read_write_training.c
./src/northbridge/intel/haswell/Kconfig
./src/northbridge/intel/haswell/raminit.c
./src/northbridge/intel/i82830/vga.c
./src/northbridge/intel/i945/raminit.c
./src/northbridge/intel/nehalem/gma.c
./src/northbridge/intel/nehalem/raminit.c
./src/northbridge/intel/sandybridge/gma.c
./src/northbridge/intel/sandybridge/Kconfig
./src/northbridge/intel/sandybridge/raminit.c
./src/northbridge/intel/sandybridge/raminit_native.c
./src/northbridge/via/cx700/raminit.c
./src/northbridge/via/vx800/ide.c
./src/northbridge/via/vx800/uma_ram_setting.c
./src/northbridge/via/vx900/sata.c
./src/soc/intel/baytrail/acpi.c
./src/soc/intel/baytrail/Kconfig
./src/soc/intel/baytrail/romstage/raminit.c
./src/soc/intel/broadwell/acpi.c
./src/soc/intel/broadwell/Kconfig
./src/soc/intel/broadwell/romstage/raminit.c
./src/soc/intel/fsp_baytrail/acpi.c
./src/soc/intel/fsp_baytrail/fsp/Kconfig
./src/soc/intel/fsp_baytrail/Kconfig
./src/soc/qualcomm/ipq806x/Kconfig
./src/soc/samsung/exynos5250/clock.c
./src/soc/samsung/exynos5420/clock.c
./src/southbridge/amd/agesa/hudson/Kconfig
./src/southbridge/amd/cimx/sb800/Kconfig
./src/southbridge/intel/bd82x6x/Kconfig
./src/southbridge/intel/i82801ix/dmi_setup.c
./src/southbridge/intel/ibexpeak/Kconfig
./src/southbridge/intel/lynxpoint/Kconfig
./src/southbridge/intel/sch/Kconfig
./src/southbridge/sis/sis966/early_smbus.c
./src/southbridge/sis/sis966/ide.c
./src/southbridge/sis/sis966/sata.c
./src/southbridge/sis/sis966/usb2.c
./src/southbridge/sis/sis966/usb.c
./src/superio/via/vt1211/vt1211.c
./src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/cpuF10Dmi.c
./src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
./src/vendorcode/amd/agesa/f10/Proc/Mem/Main/muc.c
./src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/cpuF10Dmi.c
./src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
./src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/cpuF12Dmi.c
./src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/cpuF12WheaInitDataTables.c
./src/vendorcode/amd/agesa/f12/Proc/Fch/Hwm/Family/Hudson2/Hudson2HwmLateService.c
./src/vendorcode/amd/agesa/f12/Proc/GNB/Gfx/Family/LN/F12GfxServices.c
./src/vendorcode/amd/agesa/f12/Proc/Mem/Main/muc.c
./src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/cpuF10Dmi.c
./src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
./src/vendorcode/amd/agesa/f14/Proc/Mem/Main/muc.c
./src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/cpuF10Dmi.c
./src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
./src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x15/cpuF15WheaInitDataTables.c
./src/vendorcode/amd/agesa/f15/Proc/Mem/Main/muc.c
./src/vendorcode/amd/agesa/f15/Proc/Mem/Ps/OR/mpor3.c
./src/vendorcode/amd/agesa/f15/Proc/Mem/Tech/DDR3/mtlrdimm3.c
./src/vendorcode/amd/agesa/f15tn/Proc/CPU/Family/0x15/cpuF15WheaInitDataTables.c
./src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/GfxIntegratedInfoTableTN.c
./src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/GfxLibTN.c
./src/vendorcode/amd/agesa/f15tn/Proc/Mem/Main/muc.c
./src/vendorcode/amd/agesa/f15tn/Proc/Mem/Ps/TN/mptn3.c
./src/vendorcode/amd/agesa/f15tn/Proc/Mem/Tech/DDR3/mtlrdimm3.c
./src/vendorcode/amd/agesa/f16kb/Proc/CPU/Family/0x16/cpuF16WheaInitDataTables.c
./src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbGfxIntTableV3/GfxLibV3.c
./src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbInitKB/GnbF1TableKB.c
./src/vendorcode/amd/agesa/f16kb/Proc/Mem/Main/muc.c
./src/vendorcode/amd/agesa/f16kb/Proc/Mem/Ps/KB/mpkb3.c
./src/vendorcode/amd/cimx/sb800/SATA.c
./src/vendorcode/google/chromeos/build-snow
./util/amdtools/example_input/lspci-cb-48G-667MHz-18.2-20090909e
./util/amdtools/example_input/lspci-prop-48G-667MHz-18.2
./util/cbfstool/linux_trampoline.c
./util/ifdtool/ifdtool.c
./util/kconfig/zconf.hash.c_shipped
./util/kconfig/zconf.lex.c_shipped
./util/kconfig/zconf.tab.c_shipped
./util/nvramtool/accessors/layout-bin.c
./util/romcc/do_tests.sh
./util/romcc/tests/include/linux_console.h
./util/romcc/tests/linux_console.h
./util/romcc/tests/linux_test5.c
./util/romcc/tests/raminit_test6.c
./util/romcc/tests/raminit_test7.c
./util/romcc/tests/simple_test14.c
./util/romcc/tests/simple_test30.c
./util/romcc/tests/simple_test38.c
./util/romcc/tests/simple_test39.c
./util/romcc/tests/simple_test54.c
./util/romcc/tests/simple_test59.c
./util/romcc/tests/simple_test72.c
./util/romcc/tests/simple_test73.c
./util/sconfig/lex.yy.c_shipped
./util/sconfig/sconfig.tab.c_shipped
./util/superiotool/fintek.c
./util/superiotool/ite.c
./util/superiotool/smsc.c
./util/superiotool/winbond.c
./src/mainboard/google/slippy/Micron_4KTF25664HZ.spd.hex
./src/mainboard/google/falco/Micron_4KTF25664HZ.spd.hex
./src/mainboard/google/peppy/Micron_4KTF25664HZ.spd.hex
./src/mainboard/google/link/micron_4Gb_1600_1.35v_x16.spd.hex
./src/mainboard/google/rambi/spd/micron_1GiB_dimm_MT41K128M16JT-125.spd.hex
./src/mainboard/google/rambi/spd/micron_2GiB_dimm_MT41K256M16HA-125.spd.hex
./src/mainboard/google/bolt/micron_4Gb_1600_1.35v_x16.spd.hex
./src/mainboard/google/link/samsung_4Gb_1600_1.35v_x16.spd.hex
./src/mainboard/google/link/elpida_4Gb_1600_x16.spd.hex
./src/mainboard/google/slippy/Hynix_HMT425S6AFR6A.spd.hex
./src/mainboard/google/falco/Hynix_HMT425S6AFR6A.spd.hex
./src/mainboard/google/falco/Elpida_EDJ4216EFBG.spd.hex
./src/mainboard/google/rambi/spd/hynix_1GiB_dimm_H5TC2G63FFR-PBA.spd.hex
./src/mainboard/google/rambi/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
./src/mainboard/google/bolt/samsung_4Gb_1600_1.35v_x16.spd.hex
./src/mainboard/google/bolt/elpida_4Gb_1600_x16.spd.hex
./src/mainboard/google/peppy/Hynix_HMT425S6AFR6A.spd.hex
./src/mainboard/google/peppy/Elpida_EDJ4216EFBG.spd.hex
./src/mainboard/google/falco/Samsung_M471B5674QH0.spd.hex
./src/mainboard/google/samus/spd/empty.spd.hex
./src/mainboard/google/samus/spd/elpida_4.spd.hex
./src/mainboard/google/samus/spd/hynix_4.spd.hex
./src/mainboard/google/samus/spd/elpida_16.spd.hex
./src/mainboard/google/samus/spd/hynix_8.spd.hex
./src/mainboard/google/samus/spd/hynix_16.spd.hex
./src/mainboard/google/samus/spd/samsung_8.spd.hex
./src/mainboard/google/samus/spd/elpida_8.spd.hex
./src/mainboard/google/samus/spd/samsung_4.spd.hex
./src/mainboard/google/auron/spd/Micron_4KTF25664HZ.spd.hex
./src/mainboard/google/auron/spd/Elpida_EDJ4216EFBG.spd.hex
./src/mainboard/google/auron/spd/Hynix_HMT425S6AFR6A.spd.hex
./src/mainboard/google/glados/spd/samsung_dimm_K4E6E304EE-EGCF.spd.hex
./src/mainboard/google/auron/spd/empty.spd.hex
./src/mainboard/google/cyan/spd/hynix_2GiB_dimm_HMT425S6CFR6A_H5TC4G63CFR.spd.hex
./src/mainboard/google/cyan/spd/samsung_2GiB_dimm_K4B4G1646Q-HYK0.spd.hex
./src/mainboard/google/cyan/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
./src/mainboard/google/glados/spd/hynix_dimm_H9CCNNNBLTALAR.spd.hex
./src/mainboard/google/glados/spd/empty.spd.hex
./src/mainboard/google/glados/spd/hynix_dimm_H9CCNNN8JTBLAR.spd.hex
./src/mainboard/intel/sklrvp/spd/empty.spd.hex
./src/mainboard/intel/sklrvp/spd/rvp3.spd.hex
./src/mainboard/intel/kunimitsu/spd/empty.spd.hex
./src/mainboard/intel/kunimitsu/spd/samsung_dimm_K4E8E304EE-EGCE.spd.hex
./src/mainboard/intel/strago/spd/hynix_2GiB_dimm_HMT425S6CFR6A_H5TC4G63CFR.spd.hex
./src/mainboard/intel/strago/spd/samsung_2GiB_dimm_K4B4G1646Q-HYK0.spd.hex
./src/mainboard/intel/strago/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
./src/mainboard/bap/ode_e20XX/BAP_Q7.spd.hex
./src/northbridge/intel/nehalem/raminit_tables.c
./src/northbridge/intel/sandybridge/raminit_patterns.h
./src/southbridge/nvidia/mcp55/early_setup_ss.h
./src/southbridge/nvidia/ck804/early_setup_ss.h
./src/southbridge/sis/sis966/early_setup_ss.h
./util/crossgcc/patches/gcc-4.9.2_riscv.patch
./util/crossgcc/patches/binutils-2.25_riscv.patch
./src/southbridge/amd/pi/hudson/Kconfig
./src/drivers/xgi/common/vb_setmode.c
./src/drivers/xgi/common/vb_table.h
./src/drivers/xgi/common/XGI_main.h
./src/mainboard/siemens/mc_tcu3/romstage.c
./src/mainboard/siemens/mc_tcu3/lcd_panel.c
./src/mainboard/siemens/mc_tcu3/modhwinfo.c
./src/mainboard/pcengines/apu1/Kconfig
./src/mainboard/asus/kfsn4-dre/get_bus_conf.c
./src/mainboard/google/samus/spd/spd.c
./src/mainboard/hp/abm/mptable.c
./src/northbridge/amd/pi/00630F01/Kconfig
./src/cpu/amd/microcode/microcode.c
./src/lib/tlcl_structures.h
./util/rockchip/make_idb.py
./util/autoport/readme.md
./util/bimgtool/bimgtool.c
./util/cbfstool/fmd_parser.c_shipped
./util/cbfstool/fmd_scanner.c_shipped
./Documentation/CorebootBuildingGuide.tex
./Documentation/hypertransport.svg
./Documentation/codeflow.svg
./src/soc/broadcom/cygnus/ddr_init.c
./src/soc/broadcom/cygnus/ddr_init_table.c
./src/soc/qualcomm/ipq806x/lcc.c
./src/soc/intel/braswell/acpi.c
./src/soc/intel/braswell/Kconfig
./src/vendorcode/amd/pi/Kconfig
./src/drivers/intel/fsp1_1/Kconfig
./src/drivers/intel/fsp1_1/fsp_gop.c
./src/drivers/i2c/ww_ring/ww_ring_programs.c
./src/mainboard/google/auron/spd/spd.c
./src/mainboard/google/jecht/lan.c
./src/mainboard/gigabyte/ga-b75m-d3v/romstage.c
./src/mainboard/amd/lamar/Kconfig
./payloads/external/GRUB2/Kconfig
./payloads/external/FILO/Kconfig
./payloads/external/SeaBIOS/Kconfig
./src/soc/intel/common/fsp_ramstage.c
./src/soc/intel/skylake/Kconfig
./src/soc/intel/braswell/gpio.c
./src/soc/nvidia/tegra210/Kconfig
./src/soc/nvidia/tegra210/mtc.c
./src/southbridge/intel/common/firmware/Kconfig
./src/mainboard/google/cyan/spd/spd.c
./src/mainboard/google/cyan/Kconfig
./src/mainboard/google/glados/spd/spd.c
./src/mainboard/intel/sklrvp/spd/spd.c
./src/mainboard/intel/kunimitsu/spd/spd.c
./src/mainboard/intel/strago/spd/spd.c
./src/mainboard/intel/strago/Kconfig
./src/mainboard/amd/bettong/mptable.c
./src/northbridge/amd/pi/00660F01/Kconfig


code:
.spd.hex files - serial presence detect. These are not blobs
see JEDEC standard or https://en.wikipedia.org/wiki/Serial_presence_detect
These are added to the nonblobs file

src/northbridge/intel/nehalem/raminit_tables.c"
src/northbridge/intel/sandybridge/raminit_patterns.h
These are used by native raminit for the relevant platforms, and are not blobs

"src/southbridge/nvidia/mcp55/early_setup_ss.h" \
"src/southbridge/nvidia/ck804/early_setup_ss.h" \
"src/southbridge/sis/sis966/early_setup_ss.h"
not blobs

The text in this file is CC-BY-SA 4.0 or higher. All contributions to it must
be made under the same license.


code:
#!/bin/bash

#  grub-assemble gen.sh: generate GRUB ELF files (coreboot payloads)
#
#	Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
#    This program 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.
#
#    This program 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/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

if (( $# != 1 )); then
	printf "Usage: ./gen.sh mode\n"
	printf "Example: ./gen.sh vesafb\n"
	printf "Example: ./gen.sh txtmode\n"
	printf "You need to specify exactly 1 argument\n"
	exit 1
fi

# This is where GRUB is expected to be (outside of the grub-assemble, instead in main checkout)
grubdir="../../../grub"

source "modules.conf"

list_keymaps () {
	for keylayout in keymap/original/*
	do
		keymap="${keylayout##*/}"
		printf "/boot/grub/layouts/%s.gkb=keymap/%s.gkb " "${keymap}" "${keymap}"
	done
}
keymaps=$(list_keymaps)

printf "Creating GRUB ELF executable for configuration '%s'\n" "${1}"
if [ "${1}" = "vesafb" ]
then
	# Generate the grub.elf (vesafb)
	$grubdir/grub-mkstandalone \
	  --grub-mkimage="${grubdir}/grub-mkimage" \
	  -O i386-coreboot \
	  -o "grub_vesafb.elf" \
	  -d "${grubdir}/grub-core/" \
	  --fonts= --themes= --locales=  \
	  --modules="${grub_modules}" \
	  --install-modules="${grub_install_modules}" \
	  /boot/grub/grub.cfg="../../../resources/grub/config/grub_memdisk.cfg" \
	  /dejavusansmono.pf2="../../../resources/grub/font/dejavusansmono.pf2" \
	  "${keymaps}"
elif [ "${1}" = "txtmode" ]
then
	# Generate the grub.elf (txtmode)
	"${grubdir}/grub-mkstandalone" \
	  --grub-mkimage="${grubdir}/grub-mkimage" \
	  -O i386-coreboot \
	  -o "grub_txtmode.elf" \
	  -d "${grubdir}/grub-core/" \
	  --fonts= --themes= --locales=  \
	  --modules="${grub_modules}" \
	  --install-modules="${grub_install_modules}" \
	  /boot/grub/grub.cfg="../../../resources/grub/config/grub_memdisk.cfg" \
	  /memtest="../../../memtest86plus/memtest" \
	  "${keymaps}"
else
	printf "grub-assemble gen.sh: invalid mode '%s'\n" "${1}"
	exit 1
fi
printf "\n\n"


code:
# Install modules (installed, but not automatically loaded)
grub_install_modules=" \
adler32 \
all_video \
archelp \
ata \
backtrace \
bitmap \
bitmap_scale \
cmp \
cpio_be \
cpio \
cpuid \
crc64 \
cs5536 \
div_test \
efiemu \
elf \
eval \
exfat \
extcmd \
file \
fshelp \
gettext \
gfxmenu \
gptsync \
gzio \
hashsum \
hexdump \
http \
linux16 \
loadenv \
lzopio \
mda_text \
mmap \
mpi \
msdospart \
multiboot2 \
multiboot \
nativedisk \
net \
newc \
ntfscomp \
ntfs \
odc \
offsetio \
parttool \
priority_queue \
procfs \
progress \
read \
relocator \
scsi \
search_fs_file \
search_fs_uuid \
search_label \
search \
setjmp \
setpci \
sleep \
squash4 \
tar \
terminfo \
testload \
testspeed \
tftp \
time \
trig \
tr \
true \
udf \
ufs1_be \
ufs1 \
ufs2 \
usbserial_common \
usbserial_ftdi \
usbserial_pl2303 \
usbserial_usbdebug \
usbtest \
video_colors \
videotest_checksum \
xzio \
"

# Modules (and always loaded)
grub_modules=" \
acpi \
ahci \
at_keyboard \
boot \
cat \
cbfs \
cbls \
cbtime \
chain \
cmosdump \
cmostest \
cbmemc \
crypto \
cryptodisk \
configfile \
datehook \
date \
datetime \
diskfilter \
disk \
echo \
ext2 \
ehci \
fat \
halt \
help \
iorw \
iso9660 \
keystatus \
linux \
loopback \
ls \
lsacpi \
lsmmap \
lspci \
luks \
lvm \
mdraid09_be \
mdraid09 \
mdraid1x \
raid5rec \
raid6rec \
memdisk \
minicmd \
memrw \
morse \
normal \
ohci \
part_gpt \
part_msdos \
password \
password_pbkdf2 \
pbkdf2 \
pcidump \
pci \
play \
probe \
reboot \
serial \
terminal \
test \
usb_keyboard \
usbms \
uhci \
gcry_arcfour \
gcry_blowfish \
gcry_camellia \
gcry_cast5 \
gcry_crc \
gcry_des \
gcry_dsa \
gcry_idea \
gcry_md4 \
gcry_md5 \
gcry_rfc2268 \
gcry_rijndael \
gcry_rmd160 \
gcry_rsa \
gcry_seed \
gcry_serpent \
gcry_sha1 \
gcry_sha256 \
gcry_sha512 \
gcry_tiger \
gcry_twofish \
gcry_whirlpool \
hdparm \
regexp \
spkmodem \
syslinuxcfg \
usb \
verify \
videoinfo \
videotest \
xfs \
btrfs \
zfs \
sfs \
romfs \
reiserfs \
nilfs2 \
minix_be \
minix3_be \
minix3 \
minix2_be \
minix2 \
minix \
jfs \
hfsplus \
hfs \
bfs \
afs \
affs \
gfxmenu \
gfxterm_background \
gfxterm_menu \
jpeg \
png \
tga \
pata \
bsd \
part_bsd \
"


code:
CFLAGS ?= -O2 -Wall -W -ggdb

i945-pwm: i945-pwm.c
	$(CC) -std=gnu99 $(CFLAGS) $(LDFLAGS) -o $@ $< -lpci -lz

clean:
	rm -f i945-pwm


code:
/*
  Copyright (C) 2014  Michał Masłowski  <mtjm@mtjm.eu>

  This program 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.

  This program 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/>.
*/

/* Try several backlight PWM frequencies and duty cycles to see which
   expose the noise on X60 with coreboot.
*/

#include <assert.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pci/pci.h>

static struct pci_access *pacc;
static uint32_t *map;
static int fd;

#define REGISTER 0x61254

static void
init (void)
{
  fd = -1;
  /* Find the device. */
  struct pci_dev *dev;
  pacc = pci_alloc ();
  pacc->writeable = 1;
  pci_init (pacc);
  pci_scan_bus (pacc);
  for (dev = pacc->devices; dev != NULL; dev = dev->next)
    {
      pci_fill_info (dev, PCI_FILL_IDENT | PCI_FILL_BASES);
      if (dev->vendor_id != 0x8086 || dev->device_id != 0x27a2)
        continue;
      break;
    }
  if (dev == NULL)
    {
      fprintf (stderr, "Device not found.\n");
      goto fail;
    }
  /* Map a part of its MMIO. */
  fd = open ("/dev/mem", O_RDWR);
  if (fd == -1)
    {
      fprintf (stderr, "Cannot open memory.  Are you root?\n");
      goto fail;
    }
  map = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, dev->base_addr[0] + (REGISTER & (~4095)));
  if (map != MAP_FAILED)
    return;
  else
    perror ("mmap failed");
 fail:
  if (pacc != NULL)
    pci_cleanup (pacc);
  if (fd != -1)
    close (fd);
  exit (1);
}

static void
set_pwm (uint16_t freq, uint16_t duty)
{
  assert (duty <= freq);
  map[((REGISTER - 4) & 4095) >> 2] = 0x80000000;
  map[(REGISTER & 4095) >> 2] = ((freq | 1) << 16) | duty;
}

int
main (void)
{
  init ();
  int exponent = 8;
  int diff = 0;
  int divisor = 2;
  uint16_t freq = 0x61;
  uint16_t duties[] = {
#if 1
    // i945
    0xf,
    0x13,
    0x19,
    0x1f,
    0x23,
    0x29,
    0x2f,
    0x35,
    0x39,
    0x3f,
    0x45,
    0x4b,
    0x4f,
    0x55,
    0x5b,
    0x61
#else
    // gm45
    0x2,
    0x4,
    0x5,
    0x7,
    0x9,
    0xb,
    0xd,
    0x11,
    0x14,
    0x17,
    0x1c,
    0x20,
    0x27,
    0x31,
    0x41,
    0x61,
#endif
  };
#if 1
  for (unsigned int di = 0; di < sizeof (duties) / sizeof (duties[0]); di++)
    {
      uint16_t duty = duties[di];
#else
      for (uint16_t duty = 0; duty < 0x61; duty++)
        {
#endif
#if 0
        }
#endif
      uint16_t pwm_freq = (freq + diff) << exponent;
      pwm_freq += (pwm_freq >> divisor);
      //pwm_freq |= 0x33;
      uint16_t pwm_duty = (duty + diff) << exponent;
      pwm_duty += (pwm_duty >> divisor);
      //pwm_duty |= 0x32;
      set_pwm (pwm_freq, pwm_duty);
      sleep (1);
    }
  if (pacc != NULL)
    pci_cleanup (pacc);
  if (map != NULL)
    munmap (map, 4096);
  if (fd != -1)
    close (fd);
  return 0;
}


code:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Copyright (C) 2014  Michał Masłowski  <mtjm@mtjm.eu>
#
# Licensed under copyleft-next version 0.3.0.  See
# https://gitorious.org/copyleft-next/copyleft-next/raw/master:Releases/copyleft-next-0.3.0
# for more information.

"""Get values of interesting i945 graphics parameters from a running system.

This script might show the values for GPU registers specified in
devicetree.cb on coreboot mainboard ports using i945 native VGA init
from <http://review.coreboot.org/#/c/5320/>.

Run as root.
"""

import mmap
import re
import struct
import subprocess

_MEMORY = re.compile(r"^\s+Memory\s+at\s+([0-9a-f]+)\s+\(32-bit, non-prefetchable\)\s+\[size=[0-9]+K\]$")

def get_pci_data():
    # lspci has a machine readable format, but it doesn't have the needed data.
    for devid in ("8086:27a2",):
        lspci = subprocess.Popen(("lspci", "-vn", "-d", devid),
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        address = None
        memory = None
        for line in lspci.communicate()[0].split("\n"):
            if line and line[0] == "0":
                address = line.split()[0]
            match = _MEMORY.match(line)
            if match is not None:
                memory = int(match.group(1), 16)
                break
        yield (address, memory)

def config_byte(address, offset):
    """Return byte at specified offset in PCI config space of device
    identified by address."""
    with open("/sys/bus/pci/devices/0000:%s/config" % address, "rb") as f:
        f.seek(offset)
        return struct.unpack("=B", f.read(1))

addr0, func0 = list(get_pci_data())[0]

def read32(fo, base, offset):
    memory = mmap.mmap(fo.fileno(), offset + 4,
                       mmap.MAP_SHARED, mmap.ACCESS_READ,
                       offset=base)
    try:
        memory.seek(offset)
        val = memory.read(4)
        return struct.unpack("=I", val)[0]
    finally:
        memory.close()

# Some i915 register names.
PORT_HOTPLUG_EN = 0x61110
BLC_PWM_CTL = 0x61254
LVDS = 0x61180

# Bits in LVDS.
LVDS_CLOCK_B_POWERUP_ALL = 3 << 4
LVDS_CLOCK_BOTH_POWERUP_ALL = 3 << 2

# Expansion of DPLL(1).
DPLL1 = ((0x06014) + (1)*((0x06018)-(0x06014)))

# Bits there.
DPLL_INTEGRATED_CLOCK_VLV = (1<<13)
DPLL_INTEGRATED_CRI_CLK_VLV = (1<<14)

if __name__ == "__main__":
    with open("/dev/mem", "rb") as mem:
        print "gpu_hotplug = 0x%08x" % read32(mem, func0, PORT_HOTPLUG_EN)
        dpll = read32(mem, func0, DPLL1)
        spread_spectrum = dpll & (DPLL_INTEGRATED_CLOCK_VLV \
                                  | DPLL_INTEGRATED_CRI_CLK_VLV)
        if spread_spectrum != 0:
            spread_spectrum = 1
        print "gpu_lvds_use_spread_spectrum_clock = %d" % spread_spectrum
        lvds = read32(mem, func0, LVDS)
        dual_channel = lvds & (LVDS_CLOCK_B_POWERUP_ALL \
                               | LVDS_CLOCK_BOTH_POWERUP_ALL)
        if dual_channel != 0:
            dual_channel = 1
        print "gpu_lvds_is_dual_channel = %d" % dual_channel
        backlight = read32(mem, func0, BLC_PWM_CTL)
        print "gpu_backlight = 0x%08x" % backlight
        # Using display clock from i945_get_display_clock_speed in
        # drivers/gpu/drm/i915/intel_display.c.  Result multiplied by
        # two to match BIOS-reported PWM frequency on my X60t.
        mod_freq = 2 * 400000000 / ((backlight >> 16) * 128.0)
        print "backlight modulation frequency = %f Hz" % mod_freq
        print "duty cycle = %d%%" % (100.0 * (backlight & 0xffff)
                                     / (backlight >> 16))
        print "legacy backlight brightness = 0x%02x" % config_byte(addr0, 0xf4)


code:
#
# Makefile for ich9deblob utility from libreboot project
#
# Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
#
# This program 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.
#
# This program 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/>.
#

CC=gcc
FORCEC99=-std=c99
CFLAGS=-I. -Wall -Wextra -g $(FORCEC99)
NOLINKER=-c

all: ich9deblob ich9gen demefactory

ich9deblob: obj/ich9deblob.o obj/common/descriptor_gbe.o \
		obj/descriptor/descriptor.o obj/gbe/gbe.o obj/common/x86compatibility.o

	$(CC) $(CFLAGS) obj/ich9deblob.o obj/common/descriptor_gbe.o \
		obj/common/x86compatibility.o obj/descriptor/descriptor.o obj/gbe/gbe.o \
		 -o ich9deblob

ich9gen: obj/ich9gen.o obj/ich9gen/mkdescriptor.o obj/ich9gen/mkgbe.o \
		obj/common/descriptor_gbe.o \
		obj/descriptor/descriptor.o obj/gbe/gbe.o obj/common/x86compatibility.o

	$(CC) $(CFLAGS) obj/ich9gen.o obj/ich9gen/mkdescriptor.o obj/ich9gen/mkgbe.o \
	 obj/common/descriptor_gbe.o \
		obj/common/x86compatibility.o obj/descriptor/descriptor.o obj/gbe/gbe.o \
		 -o ich9gen

demefactory: obj/demefactory.o obj/common/descriptor_gbe.o \
		obj/descriptor/descriptor.o obj/gbe/gbe.o obj/common/x86compatibility.o

	$(CC) $(CFLAGS) obj/demefactory.o obj/common/descriptor_gbe.o \
		obj/common/x86compatibility.o obj/descriptor/descriptor.o obj/gbe/gbe.o \
		 -o demefactory

# for demefactory
# ----------------------------------------------------------------------

obj/demefactory.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/demefactory.c -o obj/demefactory.o

# for ich9deblob
# ----------------------------------------------------------------------

obj/ich9deblob.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/ich9deblob.c -o obj/ich9deblob.o

# for ich9gen
# ----------------------------------------------------------------------

obj/ich9gen.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/ich9gen.c -o obj/ich9gen.o

obj/ich9gen/mkdescriptor.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/ich9gen/mkdescriptor.c -o obj/ich9gen/mkdescriptor.o

obj/ich9gen/mkgbe.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/ich9gen/mkgbe.c -o obj/ich9gen/mkgbe.o

# for demefactory, ich9deblob and ich9gen:
# ----------------------------------------------------------------------

obj/common/descriptor_gbe.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/common/descriptor_gbe.c -o obj/common/descriptor_gbe.o

obj/common/x86compatibility.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/common/x86compatibility.c -o obj/common/x86compatibility.o

obj/descriptor/descriptor.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/descriptor/descriptor.c -o obj/descriptor/descriptor.o

obj/gbe/gbe.o:
	$(CC) $(CFLAGS) $(NOLINKER) src/gbe/gbe.c -o obj/gbe/gbe.o

# make clean
# ----------------------------------------------------------------------
clean:
	rm -Rf ich9deblob ich9gen demefactory obj/*.o obj/*/*.o


code:
/*
 *  descriptor_gbe.c
 *  This file is part of the ich9deblob utility from the libreboot project
 *
 * Purpose: common descriptor/gbe functions used by ich9deblob
 *
 *  Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *
 *  This program 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.
 *
 *  This program 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/>.
 */

#include "descriptor_gbe.h"

/*
 * create 12KiB file with descriptor, and then gbe immediately after.
 */
int notCreatedDescriptorGbeFile(struct DESCRIPTORREGIONRECORD descriptorStruct, struct GBEREGIONRECORD_8K gbeStruct8k, char* fileName)
{
	FILE* fileStream = NULL;

	/* delete old file before continuing */
	remove(fileName);

	/* open new file for writing the descriptor+gbe */
	fileStream = fopen(fileName, "ab");

	/* write the descriptor region into the first part */
	if (DESCRIPTORREGIONSIZE != fwrite((uint8_t*)&descriptorStruct, 1, sizeof(descriptorStruct), fileStream))
	{
		printf("\nerror: writing descriptor region failed\n");
		return 1;
	}

	/* add gbe to the end of the file */
	if (GBEREGIONSIZE_8K != fwrite((uint8_t*)&gbeStruct8k, 1, sizeof(gbeStruct8k), fileStream))
	{
		printf("\nerror: writing GBe region failed\n");
		return 1;
	}

	fclose(fileStream);

	printf("descriptor and gbe successfully written to the file: %s\n", fileName);
	printf("Now do: dd if=%s of=libreboot.rom bs=1 count=12k conv=notrunc\n", fileName);
	printf("(in other words, add the modified descriptor+gbe to your ROM image)\n\n");

	return 0;
}

/*
 * create 4KiB file with descriptor
 */
int notCreated4kDescriptorFile(struct DESCRIPTORREGIONRECORD descriptorStruct, char* fileName)
{
	FILE* fileStream = NULL;

	/* delete old file before continuing */
	remove(fileName);

	/* open new file for writing the descriptor+gbe */
	fileStream = fopen(fileName, "ab");

	/* write the descriptor region into the first part */
	if (DESCRIPTORREGIONSIZE != fwrite((uint8_t*)&descriptorStruct, 1, sizeof(descriptorStruct), fileStream))
	{
		printf("\nerror: writing descriptor region failed\n");
		return 1;
	}

	fclose(fileStream);

	printf("descriptor successfully written to the file: %s\n", fileName);
	printf("Now do: dd if=%s of=yourrom.rom bs=1 count=4k conv=notrunc\n", fileName);
	printf("(in other words, add the modified descriptor to your ROM image)\n\n");

	return 0;
}


code:
/*
 *  gbe_descriptor.h
 *  This file is part of the ich9deblob utility from the libreboot project
 *
 * Purpose: header file for descriptor_gbe.c
 *
 *  Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *
 *  This program 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.
 *
 *  This program 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/>.
 */

#ifndef COMMON_DESCRIPTOR_GBE_H
#define COMMON_DESCRIPTOR_GBE_H

#include <stdio.h>
#include <string.h>
#include <stdint.h>

#include "../descriptor/descriptor.h" /* structs describing what's in the descriptor region */
#include "../gbe/gbe.h"               /* structs describing what's in the gbe region */

int notCreatedDescriptorGbeFile(struct DESCRIPTORREGIONRECORD descriptorStruct, struct GBEREGIONRECORD_8K gbeStruct8k, char* fileName);
int notCreated4kDescriptorFile(struct DESCRIPTORREGIONRECORD descriptorStruct, char* fileName);

#endif


code:
/*
 *  x86compatibility.c
 *  This file is part of the ich9deblob utility from the libreboot project
 *
 * Purpose: compiler/cpu compatibility checks. ich9deblob is not portable, yet.
 *
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *                     Francis Rowe <info@gluglug.org.uk>
 *
 *  This program 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.
 *
 *  This program 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/>.
 */

#include "x86compatibility.h"

/*
 * ---------------------------------------------------------------------
 * x86 compatibility checking:
 * ---------------------------------------------------------------------
 */

/* fail if struct size is incorrect */
int structSizesIncorrect(struct DESCRIPTORREGIONRECORD descriptorDummy, struct GBEREGIONRECORD_8K gbe8kDummy)
{
	unsigned int descriptorRegionStructSize = sizeof(descriptorDummy);
	unsigned int gbeRegion8kStructSize = sizeof(gbe8kDummy);

	/* check compiler bit-packs in a compatible way. basically, it is expected that this code will be used on x86 */
	if (DESCRIPTORREGIONSIZE != descriptorRegionStructSize){
		printf("\nerror: compiler incompatibility: descriptor struct length is %i bytes (should be %i)\n", descriptorRegionStructSize, DESCRIPTORREGIONSIZE);
		return 1;
	}
	if (GBEREGIONSIZE_8K != gbeRegion8kStructSize){
		printf("\nerror: compiler incompatibility: gbe struct length is %i bytes (should be %i)\n", gbeRegion8kStructSize, GBEREGIONSIZE_8K);
		return 1;
	}

	return 0;
}

/* fail if members are presented in the wrong order */
int structMembersWrongOrder()
{
	int i;
	struct DESCRIPTORREGIONRECORD descriptorDummy;
	uint8_t *meVsccTablePtr = (uint8_t*)&descriptorDummy.meVsccTable;

	/* These do not use bitfields.  */
	descriptorDummy.meVsccTable.jid0 = 0x01020304;  /* unsigned int 32-bit */
	descriptorDummy.meVsccTable.vscc0 = 0x10203040; /* unsigned int 32-bit */
	descriptorDummy.meVsccTable.jid1 = 0x11223344;  /* unsigned int 32-bit */
	descriptorDummy.meVsccTable.vscc1 = 0x05060708; /* unsigned int 32-bit */
	descriptorDummy.meVsccTable.jid2 = 0x50607080;  /* unsigned int 32-bit */
	descriptorDummy.meVsccTable.vscc2 = 0x55667788; /* unsigned int 32-bit */
	descriptorDummy.meVsccTable.padding[0] = 0xAA;  /* unsigned char 8-bit */
	descriptorDummy.meVsccTable.padding[1] = 0xBB;  /* unsigned char 8-bit */
	descriptorDummy.meVsccTable.padding[2] = 0xCC;  /* unsigned char 8-bit */
	descriptorDummy.meVsccTable.padding[3] = 0xDD;  /* unsigned char 8-bit */

	/*
	 * Look from the top down, and concatenate the unsigned ints but
	 * with each unsigned in little endian order.
	 * Then, concatenate the unsigned chars in big endian order. (in the padding array)
	 *
	 * combined, these should become:
	 * 01020304 10203040 11223344 05060708 50607080 55667788 AA BB CC DD (ignore this. big endian. just working it out manually:)
	 * 04030201 40302010 44332211 08070605 80706050 88776655 AA BB CC DD (ignore this. not byte-separated, just working it out:)
	 * 04 03 02 01 40 30 20 10 44 33 22 11 08 07 06 05 80 70 60 50 88 77 66 55 AA BB CC DD <-- it should match this
	 */

	if (
			!
			(
				*meVsccTablePtr      == 0x04 && *(meVsccTablePtr+1)  == 0x03 && *(meVsccTablePtr+2)  == 0x02 && *(meVsccTablePtr+3)  == 0x01
			&& *(meVsccTablePtr+4)  == 0x40 && *(meVsccTablePtr+5)  == 0x30 && *(meVsccTablePtr+6)  == 0x20 && *(meVsccTablePtr+7)  == 0x10
			&& *(meVsccTablePtr+8)  == 0x44 && *(meVsccTablePtr+9)  == 0x33 && *(meVsccTablePtr+10) == 0x22 && *(meVsccTablePtr+11) == 0x11
			&& *(meVsccTablePtr+12) == 0x08 && *(meVsccTablePtr+13) == 0x07 && *(meVsccTablePtr+14) == 0x06 && *(meVsccTablePtr+15) == 0x05
			&& *(meVsccTablePtr+16) == 0x80 && *(meVsccTablePtr+17) == 0x70 && *(meVsccTablePtr+18) == 0x60 && *(meVsccTablePtr+19) == 0x50
			&& *(meVsccTablePtr+20) == 0x88 && *(meVsccTablePtr+21) == 0x77 && *(meVsccTablePtr+22) == 0x66 && *(meVsccTablePtr+23) == 0x55
			&& *(meVsccTablePtr+24) == 0xAA && *(meVsccTablePtr+25) == 0xBB && *(meVsccTablePtr+26) == 0xCC && *(meVsccTablePtr+27) == 0xDD
	      )
	   ) {

		printf("\nStruct member order check (descriptorDummy.meVsccTable) with junk/dummy data:");
		printf("\nShould be: 04 03 02 01 40 30 20 10 44 33 22 11 08 07 06 05 80 70 60 50 88 77 66 55 aa bb cc dd ");
		printf("\nAnd it is: ");

		for (i = 0; i < 28; i++) {
			printf("%02x ", *(meVsccTablePtr + i));
		}
		printf("\nIncorrect order.\n");

		return 1;
	}

	return 0;
}

/* fail if bit fields are presented in the wrong order */
int structBitfieldWrongOrder()
{
	int i;
	struct DESCRIPTORREGIONRECORD descriptorDummy;
	uint8_t *flMap0Ptr = (uint8_t*)&descriptorDummy.flMaps.flMap0;

	descriptorDummy.flMaps.flMap0.FCBA = 0xA2;      /* :8 --> 10100010 */
	descriptorDummy.flMaps.flMap0.NC = 0x02;        /* :2 --> 10       */
	descriptorDummy.flMaps.flMap0.reserved1 = 0x38; /* :6 --> 111000   */
	descriptorDummy.flMaps.flMap0.FRBA = 0xD2;      /* :8 --> 11010010 */
	descriptorDummy.flMaps.flMap0.NR = 0x05;        /* :3 --> 101      */
	descriptorDummy.flMaps.flMap0.reserved2 = 0x1C; /* :5 --> 11100    */

	/*
	 * Look from the top bottom up, and concatenate the binary strings.
	 * Then, convert the 8-bit groups to hex and reverse the (8-bit)byte order
	 *
	 * combined, these should become (in memory), in binary:
	 * 10100010 11100010 11010010 11100101
	 * or in hex:
	 * A2 E2 D2 E5
	 */

	if (!(*flMap0Ptr == 0xA2 && *(flMap0Ptr+1) == 0xE2 && *(flMap0Ptr+2) == 0xD2 && *(flMap0Ptr+3) == 0xE5))
	{
		printf("\nBitfield order check (descriptorDummy.flMaps.flMaps0) with junk/dummy data:");
		printf("\nShould be: a2 e2 d2 e5 ");
		printf("\nAnd it is: ");

		for (i = 0; i < 4; i++) {
			printf("%02x ", *(flMap0Ptr + i));
		}
		printf("\nIncorrect order.\n");

		return 1;
	}

	return 0;
}

/* Compatibility checks. This version of ich9deblob is not yet porable. */
int systemOrCompilerIncompatible(struct DESCRIPTORREGIONRECORD descriptorStruct, struct GBEREGIONRECORD_8K gbeStruct8k)
{
	if (structSizesIncorrect(descriptorStruct, gbeStruct8k)) return 1;
	if (IS_BIG_ENDIAN) {
		printf("big endian not supported\n");
		return 1;
	}
	if (structBitfieldWrongOrder()) return 1;
	if (structMembersWrongOrder()) return 1;
	return 0;
}


code:
/*
 *  x86compatibility.h
 *  This file is part of the ich9deblob utility from the libreboot project
 *
 * Purpose: keep gcc/make happy. no actual code here, just function definitions.
 *
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *                     Francis Rowe <info@gluglug.org.uk>
 *
 *  This program 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.
 *
 *  This program 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/>.
 */

#ifndef X86COMPATIBILITY_H
#define X86COMPATIBILITY_H

#include <stdio.h>
#include <string.h>
#include <stdint.h>

/* http://esr.ibiblio.org/?p=5095 */
#define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)

#include "../descriptor/descriptor.h" /* structs describing what's in the descriptor region */
#include "../gbe/gbe.h"               /* structs describing what's in the gbe region */

int structSizesIncorrect(struct DESCRIPTORREGIONRECORD descriptorDummy, struct GBEREGIONRECORD_8K gbe8kDummy);
int structMembersWrongOrder();
int structBitfieldWrongOrder();
int systemOrCompilerIncompatible(struct DESCRIPTORREGIONRECORD descriptorStruct, struct GBEREGIONRECORD_8K gbeStruct8k);

#endif