code:
#!/bin/bash

#
#  helper script: generate the source release archive
#
#	Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
#	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)"
	versiondate="$(cat versiondate)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
	versiondate="$(git show -s --format=%ct)"
fi
versiondir="release/oldbuildsystem/${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
	if [ "${resource}" = "release" ]; then
		continue
	fi
	cp -R "${resource}" "${distdir}/"
done

# this has to be done before generating
# the "version" file
if [ ! -f "version" ]; then
	# generate ChangeLog and NEWS files
	rm -f "ChangeLog" "NEWS"
	git log > "${distdir}/ChangeLog"
	cp "${distdir}/ChangeLog" "${distdir}/NEWS"
else
	# building from release archive
	cp "ChangeLog" "${distdir}/"
	cp "NEWS" "${distdir}/"
fi

if [ -f "RELEASE" ]; then
    rm -f "${distdir}/ChangeLog"
    rm -f "${distdir}/NEWS"
    cp "RELEASE" "${distdir}/ChangeLog"
    cp "RELEASE" "${distdir}/NEWS"
fi

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

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

# Clean old builds.
(cd "${distdir}/" && ./oldbuild 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*
rm -Rf "${distdir}/seabios/".git*

rm -f "${distdir}"/*.vim

# 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/"

rm -Rf "${distdir}/resources/grub/patch/"
rm -Rf "${distdir}/resources/memtest86plus/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 Leah Rowe <info@minifree.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/>.
#

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

if [ -f "version" ]; then
	# _src release archive is being used
	version="$(cat version)"
	versiondate="$(cat versiondate)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
	versiondate="$(git show -s --format=%ct)"
fi
versiondir="release/oldbuildsystem/${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}/"

# this has to be done before generating
# the "version" file
if [ ! -f "version" ]; then
	# generate ChangeLog and NEWS files
	rm -f "ChangeLog" "NEWS"
	git log > "${distdir}/ChangeLog"
	cp "${distdir}/ChangeLog" "${distdir}/NEWS"
else
	# building from release archive
	cp "ChangeLog" "${distdir}/"
	cp "NEWS" "${distdir}/"
fi

if [ -f "RELEASE" ]; then
    rm -f "${distdir}/ChangeLog"
    rm -f "${distdir}/NEWS"
    cp "RELEASE" "${distdir}/ChangeLog"
    cp "RELEASE" "${distdir}/NEWS"
fi

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

# 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}"

repo_name: zyliwax/libreboot

license: mit


code:
#!/bin/bash

#
#  helper script: generate the release archives
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.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 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)"
	versiondate="$(cat versiondate)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
	versiondate="$(git show -s --format=%ct)"
fi
versiondir="release/oldbuildsystem/${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}/"

# this has to be done before generating
# the "version" file
if [ ! -f "version" ]; then
	# generate ChangeLog and NEWS files
	rm -f "ChangeLog" "NEWS"
	git log > "${distdir}/ChangeLog"
	cp "${distdir}/ChangeLog" "${distdir}/NEWS"
else
	# building from release archive
	cp "ChangeLog" "${distdir}/"
	cp "NEWS" "${distdir}/"
fi

if [ -f "RELEASE" ]; then
    rm -f "${distdir}/ChangeLog"
    rm -f "${distdir}/NEWS"
    cp "RELEASE" "${distdir}/ChangeLog"
    cp "RELEASE" "${distdir}/NEWS"
fi

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

# --------------
# 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
./oldbuild 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
./oldbuild 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 "crossgcc/util/"
cp -R "cbfstool" "cbfstool_/"
cd "cbfstool/"
sed -i '/.*fmd_scanner.o.*-Wno-unused-function$/ s/$/ -Wno-sign-compare/'  Makefile.inc # build fix for latest flex version
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 "crossgcc/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}/"

# grubeditor.sh script
cp "resources/scripts/misc/grubeditor.sh" "${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 SeaGRUB and put them in ./bin/
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
#	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 git or release archive

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

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

# The GRUB files should be deleted first
rm -f "coreboot/grub"*.{elf,cfg}
rm -f "coreboot/"*/*/grub*.{elf,cfg}

[ -d bin ] || mkdir "bin/"

# 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,"${romtype}"}.cfg > "grub_${keymap}_${romtype}.cfg"
		printf "keymap %s\n" "${keymap}" >> "grub_${keymap}_${romtype}.cfg"
		cat ../resources/grub/config/menuentries/{common,"${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
)

# Build ROM images for supported boards
buildrom() {
	board="$1"
	if [ -f "resources/libreboot/config/grub/${board}/config" ]; then
		./oldbuild 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

# 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" "t400" "t500" "w500"
	do
		for romsize in "4m" "8m" "16m"
		do
			if [ -d "${board}_${romsize}b/" ]; then
				cd "${board}_${romsize}b/"
				if [ -f "../../../gm45macaddress" ]; then
					../../../resources/utilities/ich9deblob/ich9gen --macaddress $(cat ../../../gm45macaddress)
				else
					../../../resources/utilities/ich9deblob/ich9gen
				fi
				for rom in *.rom
				do
					dd if="ich9fdgbe_${romsize}.bin" of="${rom}" bs=1 count=12k conv=notrunc
				done
				rm -f "ich9fd"*.bin "mk"*.[ch]
				cd "../"
			fi
		done
	done
	cd ../../
fi

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

printf "\n\n"


code:
#!/bin/bash

#  helper script: create ROM images for a given system, with SeaGRUB
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
#	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 git or release archive

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
if [ -z ${NPROC+x} ]; then
    cores="$(nproc)"
else
    case ${NPROC} in
        ''|*[!0-9]*)
            printf "value '%s' for NPROC is invalid. non-numeric. Exiting.\n" "${NPROC}"
            exit 1
            ;;
    esac
    cores="${NPROC}"
fi

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

boardtarget="${1}"

if [ -f "version" ]; then
	# release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi

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

(
cbrevision="$(cat resources/libreboot/config/grub/${boardtarget}/cbrevision)"
vbootrevision="$(cat resources/libreboot/config/grub/${boardtarget}/vbootrevision)"
branchname="grub_${boardtarget}"

cd "coreboot/${cbrevision}/${cbrevision}/"
git checkout ${branchname}
(
    cd "3rdparty/vboot/"
    git checkout ${branchname}
)

# Make sure to remove these first
rm -f *.{elf,cfg}

printf 'libreboot-%s\n' "${version}" > ".coreboot-version" # needed for reproducible builds in coreboot

# 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}" = "kgpe-d16" ] || [ "${boardtarget}" = "ga-g41m-es2l" ] || [ "${boardtarget}" = "kcma-d8" ] || [ "${boardtarget}" = "d510mo" ]; then
		if [ "${romtype}" = "vesafb" ]; then
			printf "Only text-mode is reported to work on KGPE-D16, KCMA-D8, D510MO and ga-g41m-es2l\n"
			printf "TODO: get tpearson to fix it\n"
			continue
		fi
	fi

	# Build coreboot ROM image
	make clean
	mv "config_${romtype}" ".config"
	cp "../../grub_${romtype}.elf" "grub.elf"
    if [ "${boardtarget}" = "d510mo" ] || [ "${boardtarget}" = "ga-g41m-es2l" ]; then
        # Do not use SeaGRUB
        cp grub.elf payload.elf
	    make -j${cores}
        mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"

        # We dont need seabios.elf anymore
        rm -f "payload.elf"
    else
        # Use SeaGRUB
        cp "../../../seabios/out/bios.bin.elf" "payload.elf"
	    make -j${cores}

	    mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"

        # We dont need seabios.elf anymore
         rm -f "payload.elf"
        # Add the grub.elf to CBFS
        ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-payload -c lzma -f grub.elf -n img/grub2

        # Set bootorder so that seabios loads grub by default
        printf "/rom@img/grub2\n" > bootorder
        ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f bootorder -n bootorder -t raw
        rm -f bootorder

        # Add 0s delay to seabios, so that the user is not burdened by seeing
        # that horrible interface that seabios has
        ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 0 -n etc/show-boot-menu || "already exists"

        # Add a file to CBFS that tells SeaBIOS not to load option ROMs
        ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 0 -n etc/pci-optionrom-exec || "already exists"

        # keyboard spinup timeout
       ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" remove -n etc/ps2-keyboard-spinup || printf "does not exist"
       ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 3000 -n etc/ps2-keyboard-spinup || printf "already exists"
    fi

    printf "%s\n" "${version}" > lbversion
    ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f lbversion -n lbversion -t raw
    rm -f "lbversion"

    # we dont need that grub.elf now
    rm -f "grub.elf"

	# .config no longer needed
	rm -f ".config"

	# Add the background image
	if [ "$romtype" = "vesafb" ]
	then
		if [ "$1" = "macbook21" ] || [ "$1" = "x200_4mb" ] || [ "$1" = "x200_8mb" ] || [ "$1" = "x200_16mb" ] || [ "$1" = "r400_4mb" ] || [ "$1" = "r400_8mb" ] || [ "$1" = "r400_16mb" ] || [ "$1" = "t400_4mb" ] || [ "$1" = "t400_8mb" ] || [ "$1" = "t400_16mb" ] || [ "$1" = "t500_4mb" ] || [ "$1" = "t500_8mb" ] || [ "$1" = "t500_16mb" ] || [ "$1" = "w500_4mb" ] || [ "$1" = "w500_8mb" ] || [ "$1" = "w500_16mb" ]

		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

# Clean up and prepare bin/ containing all ROM images

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

# delete old ROM images
rm -Rf "../../../bin/grub/${boardtarget}/"
# put new ROM images in ../bin/grub/
[ -d "../../../bin/grub/" ] || mkdir -p "../../../bin/grub/"
mv "${boardtarget}/" "../../../bin/grub/"

# version info file no longer needed
rm -f ".coreboot-version"

git checkout master
(
    cd "3rdparty/vboot/"
    git checkout master
)
)

printf "\n\n"


code:
#!/bin/bash

#
#  helper script: build ROM images with SeaBIOS and put them in ./bin/seabios/
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
#	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 git or release archive

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

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

[ -d bin ] || mkdir "bin/"

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

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

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

printf "\n\n"


code:
#!/bin/bash

#  helper script: create ROM images for a given system, with SeaBIOS
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
#	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 git or release archive

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
if [ -z ${NPROC+x} ]; then
    cores="$(nproc)"
else
    case ${NPROC} in
        ''|*[!0-9]*)
            printf "value '%s' for NPROC is invalid. non-numeric. Exiting.\n" "${NPROC}"
            exit 1
            ;;
    esac
    cores="${NPROC}"
