In preparation for v3 and the upcoming openvsa changes,
rearrange the VSA fetching code.  We now fetch an 
uncompressed blob, and do the compressing within buildrom.
I'm mainly concentrating on v2 right now (this is not quite
v3 friendly), but it will be.

Also, work around a hopefully temporary bug on the AMD
servers.

Signed-off-by: Jordan Crouse <jordan.crouse@amd.com>
Index: buildrom-devel/packages/coreboot-v2/geodelx.mk
===================================================================
--- buildrom-devel.orig/packages/coreboot-v2/geodelx.mk	2008-02-20 15:20:45.000000000 -0700
+++ buildrom-devel/packages/coreboot-v2/geodelx.mk	2008-02-20 16:10:05.000000000 -0700
@@ -10,16 +10,11 @@
 CBV2_URL=svn://coreboot.org/repos/trunk/coreboot-v2
 CBV2_TARBALL=coreboot-svn-$(CBV2_TAG).tar.gz
 CBV2_PAYLOAD_TARGET=$(CBV2_BUILD_DIR)/payload.$(CBV2_PAYLOAD_FILE_EXT)
-VSA_URL=http://www.amd.com/files/connectivitysolutions/geode/geode_lx/
-CBV2_VSA=lx_vsa.36k.bin
+
 TARGET_ROM = $(COREBOOT_VENDOR)-$(COREBOOT_BOARD).rom
 
 include $(PACKAGE_DIR)/coreboot-v2/coreboot.inc
 
-$(SOURCE_DIR)/$(CBV2_VSA):
-	@ echo "Fetching the VSA blob..."
-	wget -P $(SOURCE_DIR) $(VSA_URL)/$(CBV2_VSA).gz  -O $@
-
 $(SOURCE_DIR)/$(CBV2_TARBALL):
 	@ echo "Fetching the coreboot rev $(CBV2_TAG) code..."
 	@ mkdir -p $(SOURCE_DIR)/coreboot
@@ -27,12 +22,10 @@
 	$(CBV2_TAG) $(SOURCE_DIR)/$(CBV2_TARBALL) \
 	> $(CBV2_FETCH_LOG) 2>&1
 
-# Special rule - append the VSA
-
-$(OUTPUT_DIR)/$(TARGET_ROM): $(CBV2_OUTPUT) $(SOURCE_DIR)/$(CBV2_VSA)
+$(OUTPUT_DIR)/$(TARGET_ROM): $(CBV2_OUTPUT) $(GEODE_PADDED_VSA)
 	@ mkdir -p $(OUTPUT_DIR)
-	@ cat $(SOURCE_DIR)/$(CBV2_VSA) $(CBV2_OUTPUT) > $@
+	@ cat $(GEODE_PADDED_VSA) $(CBV2_OUTPUT) > $@
 
