code:
From f721cdd46196a99dbcc41f0f7ecaf2ee17a147fe Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Wed, 2 Nov 2016 19:16:50 +0100
Subject: [PATCH] programmer.h: Define ich_generation after enum declaration

This moves the ich_generation definition after the declaration of its
associated enum.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 programmer.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/programmer.h b/programmer.h
index 191fb1e..86a695a 100644
--- a/programmer.h
+++ b/programmer.h
@@ -275,7 +275,6 @@ int board_flash_enable(const char *vendor, const char *part);
 /* chipset_enable.c */
 int chipset_flash_enable(void);
 int get_target_bus_from_chipset(enum chipbustype *target_bus);
-enum ich_chipset ich_generation;

 /* processor_enable.c */
 int processor_flash_enable(void);
@@ -603,6 +602,8 @@ enum ich_chipset {
 };

 #if CONFIG_INTERNAL == 1
+enum ich_chipset ich_generation;
+
 extern uint32_t ichspi_bbar;
 int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
 		 enum ich_chipset ich_generation);
--
2.10.2


code:
diff --git a/hwaccess.h b/hwaccess.h
index 0299ecb..a6732c2 100644
--- a/hwaccess.h
+++ b/hwaccess.h
@@ -24,11 +24,9 @@
 #ifndef __HWACCESS_H__
 #define __HWACCESS_H__ 1

-#if defined (__i386__) || defined (__x86_64__)
-#if defined(__GLIBC__)
+#if defined (__i386__) || defined (__x86_64__) || defined(__arm__)
 #include <sys/io.h>
 #endif
-#endif

 #if NEED_PCI == 1
 /*
@@ -72,7 +70,6 @@

 #if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
 /* Nonstandard libc-specific macros for determining endianness. */
-#if defined(__GLIBC__)
 #include <endian.h>
 #if BYTE_ORDER == LITTLE_ENDIAN
 #define __FLASHROM_LITTLE_ENDIAN__ 1
@@ -80,7 +77,6 @@
 #define __FLASHROM_BIG_ENDIAN__ 1
 #endif
 #endif
-#endif

 #if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
 #error Unable to determine endianness. Please add support for your arch or libc.

license: mit


code:
diff --git a/linux_spi.c b/linux_spi.c
index 0199cf5..d56e8b0 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -20,11 +20,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
 #include <errno.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <linux/spi/spidev.h>
+#include <linux/ioctl.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>


code:
diff --git a/fdtmap.h b/fdtmap.h
index 68eeef9..fe75291 100644
--- a/fdtmap.h
+++ b/fdtmap.h
@@ -36,6 +36,12 @@
 #ifndef FLASHMAP_LIB_FDTMAP_H__
 #define FLASHMAP_LIB_FDTMAP_H__

+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <fcntl.h>
+
 #define FDTMAP_SIGNATURE	"__FDTM__"

 struct romlayout;
diff --git a/fmap.h b/fmap.h
index b3c0a34..8aa82f7 100644
--- a/fmap.h
+++ b/fmap.h
@@ -38,7 +38,12 @@
 #ifndef FLASHMAP_LIB_FMAP_H__
 #define FLASHMAP_LIB_FMAP_H__

+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #include <inttypes.h>
+#include <fcntl.h>

 struct flashctx;


code:
diff --git a/Makefile b/Makefile
index a2f95cf..fcfce9b 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ PKG_CONFIG ?= pkg-config
 WARNERROR ?= yes

 ifneq ($(NOWARNERROR),yes)
-CFLAGS += -Werror
+CFLAGS +=
 endif

 ifeq ($(CONFIG_STATIC),yes)
@@ -354,7 +354,7 @@ CONFIG_BUSPIRATE_SPI ?= no
 CONFIG_RAIDEN_DEBUG_SPI ?= no

 # Enable Linux I2C for ChromeOS EC
-CONFIG_LINUX_I2C ?= no
+CONFIG_LINUX_I2C ?= yes

 CONFIG_LINUX_MTD ?= no

@@ -401,6 +401,7 @@ PROGRAMMER_OBJS += ichspi.o ich_descriptors.o
 else
 ifeq ($(ARCH),arm)
 PROGRAMMER_OBJS += cros_ec_i2c.o
+CONFIG_SATAMV := no
 endif
 NEED_PCI := yes
 endif
@@ -453,7 +454,7 @@ endif

 ifeq ($(CONFIG_FT2232_SPI), yes)
 FTDILIBS := $(shell $(PKG_CONFIG) --libs libftdi1 2>/dev/null ||	\
-		    $(PKG_CONFIG) --libs libftdi 2>/dev/null || echo "-lftdi -lusb")
+		    $(PKG_CONFIG) --libs libftdi 2>/dev/null || echo "-lftdi -lusb-1.0")
 FTDICFLAGS := $(shell $(PKG_CONFIG) --cflags libftdi1 2>/dev/null ||	\
 		      $(PKG_CONFIG) --cflags libftdi 2>/dev/null)
 # This is a totally ugly hack.
@@ -528,7 +529,7 @@ endif

 ifeq ($(CONFIG_DEDIPROG), yes)
 FEATURE_CFLAGS += -D'CONFIG_DEDIPROG=1'
-FEATURE_LIBS += -lusb
+FEATURE_LIBS += -lusb-1.0
 PROGRAMMER_OBJS += dediprog.o
 endif


code:
generic
lenovobios

path: projects/flashrom/configs/targets


code:
#!/usr/bin/env bash

# Copyright (C) 2016 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/>.

arguments() {
	project_arguments_targets "$project" "$@"
}

usage() {
	project_usage_actions "$project"
	project_usage_arguments "$project" "$@"
}

download() {
	local repository=$project

	project_download_git "$project" "$repository" 'https://review.coreboot.org/flashrom.git https://github.com/stefanct/flashrom.git' "$@"
}

download_check() {
	local repository=$project

	project_download_check_git "$project" "$repository" "$@"
}

extract() {
	local repository=$project

	project_extract "$project" "$@"
}

extract_check() {
	local repository=$project

	project_extract_check "$project" "$@"
}

update() {
	local repository=$project

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository=$project

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local repository=$project

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	if git_project_check "$repository"
	then
		git_project_checkout "$project" "$repository" "$@"
	fi

	local sources_path=$(project_sources_path "$project" "$repository" "$@")
	local build_path=$(project_build_path "$project" "$@")

	mkdir -p "$build_path"

	make -C "$sources_path" -j$TASKS

	cp "$sources_path/flashrom" "$build_path"

	make -C "$sources_path" "clean"
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local repository=$project

	project_release_install_archive "$project" "$TOOLS" "$@"

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository=$project

	project_release_install_archive_check "$project" "$TOOLS" "$@"

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/flashrom/flashrom


code:
From 4a262ea16a10a6067d48d70a2195151dea9292c6 Mon Sep 17 00:00:00 2001
From: Andrew Robbins <contact@andrewrobbins.info>
Date: Fri, 2 Mar 2018 00:13:16 -0500
Subject: [PATCH] Purge redundant Macronix chips

Removing the redundant Macronix chips avoids the situation where X60
owners have to specify their particular chip on the command line with
flashrom's '--chip' flag.
---
 flashchips.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/flashchips.c b/flashchips.c
index 1ab4986..7f85415 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -7595,7 +7595,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L1605A/MX25L1606E/MX25L1608E",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L1605,
+		.model_id	= 0xDEAD,
 		.total_size	= 2048,
 		.page_size	= 256,
 		/* OTP: 64B total; enter 0xB1, exit 0xC1 (MX25L1606E and MX25L1608E only) */
@@ -7634,7 +7634,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L1605D/MX25L1608D/MX25L1673E",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L1605,
+		.model_id	= 0xDEAD,
 		.total_size	= 2048,
 		.page_size	= 256,
 		.feature_bits	= FEATURE_WRSR_WREN,
@@ -7776,7 +7776,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L3205D/MX25L3208D",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L3205,
+		.model_id	= 0xDEAD,
 		.total_size	= 4096,
 		.page_size	= 256,
 		/* OTP: 64B total; enter 0xB1, exit 0xC1 */
@@ -7812,7 +7812,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L3206E/MX25L3208E",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L3205,
+		.model_id	= 0xDEAD,
 		.total_size	= 4096,
 		.page_size	= 256,
 		/* OTP: 64B total; enter 0xB1, exit 0xC1 */
@@ -7851,7 +7851,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L3273E",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L3205,
+		.model_id	= 0xDEAD,
 		.total_size	= 4096,
 		.page_size	= 256,
 		/* OTP: 64B total; enter 0xB1, exit 0xC1 */
@@ -7962,7 +7962,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L6405D",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L6405,
+		.model_id	= 0xDEAD,
 		.total_size	= 8192,
 		.page_size	= 256,
 		/* OTP: 64B total; enter 0xB1, exit 0xC1 */
@@ -7998,7 +7998,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L6406E/MX25L6408E",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L6405,
+		.model_id	= 0xDEAD,
 		.total_size	= 8192,
 		.page_size	= 256,
 		/* MX25L6406E supports SFDP */
@@ -8038,7 +8038,7 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L6436E/MX25L6445E/MX25L6465E/MX25L6473E/MX25L6473F",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= MACRONIX_MX25L6405,
+		.model_id	= 0xDEAD,
 		.total_size	= 8192,
 		.page_size	= 256,
 		/* supports SFDP */
--
1.9.1


code:
From 886f1db7edbfc9ef4c9727b4f564c1e7e35d6565 Mon Sep 17 00:00:00 2001
From: consts <grudnevkv@gmail.com>
Date: Fri, 2 Mar 2018 07:03:37 +0000
Subject: [PATCH] Workaround for MX25 chips

https://notabug.org/libreboot/libreboot/issues/193
---
 cli_classic.c | 5 +++++
 programmer.h  | 1 +
 spi.c         | 9 +++++++++
 3 files changed, 15 insertions(+)

diff --git a/cli_classic.c b/cli_classic.c
index 31f7394..c60168c 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -62,6 +62,7 @@ static void cli_classic_usage(const char *name)
 	       " -o | --output <logfile>            log output to <logfile>\n"
 	       "      --flash-contents <ref-file>   assume flash contents to be <ref-file>\n"
 	       " -L | --list-supported              print supported devices\n"
+	       " -m | --workaround-mx               keep flash busy before sending command\n"
 #if CONFIG_PRINT_WIKI == 1
 	       " -z | --list-supported-wiki         print supported devices in wiki syntax\n"
 #endif
@@ -136,6 +137,7 @@ int main(int argc, char *argv[])
 		{"help",		0, NULL, 'h'},
 		{"version",		0, NULL, 'R'},
 		{"output",		1, NULL, 'o'},
+		{"workaround-mx", 	0, NULL, 'm'},
 		{NULL,			0, NULL, 0},
 	};