fi

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

boardtarget="${1}"

if [ -f "version" ]; then
	# release archive is being used
	version="$(cat version)"
else
	# git repo is being used
	version="$(git describe --tags HEAD)"
fi

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

(
cbrevision="$(cat resources/libreboot/config/seabios/${boardtarget}/cbrevision)"
vbootrevision="$(cat resources/libreboot/config/seabios/${boardtarget}/vbootrevision)"
branchname="seabios_${boardtarget}"

cd "coreboot/${cbrevision}/${cbrevision}/"
git checkout ${branchname}
(
    cd "3rdparty/vboot/"
    git checkout ${branchname}
)

# Make sure to remove these first
rm -f *{elf,cfg}

printf 'libreboot-%s\n' "${version}" > ".coreboot-version" # needed for reproducible builds in coreboot

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

for romtype in txtmode vesafb
do
	if [ "${boardtarget}" = "kgpe-d16" ] || [ "${boardtarget}" = "kcma-d8" ] || [ "${boardtarget}" = "d945gclf" ]; then
		if [ "${romtype}" = "vesafb" ]; then
			printf "Only text-mode is reported to work on KGPE-D16, KCMA-D8, d945gclf\n"
			continue
		fi
	fi

    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/seabios/${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/seabios/${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

	# Build coreboot ROM image
	make clean
	cp "../../../seabios/out/bios.bin.vga.elf" "payload.elf"
    mv "config_${romtype}" .config
    make -j${cores}
	rm -f "payload.elf"
	mv "build/coreboot.rom" "${boardtarget}_${romtype}.rom"

    # Now add SeaVGABIOS (SeaBIOS wrapper for coreboot native video init)
    ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add -f ../../../seabios/out/vgabios.bin -n vgaroms/vgabios.bin -t raw

    # Add a file to CBFS that tells SeaBIOS not to load option ROMs
    ./util/cbfstool/cbfstool "${boardtarget}_${romtype}.rom" add-int -i 0 -n etc/pci-optionrom-exec || "already exists"

	# .config no longer needed
	rm -f ".config"
done

# Clean up and prepare bin/ containing all ROM images

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

# delete old ROM images
rm -Rf "../../../bin/seabios/${boardtarget}/"
# put new ROM images in ../bin/grub/
[ -d "../../../bin/seabios/" ] || mkdir -p "../../../bin/seabios/"
mv "${boardtarget}/" "../../../bin/seabios/"

# version info file no longer needed
rm -f ".coreboot-version"

git checkout master
(
    cd "3rdparty/vboot/"
    git checkout master
)
)

printf "\n\n"


code:
#!/bin/bash

#  helper script: downloads bucts and patches it
#
#	Copyright (C) 2014, 2015 Leah Rowe <info@minifree.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 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, 2016 Leah Rowe <info@minifree.org>
#	Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
#
#    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

if [ -f "version" ]; then
	# _src release archive is being used
	version="libreboot-$(cat version)"
else
	# git repo is being used
	version="libreboot-$(git describe --tags HEAD)"
fi

make_coreboot_src_directory() {
    payload="${1}"
    cbrevision="${2}"
    vbootrevision="${3}"
    firmwarepath="${4}" # libreboot_src/coreboot/
(
    cd "${firmwarepath}/"
    # copy coreboot directory there
    rm -Rf "${payload:?}/${cbrevision:?}/"
    if [ ! -d "${payload}/" ]; then
        mkdir -p "${payload}/"
    fi
    cp -R "coreboot/" "${payload}/${cbrevision}/"

    # We need to reset that revision of coreboot to the specified revision
    cd "${payload}/${cbrevision}/"
    git reset --hard ${cbrevision}

    if [ "${vbootrevision}" != "no_vboot_revision" ]; then
        # reset vboot revision. in practise, we always use the same
        # vboot revision on all boards that use a given coreboot revision
        cd "3rdparty/vboot/"
        git reset --hard ${vbootrevision}
    fi
)
}

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/"

mkdir "coreboot/"

cd "coreboot/"

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

# download it using git
git clone https://review.coreboot.org/coreboot || git clone https://github.com/coreboot/coreboot.git

# there are modifications required
cd "coreboot/"

# Define a common version (based on the libreboot version)
# Most likely redundant, because the build system needs to update
# this every time when building a ROM image anyway
printf '%s\n' "${version}" >".coreboot-version"

# vboot submodule is needed
# ------------------------------------------------------------------------------

git submodule update --init --checkout -- 3rdparty/vboot/

# Create branches, with patches in each branch
# Create separate coreboot source directories *for each board*
# ------------------------------------------------------------------------------

for payloads in ../../resources/libreboot/config/*; do

	if [ ! -d "${payloads}/" ]; then
		continue
	fi

	payload="${payloads##*/}"

	for boardconfig in ../../resources/libreboot/config/${payload}/*; do

		if [ ! -d "${boardconfig}/" ]; then
			continue
		fi

		cbrevision=$(cat "${boardconfig}/cbrevision")
		vbootrevision=$(cat "${boardconfig}/vbootrevision")

        # the same vboot revision is always used for coreboot revision,
        # so we don't need to wworry about checking for that here

        if [ -d "../${cbrevision}/${cbrevision}" ]; then
            continue
            # the directory already exists, no need to recreate it
        fi

		make_coreboot_src_directory ${cbrevision} ${cbrevision} ${vbootrevision} ..
	done
done

# go back to _src/coreboot/ (containing all coreboot directories)
cd "../"
# delete the gitted one (not needed anymore)
rm -Rf "coreboot/"

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

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

# Delete crossgcc from non-crossgcc coreboot archives
# (the build system will create symlinks later when building the ROM images)
for payload in *; do
	if [ "${payload##*/}" != "crossgcc" ]; then
		rm -Rf ${payload:?}/*/util/crossgcc/
	fi
done
cd "../"

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

printf "\n\n"


code:
#!/bin/bash

#  helper script: downloads crossgcc, for building coreboot
#
#	Copyright (C) 2016 Leah Rowe <info@minifree.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

if [ -f "version" ]; then
	# _src release archive is being used
	version="libreboot-$(cat version)"
else
	# git repo is being used
	version="libreboot-$(git describe --tags HEAD)"
fi

# coreboot revisios used for crossgcc
crossgccrevision="35562d8b6477058e6bca31b5cedd9d4897124fc7"
vbootrevision="d187cd3fc792f8bcefbee4587c83eafbd08441fc"

rm -Rf "crossgcc/"
(
    git clone https://review.coreboot.org/coreboot crossgcc || git clone https://github.com/coreboot/coreboot.git crossgcc
    cd "crossgcc/"
    git reset --hard ${crossgccrevision}
    git submodule update --init --checkout -- 3rdparty/vboot/
    (
        cd 3rdparty/vboot/
        git reset --hard ${vbootrevision}
    )
    # workaround to fix the error on debian stretch and later, when building
    # GMP. If -pie is enabled in GCC, then --with-pic must be used when compiling
    git am ../resources/libreboot/patch/crossgcc/gccfix.diff
    rm -Rf .git* */*/.git*
)

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


