From 99d226cca1bd66d7b3c74cb42f8d36a779fa3ff4 Mon Sep 17 00:00:00 2001
From: Francis Rowe <info@gluglug.org.uk>
Date: Sat, 16 May 2015 13:44:44 -0400
Subject: coreboot-libre: delete unused code (reduce size of src archive)

---
diff --git a/docs/maintain/index.html b/docs/maintain/index.html
index 3c45771..52b3830 100644
--- a/docs/maintain/index.html
+++ b/docs/maintain/index.html
@@ -275,6 +275,14 @@
 			</p>
 			
 			<p>
+				You should also make sure to update
+				<i>resources/scripts/helpers/build/trim/coreboot</i>
+				which purges unused parts of coreboot. Basically, if it's
+				purging parts that you now need, then that's a bug and you
+				should fix it.
+			</p>
+			
+			<p>
 				You should also test the resulting ROM images from building
 				with the new or modified coreboot revision.
 			</p>
@@ -326,6 +334,15 @@
 				configuration:<br/>
 				$ <b>./build config corebootmodify</b> (adding a board name on the end is optional)
 			</p>
+			
+			<p>
+				You should also make sure to update the whitelist in
+				<i>resources/scripts/helpers/build/trim/coreboot</i>
+				which purges unused parts of coreboot (including boards). 
+				Basically, if it's
+				purging parts that you now need, then that's a bug and you
+				should fix it.
+			</p>
 
 			<p>
 				<a href="#pagetop">Back to top of page</a>.
diff --git a/docs/release.html b/docs/release.html
index 392e990..048f67b 100644
--- a/docs/release.html
+++ b/docs/release.html
@@ -114,6 +114,12 @@
 				Changes for this release (earliest changes last, recent changes first)
 			</h2>
 				<ul>
+					<li>coreboot-libre: delete unused code (reduce size of src archive)</li>
+					<li>Flashing guides: make them more friendly to colourblind people</li>
+					<li>
+						docs/gnulinux/encrypted_*.html: Remove mention of password length
+						- it was arbitrary and pointless.
+					</li>
 					<li>docs/maintain/index.html: Finish the guide</li>
 					<li>
 						scripts/download/coreboot: use diffs included in libreboot, not external gerrit cherry-picks
diff --git a/resources/libreboot/config/qemu_i440fx_piix4/config b/resources/libreboot/config/qemu_i440fx_piix4/config
index ab19908..c37611d 100644
--- a/resources/libreboot/config/qemu_i440fx_piix4/config
+++ b/resources/libreboot/config/qemu_i440fx_piix4/config
@@ -292,8 +292,6 @@ CONFIG_NATIVE_VGA_INIT_USE_EDID=y
 CONFIG_MAINBOARD_HAS_NATIVE_VGA_INIT_TEXTMODECFG=y
 # CONFIG_VGA_ROM_RUN is not set
 # CONFIG_ON_DEVICE_ROM_RUN is not set
-# CONFIG_PCI_OPTION_ROM_RUN_REALMODE is not set
-# CONFIG_PCI_OPTION_ROM_RUN_YABEL is not set
 # CONFIG_MULTIPLE_VGA_ADAPTERS is not set
 # CONFIG_SPD_CACHE is not set
 CONFIG_PCI=y
@@ -428,8 +426,6 @@ CONFIG_PAYLOAD_ELF=y
 # CONFIG_PAYLOAD_FILO is not set
 # CONFIG_PAYLOAD_GRUB2 is not set
 # CONFIG_PAYLOAD_TIANOCORE is not set
-# CONFIG_SEABIOS_STABLE is not set
-# CONFIG_SEABIOS_MASTER is not set
 # CONFIG_SEABIOS_THREAD_OPTIONROMS is not set
 # CONFIG_SEABIOS_VGA_COREBOOT is not set
 CONFIG_PAYLOAD_FILE="grub.elf"
diff --git a/resources/libreboot/config/qemu_q35_ich9/config b/resources/libreboot/config/qemu_q35_ich9/config
index 9c048e9..37855a9 100644
--- a/resources/libreboot/config/qemu_q35_ich9/config
+++ b/resources/libreboot/config/qemu_q35_ich9/config
@@ -294,8 +294,6 @@ CONFIG_NATIVE_VGA_INIT_USE_EDID=y
 CONFIG_MAINBOARD_HAS_NATIVE_VGA_INIT_TEXTMODECFG=y
 # CONFIG_VGA_ROM_RUN is not set
 # CONFIG_ON_DEVICE_ROM_RUN is not set
-# CONFIG_PCI_OPTION_ROM_RUN_REALMODE is not set
-# CONFIG_PCI_OPTION_ROM_RUN_YABEL is not set
 # CONFIG_MULTIPLE_VGA_ADAPTERS is not set
 # CONFIG_SPD_CACHE is not set
 CONFIG_PCI=y
@@ -430,8 +428,6 @@ CONFIG_PAYLOAD_ELF=y
 # CONFIG_PAYLOAD_FILO is not set
 # CONFIG_PAYLOAD_GRUB2 is not set
 # CONFIG_PAYLOAD_TIANOCORE is not set