@@ -347,6 +349,9 @@ int main(int argc, char *argv[])
 			}
 #endif /* STANDALONE */
 			break;
+		case 'm': /* --workaround-mx */
+			workaround_mx = 1;
+			break;
 		default:
 			cli_classic_abort_usage();
 			break;
diff --git a/programmer.h b/programmer.h
index 139f4fa..f54e690 100644
--- a/programmer.h
+++ b/programmer.h
@@ -664,6 +664,7 @@ enum ich_chipset {
 	CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */
 	CHIPSET_C620_SERIES_LEWISBURG,
 };
+extern int workaround_mx; /* workaround for MX25* chips, makes flash operations more reliable, less failures */

 /* ichspi.c */
 #if CONFIG_INTERNAL == 1
diff --git a/spi.c b/spi.c
index 56f1fdf..4e61d88 100644
--- a/spi.c
+++ b/spi.c
@@ -30,10 +30,19 @@
 #include "programmer.h"
 #include "spi.h"

+int workaround_mx; /* Make operations with MX25* chips more reliable */
+
 int spi_send_command(struct flashctx *flash, unsigned int writecnt,
 		     unsigned int readcnt, const unsigned char *writearr,
 		     unsigned char *readarr)
 {
+	if (workaround_mx) {
+		const unsigned char cmd[JEDEC_READ_OUTSIZE] = {JEDEC_READ, 0, 0, 0};
+		unsigned char buf[256];
+		/* keep flash busy for some time, keep CS warm before sending actual command */
+		flash->mst->spi.command(flash, sizeof(cmd), sizeof(buf), cmd, buf);
+	}
+	/* actual command */
 	return flash->mst->spi.command(flash, writecnt, readcnt, writearr,
 				       readarr);
 }
--
1.9.1


code:
From 85eea125194414b6afc8053565bb333f06054421 Mon Sep 17 00:00:00 2001
From: Leah Rowe <leah@libreboot.org>
Date: Fri, 2 Mar 2018 06:47:34 +0000
Subject: [PATCH] Lenovobios adaptation for Macronix and SST chips

---
 flashchips.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/flashchips.c b/flashchips.c
