mb/amb/birman*/gpio: remove configuration for VDD_MEM_VID[0,1]
[coreboot2.git] / payloads / external / tint / generate_core.sh
blob834906b5fcffd5d743bbd0e42c39e7f46ab9f5cd
1 #!/bin/sh
3 # generate_core.sh extracts the core part from buildgcc script,
4 # most importantly the checksum calculation/verification functions.
6 # Copyright (C) 2019 Mike Banon <mikebdp2@gmail.com>
8 ##############################################################################
10 # USAGE:
11 # ./generate_core.sh <buildgcc> <corescript> prepare_before_patch
12 # where
13 # buildgcc - path to input buildgcc script
14 # corescript - path to output core part script
15 # prepare_before_patch - optional argument to insert prepare_${package}
16 # call into the unpack_and_patch function, e.g.
17 # for removing some files with rm command
18 # in order to reduce the size of patch file
20 ##############################################################################
22 buildgcc="$1"
23 corescript="$2"
24 prepare_before_patch="$3"
27 # Imports the source file fragment between start and end into the
28 # destination file, optionally excluding the last line if not needed
31 import_from_file() {
32 source="$1"
33 destination="$2"
34 start="$3"
35 end="$4"
36 last_line_disabled="$5"
37 if [ -z "${last_line_disabled}" ] ; then
38 sed -n "/^${start}/,/^${end}/{/^${start}/{p;n};{p}}" "$source" >> "$destination"
39 else
40 sed -n "/^${start}/,/^${end}/{/^${start}/{p;n};/^${end}/{q};{p}}" "$source" >> "$destination"
45 # Import the color defines together with UNAME/HALT_FOR_TOOLS variables
48 import_from_file "$buildgcc" "$corescript" "red=" "HALT_FOR_TOOLS=0" || exit "$?"
51 # Import the core functions
54 FUNCTIONS="please_install searchtool download compute_hash error_hash_mismatch verify_hash unpack_and_patch"
56 for F in $FUNCTIONS ; do
57 import_from_file "$buildgcc" "$corescript" "$F()" "}" || exit "$?"
58 done
61 # Import a fragment where we find tar/patch/make and other essential tools
64 import_from_file "$buildgcc" "$corescript" "# Find all the required tools" "# Allow" "last_line_disabled" || exit "$?"
67 # Import a fragment with conditional exit if some required tools were not found
70 import_from_file "$buildgcc" "$corescript" "if \[ \"\$HALT_FOR_TOOLS" "fi" || exit "$?"
73 # Avoid the unnecessary subdirectories holding a single file each
76 sed -i -e "s/patches\///g" "$corescript"
77 sed -i -e "s/sum\///g" "$corescript"
78 sed -i -e "s/tarballs\///g" "$corescript"
79 sed -i -e "s/cd tarballs || exit 1//g" "$corescript"
80 sed -i -e "s/cd \.\.//g" "$corescript"
83 # Get the known checksum without using a dedicated single-line file
86 sed -i -e "s/\tknown_hash=\"\$(get_known_hash.*/\tknown_hash=\"\$2\"/g" "$corescript"
89 # Update the paths printed at the error messages
92 sed -i -e "s/util\/crossgcc\///g" "$corescript"
95 # Insert prepare_${package} function call between the unpack and patch operations
98 if [ ! -z "${prepare_before_patch}" ] ; then
99 sed -i -e "/\$TAR \$FLAGS \"\$(basename \"\$archive\")\"/a prepare_\${package} || exit \"\$?\"" "$corescript"
100 sed -i -e "/\$TAR \$FLAGS \"\$archive\"/a prepare_\${package} || exit \"\$?\"" "$corescript"