code:
#!/bin/bash

#  helper script: downloads flashrom and patches it
#
#	Copyright (C) 2014, 2015 Leah Rowe <info@minifree.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 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 git
git clone https://github.com/stefanct/flashrom.git

(
cd "flashrom/"

# reset to known revision
git checkout 0.9.9
git reset --hard

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

printf "Enabling whitelist for X200S, X200 Tablet, T400, T500, W500 and R400\n"
git am "../resources/flashrom/patch/0001-New-laptops-whitelisted-ThinkPad-R400-and-ThinkPad-T.patch"

printf "Enabling whitelist for Libiquity Taurinus X200\n"
git am "../resources/flashrom/patch/0002-Add-whitelist-for-Taurinus-X200-laptop.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"
git am "../resources/flashrom/patch/0003-purged-chips.patch"
)

printf "\n\n"


code:
#!/bin/bash

#  helper script: Downloads GRUB and patches it.
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.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

# 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 || git clone http://git.savannah.gnu.org/r/grub.git

# modifications are required
cd "grub/"

# reset to known revision
git reset --hard 7f2a856faec951b7ab816880bd26e1e10b17a596

# 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"

# GRUB enhancement patches from grub.johnlane.ie (rebased in libreboot's GRUB, unofficially, on 30 November 2015)
git am "../resources/grub/patch/grub.johnlane.ie/0001-Cryptomount-support-LUKS-detached-header.patch"
git am "../resources/grub/patch/grub.johnlane.ie/0002-Cryptomount-support-key-files.patch"
git am "../resources/grub/patch/grub.johnlane.ie/0003-Cryptomount-luks-allow-multiple-passphrase-attempts.patch"
git am "../resources/grub/patch/grub.johnlane.ie/0004-Cryptomount-support-plain-dm-crypt.patch"
git am "../resources/grub/patch/grub.johnlane.ie/0005-Cryptomount-support-for-hyphens-in-UUID.patch"
# hotfix from kl3 (merged from autoboot) (ditto)
git am "../resources/grub/patch/grub.johnlane.ie/0006-grub-core-disk-cryptodisk.c-Point-to-const-char.patch"