-# CONFIG_SEABIOS_STABLE is not set
-# CONFIG_SEABIOS_MASTER is not set
 # CONFIG_SEABIOS_THREAD_OPTIONROMS is not set
 # CONFIG_SEABIOS_VGA_COREBOOT is not set
 CONFIG_PAYLOAD_FILE="grub.elf"
diff --git a/resources/scripts/helpers/build/release/archives b/resources/scripts/helpers/build/release/archives
index 74547ef..a70f348 100755
--- a/resources/scripts/helpers/build/release/archives
+++ b/resources/scripts/helpers/build/release/archives
@@ -404,6 +404,9 @@ rm -rf libreboot_src/resources/utilities/coreboot-libre/
 rm -rf libreboot_src/resources/scripts/helpers/build/release
 rm -f libreboot_src/download
 rm -rf libreboot_src/resources/scripts/helpers/download/
+# no need for script to purge sources, since purged sources
+# are already included in libreboot_src
+rm -rf libreboot_src/resources/scripts/helpers/build/trim/
 
 # Patches are not needed, because they are
 # already merged in libreboot_src/coreboot/
diff --git a/resources/scripts/helpers/build/trim/coreboot b/resources/scripts/helpers/build/trim/coreboot
new file mode 100755
index 0000000..efb7960
--- /dev/null
+++ b/resources/scripts/helpers/build/trim/coreboot
@@ -0,0 +1,313 @@
+#!/bin/bash
+
+#  helper: trim the coreboot-libre source code (delete unused parts)
+#
+#	Copyright (C) 2015 Francis Rowe <info@gluglug.org.uk>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# This script assumes that the working directory is the root
+# of libreboot_src or git
+
+[ "x${DEBUG+set}" = 'xset' ] && set -v
+set -u -e
+
+printf "purging unused parts of coreboot-libre...\n"
+
+printf "Size of coreboot directory before the purge: $(du -ch coreboot | grep total)\n"
+
+cd coreboot/
+
+# __UNUSED BOARDS_______________________________________________________
+
+printf "deleting unused boards\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/mainboard/
+
+whitelist=" \
+$(find ./apple/macbook21/) \
+$(find ./emulation/qemu-i440fx/) \
+$(find ./emulation/qemu-q35/ ) \
+$(find ./lenovo/r400/) \
+$(find ./lenovo/t60/) \
+$(find ./lenovo/t400/) \
+$(find ./lenovo/t500/) \
+$(find ./lenovo/x60/) \
+$(find ./lenovo/x200/) \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+# __UNUSED VENDORCODE___________________________________________________
+
+printf "deleting unused vendor code\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/vendorcode/
+
+whitelist=" \
+./google/chromeos/chromeos.h \
+./google/chromeos/gnvs.h \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+# __Unused architectures________________________________________________
+
+printf "deleting unused CPU architectures\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/arch/
+
+whitelist=" \
+$(find ./x86/) \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+# __Unused SoC code_____________________________________________________
+
+printf "deleting unused SoCs\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/soc/
+
+whitelist=" \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+# __Unused northbridge code_____________________________________________
+
+printf "deleting unused northbridges\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/northbridge/
+
+whitelist=" \
+$(find ./intel/i945/) \
+$(find ./intel/gm45/) \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+# __Unused southbridge code_____________________________________________
+
+printf "deleting unused southbridges\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/southbridge/
+
+whitelist=" \
+$(find ./intel/i82371eb/) \
+$(find ./intel/i82801gx/) \
+$(find ./intel/i82801ix/) \
+$(find ./intel/common/) \
+$(find ./ti/pci1x2x/) \
+$(find ./ricoh/rl5c476/) \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+# __Unused CPU code_____________________________________________________
+
+printf "deleting unused CPUs\n"
+
+# keep the Kconfig files in place, otherwise there are build errors
+
+cd src/cpu/
+
+whitelist=" \
+$(find ./intel/) \
+$(find ./x86/) \
+$(find -type f -name 'Kconfig') \
+$(find -type f -name 'Makefile.inc') \
+"
+
+for file in $(find -type f); do
+
+	# keep files that are in the whitelist
+	cnt="0"
+	for keep in $whitelist; do
+		if [ "$keep" = "$file" ]; then
+			cnt="1"
+			break
+		fi
+	done
+	if [ "$cnt" = "1" ]; then
+		continue
+	fi
+	
+	# delete if it's not in the whitelist
+	rm -f $file
+	
+done
+
+cd ../../
+
+# ______________________________________________________________________
+
+cd ../
+
+printf "Size of coreboot directory after the purge: $(du -ch coreboot | grep total)\n"
+
+printf "...done\n"
+
+printf "\n\n"
diff --git a/resources/scripts/helpers/download/coreboot b/resources/scripts/helpers/download/coreboot
index cbf71d5..e4363ee 100755
--- a/resources/scripts/helpers/download/coreboot
+++ b/resources/scripts/helpers/download/coreboot
@@ -144,6 +144,9 @@ cd ../
 printf "Deblobbing coreboot\n"
 ./resources/utilities/coreboot-libre/deblob
 
+# Delete the unused parts of coreboot-libre
+./build trim coreboot
+
 printf "\n\n"
 
 # ------------------- DONE ----------------------
--
cgit v0.9.1