#!/bin/bash

#  helper script: downloads depthcharge and patches it
#
#	Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# This script assumes that the working directory is the
# root of libreboot_src or libreboot git.

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

# Get depthcharge and patch it

printf "Downloading depthcharge\n"

rm -Rf "depthcharge/"

# Get depthcharge
# ------------------------------------------------------------------------------

# download depthcharge from git
git clone https://chromium.googlesource.com/chromiumos/platform/depthcharge

# enter the tree to patch it
cd "depthcharge/"

# reset to the latest previously tested revision
git reset --hard 3a5d54e31267578f48fb283fae56a405108f1498

# Patch depthcharge
# ------------------------------------------------------------------------------

printf "arm: armv7-a march abi flag for ARMv7 hardware\n"
git am "../resources/depthcharge/patch/0001-arm-armv7-a-march-abi-flag-for-ARMv7-hardware.patch"

printf "Coreboot image integration removal\n"
git am "../resources/depthcharge/patch/0002-Coreboot-image-integration-removal.patch"

printf "DOTCONFIG location correction\n"
git am "../resources/depthcharge/patch/0003-DOTCONFIG-location-correction.patch"

printf "Adaptation for a read-only boot path when no vboot handoff data is found\n"
git am "../resources/depthcharge/patch/0004-Adaptation-for-a-read-only-boot-path-when-no-vboot-h.patch"

printf "Proper firmware index report for read-only boot path\n"
git am "../resources/depthcharge/patch/0005-Proper-firmware-index-report-for-read-only-boot-path.patch"

printf "fdt: nonvolatile-context-storage report to mkbp for EC NV storage\n"
git am "../resources/depthcharge/patch/0006-fdt-nonvolatile-context-storage-report-to-mkbp-for-E.patch"

printf "vboot: Display callbacks for developer and recovery mode screens\n"
git am "../resources/depthcharge/patch/0007-vboot-Display-callbacks-for-developer-and-recovery-m.patch"

# leave the tree
cd "../"

printf "\n\n"