# Needed for reproducible builds in GRUB
git am "../resources/grub/patch/reproducible/0001-mkstandalone-add-argument-fixed-time-to-override-mti.patch"
git am "../resources/grub/patch/reproducible/0002-mkrescue-add-argument-fixed-time-to-get-reproducible.patch"
git am "../resources/grub/patch/reproducible/0003-Makefile-use-FIXED_TIMESTAMP-for-mkstandalone-if-set.patch"

cd "../"

# Also download SeaBIOS, which we use with GRUB, to implement SeaGRUB
./download seabios

printf "\n\n"

path: resources/scripts/helpers/download/grub


code:
#!/bin/bash

#  helper script: Downloads MemTest86+ and patches it
#
#	Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
#	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/"

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

(
cd "memtest86plus/"
for patch in ../resources/memtest86plus/patch/*; do
	patch < "${patch}"
done
)

printf "\n\n"


code:
#!/bin/bash
#
#   Copyright (C) 2015, 2016 Leah Rowe <info@minifree.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 SeaBIOS, revert to commit last used and apply patches.

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

printf "Downloading SeaBIOS\n"

rm -rf "seabios/"

# Get latest SeaBIOS
# ------------------------------------------------------------------------------

# download it using git
git clone git://git.seabios.org/seabios.git seabios

(
# modifications are required
cd "seabios/"

# Reset to the last commit that was tested (we use stable releases for seabios)
# ------------------------------------------------------------------------------

git reset --hard rel-1.9.1
)


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
#
# grubeditor.sh -- conveniently edit grub{test}.cfg files by automating their
# extraction with cbfstool and the user's editor of choice.
#
#  Copyright (C) 2017 Zyliwax <zyliwax@protonmail.com>
#
#    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/>.
#

# Usage:
# ./grubeditor.sh [options] romimage
#
# Supported options:
#
# -h | --help: show usage help
#
# -r | --realcfg: generate grub.cfg instead of grubtest.cfg
#
# -i | --inplace: do not create a .modified romfile, instead modify the
# existing file
#
# -e | --editor /path/to/editor: open the cfg file with /path/to/editor instead
# of $EDITOR
#
# -s | --swapcfg: swap grub.cfg and grubtest.cfg, incompatible with other
# options besides -i
#
# -x | --extractcfg: extract either grub.cfg or grubtest.cfg depending on
# whether -r is set
#
# -d | --diffcfg: diff grub.cfg and grubtest.cfg, incompatible with other
# options besides -D
#
# -D | --differ [/path/to/]differ: use /path/to/differ instead of "diff", can
# be an interactive program like vimdiff
#

# THIS BLOCK IS EXPERIMENTAL
# Allow debugging by running DEBUG= ${0}.
[[ "x${DEBUG+set}" = 'xset' ]] && set -v
# -u kills the script if any variables are unassigned
# -e kills the script if any function returns not-zero
#set -u

# Version number of script
geversion="0.1.1"

# Define the list of available option in both short and long form.
shortopts="hrie:sdD:"
longopts="help,realcfg,inplace,editor:,swapcfgs,diffcfgs,differ:"

# Variables for modifying the program's operation
edit_realcfg=0
edit_inplace=0
do_swapcfgs=0
do_diffcfgs=0
# Path to cbfstool, filled by detect_architecture
# (Possible to provide explicitly and disclaim warranty?)
cbfstool=""
# Editor variables
use_editor=""
default_editor="vi"
editor_rawarg=""
# Differ variables
use_differ=""
default_differ="diff"
differ_rawarg=""
# Last but not least, the rom file itself
romfile=""

# This program works primarily from a cascade of functions. Let's define them.

get_options() {
    # Test for enhanced getopt.
    getopt --test > /dev/null
    if [[ $? -ne 4 ]]; then
        echo "Your environment lacks enhanced getopt, so you cannot run this script properly."
        exit 205
    fi

    # Parse the command line options based on the previously defined values.
    parsedopts=$(getopt --options ${shortopts} --longoptions ${longopts} --name "${0}" -- "$@")
    if [[ $? -ne 0 ]]; then # getopt didn't approve of your arguments
        echo "Unrecognized options."
        exit 206
    fi

    # Use eval set to properly quote the arguments
    eval set -- "$parsedopts"

    # Interpret the arguments one-by-one until you run out.
    while [[ 1 ]]; do
        case "$1" in
            -h|--help)
                show_help
                # I return non-zero here just so nobody thinks we successfully edited grub{,test}.cfg
                exit 200
                ;;
            -v|--version)
                show_version
                # I return non-zero here just so nobody thinks we successfully edited grub{,test}.cfg
                exit 201
                ;;
            -r|--realcfg)
                edit_realcfg=1
                shift
                ;;
            -i|--inplace)
                edit_inplace=1
                shift
                ;;
            -e|--editor)
                editor_rawarg="$2"
                shift 2
                ;;
            -s|--swapcfgs)
                do_swapcfgs=1
                shift
                ;;
            -d|--diffcfgs)
                do_diffcfgs=1
                shift
                ;;
            -D|--differ)
                differ_rawarg="$2"
                shift 2
                ;;
            --)
                # Stop interpreting arguments magically.
                shift
                break
                ;;
            *)
                echo "Something went wrong while interpreting the arguments!"
                echo "I hit \"${1}\" and don't know what to do with it."
                exit 209
                ;;
        esac
    done

    # The only option remaining should be the input file. Ensure it was
    # provided before proceeding with the rest of the script and capture it if
    # it was.
    if [[ $# -ne 1 ]]; then
        echo "You have specified multiple (or no) input files, which is unsupported."
        echo "Please rerun this command with just a single filename to remove any chance for ambiguity."
        exit 210
    fi
    romfile="$1"
}

determine_architecture() {
    # The cbfstool in _util is packed only for i686, x86_64, and armv7l. This
    # procedure is necessary for this process to not fail. After this process
    # is over, the variable $cbfstool gets filled with the appropriate value
    # for use by the rest of the script.
    arch="$(uname -m)"
    case "${arch}" in
        armv7l|i686|x86_64)
            echo "Supported architecture \"${arch}\" detected. You may proceed."
            cbfstool="${0%/*}/cbfstool/${arch}/cbfstool"
            ;;
        *)
            echo "Unsupported architecture \"${arch}\" detected! You may not proceed."
            exit 230
            ;;
    esac
}

determine_operation() {
    if [[ $do_swapcfgs -eq 1 ]]; then
        swap_configs
        exit $?
    elif [[ $do_diffcfgs -eq 1 ]]; then
        diff_configs
        exit $?
    else
        edit_config
        exit $?
    fi
}

# These functions are not part of the primary function cascade but are
# referenced within them either directly or indirectly from other helper
# functions depending on the operations requested by the user.

# External command finders.
find_differ() {
    found_differ=0

    if [[ -n "${differ_rawarg}" ]]; then
        which "${differ_rawarg}" &> /dev/null
        if [[ $? -eq 0 ]]; then
            echo "Using differ \"${differ_rawarg}\"..."
            use_differ="${differ_rawarg}"
            found_differ=1
        else
            echo "The provided \"${differ_rawarg}\" is not a valid command!"
            echo "Defaulting to ${default_differ}..."
            use_differ="${default_differ}"
        fi
    fi

    if [[ $found_differ -eq 1 ]]; then
        return
    else
        echo "Defaulting to ${default_differ}..."
        use_differ="${default_differ}"
    fi
}

find_editor() {
    found_editor=0

    if [[ -n "${editor_rawarg}" ]]; then
        which "${editor_rawarg}" &> /dev/null
        if [[ $? -eq 0 ]]; then
            echo "Using editor \"${editor_rawarg}\"..."
            use_editor="${editor_rawarg}"
            found_editor=1
        else
            echo "The provided \"${editor_rawarg}\" is not a valid command!"
            echo "Defaulting to ${default_editor}..."
            use_editor="${default_editor}"
        fi
    fi

    if [[ $found_editor -eq 1 ]]; then
        return
    else
        if [[ -n "${EDITOR}" ]]; then
            which "${EDITOR}" &> /dev/null
            if [[ $? -ne 0 ]]; then
                echo "Your \$EDITOR is defined as ${EDITOR}, but is not a valid command!"
                echo "(This is bad. I highly suggest fixing this in your ~/.bashrc.)"
                echo "Defaulting to ${default_editor}..."
                use_editor="${default_editor}"
            else
                echo "Using your defined \$EDITOR \"$EDITOR\"..."
                use_editor="${EDITOR}"
            fi
        else
            echo "\$EDITOR blank, defaulting to ${default_editor}..."
            use_editor="${default_editor}"
        fi
    fi
}

# Filename randomizer.
random_filer() {
    # Inputs:
    # $1 is a descriptive label for the file
    # $2 is directory (becomes /tmp if not set)
    [[ -n "${1}" ]] && label="${1}" || label="tempfile"
    [[ -n "${2}" ]] && savedir="${2%/}" || savedir="/tmp"

    # Hardcoded string size for multiple good reasons (no processing weird
    # input, prevent malicious overflows, etc.)
    size=5

    # Loop forever until a free filename is found.
    while [[ 1 ]]; do

        # Read data from /dev/urandom and convert into random ASCII strings.
        rand=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w $size | head -n 1)

        # Build a complete filename with a hardcoded extension.
        possible="${savedir}/${label}_${rand}.tmp.cfg"

        # See if file doesn't exist and return it as string or keep going.
        if [[ ! -f "${possible}" ]]; then
            echo "${possible}"
            break
        fi

    done
}

# Primary command functions.
show_help() {
    cat << HELPSCREEN
"${0}" -- conveniently edit grub{test}.cfg files in Libreboot ROM image files by automating their extraction with cbfstool and the user's editor of choice.

Usage:

"${0}" [OPTIONS] [ROMFILE]

Options:

-h | --help: show usage help

-r | --realcfg: generate grub.cfg instead of grubtest.cfg

-i | --inplace: do not create a .modified romfile, instead modify the
existing file

-e | --editor [/path/to/]editor: open the cfg file with /path/to/editor instead of the value of \$EDITOR

-s | --swapcfg: swap grub.cfg and grubtest.cfg

-d | --diffcfg: diff grub.cfg and grubtest.cfg

-D | --differ [/path/to/]differ: use /path/to/differ instead of "diff", can be an interactive program like vimdiff
HELPSCREEN
}

show_version() {
    echo "${geversion}"
}

swap_configs() {
    # Procedure:
    # 1. Call cbfstool twice, once each to extract grub.cfg and grubtest.cfg.
    # 2. If --inplace not specified, copy ${romfile} to ${romfile}.modified and
    # implement remaining steps on this copy. Otherwise, implement remaining
    # steps on ${romfile}.
    # 3. Call cbfstool twice, once each to delete grub.cfg and grubtest.cfg
    # from romfile.
    # 4. Call cbfstool twice, once to embed grubtest.cfg as grub.cfg into
    # romfile and again to embed grub.cfg as grubtest.cfg into romfile.
    # 5. Delete the extracted grub.cfg and grubtest.cfg files.
    # 6. You're done!

    # Extract config files from provided romfile.
    real2test="$(random_filer "real2test")"
    test2real="$(random_filer "test2real")"
    "${cbfstool}" "${romfile}" extract -n grub.cfg -f "${real2test}"
    "${cbfstool}" "${romfile}" extract -n grubtest.cfg -f "${test2real}"

    # Determine whether to edit inplace or make a copy.
    if [[ $edit_inplace -eq 1 ]]; then
        outfile="${romfile}"
    else
        cp "${romfile}" "${romfile}.modified"
        outfile="${romfile}.modified"
    fi

    # Remove config files from the output file.
    "${cbfstool}" "${outfile}" remove -n grub.cfg
    "${cbfstool}" "${outfile}" remove -n grubtest.cfg

    # Embed new configs into the output file.
    "${cbfstool}" ${outfile} add -t raw -n grub.cfg -f "${test2real}"
    "${cbfstool}" ${outfile} add -t raw -n grubtest.cfg -f "${real2test}"

    # Delete the tempfiles.
    rm "${test2real}" "${real2test}"
}

diff_configs() {
    # Procedure:
    # 1. Call cbfstool twice, once to extract grub.cfg and grubtest.cfg.
    # 2. Execute ${use_differ} grub.cfg grubtest.cfg #.
    # 3. Delete the extracted grub.cfg and grubtest.cfg files.
    # 4. You're done!

    # Determine the differ command to use.
    find_differ

    grubcfg="$(random_filer "grubcfg")"
    testcfg="$(random_filer "testcfg")"

    # Extract config files from provided romfile.
    "${cbfstool}" "${romfile}" extract -n grub.cfg -f "${grubcfg}"
    "${cbfstool}" "${romfile}" extract -n grubtest.cfg -f "${testcfg}"

    # Run the differ command with real as first option, test as second option.
    "${use_differ}" "${grubcfg}" "${testcfg}"

    # Delete the temporary copies of the configuration files.
    rm "${grubcfg}"
    rm "${testcfg}"
}

edit_config() {
    # Procedure:
    # 1. If --realcfg specified, set ${thisconfig} to "grub.cfg". Otherwise,
    # set ${thisconfig} to "grubtest.cfg".
    # 2. Call cbfstool once to extract ${thisconfig} from ${romfile}.
    # 3. Run ${use_editor} ${thisconfig}.
    # 4. If ${use_editor} returns zero, proceed with update procedure:
    # 5. Call cbfstool once to extract ${thisconfig} from ${romfile}.
    # 6. Quietly diff the extracted file with the edited file. If diff returns
    # zero, take no action: warn the user that the files were the same, delete
    # both files, then skip the remaining steps (you're done)! Otherwise, the
    # files are different and you must continue with the update procedure.
    # 7. If --inplace not specified, copy ${romfile} to ${romfile}.modified and
    # implement remaining steps on this copy. Otherwise, implement remaining
    # steps on ${romfile}.
    # 8. Call cbfstool once to delete internal pre-update ${thisconfig} from
    # the rom file.
    # 9. Call cbfstool once to embed the updated ${thisconfig} that was just
    # edited into the rom file.
    # 10. Alert the user of success (either explicitly or by not saying
    # anything, either way return zero).
    # 11. You're done!

    # Determine the editor command to use.
    find_editor

    # Determine whether we are editing the real config or the test config.
    if [[ $edit_realcfg -eq 1 ]]; then
        thisconfig="grub.cfg"
    else
        thisconfig="grubtest.cfg"
    fi

    # Extract the desired configuration file from the romfile.
    tmp_editme="$(random_filer "${thisconfig%.cfg}")"
    "${cbfstool}" "${romfile}" extract -n "${thisconfig}" -f "${tmp_editme}"

    # Launch the editor!
    "${use_editor}" "${tmp_editme}"

    # Did the user commit the edit?
    if [[ $? -eq 0 ]]; then
        # See if it actually changed from what exists in the cbfs.
        tmp_refcfg="/tmp/${thisconfig%.cfg}_ref.cfg"
        "${cbfstool}" "${romfile}" extract -n "${thisconfig}" -f "${tmp_refcfg}"
        # Diff the files as quietly as possible.
        diff -q "${tmp_editme}" "${tmp_refcfg}" &> /dev/null
        if [[ $? -ne 0 ]]; then
            # The files differ, so it won't be frivolous to update the config.
            # See if the user wants to edit the file in place.
            # (This code should really be genericized and placed in a function
            # to avoid repetition.)
            if [[ $edit_inplace -eq 1 ]]; then
                outfile="${romfile}"
            else
                cp "${romfile}" "${romfile}.modified"
                outfile="${romfile}.modified"
            fi
            # Remove the old config, add in the new one.
            "${cbfstool}" "${outfile}" remove -n "${thisconfig}"
            "${cbfstool}" "${outfile}" add -t raw -n "${thisconfig}" -f "${tmp_editme}"
        else
            echo "No changes to config file. Not updating the ROM image."
        fi
        # We are done with the config files. Delete them.
        rm "${tmp_editme}"
        rm "${tmp_refcfg}"
    fi
}

# Run through the primary function cascade.
get_options $@
determine_architecture
determine_operation


code:
#! /bin/sh
################################################################################
#   Copyright (C) 2016 Namine Ritsu <ritsu73@ecantorix.moe>                    #
#                                                                              #
#   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/>.      #
#                                                                              #
################################################################################

### BEGIN INIT INFO
# Provides:		libreboot_usb_bugfix
# Required-Start:	$remote_fs $syslog
# Required-Stop:	$remote_fs $syslog
# Default-Start:	2 3 4 5
# Default-Stop:
# Short-Description:	Disable USB wakeup on libreboot machines
### END INIT INFO

case "$1" in
  start)
	EHC1=$(cat /proc/acpi/wakeup | grep EHC1 | grep enabled | wc -l)
	EHC2=$(cat /proc/acpi/wakeup | grep EHC2 | grep enabled | wc -l)
	if [ "$EHC1" -gt 0 ]
	then
		echo EHC1 > /proc/acpi/wakeup
	fi
	if [ "$EHC2" -gt 0 ]
	then
		echo EHC2 > /proc/acpi/wakeup
	fi
	;;
  status)
	cat /proc/acpi/wakeup | grep EHC
	;;
  *)
	echo "Usage: /etc/init.d/libreboot_usb_bugfix {start|status}"
	exit 1
esac

exit 0


code:
#!/bin/bash

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

[ "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:
#
# Automatically generated file; DO NOT EDIT.
# SeaBIOS Configuration
#

#
# General Features
#
CONFIG_COREBOOT=y
# CONFIG_QEMU is not set
# CONFIG_CSM is not set
# CONFIG_QEMU_HARDWARE is not set
CONFIG_THREADS=y
CONFIG_RELOCATE_INIT=y
CONFIG_BOOTMENU=y
CONFIG_BOOTSPLASH=y
CONFIG_BOOTORDER=y
CONFIG_COREBOOT_FLASH=y
CONFIG_LZMA=y
CONFIG_CBFS_LOCATION=0
CONFIG_MULTIBOOT=y
CONFIG_ENTRY_EXTRASTACK=y
CONFIG_MALLOC_UPPERMEMORY=y
CONFIG_ROM_SIZE=0

#
# Hardware support
#
CONFIG_ATA=y
# CONFIG_ATA_DMA is not set
# CONFIG_ATA_PIO32 is not set
CONFIG_AHCI=y
CONFIG_SDCARD=y
CONFIG_MEGASAS=y
CONFIG_FLOPPY=y
CONFIG_FLASH_FLOPPY=y
CONFIG_PS2PORT=y
CONFIG_USB=y
CONFIG_USB_UHCI=y
CONFIG_USB_OHCI=y
CONFIG_USB_EHCI=y
CONFIG_USB_XHCI=y
CONFIG_USB_MSC=y
CONFIG_USB_UAS=y
CONFIG_USB_HUB=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_MOUSE=y
CONFIG_SERIAL=y
CONFIG_LPT=y
CONFIG_RTC_TIMER=y
CONFIG_HARDWARE_IRQ=y
CONFIG_PMTIMER=y
CONFIG_TSC_TIMER=y

#
# BIOS interfaces
#
CONFIG_DRIVES=y
CONFIG_CDROM_BOOT=y
CONFIG_CDROM_EMU=y
CONFIG_PCIBIOS=y
CONFIG_APMBIOS=y
CONFIG_PNPBIOS=y
CONFIG_OPTIONROMS=y
CONFIG_PMM=y
CONFIG_BOOT=y
CONFIG_KEYBOARD=y
CONFIG_KBD_CALL_INT15_4F=y
CONFIG_MOUSE=y
CONFIG_S3_RESUME=y
CONFIG_VGAHOOKS=y
# CONFIG_DISABLE_A20 is not set
CONFIG_TCGBIOS=y

#
# VGA ROM
#
CONFIG_NO_VGABIOS=y
# CONFIG_VGA_GEODEGX2 is not set
# CONFIG_VGA_GEODELX is not set
# CONFIG_VGA_COREBOOT is not set
# CONFIG_BUILD_VGABIOS is not set
CONFIG_VGA_EXTRA_STACK_SIZE=512

#
# Debugging
#
CONFIG_DEBUG_LEVEL=1
# CONFIG_DEBUG_SERIAL is not set
CONFIG_DEBUG_COREBOOT=y

path: resources/seabios/config/config


code:
#
# Automatically generated file; DO NOT EDIT.
# SeaBIOS Configuration
#

#
# General Features
#
CONFIG_COREBOOT=y
# CONFIG_QEMU is not set
# CONFIG_CSM is not set
# CONFIG_QEMU_HARDWARE is not set
CONFIG_THREADS=y
CONFIG_RELOCATE_INIT=y
CONFIG_BOOTMENU=y
CONFIG_BOOTSPLASH=y
CONFIG_BOOTORDER=y
CONFIG_COREBOOT_FLASH=y
CONFIG_LZMA=y
CONFIG_CBFS_LOCATION=0
CONFIG_MULTIBOOT=y
CONFIG_ENTRY_EXTRASTACK=y
CONFIG_MALLOC_UPPERMEMORY=y
CONFIG_ROM_SIZE=0

#
# Hardware support
#
CONFIG_ATA=y
# CONFIG_ATA_DMA is not set
# CONFIG_ATA_PIO32 is not set
CONFIG_AHCI=y
CONFIG_SDCARD=y
CONFIG_MEGASAS=y
CONFIG_FLOPPY=y
CONFIG_FLASH_FLOPPY=y
CONFIG_PS2PORT=y
CONFIG_USB=y
CONFIG_USB_UHCI=y
CONFIG_USB_OHCI=y
CONFIG_USB_EHCI=y
CONFIG_USB_XHCI=y
CONFIG_USB_MSC=y
CONFIG_USB_UAS=y
CONFIG_USB_HUB=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_MOUSE=y
CONFIG_SERIAL=y
CONFIG_LPT=y
CONFIG_RTC_TIMER=y
CONFIG_HARDWARE_IRQ=y
CONFIG_PMTIMER=y
CONFIG_TSC_TIMER=y

#
# BIOS interfaces
#
CONFIG_DRIVES=y
CONFIG_CDROM_BOOT=y
CONFIG_CDROM_EMU=y
CONFIG_PCIBIOS=y
CONFIG_APMBIOS=y
CONFIG_PNPBIOS=y
CONFIG_OPTIONROMS=y
CONFIG_PMM=y
CONFIG_BOOT=y
CONFIG_KEYBOARD=y
CONFIG_KBD_CALL_INT15_4F=y
CONFIG_MOUSE=y
CONFIG_S3_RESUME=y
CONFIG_VGAHOOKS=y
# CONFIG_DISABLE_A20 is not set
CONFIG_TCGBIOS=y

#
# VGA ROM
#
# CONFIG_NO_VGABIOS is not set
# CONFIG_VGA_GEODEGX2 is not set
# CONFIG_VGA_GEODELX is not set
CONFIG_VGA_COREBOOT=y
CONFIG_BUILD_VGABIOS=y
CONFIG_VGA_EMULATE_TEXT=y
CONFIG_VGA_FIXUP_ASM=y
CONFIG_VGA_ALLOCATE_EXTRA_STACK=y
CONFIG_VGA_EXTRA_STACK_SIZE=512
CONFIG_VGA_VBE=y

#
# Debugging
#
CONFIG_DEBUG_LEVEL=1
# CONFIG_DEBUG_SERIAL is not set
CONFIG_DEBUG_COREBOOT=y


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

The usual git commands apply.


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/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/minnowmax/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/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/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/intel/kunimitsu/spd/hynix_dimm_H9CCNNNBLTALAR-NUD-2G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/samsung_dimm_K4E8E304EE-EGCF-1G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/samsung_dimm_K4E6E304EE-EGCF-2G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/hynix_dimm_H9CCNNN8JTALAR-NUD-1G-1866.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/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
util/crossgcc/patches/gcc-5.2.0_riscv.patch
util/xcompile/xcompile
src/northbridge/intel/sandybridge/raminit_mrc.c
src/northbridge/intel/fsp_rangeley/fsp/Kconfig
src/drivers/intel/fsp1_1/car.c
src/mainboard/intel/mohonpeak/Kconfig
src/mainboard/apple/macbookair4_2/early_southbridge.c
src/cpu/intel/fsp_model_406dx/acpi.c
src/northbridge/intel/fsp_sandybridge/fsp/Kconfig
src/drivers/aspeed/common/ast_dram_tables.h
src/drivers/aspeed/common/ast_tables.h
src/mainboard/intel/cougar_canyon2/Kconfig
src/cpu/amd/family_10h-family_15h/processor_name.c
src/cpu/amd/family_10h-family_15h/init_cpus.c
src/cpu/intel/fsp_model_206ax/acpi.c


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:
./3rdparty/vboot/tests/testcases/padding_test_vectors.inc
It's not a blob, see tests/rsa_padding_test.h for explanation.

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

#  DEBLOB script: deblobs the version of coreboot used for this release.
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.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 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"

for payloads in resources/libreboot/config/*; do

	if [ ! -d "${payloads}/" ]; then
		continue
	fi

	payload="${payloads##*/}"

	for boards in "${payloads}/"*; do

		if [ ! -d "${boards}/" ]; then
			continue
		fi

		board="${boards##*/}"
		cbrevision="$(cat "resources/libreboot/config/${payload}/${board}/cbrevision")"
        vbrevision="$(cat "resources/libreboot/config/${payload}/${board}/vbootrevision")"
		boardpath="coreboot/${cbrevision}/${cbrevision}"

		# deblob coreboot
		for blob in $(cat "resources/utilities/coreboot-libre/blobs/coreboot/${cbrevision}/blobs.list"); do
			rm -f "${boardpath}/${blob}"
		done

		# deblob 3rdparty
		# only non-crossgcc archives have 3rdparty (vboot) present.
		if [ "${payload}" != "crossgcc" ]; then
			vbootrevision="$(cat "resources/libreboot/config/${payload}/${board}/vbootrevision")"
			# deblob 3rdparty
			for blob in $(cat "resources/utilities/coreboot-libre/blobs/vboot/${vbootrevision}/blobs.list"); do
				rm -f "${boardpath}/${blob}"
			done
		fi

	done
done

# Now also do the same for crossgcc coreboot
for blob in $(cat "resources/utilities/coreboot-libre/blobs/coreboot/crossgcc/blobs.list"); do
    rm -f "crossgcc/${blob}"
done
for blob in $(cat "resources/utilities/coreboot-libre/blobs/vboot/crossgcc/blobs.list"); do
    rm -f "crossgcc/${blob}"
done

printf "\n\n"


code:
#!/bin/bash

#  find blobs in coreboot
#
#	Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.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/>.
#

[ "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/coreboot/"
cd "../../../coreboot/coreboot/"

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

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:
#!/bin/bash

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

[ "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

if [ -f "../../../versiondate" ]; then
	# _src release archive is being used
	versiondate="$(cat ../../../versiondate)"
else
	# git repo is being used
	versiondate="$(git show -s --format=%ct)"
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=  \
	  --fixed-time ${versiondate} \
	  --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=  \
	  --fixed-time ${versiondate} \
	  --modules="${grub_modules}" \
	  --install-modules="${grub_install_modules}" \
	  /boot/grub/grub.cfg="../../../resources/grub/config/grub_memdisk.cfg" \
	  /memtest.bin="../../../memtest86plus/memtest.bin" \
	  ${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