-coreboot: $(OUTPUT_DIR)/$(TARGET_ROM)
-coreboot-clean: generic-coreboot-clean
-coreboot-distclean: generic-coreboot-distclean
+coreboot: geodevsa $(OUTPUT_DIR)/$(TARGET_ROM)
+coreboot-clean: geodevsa-clean generic-coreboot-clean
+coreboot-distclean: geodevsa-distclean generic-coreboot-distclean
Index: buildrom-devel/packages/utils/nrv2b.mk
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ buildrom-devel/packages/utils/nrv2b.mk	2008-02-20 16:10:05.000000000 -0700
@@ -0,0 +1,47 @@
+NRV2B_URL=svn://coreboot.org/repos/trunk/coreboot-v2/util/nrv2b
+NRV2B_TAG=3086
+
+NRV2B_DIR=$(BUILD_DIR)/nrv2b
+NRV2B_SRC_DIR=$(NRV2B_DIR)/svn
+NRV2B_STAMP_DIR=$(NRV2B_DIR)/stamps
+NRV2B_LOG_DIR=$(NRV2B_DIR)/logs
+NRV2B_TARBALL=nrv2b-svn-$(NRV2B_TAG).tar.gz
+
+ifeq ($(CONFIG_VERBOSE),y)
+NRV2B_BUILD_LOG=/dev/stdout
+NRV2B_FETCH_LOG=/dev/stdout
+else
+NRV2B_BUILD_LOG=$(NRV2B_LOG_DIR)/build.log
+NRV2B_FETCH_LOG=$(NRV2B_LOG_DIR)/fetch.log
+endif
+
+$(SOURCE_DIR)/$(NRV2B_TARBALL):
+	mkdir -p $(SOURCE_DIR)/nrv2b
+	@ $(BIN_DIR)/fetchsvn.sh $(NRV2B_URL) $(SOURCE_DIR)/nrv2b \
+	$(NRV2B_TAG) $@ > $(NRV2B_FETCH_LOG) 2>&1
+
+$(NRV2B_STAMP_DIR)/.unpacked: $(SOURCE_DIR)/$(NRV2B_TARBALL)
+	@ tar -C $(NRV2B_DIR) -zxf $(SOURCE_DIR)/$(NRV2B_TARBALL)
+	@ touch $@
+
+$(NRV2B_SRC_DIR)/nrv2b: $(NRV2B_STAMP_DIR)/.unpacked
+	@ (unset CFLAGS; unset LDFLAGS; \
+	$(MAKE) -C $(NRV2B_SRC_DIR) \
+	 > $(NRV2B_BUILD_LOG) 2>&1)
+
+$(STAGING_DIR)/bin/nrv2b: $(NRV2B_SRC_DIR)/nrv2b
+	mkdir -p $(STAGING_DIR)/bin
+	cp $< $@
+
+$(NRV2B_STAMP_DIR) $(NRV2B_LOG_DIR):
+	@ mkdir -p $@
+
+nrv2b: $(NRV2B_STAMP_DIR) $(NRV2B_LOG_DIR) $(STAGING_DIR)/bin/nrv2b
+
+nrv2b-clean:
+	@ echo "Cleaning nrv2b..."
+	@ $(MAKE) -C $(NRV2B_SRC_DIR) clean > /dev/null 2>&1
+
+nrv2b-distclean:
+	@ rm -r $(NRV2B_DIR)
+
Index: buildrom-devel/packages/geodevsa/amdvsa.inc
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ buildrom-devel/packages/geodevsa/amdvsa.inc	2008-02-20 16:10:05.000000000 -0700
@@ -0,0 +1,21 @@
+# Target file for the AMD VSA binary - included from geodevsa.mk
+
+AMDVSA_URL=http://www.amd.com/files/connectivitysolutions/geode/geode_lx/
+AMDVSA_BIN=amd_vsa_lx_1.01.bin
+
+# 2008-02-19 - the AMD URL above is broken, when trying to wget
+# amd_vsa_lx_1.01.bin.gz it arrives uncompressed instead.  This
+# breakage is expected to be fixed; but to properly
+# handle this temporary situation without breakage down the line,
+# we do the unsual check of the file type below:
+# Jordan
+
+$(SOURCE_DIR)/$(AMDVSA_BIN):
+	@ echo "Fetching the AMD VSA binary..."
+	wget -P $(SOURCE_DIR) $(AMDVSA_URL)/$(AMDVSA_BIN).gz -O $@.gz
+	@ if file $@.gz | grep -q "COM executable"; then \
+	mv $@.gz $@; else gunzip -q $@.gz; fi
+
+$(GEODE_UNCOMPRESSED_VSA): $(SOURCE_DIR)/$(AMDVSA_BIN)
+	@ mkdir -p $(shell dirname $(GEODE_UNCOMPRESSED_VSA))
+	@ cp $< $@
Index: buildrom-devel/packages/geodevsa/geodevsa.mk
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ buildrom-devel/packages/geodevsa/geodevsa.mk	2008-02-20 16:10:05.000000000 -0700
@@ -0,0 +1,33 @@
+# Master targets for VSA manipulation
+
+GEODE_UNCOMPRESSED_VSA=$(OUTPUT_DIR)/vsa/geodevsa.bin
+GEODE_COMPRESSED_VSA=$(OUTPUT_DIR)/vsa/geodevsa.bin.nrv
+GEODE_PADDED_VSA=$(OUTPUT_DIR)/vsa/geodevsa.bin.nrv.pad
+
+GEODE_VSA_SIZE=36864
+
+ifeq ($(CONFIG_COREBOOT_V2),y)
+VSA_BUILD_TARGET = $(GEODE_PADDED_VSA)
+else
+VSA_BUILD_TARGET = $(GEODE_UNCOMPRESSED_VSA)
+endif
+
+include $(PACKAGE_DIR)/geodevsa/amdvsa.inc
+
+$(GEODE_COMPRESSED_VSA): $(GEODE_UNCOMPRESSED_VSA)
+	@ $(STAGING_DIR)/bin/nrv2b e $(GEODE_UNCOMPRESSED_VSA) $@ \
+	> /dev/null 2>&1
+
+$(GEODE_PADDED_VSA): $(GEODE_COMPRESSED_VSA)
+	@ cp $< $@
+	@ (size=`stat -c %s $<`; count=`expr $(GEODE_VSA_SIZE) - $$size`; \
+	dd if=/dev/zero bs=1 count=$$count  >> $@ 2> /dev/null)
+
+geodevsa: $(VSA_BUILD_TARGET)
+
+geodevsa-clean:
+	@ rm -f $(GEODE_UNCOMPRESSED_VSA) $(GEODE_COMPRESSED_VSA)
+	@ rm -f $(GEODE_PADDED_VSA)
+
+geodevsa-distclean:
+	@ rm -rf $(OUTPUT_DIR)/vsa
Index: buildrom-devel/Config.in
===================================================================
--- buildrom-devel.orig/Config.in	2008-02-20 15:20:45.000000000 -0700
+++ buildrom-devel/Config.in	2008-02-20 16:10:05.000000000 -0700
@@ -124,6 +124,10 @@
 	bool
 	default n
 