index 7f85415..16b166b 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -7634,12 +7634,12 @@ const struct flashchip flashchips[] = {
 		.name		= "MX25L1605D/MX25L1608D/MX25L1673E",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= MACRONIX_ID,
-		.model_id	= 0xDEAD,
+		.model_id	= 0x14,
 		.total_size	= 2048,
 		.page_size	= 256,
 		.feature_bits	= FEATURE_WRSR_WREN,
 		.tested		= TEST_OK_PREW,
-		.probe		= probe_spi_rdid,
+		.probe		= probe_spi_res1,
 		.probe_timing	= TIMING_ZERO,
 		.block_erasers	=
 		{
@@ -10442,7 +10442,7 @@ const struct flashchip flashchips[] = {
 		},
 		.printlock	= spi_prettyprint_status_register_bp2_srwd,
 		.unlock		= spi_disable_blockprotect,
-		.write		= spi_chip_write_256,
+		.write		= spi_chip_write_1,
 		.read		= spi_chip_read, /* Fast read (0x0B), dual I/O supported */
 		.voltage	= {2700, 3600},
 	},
@@ -12735,12 +12735,12 @@ const struct flashchip flashchips[] = {
 		.name		= "SST25VF016B",
 		.bustype	= BUS_SPI,
 		.manufacture_id	= SST_ID,
-		.model_id	= SST_SST25VF016B,
+		.model_id	= 0x41,
 		.total_size	= 2048,
 		.page_size	= 256,
 		.feature_bits	= FEATURE_WRSR_EITHER,
 		.tested		= TEST_OK_PREW,
-		.probe		= probe_spi_rdid,
+		.probe		= probe_spi_res2,
 		.probe_timing	= TIMING_ZERO,
 		.block_erasers	=
 		{
@@ -12763,7 +12763,7 @@ const struct flashchip flashchips[] = {
 		},
 		.printlock	= spi_prettyprint_status_register_sst25vf016,
 		.unlock		= spi_disable_blockprotect,
-		.write		= spi_aai_write,
+		.write		= spi_chip_write_1,
 		.read		= spi_chip_read,
 		.voltage	= {2700, 3600},
 	},
--
1.9.1


code:
#!/usr/bin/env bash

# Copyright (C) 2016 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/>.

arguments() {
	project_arguments_targets "$project" "$@"
}

usage() {
	project_usage_actions "$project"
	project_usage_arguments "$project" "$@"
}

download() {
	local repository="$project"

	project_download_git "$project" \
			     "$repository" \
			     'https://anongit.freedesktop.org/git/fontconfig' \
			     "$@"
}

download_check() {
	local repository="$project"

	project_download_check_git "$project" "$repository" "$@"
}

extract() {
	local repository="$project"

	project_extract "$project" "$@"
}

extract_check() {
	local repository="$project"

	project_extract_check "$project" "$@"
}

update() {
	local repository="$project"

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository="$project"

	project_update_check_git "$project" "$repository" "$@"
}

release() {
	local repository="$project"

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository="$project"

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/fontconfig/fontconfig


code:
set root=(fd0)
set prefix=($root)/boot/grub

source (cbfsdisk)/fallback/grub.cfg

path: projects/grub/configs/bios/config


code:
i386-pc/acpi.mod:i386-pc/acpi.mod
i386-pc/adler32.mod:i386-pc/adler32.mod
i386-pc/affs.mod:i386-pc/affs.mod
i386-pc/afs.mod:i386-pc/afs.mod
i386-pc/ahci.mod:i386-pc/ahci.mod
i386-pc/all_video.mod:i386-pc/all_video.mod
i386-pc/archelp.mod:i386-pc/archelp.mod
i386-pc/ata.mod:i386-pc/ata.mod
i386-pc/at_keyboard.mod:i386-pc/at_keyboard.mod
i386-pc/backtrace.mod:i386-pc/backtrace.mod
i386-pc/bfs.mod:i386-pc/bfs.mod
i386-pc/biosdisk.mod:i386-pc/biosdisk.mod
i386-pc/bitmap.mod:i386-pc/bitmap.mod
i386-pc/bitmap_scale.mod:i386-pc/bitmap_scale.mod
i386-pc/boot.mod:i386-pc/boot.mod
i386-pc/bsd.mod:i386-pc/bsd.mod
i386-pc/btrfs.mod:i386-pc/btrfs.mod
i386-pc/cat.mod:i386-pc/cat.mod
i386-pc/cbfs.mod:i386-pc/cbfs.mod
i386-pc/cbls.mod:i386-pc/cbls.mod
i386-pc/cbmemc.mod:i386-pc/cbmemc.mod
i386-pc/cbtime.mod:i386-pc/cbtime.mod
i386-pc/chain.mod:i386-pc/chain.mod
i386-pc/cmosdump.mod:i386-pc/cmosdump.mod
i386-pc/cmostest.mod:i386-pc/cmostest.mod
i386-pc/cmp.mod:i386-pc/cmp.mod
i386-pc/configfile.mod:i386-pc/configfile.mod
i386-pc/cpio.mod:i386-pc/cpio.mod
i386-pc/cpio_be.mod:i386-pc/cpio_be.mod
i386-pc/cpuid.mod:i386-pc/cpuid.mod
i386-pc/crc64.mod:i386-pc/crc64.mod
i386-pc/crypto.mod:i386-pc/crypto.mod
i386-pc/cryptodisk.mod:i386-pc/cryptodisk.mod
i386-pc/cs5536.mod:i386-pc/cs5536.mod
i386-pc/date.mod:i386-pc/date.mod
i386-pc/datehook.mod:i386-pc/datehook.mod
i386-pc/datetime.mod:i386-pc/datetime.mod
i386-pc/disk.mod:i386-pc/disk.mod
i386-pc/diskfilter.mod:i386-pc/diskfilter.mod
i386-pc/div_test.mod:i386-pc/div_test.mod
i386-pc/echo.mod:i386-pc/echo.mod
i386-pc/efiemu.mod:i386-pc/efiemu.mod
i386-pc/ehci.mod:i386-pc/ehci.mod
i386-pc/elf.mod:i386-pc/elf.mod
i386-pc/eval.mod:i386-pc/eval.mod
i386-pc/exfat.mod:i386-pc/exfat.mod
i386-pc/ext2.mod:i386-pc/ext2.mod
i386-pc/extcmd.mod:i386-pc/extcmd.mod
i386-pc/fat.mod:i386-pc/fat.mod
i386-pc/file.mod:i386-pc/file.mod
i386-pc/fshelp.mod:i386-pc/fshelp.mod
i386-pc/gcry_arcfour.mod:i386-pc/gcry_arcfour.mod
i386-pc/gcry_blowfish.mod:i386-pc/gcry_blowfish.mod
i386-pc/gcry_camellia.mod:i386-pc/gcry_camellia.mod
i386-pc/gcry_cast5.mod:i386-pc/gcry_cast5.mod
i386-pc/gcry_crc.mod:i386-pc/gcry_crc.mod
i386-pc/gcry_des.mod:i386-pc/gcry_des.mod
i386-pc/gcry_dsa.mod:i386-pc/gcry_dsa.mod
i386-pc/gcry_idea.mod:i386-pc/gcry_idea.mod
i386-pc/gcry_md4.mod:i386-pc/gcry_md4.mod
i386-pc/gcry_md5.mod:i386-pc/gcry_md5.mod
i386-pc/gcry_rfc2268.mod:i386-pc/gcry_rfc2268.mod
i386-pc/gcry_rijndael.mod:i386-pc/gcry_rijndael.mod
i386-pc/gcry_rmd160.mod:i386-pc/gcry_rmd160.mod
i386-pc/gcry_rsa.mod:i386-pc/gcry_rsa.mod
i386-pc/gcry_seed.mod:i386-pc/gcry_seed.mod
i386-pc/gcry_serpent.mod:i386-pc/gcry_serpent.mod
i386-pc/gcry_sha1.mod:i386-pc/gcry_sha1.mod
i386-pc/gcry_sha256.mod:i386-pc/gcry_sha256.mod
i386-pc/gcry_sha512.mod:i386-pc/gcry_sha512.mod
i386-pc/gcry_tiger.mod:i386-pc/gcry_tiger.mod
i386-pc/gcry_twofish.mod:i386-pc/gcry_twofish.mod
i386-pc/gcry_whirlpool.mod:i386-pc/gcry_whirlpool.mod
i386-pc/gettext.mod:i386-pc/gettext.mod
i386-pc/gfxmenu.mod:i386-pc/gfxmenu.mod
i386-pc/gfxterm_background.mod:i386-pc/gfxterm_background.mod
i386-pc/gfxterm_menu.mod:i386-pc/gfxterm_menu.mod
i386-pc/gptsync.mod:i386-pc/gptsync.mod
i386-pc/gzio.mod:i386-pc/gzio.mod
i386-pc/halt.mod:i386-pc/halt.mod
i386-pc/hashsum.mod:i386-pc/hashsum.mod
i386-pc/hdparm.mod:i386-pc/hdparm.mod
i386-pc/help.mod:i386-pc/help.mod
i386-pc/hexdump.mod:i386-pc/hexdump.mod
i386-pc/hfs.mod:i386-pc/hfs.mod
i386-pc/hfsplus.mod:i386-pc/hfsplus.mod
i386-pc/http.mod:i386-pc/http.mod
i386-pc/iorw.mod:i386-pc/iorw.mod
i386-pc/iso9660.mod:i386-pc/iso9660.mod
i386-pc/jfs.mod:i386-pc/jfs.mod
i386-pc/jpeg.mod:i386-pc/jpeg.mod
i386-pc/keystatus.mod:i386-pc/keystatus.mod
i386-pc/linux.mod:i386-pc/linux.mod
i386-pc/linux16.mod:i386-pc/linux16.mod
i386-pc/loadenv.mod:i386-pc/loadenv.mod
i386-pc/loopback.mod:i386-pc/loopback.mod
i386-pc/ls.mod:i386-pc/ls.mod
i386-pc/lsacpi.mod:i386-pc/lsacpi.mod
i386-pc/lsmmap.mod:i386-pc/lsmmap.mod
i386-pc/lspci.mod:i386-pc/lspci.mod
i386-pc/luks.mod:i386-pc/luks.mod
i386-pc/lvm.mod:i386-pc/lvm.mod
i386-pc/lzopio.mod:i386-pc/lzopio.mod
i386-pc/mda_text.mod:i386-pc/mda_text.mod
i386-pc/mdraid09.mod:i386-pc/mdraid09.mod
i386-pc/mdraid09_be.mod:i386-pc/mdraid09_be.mod
i386-pc/mdraid1x.mod:i386-pc/mdraid1x.mod
i386-pc/memdisk.mod:i386-pc/memdisk.mod
i386-pc/memrw.mod:i386-pc/memrw.mod
i386-pc/minicmd.mod:i386-pc/minicmd.mod
i386-pc/minix.mod:i386-pc/minix.mod
i386-pc/minix2.mod:i386-pc/minix2.mod
i386-pc/minix2_be.mod:i386-pc/minix2_be.mod
i386-pc/minix3.mod:i386-pc/minix3.mod
i386-pc/minix3_be.mod:i386-pc/minix3_be.mod
i386-pc/minix_be.mod:i386-pc/minix_be.mod
i386-pc/mmap.mod:i386-pc/mmap.mod
i386-pc/morse.mod:i386-pc/morse.mod
i386-pc/mpi.mod:i386-pc/mpi.mod
i386-pc/msdospart.mod:i386-pc/msdospart.mod
i386-pc/multiboot.mod:i386-pc/multiboot.mod
i386-pc/multiboot2.mod:i386-pc/multiboot2.mod
i386-pc/nativedisk.mod:i386-pc/nativedisk.mod
i386-pc/net.mod:i386-pc/net.mod
i386-pc/newc.mod:i386-pc/newc.mod
i386-pc/nilfs2.mod:i386-pc/nilfs2.mod
i386-pc/normal.mod:i386-pc/normal.mod
i386-pc/ntfs.mod:i386-pc/ntfs.mod
i386-pc/ntfscomp.mod:i386-pc/ntfscomp.mod
i386-pc/odc.mod:i386-pc/odc.mod
i386-pc/offsetio.mod:i386-pc/offsetio.mod
i386-pc/ohci.mod:i386-pc/ohci.mod
i386-pc/part_bsd.mod:i386-pc/part_bsd.mod
i386-pc/part_gpt.mod:i386-pc/part_gpt.mod
i386-pc/part_msdos.mod:i386-pc/part_msdos.mod
i386-pc/parttool.mod:i386-pc/parttool.mod
i386-pc/password.mod:i386-pc/password.mod
i386-pc/password_pbkdf2.mod:i386-pc/password_pbkdf2.mod
i386-pc/pata.mod:i386-pc/pata.mod
i386-pc/pbkdf2.mod:i386-pc/pbkdf2.mod
i386-pc/pci.mod:i386-pc/pci.mod
i386-pc/pcidump.mod:i386-pc/pcidump.mod
i386-pc/play.mod:i386-pc/play.mod
i386-pc/png.mod:i386-pc/png.mod
i386-pc/priority_queue.mod:i386-pc/priority_queue.mod
i386-pc/probe.mod:i386-pc/probe.mod
i386-pc/procfs.mod:i386-pc/procfs.mod
i386-pc/progress.mod:i386-pc/progress.mod
i386-pc/raid5rec.mod:i386-pc/raid5rec.mod
i386-pc/raid6rec.mod:i386-pc/raid6rec.mod
i386-pc/read.mod:i386-pc/read.mod
i386-pc/reboot.mod:i386-pc/reboot.mod
i386-pc/regexp.mod:i386-pc/regexp.mod
i386-pc/reiserfs.mod:i386-pc/reiserfs.mod
i386-pc/relocator.mod:i386-pc/relocator.mod
i386-pc/romfs.mod:i386-pc/romfs.mod
i386-pc/scsi.mod:i386-pc/scsi.mod
i386-pc/search.mod:i386-pc/search.mod
i386-pc/search_fs_file.mod:i386-pc/search_fs_file.mod
i386-pc/search_fs_uuid.mod:i386-pc/search_fs_uuid.mod
i386-pc/search_label.mod:i386-pc/search_label.mod
i386-pc/serial.mod:i386-pc/serial.mod
i386-pc/setjmp.mod:i386-pc/setjmp.mod
i386-pc/setpci.mod:i386-pc/setpci.mod
i386-pc/sfs.mod:i386-pc/sfs.mod
i386-pc/sleep.mod:i386-pc/sleep.mod
i386-pc/spkmodem.mod:i386-pc/spkmodem.mod
i386-pc/squash4.mod:i386-pc/squash4.mod
i386-pc/syslinuxcfg.mod:i386-pc/syslinuxcfg.mod
i386-pc/tar.mod:i386-pc/tar.mod
i386-pc/terminal.mod:i386-pc/terminal.mod
i386-pc/terminfo.mod:i386-pc/terminfo.mod
i386-pc/test.mod:i386-pc/test.mod
i386-pc/testload.mod:i386-pc/testload.mod
i386-pc/testspeed.mod:i386-pc/testspeed.mod
i386-pc/tftp.mod:i386-pc/tftp.mod
i386-pc/tga.mod:i386-pc/tga.mod
i386-pc/time.mod:i386-pc/time.mod
i386-pc/tr.mod:i386-pc/tr.mod
i386-pc/trig.mod:i386-pc/trig.mod
i386-pc/true.mod:i386-pc/true.mod
i386-pc/udf.mod:i386-pc/udf.mod
i386-pc/ufs1.mod:i386-pc/ufs1.mod
i386-pc/ufs1_be.mod:i386-pc/ufs1_be.mod
i386-pc/ufs2.mod:i386-pc/ufs2.mod
i386-pc/uhci.mod:i386-pc/uhci.mod
i386-pc/usb.mod:i386-pc/usb.mod
i386-pc/usb_keyboard.mod:i386-pc/usb_keyboard.mod
i386-pc/usbms.mod:i386-pc/usbms.mod
i386-pc/usbserial_common.mod:i386-pc/usbserial_common.mod
i386-pc/usbserial_ftdi.mod:i386-pc/usbserial_ftdi.mod
i386-pc/usbserial_pl2303.mod:i386-pc/usbserial_pl2303.mod
i386-pc/usbserial_usbdebug.mod:i386-pc/usbserial_usbdebug.mod
i386-pc/usbtest.mod:i386-pc/usbtest.mod
i386-pc/verify.mod:i386-pc/verify.mod
i386-pc/video_colors.mod:i386-pc/video_colors.mod
i386-pc/videoinfo.mod:i386-pc/videoinfo.mod
i386-pc/videotest.mod:i386-pc/videotest.mod
i386-pc/videotest_checksum.mod:i386-pc/videotest_checksum.mod
i386-pc/xfs.mod:i386-pc/xfs.mod
i386-pc/xzio.mod:i386-pc/xzio.mod
i386-pc/zfs.mod:i386-pc/zfs.mod

path: projects/grub/configs/bios/install


code:
ahci
biosdisk
cbfs
cbmemc
configfile
ehci
ext2
fat
halt
loadenv
memdisk
minicmd
part_bsd
part_gpt
pata
reboot
test
verify


code: pc

path: projects/grub/configs/bios/platform


code:
set root=(cbfsdisk)
set prefix=($root)/fallback

source $prefix/grub.cfg

path: projects/grub/configs/coreboot/config


path: projects/grub/configs/coreboot/format


path: projects/grub/configs/coreboot/install


code:
ahci
cbfs
cbmemc
configfile
ehci
ext2
halt
loadenv
minicmd
part_bsd
part_gpt
pata
reboot
test
usbms
verify


code: coreboot

path: projects/grub/configs/coreboot/platform


path: projects/grub/configs/fonts/font-file


code:
bios
coreboot
uefi

path: projects/grub/configs/targets


path: projects/grub/configs/uefi/config


code: efi

path: projects/grub/configs/uefi/platform


code:
#!/usr/bin/env bash

# Copyright (C) 2016 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/>.

arguments() {
	project_arguments_targets "$project" "$@"
}

usage() {
	project_usage_actions "$project"
	project_usage_arguments "$project" "$@"
}

download() {
	local repository="$project"

	project_download_git "$project" "$repository" 'https://git.savannah.gnu.org/r/grub.git' "$@"
}

download_check() {
	local repository="$project"

	project_download_check_git "$project" "$repository" "$@"
}

extract() {
	project_extract "$project" "$@"
}

extract_check() {
	project_extract_check "$project" "$@"
}

update() {
	local repository="$project"

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository="$project"

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local target="$1"
	local repository="$project"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	if git_project_check "$repository"; then
		git_project_checkout "$project" "$repository" "$@"
	fi

	local project_path="$(project_path "$project")"
	local sources_path="$(project_sources_path "$project" "$repository" "$@")"
	local build_path="$(project_build_path "$project" "$@")"
	local raw_keymap_path="$project_path/$CONFIGS/keymaps"

	mkdir -p "$build_path"

	grub_build_utils

	if [[ "$target" == 'bios' ]]; then
		grub_build_floppy_image
	else
		grub_build_standalone_image
	fi

	for raw_keymap in "$raw_keymap_path"/*; do
		grub_build_layout "$raw_keymap"
	done

	grub_build_font

	grub_copy_modules

	make -C "$sources_path" distclean
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local repository="$project"

	project_release_install_archive "$project" "$IMAGES" "$@"
	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository="$project"

	project_release_install_archive_check "$project" "$IMAGES" "$@"
	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/grub/grub


code:
#!/usr/bin/env bash

# Copyright (C) 2017,2018 Andrew Robbins <contact@andrewrobbins.info>
#
# 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/>.

ARCH='arch'
CONFIG='config'
FONTS='fonts'
FONT_FILE='font-file'
FONT_PROJECT='font-project'
FORMAT='format'
MODMIN='modules-minimal'
PLATFORM='platform'
PREFIX='prefix'
SIZE='size'

grub_arch() {
	project_file_contents "$project" "$CONFIGS" "$ARCH" "$@"
}

grub_font_file() {
	project_file_contents "$project" "$CONFIGS" "$FONT_FILE" "$@"
}

grub_font_project() {
	project_file_contents "$project" "$CONFIGS" "$FONT_PROJECT" "$@"
}

grub_format() {
	project_file_contents "$project" "$CONFIGS" "$FORMAT" "$@"
}

grub_platform() {
	project_file_contents "$project" "$CONFIGS" "$PLATFORM" "$@"
}

grub_prefix() {
	project_file_contents "$project" "$CONFIGS" "$PREFIX" "$@"
}

grub_size() {
	project_file_contents "$project" "$CONFIGS" "$SIZE" "$@"
}

grub_config_path() {
	project_file_path "$project" "$CONFIGS" "$CONFIG" "$@"
}

grub_modmin_path() {
	project_file_path "$project" "$CONFIGS" "$MODMIN" "$@"
}

grub_bo_search() {
	local pattern="$1"
	local comparand="$2"

	grep -Fbof <(grub_bo_dump "$pattern") <(grub_bo_dump "$comparand") | cut -d: -f1
}

grub_bo_dump() {
	local file="$1"

	od -An -t x1 -w16 -v "$file" | paste -sd '' | tr -d ' '
}

grub_bo() {
	local pattern="$1"
	local comparand="$2"

	local nibble_offset="$(grub_bo_search "$pattern" "$comparand")"

	if [[ -n "$nibble_offset" ]]; then
		printf '0x%X\n' $((nibble_offset / 2))
	else
		return 1
	fi
}

grub_blocklist_format() {
	local blocklist="$1"
	local byte

	while read -N 2 byte; do
		printf '%s' "\\x$byte"
	done <<< "$blocklist"
}

grub_blocklist_generate() {
	local -i byte_offset="$1"

	printf '%04x' $((byte_offset / 512)) | tac -rs ..
}

grub_copy_modules() {
	local grub_module_dir="$sources_path/grub-core"
	local keep_dir="$build_path/$(grub_format "$target" "$@")"

	mkdir -p "$keep_dir"

	cp -a "$grub_module_dir"/*.@(mod|lst) "$keep_dir"
}

grub_build_font() {
	local font_file="$(grub_font_file "$FONTS" "$@")"
	local font_project="$(grub_font_project "$FONTS" "$@")"
	local font_build_dir="$root/$BUILD/$font_project"

	local grub_mkfont="$sources_path/grub-mkfont"

	mkdir -p "$build_path/$FONTS"

	"$grub_mkfont" --output="$build_path/$FONTS/${font_file%.*}.pf2" \
			"$font_build_dir/$font_file"
}

grub_build_utils() {
	(
		local arch="$(grub_arch "$target" "$@")"
		local platform="$(grub_platform "$target" "$@")"

		cd "$sources_path" || return

		if git_project_check "$repository"; then
			./autogen.sh
		fi

		./configure --target="$arch" --with-platform="$platform"

		make -j"$TASKS"
	)
}

grub_build_layout() {
	local raw_layout="${1##*/}"
	local raw_layout_path="$1"
	local keymap_out_path="$build_path/keymaps"
	local grub_mklayout="$sources_path/grub-mklayout"
	local grub_kbd_layout="$keymap_out_path/$raw_layout.gkb"

	if ! [[ -e "$keymap_out_path" ]]; then
		mkdir -p "$keymap_out_path"
	elif ! [[ -d "$keymap_out_path" ]]; then
		printf '\n%s\n' "Error: File $keymap_out_path is not a directory" 1>&2

		return 1
	fi

	"$grub_mklayout" --output="$grub_kbd_layout" --input="$raw_layout_path"
}

grub_build_bootable_image() {
	local arch="$(grub_arch "$target" "$@")"
	local format="$(grub_format "$target" "$@")"
	local prefix="$(grub_prefix "$target" "$@")"
	local config_path="$(grub_config_path "$target" "$@")"
	local modmin_path="$(grub_modmin_path "$target" "$@")"

	local -a modmin=($(< "$modmin_path"))

	local grub_mkimage="$sources_path/grub-mkimage"
	local grub_module_dir="$sources_path/grub-core"

	local grub_bootimg="$grub_module_dir/boot.img"
	local grub_coreimg="$build_path/core.img"

	"$grub_mkimage" \
		--config="$config_path" \
		--directory="$grub_module_dir" \
		--output="$grub_coreimg" \
		--format="$format" \
		--prefix="$prefix" \
		"${modmin[@]}"

	cp -a "$grub_bootimg" "$build_path"
}

grub_build_floppy_image() {
	local floppyimg="$build_path/floppy.img"
	local format="$(grub_format "$target" "$@")"
	local grub_module_dir="$sources_path/grub-core"
	local size="$(grub_size "$target" "$@")"

	local -a modules

	for module in "$grub_module_dir"/*.mod; do
		modules+=($module)
	done

	if ! grub_build_bootable_image "$@"; then
		printf '\n%s\n\n' "Error: Failed to build a GRUB image" 1>&2

		return 1
	fi

	# Pre-allocate a floppy-sized image with a FAT12 filesystem
	# SeaBIOS requires floppy images to have a "correct" size
	if ! [[ -e "$floppyimg" ]]; then
		mkfs.fat -C -D 0x00 -F 12 -M 0xF9 -n SEAGRUB --invariant "$floppyimg" "$size"
	else
		printf '\n%s\n\n' "Error: File $floppyimg already exists!" 1>&2

		return 1
	fi

	grub_floppy_image_mmd "$floppyimg" /boot /boot/grub "/boot/grub/$format"
	grub_floppy_image_mcopy "$floppyimg" "/boot/grub/$format" "${modules[@]}"
	grub_floppy_image_make_bootable "$floppyimg"
}

grub_build_standalone_image() {
	local arch="$(grub_arch "$target" "$@")"
	local format="$(grub_format "$target" "$@")"
	local prefix="$(grub_prefix "$target" "$@")"
	local config_path="$(grub_config_path "$target" "$@")"
	local modmin_path="$(grub_modmin_path "$target" "$@")"

	local -a modmin=($(< "$modmin_path"))

	local grubimg="$build_path/grub2"

	local grub_mkimage="$sources_path/grub-mkimage"
	local grub_mkstandalone="$sources_path/grub-mkstandalone"
	local grub_module_dir="$sources_path/grub-core"

	"$grub_mkstandalone" \
		--grub-mkimage="$grub_mkimage" \
		--fonts='' \
		--themes='' \
		--locales='' \
		--install-modules="${modmin[*]}" \
		--directory="$grub_module_dir" \
		--format="$format" \
		--output="$grubimg" \
		/boot/grub/grub.cfg="$config_path"
}

grub_floppy_image_mmd() {
	local img="$1"
	local -a dirs=("${@:2}")

	if [[ -n "$img" ]]; then
		mmd -i "$img" "${dirs[@]}"
	else
		return 1
	fi
}

grub_floppy_image_mcopy() {
	local img="$1"
	local target="$2"
	local -a files=("${@:3}")

	if [[ -z "$img" ]]; then
		return 1
	elif [[ -z "${files[@]}" ]]; then
		mcopy -i "$img" -pv "::$target"
	else
		mcopy -i "$img" -pQv "${files[@]}" "::$target"
	fi
}

grub_floppy_image_make_bootable() {
	local floppyimg="$1"
	local bootimg="$build_path/boot.img"
	local coreimg="$build_path/core.img"
	local oem_name='\x4C\x49\x42\x52\x45\x20\x20\x20'

	# write $floppyimg Bios Parameter Block to $bootimg first
	dd if="$floppyimg" of="$bootimg" bs=1 skip=11 seek=11 count=51 conv=notrunc
	dd if=<(printf "$oem_name") of="$bootimg" bs=1 seek=3 conv=notrunc
	dd if=/dev/zero of="$floppyimg" count=1 conv=notrunc
	dd if="$bootimg" of="$floppyimg" conv=notrunc

	grub_floppy_image_mcopy "$floppyimg" /boot/grub "$bootimg"
	grub_floppy_image_mcopy "$floppyimg" /boot/grub "$coreimg"

	grub_floppy_image_update_blocklists "$coreimg" "$floppyimg"
	rm -f "$bootimg" "$coreimg"
}

grub_floppy_image_update_blocklists() {
	local coreimg="$1"
	local floppyimg="$2"

	local -i coreimg_offset="$(grub_bo "$coreimg" "$floppyimg")"
	local -i coreimg_second_sector_offset=$((coreimg_offset + 0x200))

	local -i boot_record_blocklist_offset=0x5C
	local -i coreimg_blocklist_offset=$((coreimg_offset + 0x1F4))

	# blocklists (little endian) describe the $coreimg_offset in sectors
	local boot_record_blocklist="$(grub_blocklist_generate "$coreimg_offset")"
	local coreimg_blocklist="$(grub_blocklist_generate "$coreimg_second_sector_offset")"

	if [[ $coreimg_offset -gt 0 ]]; then
		dd if=<(printf "$(grub_blocklist_format "$boot_record_blocklist")") \
			of="$floppyimg" \
			bs=1 \
			seek="$boot_record_blocklist_offset" \
			conv=notrunc

		dd if=<(printf "$(grub_blocklist_format "$coreimg_blocklist")") \
			of="$floppyimg" \
			bs=1 \
			seek="$coreimg_blocklist_offset" \
			conv=notrunc
	else
		printf 1>&2 '%s\n' "Error: ${coreimg##*/} offset not found"

		return 1
	fi
}

path: projects/grub/grub-helper


code:
Copyright (C) 2014, 2015, 2016 Leah Rowe <info@minifree.org>
Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>


code:
insmod nativedisk
insmod ehci
insmod ohci
insmod uhci
insmod usb
insmod usbms
insmod usbserial_pl2303
insmod usbserial_ftdi
insmod usbserial_usbdebug
insmod png

# Serial and keyboard configuration, very important.
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
terminal_input --append  serial
terminal_output --append serial
terminal_input --append at_keyboard
terminal_output --append cbmemc
terminal_output --append gfxterm

load_env --file (cbfsdisk)/grubenv

# User's preferred keyboard layout
if [ -n "${keymap}" ]; then
	keymap "${keymap}"
fi

# Prettify GRUB
background_image "${gfxterm_background}"

function try_user_config {
	set root="${1}"
	for dir in boot grub grub2 boot/grub boot/grub2; do
		for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
			if [ -f /"${dir}"/"${name}"grub.cfg ]; then
                unset superusers
				configfile /"${dir}"/"${name}"grub.cfg
			fi
		done
	done
}

function search_grub {
	for i in 0 1; do
		# raw devices
		try_user_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_user_config "(${1}${i},${part})"
		done
	done
}

function try_isolinux_config {
	set root="${1}"
	for dir in '' /boot; do
		if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
			syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
		elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
			syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
		fi
	done
}

function search_isolinux {
	for i in 0 1; do
		# raw devices
		try_isolinux_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_isolinux_config "(${1}${i},${part})"
		done
	done
}

menuentry 'Load Operating System (incl. fully encrypted disks)  [o]' --hotkey='o' {
# GRUB2 handles (almost) every possible disk setup, but only the location of
# /boot is actually important since GRUB2 only loads the user's config.

# LVM, RAID, filesystems and encryption on both raw devices and partitions in
# all various combinations need to be supported. Since full disk encryption is
# possible with GRUB2 as payload and probably even used by most users, this
# configuration tries to load the operating system in the following way:

# 1. Look for user configuration on unencrypted devices first to avoid
# unnecessary decryption routines in the following order:

#	1) raw devices and MBR/GPT partitions
	search_grub ahci
    search_grub ata
#	2) LVM and RAID which might be used accross multiple devices
	lvm="lvm/matrix-rootvol lvm/matrix-boot"
	raid="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
	for vol in ${lvm} ${raid}; do
		try_user_config "(${vol})"
	done
# 2. In case no configuration could be found, try decrypting devices. Look
# on raw crypto devices as well as inside LVM volumes this time.

#	The user will be prompted for a passphrase if a LUKS header was found.
	for dev in ahci0 ata0 usb0 ${lvm}; do
		cryptomount "(${dev})"
	done
#	3) encrypted devices/partitions
	for i in 0 1; do
		for part in 1 2 3 4 5; do
            for type in ahci ata; do
    			cryptomount "(${type}${i},${part})"
            done
		done
	done

#	3) encrypted devices/partitions
	search_grub crypto
#	4) LVM inside LUKS containers
	for vol in ${lvm}; do
		try_user_config "(${vol})"
	done

    # Last resort, if all else fails
    set root=ahci0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done

    # Last resort (for GA-G41-ES2L which uses IDE emulation mode for SATA)
    set root=ata0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done
}

menuentry 'Search ISOLINUX menu (AHCI)  [a]' --hotkey='a' {
	search_isolinux ahci
}

menuentry 'Search ISOLINUX menu (USB)  [u]' --hotkey='u' {
	search_isolinux usb
}

menuentry 'Search ISOLINUX menu (CD/DVD)  [d]' --hotkey='d' {
	insmod ata
	for dev in ata0 ata1 ata2 ata3 ahci1; do
		try_isolinux_config "(${dev})"
	done
}

menuentry 'Load test configuration (grubtest.cfg) inside of CBFS  [t]' --hotkey='t' {
	set root='(cbfsdisk)'
	configfile /grubtest.cfg
}

menuentry 'Search for GRUB2 configuration on external media  [s]' --hotkey='s' {
	search_grub usb
}

menuentry 'Poweroff  [p]' --hotkey='p' {
	halt
}

menuentry 'Reboot  [r]' --hotkey='r' {
	reboot
}


code:
insmod nativedisk
insmod ehci
insmod ohci
insmod uhci
insmod usb
insmod usbms
insmod usbserial_pl2303
insmod usbserial_ftdi
insmod usbserial_usbdebug
insmod png

# Serial and keyboard configuration, very important.
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
terminal_input --append  serial
terminal_output --append serial
terminal_input --append at_keyboard
terminal_output --append cbmemc
terminal_output --append gfxterm

load_env --file (cbfsdisk)/grubenv

# User's preferred keyboard layout
if [ -n "${keymap}" ]; then
	keymap "${keymap}"
fi

# Prettify GRUB
background_image "${gfxterm_background}"

function try_user_config {
	set root="${1}"
	for dir in boot grub grub2 boot/grub boot/grub2; do
		for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
			if [ -f /"${dir}"/"${name}"grub.cfg ]; then
                unset superusers
				configfile /"${dir}"/"${name}"grub.cfg
			fi
		done
	done
}

function search_grub {
	for i in 0 1; do
		# raw devices
		try_user_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_user_config "(${1}${i},${part})"
		done
	done
}

function try_isolinux_config {
	set root="${1}"
	for dir in '' /boot; do
		if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
			syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
		elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
			syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
		fi
	done
}

function search_isolinux {
	for i in 0 1; do
		# raw devices
		try_isolinux_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_isolinux_config "(${1}${i},${part})"
		done
	done
}

menuentry 'Load Operating System (incl. fully encrypted disks)  [o]' --hotkey='o' {
# GRUB2 handles (almost) every possible disk setup, but only the location of
# /boot is actually important since GRUB2 only loads the user's config.

# LVM, RAID, filesystems and encryption on both raw devices and partitions in
# all various combinations need to be supported. Since full disk encryption is
# possible with GRUB2 as payload and probably even used by most users, this
# configuration tries to load the operating system in the following way:

# 1. Look for user configuration on unencrypted devices first to avoid
# unnecessary decryption routines in the following order:

#	1) raw devices and MBR/GPT partitions
	search_grub ahci
    search_grub ata
#	2) LVM and RAID which might be used accross multiple devices
	lvm="lvm/matrix-rootvol lvm/matrix-boot"
	raid="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
	for vol in ${lvm} ${raid}; do
		try_user_config "(${vol})"
	done
# 2. In case no configuration could be found, try decrypting devices. Look
# on raw crypto devices as well as inside LVM volumes this time.

#	The user will be prompted for a passphrase if a LUKS header was found.
	for dev in ahci0 ata0 usb0 ${lvm}; do
		cryptomount "(${dev})"
	done
#	3) encrypted devices/partitions
	for i in 0 1; do
		for part in 1 2 3 4 5; do
            for type in ahci ata; do
    			cryptomount "(${type}${i},${part})"
            done
		done
	done

#	3) encrypted devices/partitions
	search_grub crypto
#	4) LVM inside LUKS containers
	for vol in ${lvm}; do
		try_user_config "(${vol})"
	done

    # Last resort, if all else fails
    set root=ahci0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done

    # Last resort (for GA-G41-ES2L which uses IDE emulation mode for SATA)
    set root=ata0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done
}

menuentry 'Search ISOLINUX menu (AHCI)  [a]' --hotkey='a' {
	search_isolinux ahci
}

menuentry 'Search ISOLINUX menu (USB)  [u]' --hotkey='u' {
	search_isolinux usb
}

menuentry 'Search ISOLINUX menu (CD/DVD)  [d]' --hotkey='d' {
	insmod ata
	for dev in ata0 ata1 ata2 ata3 ahci1; do
		try_isolinux_config "(${dev})"
	done
}

menuentry 'Load standard configuration (grub.cfg) inside of CBFS  [t]' --hotkey='t' {
	set root='(cbfsdisk)'
	configfile /grub.cfg
}

menuentry 'Search for GRUB2 configuration on external media  [s]' --hotkey='s' {
	search_grub usb
}

menuentry 'Poweroff  [p]' --hotkey='p' {
	halt
}

menuentry 'Reboot  [r]' --hotkey='r' {
	reboot
}


path: projects/grub/install/textmode/AUTHORS


code:
insmod nativedisk
insmod ehci
insmod ohci
insmod uhci
insmod usb
insmod usbms
insmod usbserial_pl2303
insmod usbserial_ftdi
insmod usbserial_usbdebug

# Serial and keyboard configuration, very important.
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
terminal_input --append  serial
terminal_output --append serial
terminal_input --append at_keyboard
terminal_output --append cbmemc
terminal_output --append gfxterm

load_env --file (cbfsdisk)/grubenv

# User's preferred keyboard layout
if [ -n "${keymap}" ]; then
	keymap "${keymap}"
fi

function try_user_config {
	set root="${1}"
	for dir in boot grub grub2 boot/grub boot/grub2; do
		for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
			if [ -f /"${dir}"/"${name}"grub.cfg ]; then
                unset superusers
				configfile /"${dir}"/"${name}"grub.cfg
			fi
		done
	done
}

function search_grub {
	for i in 0 1; do
		# raw devices
		try_user_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_user_config "(${1}${i},${part})"
		done
	done
}

function try_isolinux_config {
	set root="${1}"
	for dir in '' /boot; do
		if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
			syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
		elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
			syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
		fi
	done
}

function search_isolinux {
	for i in 0 1; do
		# raw devices
		try_isolinux_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_isolinux_config "(${1}${i},${part})"
		done
	done
}

menuentry 'Load Operating System (incl. fully encrypted disks)  [o]' --hotkey='o' {
# GRUB2 handles (almost) every possible disk setup, but only the location of
# /boot is actually important since GRUB2 only loads the user's config.

# LVM, RAID, filesystems and encryption on both raw devices and partitions in
# all various combinations need to be supported. Since full disk encryption is
# possible with GRUB2 as payload and probably even used by most users, this
# configuration tries to load the operating system in the following way:

# 1. Look for user configuration on unencrypted devices first to avoid
# unnecessary decryption routines in the following order:

#	1) raw devices and MBR/GPT partitions
	search_grub ahci
    search_grub ata
#	2) LVM and RAID which might be used accross multiple devices
	lvm="lvm/matrix-rootvol lvm/matrix-boot"
	raid="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
	for vol in ${lvm} ${raid}; do
		try_user_config "(${vol})"
	done
# 2. In case no configuration could be found, try decrypting devices. Look
# on raw crypto devices as well as inside LVM volumes this time.

#	The user will be prompted for a passphrase if a LUKS header was found.
	for dev in ahci0 ata0 usb0 ${lvm}; do
		cryptomount "(${dev})"
	done
#	3) encrypted devices/partitions
	for i in 0 1; do
		for part in 1 2 3 4 5; do
            for type in ahci ata; do
    			cryptomount "(${type}${i},${part})"
            done
		done
	done

#	3) encrypted devices/partitions
	search_grub crypto
#	4) LVM inside LUKS containers
	for vol in ${lvm}; do
		try_user_config "(${vol})"
	done

    # Last resort, if all else fails
    set root=ahci0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done

    # Last resort (for GA-G41-ES2L which uses IDE emulation mode for SATA)
    set root=ata0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done
}

menuentry 'Search ISOLINUX menu (AHCI)  [a]' --hotkey='a' {
	search_isolinux ahci
}

menuentry 'Search ISOLINUX menu (USB)  [u]' --hotkey='u' {
	search_isolinux usb
}

menuentry 'Search ISOLINUX menu (CD/DVD)  [d]' --hotkey='d' {
	insmod ata
	for dev in ata0 ata1 ata2 ata3 ahci1; do
		try_isolinux_config "(${dev})"
	done
}

menuentry 'Load test configuration (grubtest.cfg) inside of CBFS  [t]' --hotkey='t' {
	set root='(cbfsdisk)'
	configfile /grubtest.cfg
}

menuentry 'Search for GRUB2 configuration on external media  [s]' --hotkey='s' {
	search_grub usb
}

menuentry 'Load MemTest86+  [m]' --hotkey='m' {
	linux16 (cbfsdisk)/memtest.bin
}

menuentry 'Poweroff  [p]' --hotkey='p' {
	halt
}

menuentry 'Reboot  [r]' --hotkey='r' {
	reboot
}


code:
insmod nativedisk
insmod ehci
insmod ohci
insmod uhci
insmod usb
insmod usbms
insmod usbserial_pl2303
insmod usbserial_ftdi
insmod usbserial_usbdebug

# Serial and keyboard configuration, very important.
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
terminal_input --append  serial
terminal_output --append serial
terminal_input --append at_keyboard
terminal_output --append cbmemc
terminal_output --append gfxterm

load_env --file (cbfsdisk)/grubenv

# User's preferred keyboard layout
if [ -n "${keymap}" ]; then
	keymap "${keymap}"
fi

function try_user_config {
	set root="${1}"
	for dir in boot grub grub2 boot/grub boot/grub2; do
		for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
			if [ -f /"${dir}"/"${name}"grub.cfg ]; then
                unset superusers
				configfile /"${dir}"/"${name}"grub.cfg
			fi
		done
	done
}

function search_grub {
	for i in 0 1; do
		# raw devices
		try_user_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_user_config "(${1}${i},${part})"
		done
	done
}

function try_isolinux_config {
	set root="${1}"
	for dir in '' /boot; do
		if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
			syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
		elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
			syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
		fi
	done
}

function search_isolinux {
	for i in 0 1; do
		# raw devices
		try_isolinux_config "(${1}${i})"
		for part in 1 2 3 4 5; do
			# MBR/GPT partitions
			try_isolinux_config "(${1}${i},${part})"
		done
	done
}

menuentry 'Load Operating System (incl. fully encrypted disks)  [o]' --hotkey='o' {
# GRUB2 handles (almost) every possible disk setup, but only the location of
# /boot is actually important since GRUB2 only loads the user's config.

# LVM, RAID, filesystems and encryption on both raw devices and partitions in
# all various combinations need to be supported. Since full disk encryption is
# possible with GRUB2 as payload and probably even used by most users, this
# configuration tries to load the operating system in the following way:

# 1. Look for user configuration on unencrypted devices first to avoid
# unnecessary decryption routines in the following order:

#	1) raw devices and MBR/GPT partitions
	search_grub ahci
    search_grub ata
#	2) LVM and RAID which might be used accross multiple devices
	lvm="lvm/matrix-rootvol lvm/matrix-boot"
	raid="md/0 md/1 md/2 md/3 md/4 md/5 md/6 md/7 md/8 md/9"
	for vol in ${lvm} ${raid}; do
		try_user_config "(${vol})"
	done
# 2. In case no configuration could be found, try decrypting devices. Look
# on raw crypto devices as well as inside LVM volumes this time.

#	The user will be prompted for a passphrase if a LUKS header was found.
	for dev in ahci0 ata0 usb0 ${lvm}; do
		cryptomount "(${dev})"
	done
#	3) encrypted devices/partitions
	for i in 0 1; do
		for part in 1 2 3 4 5; do
            for type in ahci ata; do
    			cryptomount "(${type}${i},${part})"
            done
		done
	done

#	3) encrypted devices/partitions
	search_grub crypto
#	4) LVM inside LUKS containers
	for vol in ${lvm}; do
		try_user_config "(${vol})"
	done

    # Last resort, if all else fails
    set root=ahci0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done

    # Last resort (for GA-G41-ES2L which uses IDE emulation mode for SATA)
    set root=ata0,1
    for p in / /boot/; do
        if [ -f "${p}vmlinuz" ]; then
            linux ${p}vmlinuz root=/dev/sda1 rw
            if [ -f "${p}initrd.img" ]; then
                initrd ${p}initrd.img
            fi
        fi
    done
}

menuentry 'Search ISOLINUX menu (AHCI)  [a]' --hotkey='a' {
	search_isolinux ahci
}

menuentry 'Search ISOLINUX menu (USB)  [u]' --hotkey='u' {
	search_isolinux usb
}

menuentry 'Search ISOLINUX menu (CD/DVD)  [d]' --hotkey='d' {
	insmod ata
	for dev in ata0 ata1 ata2 ata3 ahci1; do
		try_isolinux_config "(${dev})"
	done
}

menuentry 'Load standard configuration (grub.cfg) inside of CBFS  [t]' --hotkey='t' {
	set root='(cbfsdisk)'
	configfile /grub.cfg
}

menuentry 'Search for GRUB2 configuration on external media  [s]' --hotkey='s' {
	search_grub usb
}

menuentry 'Load MemTest86+  [m]' --hotkey='m' {
	linux16 (cbfsdisk)/memtest.bin
}

menuentry 'Poweroff  [p]' --hotkey='p' {
	halt
}

menuentry 'Reboot  [r]' --hotkey='r' {
	reboot
}


code:
From 721f09ef24e1879667ac3469c17774450602b29e Mon Sep 17 00:00:00 2001
From: Leah Rowe <info@minifree.org>
Date: Sat, 14 Feb 2015 01:24:23 +0000
Subject: [PATCH 01/10] grub-core/normal/main.c: Display "FREE AS IN FREEDOM",
 not version

---
 grub-core/normal/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 78a70a8..982bde3 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -208,7 +208,7 @@ grub_normal_init_page (struct grub_term_output *term,

   grub_term_cls (term);

-  msg_formatted = grub_xasprintf (_("GNU GRUB  version %s"), PACKAGE_VERSION);
+  msg_formatted = grub_xasprintf("FREE AS IN FREEDOM");
   if (!msg_formatted)
     return;

--
1.9.1


code:
From 8dde1d7be2dd321a375570b7ff7e22bb01293044 Mon Sep 17 00:00:00 2001
From: Alexander Couzens <lynxis@fe80.eu>
Date: Fri, 4 Dec 2015 17:10:42 +0100
Subject: [PATCH 08/10] mkstandalone: add argument --fixed-time to override
 mtime of files

mkstandalone adds several files to an archive. Doing this it uses the
mtime to give these files a timestamp.
--fixed-time <TIME_EPOCH> overrides these timestamps with a given.

Replacing all timestamps with a specific one is required
to get reproducible builds. See source epoch specification of
reproducible-builds.org
---
 util/grub-mkstandalone.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c
index 4907d44..047f0cd 100644
--- a/util/grub-mkstandalone.c
+++ b/util/grub-mkstandalone.c
@@ -30,6 +30,7 @@
 #pragma GCC diagnostic error "-Wmissing-prototypes"
 #pragma GCC diagnostic error "-Wmissing-declarations"

+static time_t fixed_time;
 static char *output_image;
 static char **files;
 static int nfiles;
@@ -48,6 +49,7 @@ static struct argp_option options[] = {
    0, N_("save output in FILE [required]"), 2},
   {"format", 'O', N_("FILE"), 0, 0, 2},
   {"compression", 'C', "xz|none|auto", OPTION_HIDDEN, 0, 2},
+  {"fixed-time", 't', N_("TIMEEPOCH"), 0, N_("Use a fixed timestamp to override mtime of all files. Time since epoch is used."), 2},
   {0, 0, 0, 0, 0, 0}
 };

@@ -72,6 +74,7 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused)))
 static error_t
 argp_parser (int key, char *arg, struct argp_state *state)
 {
+  char *b;
   if (key == 'C')
     key = GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS;

@@ -80,6 +83,14 @@ argp_parser (int key, char *arg, struct argp_state *state)

   switch (key)
     {
+    case 't':
+      fixed_time = strtoll (arg, &b, 10);
+      if (*b !='\0') {
+        printf (_("invalid fixed time number: %s\n"), arg);
+        argp_usage (state);
+        exit (1);
+      }
+      break;

     case 'o':
       if (output_image)
@@ -192,7 +203,8 @@ add_tar_file (const char *from,
   if (grub_util_is_special_file (from))
     return;

-  mtime = grub_util_get_mtime (from);
+  /* use fixed_time if given for mtime */
+  mtime = fixed_time != -1 ? fixed_time : grub_util_get_mtime (from);

   optr = tcn = xmalloc (strlen (to) + 1);
   for (iptr = to; *iptr == '/'; iptr++);
--
1.9.1


code:
From 0f1e1a29d4d019e7b2b1a3ac3db7ca22c75e8d88 Mon Sep 17 00:00:00 2001
From: Alexander Couzens <lynxis@fe80.eu>
Date: Fri, 4 Dec 2015 17:10:43 +0100
Subject: [PATCH 09/10] mkrescue: add argument --fixed-time to get reproducible
 uuids

The uuid generation is based on the time.
---
 util/grub-mkrescue.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c
index 238d484..a3e0155 100644
--- a/util/grub-mkrescue.c
+++ b/util/grub-mkrescue.c
@@ -52,6 +52,7 @@ static int xorriso_arg_alloc;
 static char **xorriso_argv;
 static char *iso_uuid;
 static char *iso9660_dir;
+static time_t fixed_time;

 static void
 xorriso_push (const char *val)
@@ -110,6 +111,7 @@ static struct argp_option options[] = {
   {"product-version", OPTION_PRODUCT_VERSION, N_("STRING"), 0, N_("use STRING as product version"), 2},
   {"sparc-boot", OPTION_SPARC_BOOT, 0, 0, N_("enable sparc boot. Disables HFS+, APM, ARCS and boot as disk image for i386-pc"), 2},
   {"arcs-boot", OPTION_ARCS_BOOT, 0, 0, N_("enable ARCS (big-endian mips machines, mostly SGI) boot. Disables HFS+, APM, sparc64 and boot as disk image for i386-pc"), 2},
+  {"fixed-time", 't', N_("TIMEEPOCH"), 0, N_("use a fixed timestamp for uuid generation"), 2},
   {0, 0, 0, 0, 0, 0}
 };

@@ -153,6 +155,8 @@ enum {
 static error_t
 argp_parser (int key, char *arg, struct argp_state *state)
 {
+  char *b;
+
   if (grub_install_parse (key, arg))
     return 0;
   switch (key)
@@ -212,6 +216,15 @@ argp_parser (int key, char *arg, struct argp_state *state)
       xorriso = xstrdup (arg);
       return 0;

+    case 't':
+      fixed_time = strtoll (arg, &b, 10);
+      if (*b !='\0') {
+        printf (_("invalid fixed time number: %s\n"), arg);
+        argp_usage (state);
+        exit (1);
+      }
+      return 0;
+
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -542,7 +555,7 @@ main (int argc, char *argv[])
   {
     time_t tim;
     struct tm *tmm;
-    tim = time (NULL);
+    tim = fixed_time != -1 ? fixed_time : time (NULL);
     tmm = gmtime (&tim);
     iso_uuid = xmalloc (55);
     grub_snprintf (iso_uuid, 50,
--
1.9.1


code:
From 57174ed960905be4f9c229bbf3913b25745dbfd9 Mon Sep 17 00:00:00 2001
From: Alexander Couzens <lynxis@fe80.eu>
Date: Fri, 4 Dec 2015 17:10:44 +0100
Subject: [PATCH 10/10] Makefile: use FIXED_TIMESTAMP for mkstandalone if set

mkstandalone sets timestamps for files which can be overriden by a fixed_timestamp.
This makes it possible to build reproducible builds for coreboot.

To build a reproducible build of grub for coreboot do:
make default_payload.elf FIXED_TIMESTAMP=1134242
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 00a9663..ed7f148 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -411,7 +411,7 @@ bootcheck: $(BOOTCHECKS)
 if COND_i386_coreboot
 default_payload.elf: grub-mkstandalone grub-mkimage FORCE
 	test -f $@ && rm $@ || true
-	pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu $(shell cat grub-core/fs.lst) password_pbkdf2 $(EXTRA_PAYLOAD_MODULES)' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg
+	pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu $(shell cat grub-core/fs.lst) password_pbkdf2 $(EXTRA_PAYLOAD_MODULES)' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg $(if $(FIXED_TIMESTAMP),-t $(FIXED_TIMESTAMP))
 endif

 endif
--
1.9.1


code:
lib/libftdigpio.so:libftdigpio.so
lib/libftdii2c.so:libftdii2c.so
lib/libftdiuart.so:libftdiuart.so
servo:servo
src/toad/toad:toad
usbkm232:usbkm232

path: projects/hdctools/configs/install


code:
#!/usr/bin/env bash

# Copyright (C) 2016 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/>.

download() {
	local repository=$project

	project_download_git "$project" "$repository" "https://chromium.googlesource.com/chromiumos/third_party/hdctools" "$@"
}

download_check() {
	local repository=$project

	project_download_check_git "$project" "$repository" "$@"
}

extract() {
	local repository=$project

	project_extract "$project" "$@"
}

extract_check() {
	local repository=$project

	project_extract_check "$project" "$@"
}

update() {
	local repository=$project

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository=$project

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local repository=$project

	requirements "tidy"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	local sources_path=$(project_sources_path "$project" "$repository" "$@")
	local build_path=$(project_build_path "$project" "$@")

	if git_project_check "$repository"
	then
		git_project_checkout "$project" "$repository" "$@"
	fi

	mkdir -p "$build_path"

	make -C "$sources_path" HDCTOOLS_BUILD_DIR="$build_path" -j$TASKS
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local repository=$project

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository=$project

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/hdctools/hdctools


code:
From 05fde50f4991623525edb6b15340011af53cd31e Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Sun, 20 Nov 2016 15:08:39 +0100
Subject: [PATCH] Remove Werror flag

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 defs/c-Linux.mk | 1 -
 1 file changed, 1 deletion(-)

diff --git a/defs/c-Linux.mk b/defs/c-Linux.mk
index c2c3129..4f1bbee 100644
--- a/defs/c-Linux.mk
+++ b/defs/c-Linux.mk
@@ -34,7 +34,6 @@ HOSTOS_CWARN	=				\
 	-Wdeclaration-after-statement		\
 	-Wdisabled-optimization			\
 	-Wempty-body				\
-	-Werror					\
 	-Wextra					\
 	-Wfloat-equal				\
 	-Wformat				\
--
2.10.2


code:
ich9fdgbe_4m.bin:ich9fdgbe_4m.bin
ich9fdgbe_8m.bin:ich9fdgbe_8m.bin
ich9fdgbe_16m.bin:ich9fdgbe_16m.bin
ich9fdnogbe_4m.bin:ich9fdnogbe_4m.bin
ich9fdnogbe_8m.bin:ich9fdnogbe_8m.bin
ich9fdnogbe_16m.bin:ich9fdnogbe_16m.bin
ich9gen:ich9gen
mkgbe.c:mkgbe.c
mkgbe.h:mkgbe.h


code:
#!/usr/bin/env bash

# Copyright (C) 2016 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/>.

arguments() {
	project_arguments_targets "$project" "$@"
}

usage() {
	project_usage_actions "$project"
	project_usage_arguments "$project" "$@"
}

extract() {
	local repository="$project"

	project_extract "$project" "$@"
}

extract_check() {
	local repository="$project"

	project_extract_check "$project" "$@"
}

update() {
	local repository="$project"

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository="$project"

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local repository="$project"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	if git_project_check "$repository"; then
		git_project_checkout "$project" "$repository" "$@"
	fi

	local sources_path="$(project_sources_path "$project" "$repository" "$@")"

	local build_path="$(project_build_path "$project" "$@")"

	mkdir -p "$build_path"
	make -C "$sources_path" -j"$TASKS" ich9gen

	(
		local macaddress="$(ich9gen_macaddress)"

		cd "$build_path"

		if [[ -n $macaddress ]]; then
			"$sources_path"/ich9gen --macaddress "$macaddress"
		else
			"$sources_path"/ich9gen
		fi
	)

	cp "$sources_path/ich9gen" "$build_path"
	make -C "$sources_path" clean
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	project_release_install_archive "$project" "$TOOLS" "$@"
	project_release_sources_archive_create "$project" "$@"
}

release_check() {
	project_release_install_archive_check "$project" "$TOOLS" "$@"
	project_release_sources_archive_exists_check "$project" "$@"
}

clean() {
	project_clean "$project" "$@"
}


code:
#!/usr/bin/env bash

# Copyright (C) 2018 Andrew Robbins <contact@andrewrobbins.info>
#
# 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/>.

MACADDRESS='macaddress'

ich9gen_macaddress() {
	project_file_contents "$project" "$CONFIGS" "$MACADDRESS" "$@"
}


code:
#
# Makefile for ich9deblob utility from libreboot project
#
# 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/>.
#

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

.PHONY: all clean

all: ich9deblob ich9gen demefactory

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


code:
/*
 *  descriptor_gbe.c
 *  This file is part of the ich9deblob utility from the libreboot project
 *
 * Purpose: common descriptor/gbe functions used by ich9deblob
 *
 *  Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "descriptor_gbe.h"

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

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

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

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

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

	fclose(fileStream);

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

	return 0;
}

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

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

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

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

	fclose(fileStream);

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

	return 0;
}


code:
/*
 *  gbe_descriptor.h
 *  This file is part of the ich9deblob utility from the libreboot project
 *
 * Purpose: header file for descriptor_gbe.c
 *
 *  Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef COMMON_DESCRIPTOR_GBE_H
#define COMMON_DESCRIPTOR_GBE_H

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

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

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

#endif


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

#include "x86compatibility.h"

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

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

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

	return 0;
}

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

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

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

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

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

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

		return 1;
	}

	return 0;
}

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

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

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

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

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

		return 1;
	}

	return 0;
}

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


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

#ifndef X86COMPATIBILITY_H
#define X86COMPATIBILITY_H

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

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

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

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

#endif


code:
/*
 *  demefactory.c
 *  This file is part of the demefactory utility from the libreboot project
 *
 * Purpose: disable ME on GM45 factory firmware, but leave region intact
 * 			enable read-write on all regions
 *
 *	 Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
 *  Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * demfactory utility - main
 */

#include "demefactory.h"

int main()
{
	struct DESCRIPTORREGIONRECORD descriptorStruct;
	uint8_t* descriptorBuffer = (uint8_t*)&descriptorStruct;

	struct GBEREGIONRECORD_8K gbeStruct8k; /* not needed, except for compatibility checking */

	char* romFilename = "factory.rom";
	char* descriptorFilename = "demefactory_4kdescriptor.bin";

	unsigned int bufferLength;
	unsigned int romSize;

	/*
	 * ------------------------------------------------------------------
	 * Compatibility checks. This version of ich9deblob is not yet portable.
	 * ------------------------------------------------------------------
	 */

	if (systemOrCompilerIncompatible(descriptorStruct, gbeStruct8k)) return 1;
	/* If true, fail with error message */

	/*
	 * ------------------------------------------------------------------
	 * Extract the descriptor region from the factory.rom dump
	 * ------------------------------------------------------------------
	 */
	FILE* fp = NULL;
	fp = fopen(romFilename, "rb"); /* open factory.rom */
	if (NULL == fp)
	{
		printf("\nerror: could not open %s\n", romFilename);
		fclose(fp);
		return 1;
	}
	printf("\n%s opened successfully\n", romFilename);

	/*
	 * Get the descriptor region dump from the factory.rom
	 * (goes in factoryDescriptorBuffer variable)
	 */
	bufferLength = fread(descriptorBuffer, 1, DESCRIPTORREGIONSIZE, fp);
	if (DESCRIPTORREGIONSIZE != bufferLength) //
	{
		printf("\nerror: could not read descriptor from %s (%i) bytes read\n", romFilename, bufferLength);
		fclose(fp);
		return 1;
	}
	printf("\ndescriptor region read successfully\n");

	/* ------------------------------------------------- */

	fseek(fp, 0L, SEEK_END);
	romSize = ftell(fp);
	printf("\n%s size: [%i] bytes\n", romFilename, romSize);

	/* -------------------------------------------------- */

	fclose(fp);

	/* Debugging (before modification) */
	printDescriptorRegionLocations(descriptorStruct, "Original");

	/*
	 * ------------------------------------------------------------------
	 * Modify the descriptor region, ready to go in the modified factory.rom
	 * ------------------------------------------------------------------
	 */

	// Disable the ME/TPM:
	descriptorStruct = descriptorDisableMe(descriptorStruct);
	descriptorStruct = descriptorDisableTpm(descriptorStruct);

	/* Host/CPU is allowed to read/write all regions. */
	descriptorStruct = descriptorHostRegionsUnlocked(descriptorStruct);
	/* The ME is disallowed read-write access to all regions
	 * (this is probably redundant, since the ME is already removed from libreboot) */
	descriptorStruct = descriptorMeRegionsForbidden(descriptorStruct);

	/* Debugging (after modifying the descriptor region) */
	printDescriptorRegionLocations(descriptorStruct, "Modified");

	/*
	 * ------------------------------------------------------------------
	 * Create the file with the modified descriptor inside
	 * ------------------------------------------------------------------
	 */

	printf("\n");
	if (notCreated4kDescriptorFile(descriptorStruct, descriptorFilename)) {
		return 1;
	}

	/*
	 * ------------------------------------------------------------------
	 * Generate ich9gen data (C code that will recreate the deactivatedME descriptor from scratch)
	 * ------------------------------------------------------------------
	 */
	/* Code for generating the Descriptor struct */
	/* mkdescriptor.h */
	if (notCreatedHFileForDescriptorCFile("mkdescriptor.h", "mkdescriptor.c")) {
		return 1;
	} /* and now mkdescriptor.c */
	if (notCreatedCFileFromDescriptorStruct(descriptorStruct, "mkdescriptor.c", "mkdescriptor.h")) {
		return 1;
	}

	printf("The modified descriptor region has also been dumped as src files: mkdescriptor.c, mkdescriptor.h\n\n");

	return 0;
}


code:
/*
 *  Copyright (C) 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/>.
 */

/* Header file for demefactory.c */

#ifndef DEMEFACTORY_H
#define DEMEFACTORY_H

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

#include "common/descriptor_gbe.h"   /* common descriptor/gbe functions used by ich9deblob */
#include "common/x86compatibility.h" /* system/compiler compatibility checks. This code is not portable. */
#include "descriptor/descriptor.h"   /* structs describing what's in the descriptor region */
#include "gbe/gbe.h"                 /* structs describing what's in the gbe region */

int main();

#endif