Zheng Bao (zheng.bao@amd.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1417
-gerrit
commit f150a1500a3919eef7cf33df9a0f61cf889cd86a Author: zbao fishbaozi@gmail.com Date: Fri Aug 17 18:21:37 2012 +0800
AMD Hudson: Move the combining firmware from Python to sh.
Maybe sooner or later python is not a default tools to build coreboot. Most of the work is done by awk now. GNU extension of gawk is not used, isn't? printf, cat, awk, test, mv are the external tools. If XHCI, IMC or GEC firmware is not available and not defined, this script can skip integrating them.
Change-Id: I9944b22b0b755672a46d472c355d138abafd6393 Signed-off-by: Zheng Bao zheng.bao@amd.com Signed-off-by: zbao fishbaozi@gmail.com --- src/southbridge/amd/agesa/hudson/Makefile.inc | 7 ++- src/southbridge/amd/agesa/hudson/hudson_fwm.py | 64 ---------------------- src/southbridge/amd/agesa/hudson/hudson_fwm.sh | 74 ++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 66 deletions(-)
diff --git a/src/southbridge/amd/agesa/hudson/Makefile.inc b/src/southbridge/amd/agesa/hudson/Makefile.inc index 19ffae1..1642ba2 100644 --- a/src/southbridge/amd/agesa/hudson/Makefile.inc +++ b/src/southbridge/amd/agesa/hudson/Makefile.inc @@ -14,8 +14,11 @@ romstage-y += early_setup.c
ramstage-$(CONFIG_HAVE_ACPI_RESUME) += spi.c
-$(obj)/hudson.bin: - python $(src)/southbridge/amd/agesa/hudson/hudson_fwm.py $(CONFIG_HUDSON_FWM_POSITION) $@ $(CONFIG_HUDSON_XHCI_FWM_FILE) $(CONFIG_HUDSON_IMC_FWM_FILE) "" +$(obj)/hudson.bin: $(top)/$(strip $(patsubst "%", %, $(CONFIG_HUDSON_XHCI_FWM_FILE))) \ + $(top)/$(strip $(patsubst "%", %, $(CONFIG_HUDSON_IMC_FWM_FILE))) \ + $(top)/$(strip $(patsubst "%", %, $(CONFIG_HUDSON_GEC_FWM_FILE))) + echo " Hudson FW $@" + $(src)/southbridge/amd/agesa/hudson/hudson_fwm.sh $(CONFIG_HUDSON_FWM_POSITION) $@ $(CONFIG_HUDSON_XHCI_FWM_FILE) $(CONFIG_HUDSON_IMC_FWM_FILE) $(CONFIG_HUDSON_GEC_FWM_FILE)
ifeq ($(CONFIG_HUDSON_FWM), y) cbfs-files-y += hudson/fwm diff --git a/src/southbridge/amd/agesa/hudson/hudson_fwm.py b/src/southbridge/amd/agesa/hudson/hudson_fwm.py deleted file mode 100644 index ad60b3b..0000000 --- a/src/southbridge/amd/agesa/hudson/hudson_fwm.py +++ /dev/null @@ -1,64 +0,0 @@ -import sys, os, re -import struct -from Queue import Queue - -def main(start_addr, file_name, xhci_name, imc_name, gec_name): - fwm_sig = 0x55AA55AA # Hudson-2/3/4 firmware signature - fwm_header_len = 0x10 # 55AA55AA, imc_off, gec_off, xhci_off - - if not os.path.exists(xhci_name): - print "XHCI firmware %s does not exist\n" % xhci_name - sys.exit(1) - if not os.path.exists(imc_name): - print "IMC firmware %s does not exist\n" % imc_name - sys.exit(1) - - f = open(file_name, "w") - print "write to file " + file_name - - imc_offset = 0x10000 # 64K Bytes offset, hardcoded - imc_addr = start_addr + imc_offset; #startaddr + 0x10000 - gec_offset = 0 #TODO - gec_addr = 0 #TODO - xhci_addr = start_addr + fwm_header_len #ROMSIG take 0x10 bytes - - format="I" # one unsigned integer - data=struct.pack(format, fwm_sig) - f.write(data) - data=struct.pack(format, imc_addr) - f.write(data) - data=struct.pack(format, gec_addr) - f.write(data) - data=struct.pack(format, xhci_addr) - f.write(data) - - fwm_content = open(xhci_name).read() - f.write(fwm_content) - - imc_content = open(imc_name).read() - f.seek(0) - f.seek(imc_offset) - f.write(imc_content) -# if os.path.exists(gec_name): -# gec_conent = open(gec_name).read() -# f.seek(0) -# f.seek(gec_offset) -# f.write(gec_content) - - f.close() - print "done\n" - - -if __name__ == '__main__': - if (len(sys.argv) < 6): - print "\nUsage: %s <rom_addr> <rom_file> <xhci_rom> <imc_rom> <gec_rom>\n" % sys.argv[0] - print "Example: %s 0xFFF20000 hudson.bin xhci.bin imc.bin gec.bin\n" % sys.argv[0] - sys.exit(1) - rom_addr = int(sys.argv[1], 16) - rom_file = sys.argv[2] - xhci_file = sys.argv[3] - imc_file = sys.argv[4] - gec_file = sys.argv[5] - print "%x %s %s %s %s" % (rom_addr, rom_file, xhci_file, imc_file, gec_file) - - main(rom_addr, rom_file, xhci_file, imc_file, gec_file) diff --git a/src/southbridge/amd/agesa/hudson/hudson_fwm.sh b/src/southbridge/amd/agesa/hudson/hudson_fwm.sh new file mode 100755 index 0000000..72e8756 --- /dev/null +++ b/src/southbridge/amd/agesa/hudson/hudson_fwm.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +filesize() +{ + fwm="$1" + if [ -z $fwm ]; then + size=0 + else + [ -r $fwm ] || { echo "$$fwm not found"; exit 1; }; + size=`ls -l $fwm | awk '{print $5}'`; + fi +} + +# ROMSIG At ROMBASE + 0x20000: +# +-----------+---------------+----------------+------------+ +# |0x55AA55AA |EC ROM Address |GEC ROM Address |USB3 ROM | +# +-----------+---------------+----------------+------------+ +# In our coreboot implementation, we concatenate the ROM images +# next to the ROMSIG. EC ROM should be 64K aligned. +# Final hudson.bin: +# +-----------+---------------+----------------+------------+ +# |0x55AA55AA |EC ROM Address |GEC ROM Address |USB3 ROM | +# +-----------+---------------+----------------+------------+ +# | USB3 ROM | +# +---------------------------------------------------------+ +# | GEC ROM | +# +---------------------------------------------------------+ +# | EC ROM | +# +---------------------------------------------------------+ +# +print_romsig() +{ + echo $1 $2 $3 $4 | + LC_ALL=C awk ' + function print_raw_dword(number) + { + #printf ("%x\n", number) + printf ("%c%c%c%c", number % 0x100, number/0x100 % 0x100, number/0x10000 % 0x100, number/0x1000000); + } + { # $1=ROMSIG address, $2=EC_ROM_size, $3=GEC_ROM_size, $4=USB3_ROM_size + print_raw_dword(0x55AA55AA); + imc_offset = $1 + 16 + $3 + 65535; + imc_offset = imc_offset - (imc_offset) % 65536; #align 64K + if ($2) print_raw_dword(imc_offset); else print_raw_dword(0); + if ($3) print_raw_dword($1 + 16 + $3); else print_raw_dword(0); + if ($4) print_raw_dword($1 + 16); else print_raw_dword(0); + } ' +} + +#main +#param: +# $1=$(CONFIG_HUDSON_FWM_POSITION) +# $2=$obj +# $3=$(CONFIG_HUDSON_XHCI_FWM_FILE) +# $4=$(CONFIG_HUDSON_IMC_FWM_FILE) +# $5=$(CONFIG_HUDSON_GEC_FWM_FILE) +base=`printf %d $1` + +filesize $3 +xhci_size=$size +filesize $4 +imc_size=$size +filesize $5 +gec_size=$size + +print_romsig $base $imc_size $gec_size $xhci_size > $2.tmp +[ -z $3 ] || cat $3 >> $2.tmp +[ -z $5 ] || cat $5 >> $2.tmp +if [ ! -z $4 ]; then + ls -l $2.tmp | awk '{ print $5 }' | LC_ALL=C awk '{for (i=$1; i<($1+65535) - ($1+65535)%65536; i++) {printf "%c", 255}}' >> $2.tmp # align 64K + cat $4 >> $2.tmp +fi + +mv $2.tmp $2