+config PLATFORM_GEODE
+	bool
+	default n
+
 config PAYLOAD_64BIT
 	bool
 	default n
@@ -137,5 +141,13 @@
 	bool
 	default n
 
+# This config option will only be set by platforms that need it
+# (geode + coreboot v2)
+
+config USE_NRV2B
+	bool
+	depends PLATFORM_GEODE && COREBOOT_V2
+	default y
+
 source config/platforms/Config.in
 source config/payloads/Config.in
Index: buildrom-devel/config/payloads/payloads.conf
===================================================================
--- buildrom-devel.orig/config/payloads/payloads.conf	2008-02-20 15:20:45.000000000 -0700
+++ buildrom-devel/config/payloads/payloads.conf	2008-02-20 16:10:05.000000000 -0700
@@ -33,6 +33,7 @@
 endif
 
 HOSTTOOLS-$(CONFIG_BUILD_QEMU) += qemu
+HOSTTOOLS-$(CONFIG_USE_NRV2B) += nrv2b
 
 # Sanity check
 
Index: buildrom-devel/config/platforms/Config.in
===================================================================
--- buildrom-devel.orig/config/platforms/Config.in	2008-02-20 15:20:45.000000000 -0700
+++ buildrom-devel/config/platforms/Config.in	2008-02-20 16:11:52.000000000 -0700
@@ -45,27 +45,32 @@
        bool "AMD Geode LX 'Norwich'"
        depends VENDOR_AMD
        select PLATFORM
+       select PLATFORM_GEODE
 
 config PLATFORM_DBE61
        bool "Artec Group DBE61"
        depends VENDOR_ARTEC_GROUP
        select PLATFORM
+       select PLATFORM_GEODE
 
 config PLATFORM_ALIX1C
        bool "PC Engines ALIX1.C"
        depends VENDOR_PC_ENGINES
        select PLATFORM
+       select PLATFORM_GEODE
 
 config PLATFORM_MSM800SEV
        bool "Advanced Digital Logic MSM800SEV"
        depends VENDOR_ADVANCED_DIGITAL_LOGIC
        select PLATFORM
+       select PLATFORM_GEODE
 
 config PLATFORM_DB800
 	bool "AMD DB800"
 	depends VENDOR_AMD
 	depends COREBOOT_V2
 	select PLATFORM
+	select PLATFORM_GEODE
 
 config PLATFORM_GA_M57SLI_S4
        bool "GIGABYTE GA-M57SLI-S4"

-- 
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.



