Bao Zheng would like Zheng Bao to review this change.

View Change

[WIP]amdfwtool: Take a config file instead of command line parameters

Change-Id: Icae73d0730106aab687486e555ba947796e5e757
Signed-off-by: Zheng Bao <zheng.bao@amd.com>
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
---
M Makefile.inc
M src/soc/amd/picasso/Makefile.inc
A src/soc/amd/picasso/fw.cfg
M util/amdfwtool/Makefile
A util/amdfwtool/Makefile.inc
M util/amdfwtool/amdfwtool.c
A util/amdfwtool/amdfwtool.h
A util/amdfwtool/amdfwtool.sh
A util/amdfwtool/data_parse.c
A util/amdfwtool/sample.txt
10 files changed, 899 insertions(+), 142 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/59/42859/1
diff --git a/Makefile.inc b/Makefile.inc
index bbb6685..0e10136 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -81,7 +81,7 @@
subdirs-y += src/superio
subdirs-y += $(wildcard src/drivers/*) $(wildcard src/drivers/*/*)
subdirs-y += src/cpu src/vendorcode
-subdirs-y += util/cbfstool util/sconfig util/nvramtool util/pgtblgen
+subdirs-y += util/cbfstool util/sconfig util/nvramtool util/pgtblgen util/amdfwtool
subdirs-y += util/futility util/marvell util/bincfg util/supermicro
subdirs-y += $(wildcard src/arch/*)
subdirs-y += src/mainboard/$(MAINBOARDDIR)
@@ -566,9 +566,9 @@
cp -a $(top)/util/ifdtool/ifdtool $@

AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
-$(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
- @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
- $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<
+#$(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
+# @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
+# $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<

APCB_EDIT_TOOL:=$(top)/util/apcb/apcb_edit.py

@@ -666,7 +666,7 @@
include util/crossgcc/Makefile.inc

.PHONY: tools
-tools: $(objutil)/kconfig/conf $(objutil)/kconfig/toada $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(objutil)/sconfig/sconfig $(IFDTOOL) $(CBOOTIMAGE) $(AMDFWTOOL) $(AMDCOMPRESS) $(FUTILITY) $(BINCFG) $(IFITTOOL) $(objutil)/supermicro/smcbiosinfo
+tools: $(objutil)/kconfig/conf $(objutil)/kconfig/toada $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(objutil)/sconfig/sconfig $(IFDTOOL) $(CBOOTIMAGE) $(objutil)/amdfwtool/amdfwtool $(AMDCOMPRESS) $(FUTILITY) $(BINCFG) $(IFITTOOL) $(objutil)/supermicro/smcbiosinfo

###########################################################################
# Common recipes for all stages
@@ -1094,7 +1094,6 @@
endif

$(obj)/coreboot.rom: $(obj)/coreboot.pre $(RAMSTAGE) $(CBFSTOOL) $$(INTERMEDIATE)
-
@printf " CBFS $(subst $(obj)/,,$(@))\n"
# The full ROM may be larger than the CBFS part, so create an empty
# file (filled with \377 = 0xff) and copy the CBFS image over it.
diff --git a/src/soc/amd/picasso/Makefile.inc b/src/soc/amd/picasso/Makefile.inc
index 39269e9..20fb5c2 100644
--- a/src/soc/amd/picasso/Makefile.inc
+++ b/src/soc/amd/picasso/Makefile.inc
@@ -378,14 +378,6 @@
rm -f $@
@printf " AMDFWTOOL $(subst $(obj)/,,$(@))\n"
$(AMDFWTOOL) \
- $(OPT_AMD_PUBKEY_FILE) \
- $(OPT_PSPBTLDR_FILE) \
- $(OPT_PSPSCUREOS_FILE) \
- $(OPT_PSP_SEC_DBG_KEY_FILE) \
- $(OPT_SMUFW1_SUB2_FILE) \
- $(OPT_SMUFW2_SUB2_FILE) \
- $(OPT_SMUFW1_SUB1_FILE) \
- $(OPT_SMUFW2_SUB1_FILE) \
$(OPT_PSP_APCB_FILES) \
$(OPT_APOB_ADDR) \
--apob-nv-size $(shell printf "0x%x" \
@@ -398,38 +390,18 @@
$(OPT_PSP_BIOSBIN_DEST) \
$(OPT_PSP_BIOSBIN_SIZE) \
$(OPT_PSP_SOFTFUSE) \
- $(OPT_PSP_PMUI_FILE1) \
- $(OPT_PSP_PMUI_FILE2) \
- $(OPT_PSP_PMUI_FILE3) \
- $(OPT_PSP_PMUI_FILE4) \
- $(OPT_PSP_PMUD_FILE1) \
- $(OPT_PSP_PMUD_FILE2) \
- $(OPT_PSP_PMUD_FILE3) \
- $(OPT_PSP_PMUD_FILE4) \
- $(OPT_MP2CFG_FILE) \
- $(OPT_ABL0_FILE) \
- $(OPT_ABL1_FILE) \
- $(OPT_ABL2_FILE) \
- $(OPT_ABL3_FILE) \
- $(OPT_ABL4_FILE) \
- $(OPT_ABL5_FILE) \
- $(OPT_ABL6_FILE) \
- $(OPT_ABL7_FILE) \
$(OPT_WHITELIST_FILE) \
- $(OPT_SECG1_FILE) \
- $(OPT_SECG2_FILE) \
- $(OPT_MP2FW1_FILE) \
- $(OPT_MP2FW2_FILE) \
- $(OPT_DRIVERS_FILE) \
- $(OPT_PSP_S0I3_FILE) \
- $(OPT_IKEK_FILE) \
$(OPT_SEC_DEBUG_FILE) \
+ --config $(FIRMWARE_LOCATE)/fw.cfg \
--combo-capable \
$(OPT_TOKEN_UNLOCK) \
--flashsize $(CONFIG_ROM_SIZE) \
--location $(shell printf "0x%x" $(PICASSO_FWM_POSITION)) \
--output $@

+# --config /home/baozheng/x86/coreboot-gerrit/src/soc/amd/picasso/fw.cfg \
+
+
$(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS)
rm -f $@
@printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n"
diff --git a/src/soc/amd/picasso/fw.cfg b/src/soc/amd/picasso/fw.cfg
new file mode 100644
index 0000000..f5b9d13
--- /dev/null
+++ b/src/soc/amd/picasso/fw.cfg
@@ -0,0 +1,46 @@
+# sample PSP fw config file
+# Move to amd_blob
+# type file
+AMD_PUBKEY_FILE AmdPubKeyRV.bin
+PSPBTLDR_FILE PspBootLoader_prod_RV.sbin
+#PUBSIGNEDKEY_FILE RtmPubSignedRV.key
+PSP_SMUFW1_SUB1_FILE SmuFirmwareRV2.csbin
+PSP_SMUFW1_SUB2_FILE SmuFirmwarePCO.csbin
+PSP_SMUFW2_SUB1_FILE SmuFirmware2RV2.csbin
+PSP_SMUFW2_SUB2_FILE SmuFirmware2PCO.csbin
+PSPSCUREOS_FILE psp_os_combined_prod_RV.sbin
+#PSPTRUSTLETS_FILE dr_ftpm_prod_RV.csbin
+#PSP_SEC_DBG_KEY_FILE RavenSecureDebug_PublicKey.bin
+PSPSCUREOS_FILE psp_os_combined_prod_RV.sbin
+PSP_ABL0_FILE AgesaBootloader0_prod_RV.csbin
+PSP_ABL1_FILE AgesaBootloader1_prod_RV.csbin
+PSP_ABL2_FILE AgesaBootloader2_prod_RV.csbin
+PSP_ABL3_FILE AgesaBootloader3_prod_RV.csbin
+PSP_ABL4_FILE AgesaBootloader4_prod_RV.csbin
+PSP_ABL5_FILE AgesaBootloader5_prod_RV.csbin
+PSP_ABL6_FILE AgesaBootloader6_prod_RV.csbin
+PSP_ABL7_FILE AgesaBootloader7_prod_RV.csbin
+#PSP_SEC_DEBUG_FILE secure_unlock_prod_RV.sbin
+PSP_IKEK_FILE PspIkekRV.bin
+PSP_SECG1_FILE security_policy_RV2_FP5_AM4.sbin
+PSP_SECG2_FILE security_policy_PCO_FP5_AM4.sbin
+#PSP_MP2FW1_FILE MP2I2CFWRV2.sbin
+#PSP_MP2FW2_FILE MP2I2CFWPCO.sbin
+#PSP_MP2CFG_FILE MP2FWConfig.sbin
+PSP_DRIVERS_FILE drv_sys_prod_RV.sbin
+#PSP_SOFTFUSE 0x0000000010000001
+#PSP_S0I3_FILE dr_agesa_prod_RV.sbin
+#PSP_APOBNV_BASE
+#PSP_APOBNV_SIZE
+#
+## BDT
+#PSP_APCB0_FILE apcb.bin
+PSP_PMUI_FILE1 Appb_Rv_1D_Ddr4_Udimm_Imem.csbin
+PSP_PMUI_FILE2 Appb_Rv_2D_Ddr4_Imem.csbin
+PSP_PMUI_FILE3 Appb_Rv2_1D_ddr4_Udimm_Imem.csbin
+PSP_PMUI_FILE4 Appb_Rv2_2D_ddr4_Udimm_Imem.csbin
+PSP_PMUD_FILE1 Appb_Rv_1D_Ddr4_Udimm_Dmem.csbin
+PSP_PMUD_FILE2 Appb_Rv_2D_Ddr4_Dmem.csbin
+PSP_PMUD_FILE3 Appb_Rv2_1D_ddr4_Udimm_Dmem.csbin
+PSP_PMUD_FILE4 Appb_Rv2_2D_ddr4_Udimm_Dmem.csbin
+#PSP_MP2CFG_FILE MP2FWConfig.sbin
diff --git a/util/amdfwtool/Makefile b/util/amdfwtool/Makefile
index e9fd91b..9f7a01b 100644
--- a/util/amdfwtool/Makefile
+++ b/util/amdfwtool/Makefile
@@ -2,15 +2,47 @@
#
# All rights reserved.
#
-# SPDX-License-Identifier: BSD-3-Clause
-
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of Advanced Micro Devices, Inc. nor the names of
+# its contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
#*****************************************************************************
HOSTCC ?= cc

-amdfwtool_exe : amdfwtool.c
- $(HOSTCC) amdfwtool.c -o amdfwtool
+SRC = amdfwtool.c data_parse.c
+OBJ = $(SRC:%.c=%.o)
+TARGET = amdfwtool
+CFLAGS=-O2 -Wall -Wextra -Wshadow -Wno-sign-compare

-amdfwtool : amdfwtool_exe
+
+$(TARGET): $(OBJ)
+ $(CC) $(OBJ) $(LDFLAGS) -o $@
+
+%.o: %.c $(HEADER)
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+amdfwtool_exe : $(TARGET)
+# $(HOSTCC) amdfwtool.c -o amdfwtool
+#
+#amdfwtool : amdfwtool_exe

clean:
- @rm -f amdfwtool.o amdfwtool amdfwtool.exe
+ rm -f $(TARGET) $(OBJ)
diff --git a/util/amdfwtool/Makefile.inc b/util/amdfwtool/Makefile.inc
new file mode 100644
index 0000000..36ff207d
--- /dev/null
+++ b/util/amdfwtool/Makefile.inc
@@ -0,0 +1,52 @@
+#*****************************************************************************
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of Advanced Micro Devices, Inc. nor the names of
+# its contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#*****************************************************************************
+#HOSTCC ?= cc
+
+amdfwtoolobj = amdfwtool.o data_parse.o
+
+#TARGET = $(objutil)/amdfwtool/amdfwtool
+AMDFWTOOLCFLAGS=-O2 -Wall -Wextra -Wshadow -Wno-sign-compare
+
+
+#$(TARGET): $(OBJ)
+# $(CC) $(OBJ) $(LDFLAGS) -o $@
+
+$(objutil)/amdfwtool/%.o: $(top)/util/amdfwtool/%.c # $(HEADER)
+ printf " AMDFWTOOL\n"
+ $(HOSTCC) $(AMDFWTOOLCFLAGS) $(HOSTCFLAGS) -c -o $@ $<
+
+#amdfwtool_exe : $(TARGET)
+# $(HOSTCC) amdfwtool.c -o amdfwtool
+#
+#amdfwtool : amdfwtool_exe
+
+#clean:
+# rm -f $(TARGET) $(OBJ)
+$(objutil)/amdfwtool/amdfwtool: $(addprefix $(objutil)/amdfwtool/,$(amdfwtoolobj))
+ printf " AMDFWTOOL\n"
+ $(HOSTCC) $(addprefix $(objutil)/amdfwtool/,$(amdfwtoolobj)) -o $@
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index a5e5110..eb0cae8 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -56,6 +56,9 @@
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
+#include <libgen.h>
+
+#include "amdfwtool.h"

#ifndef CONFIG_ROM_SIZE
#define CONFIG_ROM_SIZE 0x400000
@@ -98,13 +101,6 @@
*/
#define PSP_COMBO 0

-#if defined(__GLIBC__)
-typedef unsigned long long int uint64_t;
-typedef unsigned int uint32_t;
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-#endif
-
/*
* Creates the OSI Fletcher checksum. See 8473-1, Appendix C, section C.3.
* The checksum field of the passed PDU does not need to be reset to zero.
@@ -216,92 +212,11 @@
printf("-R | --sharedmem Location of PSP/FW shared memory\n");
printf("-P | --sharedmem-size Maximum size of the PSP/FW shared memory area\n");
printf("-h | --help show this help\n");
+ printf("-C | --config config file\n");
}

-typedef enum _amd_bios_type {
- AMD_BIOS_APCB = 0x60,
- AMD_BIOS_APOB = 0x61,
- AMD_BIOS_BIN = 0x62,
- AMD_BIOS_APOB_NV = 0x63,
- AMD_BIOS_PMUI = 0x64,
- AMD_BIOS_PMUD = 0x65,
- AMD_BIOS_UCODE = 0x66,
- AMD_BIOS_APCB_BK = 0x68,
- AMD_BIOS_MP2_CFG = 0x6a,
- AMD_BIOS_PSP_SHARED_MEM = 0x6b,
- AMD_BIOS_L2_PTR = 0x70,
- AMD_BIOS_INVALID,
-} amd_bios_type;

-#define BDT_LVL1 0x1
-#define BDT_LVL2 0x2
-#define BDT_BOTH (BDT_LVL1 | BDT_LVL2)
-typedef struct _amd_bios_entry {
- amd_bios_type type;
- int region_type;
- int reset;
- int copy;
- int ro;
- int zlib;
- int inst;
- int subpr;
- uint64_t src;
- uint64_t dest;
- size_t size;
- char *filename;
- int level;
-} amd_bios_entry;
-
-typedef enum _amd_fw_type {
- AMD_FW_PSP_PUBKEY = 0,
- AMD_FW_PSP_BOOTLOADER = 1,
- AMD_FW_PSP_SMU_FIRMWARE = 8,
- AMD_FW_PSP_RECOVERY = 3,
- AMD_FW_PSP_RTM_PUBKEY = 5,
- AMD_FW_PSP_SECURED_OS = 2,
- AMD_FW_PSP_NVRAM = 4,
- AMD_FW_PSP_SECURED_DEBUG = 9,
- AMD_FW_PSP_TRUSTLETS = 12,
- AMD_FW_PSP_TRUSTLETKEY = 13,
- AMD_FW_PSP_SMU_FIRMWARE2 = 18,
- AMD_PSP_FUSE_CHAIN = 11,
- AMD_FW_PSP_SMUSCS = 95,
- AMD_DEBUG_UNLOCK = 0x13,
- AMD_WRAPPED_IKEK = 0x21,
- AMD_TOKEN_UNLOCK = 0x22,
- AMD_SEC_GASKET = 0x24,
- AMD_MP2_FW = 0x25,
- AMD_DRIVER_ENTRIES = 0x28,
- AMD_S0I3_DRIVER = 0x2d,
- AMD_ABL0 = 0x30,
- AMD_ABL1 = 0x31,
- AMD_ABL2 = 0x32,
- AMD_ABL3 = 0x33,
- AMD_ABL4 = 0x34,
- AMD_ABL5 = 0x35,
- AMD_ABL6 = 0x36,
- AMD_ABL7 = 0x37,
- AMD_FW_PSP_WHITELIST = 0x3a,
- AMD_FW_L2_PTR = 0x40,
- AMD_FW_PSP_VERSTAGE = 0x52,
- AMD_FW_IMC,
- AMD_FW_GEC,
- AMD_FW_XHCI,
- AMD_FW_INVALID,
-} amd_fw_type;
-
-#define PSP_LVL1 0x1
-#define PSP_LVL2 0x2
-#define PSP_BOTH (PSP_LVL1 | PSP_LVL2)
-typedef struct _amd_fw_entry {
- amd_fw_type type;
- uint8_t subprog;
- char *filename;
- int level;
- uint64_t other;
-} amd_fw_entry;
-
-static amd_fw_entry amd_psp_fw_table[] = {
+/* static */ amd_fw_entry amd_psp_fw_table[] = {
{ .type = AMD_FW_PSP_PUBKEY, .level = PSP_BOTH },
{ .type = AMD_FW_PSP_BOOTLOADER, .level = PSP_BOTH },
{ .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 0, .level = PSP_BOTH },
@@ -343,14 +258,14 @@
{ .type = AMD_FW_INVALID },
};

-static amd_fw_entry amd_fw_table[] = {
+amd_fw_entry amd_fw_table[] = {
{ .type = AMD_FW_XHCI },
{ .type = AMD_FW_IMC },
{ .type = AMD_FW_GEC },
{ .type = AMD_FW_INVALID },
};

-static amd_bios_entry amd_bios_table[] = {
+amd_bios_entry amd_bios_table[] = {
{ .type = AMD_BIOS_APCB, .inst = 0, .level = BDT_BOTH },
{ .type = AMD_BIOS_APCB, .inst = 1, .level = BDT_BOTH },
{ .type = AMD_BIOS_APCB, .inst = 2, .level = BDT_BOTH },
@@ -658,6 +573,28 @@
}
}

+static void dump_psp_firmwares(amd_fw_entry *fw_table)
+{
+ amd_fw_entry *index;
+
+ for (index = fw_table; index->type != AMD_FW_INVALID; index++) {
+ printf("type=%x\n", index->type);
+ if (index->filename)
+ printf (" filename=%s\n", index->filename);
+ }
+}
+
+static void dump_bdt_firmwares(amd_bios_entry *fw_table)
+{
+ amd_bios_entry *index;
+
+ for (index = fw_table; index->type != AMD_BIOS_INVALID; index++) {
+ printf("type=%x\n", index->type);
+ if (index->filename)
+ printf (" filename=%s\n", index->filename);
+ }
+}
+
static void integrate_psp_firmwares(context *ctx,
psp_directory_table *pspdir,
psp_directory_table *pspdir2,
@@ -1039,7 +976,7 @@
fill_dir_header(biosdir, count, cookie);
}
// Unused values: CDE
-static const char *optstring = "x:i:g:AMS:p:b:s:r:k:c:n:d:t:u:w:m:T:z:J:B:K:L:Y:N:UW:I:a:Q:V:e:v:j:y:G:O:X:F:H:o:f:l:hZ:qR:P:";
+static const char *optstring = "x:i:g:AMS:p:b:s:r:k:c:n:d:t:u:w:m:T:z:J:B:K:L:Y:N:UW:I:a:Q:V:e:v:j:y:G:O:X:F:H:o:f:l:hZ:qR:P:C";

static struct option long_options[] = {
{"xhci", required_argument, 0, 'x' },
@@ -1087,6 +1024,7 @@
{"apob-nv-base", required_argument, 0, 'F' },
{"apob-nv-size", required_argument, 0, 'H' },
/* other */
+ {"config", required_argument, 0, 'C' },
{"output", required_argument, 0, 'o' },
{"flashsize", required_argument, 0, 'f' },
{"location", required_argument, 0, 'l' },
@@ -1097,7 +1035,7 @@
{NULL, 0, 0, 0 }
};

-static void register_fw_fuse(char *str)
+void register_fw_fuse(char *str)
{
int i;

@@ -1145,6 +1083,40 @@
}
}

+static int register_fw_fuses(int fd, char *dir)
+{
+ struct stat fd_stat;
+ unsigned char *config_file;
+
+// fd = open(, O_RDONLY);
+// if (fd < 0) {
+// printf("Error opening file: %s: %s\n",
+// src_file, strerror(errno));
+// return -1;
+// }
+
+ if (fstat(fd, &fd_stat)) {
+ printf("fstat error 1: %s\n", strerror(errno));
+ close(fd);
+ return -2;
+ }
+
+ //if (fd_stat.st_size > room) {
+ // printf("Error: %s will not fit. Exiting.\n", src_file);
+ // close(fd);
+ // return -3;
+ //}
+
+ config_file = malloc (fd_stat.st_size+1);
+ read(fd, config_file, (size_t)fd_stat.st_size);
+
+ config_file[fd_stat.st_size+1] = '\0';
+
+ process_config(config_file, dir);
+ printf("fuse written=[%s,%d] %x\n", __func__, __LINE__, amd_psp_fw_table[16].other);
+}
+
+
static void register_bdt_data(amd_bios_type type, int sub, int ins, char name[])
{
int i;
@@ -1188,8 +1160,8 @@
psp_directory_table *pspdir;
int comboable = 0;
int fuse_defined = 0;
- int targetfd;
- char *output = NULL;
+ int targetfd, configfd;
+ char *output = NULL, *config = NULL;
context ctx = {
.rom_size = CONFIG_ROM_SIZE,
};
@@ -1427,6 +1399,9 @@
sub = instance = 0;
break;

+ case 'C':
+ config = optarg;
+ break;
case 'h':
usage();
return 0;
@@ -1434,9 +1409,29 @@
break;
}
}
+ #if 1
+ if (!config) {
+ printf("Error: config file is not specified.\n\n");
+ retval = 1;
+ }

- if (!fuse_defined)
- register_fw_fuse(DEFAULT_SOFT_FUSE_CHAIN);
+ configfd = open(config, O_RDONLY);
+
+ if (configfd >=0) {
+ printf("%s opened\n", config);
+ register_fw_fuses(configfd, dirname(config));
+ } else {
+ printf("open failed\n");
+ }
+
+
+ dump_psp_firmwares(amd_psp_fw_table);
+ dump_bdt_firmwares(amd_bios_table);
+ printf("close config file\n");
+ close (configfd);
+#endif
+ //if (!fuse_defined)
+ // register_fw_fuse(DEFAULT_SOFT_FUSE_CHAIN);

if (!output) {
printf("Error: Output value is not specified.\n\n");
@@ -1571,6 +1566,7 @@
amd_romsig->bios1_entry = BUFF_TO_RUN(ctx, biosdir);
}

+ /* TODO:Free the filename. */
targetfd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (targetfd >= 0) {
write(targetfd, amd_romsig, ctx.current - romsig_offset);
diff --git a/util/amdfwtool/amdfwtool.h b/util/amdfwtool/amdfwtool.h
new file mode 100644
index 0000000..fda41b2
--- /dev/null
+++ b/util/amdfwtool/amdfwtool.h
@@ -0,0 +1,98 @@
+#ifndef _AMD_FW_TOOL_H_
+#define _AMD_FW_TOOL_H_
+#if defined(__GLIBC__)
+typedef unsigned long long int uint64_t;
+typedef unsigned int uint32_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+#endif
+
+
+typedef enum _amd_fw_type {
+ AMD_FW_PSP_PUBKEY = 0,
+ AMD_FW_PSP_BOOTLOADER = 1,
+ AMD_FW_PSP_SMU_FIRMWARE = 8,
+ AMD_FW_PSP_RECOVERY = 3,
+ AMD_FW_PSP_RTM_PUBKEY = 5,
+ AMD_FW_PSP_SECURED_OS = 2,
+ AMD_FW_PSP_NVRAM = 4,
+ AMD_FW_PSP_SECURED_DEBUG = 9,
+ AMD_FW_PSP_TRUSTLETS = 12,
+ AMD_FW_PSP_TRUSTLETKEY = 13,
+ AMD_FW_PSP_SMU_FIRMWARE2 = 18,
+ AMD_PSP_FUSE_CHAIN = 11,
+ AMD_FW_PSP_SMUSCS = 95,
+ AMD_DEBUG_UNLOCK = 0x13,
+ AMD_WRAPPED_IKEK = 0x21,
+ AMD_TOKEN_UNLOCK = 0x22,
+ AMD_SEC_GASKET = 0x24,
+ AMD_MP2_FW = 0x25,
+ AMD_DRIVER_ENTRIES = 0x28,
+ AMD_S0I3_DRIVER = 0x2d,
+ AMD_ABL0 = 0x30,
+ AMD_ABL1 = 0x31,
+ AMD_ABL2 = 0x32,
+ AMD_ABL3 = 0x33,
+ AMD_ABL4 = 0x34,
+ AMD_ABL5 = 0x35,
+ AMD_ABL6 = 0x36,
+ AMD_ABL7 = 0x37,
+ AMD_FW_PSP_WHITELIST = 0x3a,
+ AMD_FW_L2_PTR = 0x40,
+ AMD_FW_PSP_VERSTAGE = 0x52,
+ AMD_FW_IMC,
+ AMD_FW_GEC,
+ AMD_FW_XHCI,
+ AMD_FW_INVALID,
+} amd_fw_type;
+
+typedef enum _amd_bios_type {
+ AMD_BIOS_APCB = 0x60,
+ AMD_BIOS_APOB = 0x61,
+ AMD_BIOS_BIN = 0x62,
+ AMD_BIOS_APOB_NV = 0x63,
+ AMD_BIOS_PMUI = 0x64,
+ AMD_BIOS_PMUD = 0x65,
+ AMD_BIOS_UCODE = 0x66,
+ AMD_BIOS_APCB_BK = 0x68,
+ AMD_BIOS_MP2_CFG = 0x6a,
+ AMD_BIOS_PSP_SHARED_MEM = 0x6b,
+ AMD_BIOS_L2_PTR = 0x70,
+ AMD_BIOS_INVALID,
+} amd_bios_type;
+
+
+#define BDT_LVL1 0x1
+#define BDT_LVL2 0x2
+#define BDT_BOTH (BDT_LVL1 | BDT_LVL2)
+typedef struct _amd_bios_entry {
+ amd_bios_type type;
+ char *filename;
+ int subpr;
+ int region_type;
+ int reset;
+ int copy;
+ int ro;
+ int zlib;
+ int inst;
+ uint64_t src;
+ uint64_t dest;
+ size_t size;
+ int level;
+} amd_bios_entry;
+
+
+#define PSP_LVL1 0x1
+#define PSP_LVL2 0x2
+#define PSP_BOTH (PSP_LVL1 | PSP_LVL2)
+typedef struct _amd_fw_entry {
+ amd_fw_type type;
+ char *filename;
+ uint8_t subprog;
+ int level;
+ uint64_t other;
+} amd_fw_entry;
+
+void register_fw_fuse(char *str);
+
+#endif
diff --git a/util/amdfwtool/amdfwtool.sh b/util/amdfwtool/amdfwtool.sh
new file mode 100644
index 0000000..50006f8
--- /dev/null
+++ b/util/amdfwtool/amdfwtool.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# --pubkey ../../3rdparty/blobs/soc/amd/picasso/PSP/AmdPubKeyRV.bin \
+# --bootloader /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//PspBootLoader_prod_RV.sbin \
+# --rtmpubkey /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//RtmPubSignedRV.key \
+# --secureos /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//psp_os_combined_prod_RV.sbin \
+# --securedebug /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//RavenSecureDebug_PublicKey.bin \
+
+# --trustlets /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//dr_ftpm_prod_RV.csbin \
+# --subprogram 2 --smufirmware /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//SmuFirmwarePCO.csbin \
+# --subprogram 2 --smufirmware2 /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//SmuFirmware2PCO.csbin \
+# --subprogram 1 --smufirmware /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//SmuFirmwareRV2.csbin \
+# --subprogram 1 --smufirmware2 /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//SmuFirmware2RV2.csbin \
+
+# --soft-fuse 0x0000000010000001 \
+# --subprogram 0 --instance 1 --pmu-inst /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv_1D_Ddr4_Udimm_Imem.csbin \
+# --subprogram 0 --instance 4 --pmu-inst /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv_2D_Ddr4_Imem.csbin \
+# --subprogram 1 --instance 1 --pmu-inst /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv2_1D_ddr4_Udimm_Imem.csbin \
+# --subprogram 1 --instance 4 --pmu-inst /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv2_2D_ddr4_Udimm_Imem.csbin \
+# --subprogram 0 --instance 1 --pmu-data /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv_1D_Ddr4_Udimm_Dmem.csbin \
+# --subprogram 0 --instance 4 --pmu-data /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv_2D_Ddr4_Dmem.csbin \
+# --subprogram 1 --instance 1 --pmu-data /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv2_1D_ddr4_Udimm_Dmem.csbin \
+# --subprogram 1 --instance 4 --pmu-data /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//Appb_Rv2_2D_ddr4_Udimm_Dmem.csbin \
+# --mp2-config /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//MP2FWConfig.sbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader0_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader1_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader2_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader3_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader4_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader5_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader6_prod_RV.csbin \
+# --abl-image /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//AgesaBootloader7_prod_RV.csbin \
+# --subprog 1 --sec-gasket /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//security_policy_RV2_FP5_AM4.sbin \
+# --subprog 2 --sec-gasket /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//security_policy_PCO_FP5_AM4.sbin \
+# --subprog 1 --mp2-fw /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//MP2I2CFWRV2.sbin \
+# --subprog 2 --mp2-fw /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//MP2I2CFWPCO.sbin \
+# --drv-entry-pts /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//drv_sys_prod_RV.sbin \
+# --ikek /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//PspIkekRV.bin \
+# --secdebug /home/baozheng/x86/coreboot-gerrit/3rdparty/blobs/soc/amd/picasso/PSP//secure_unlock_prod_RV.sbin \
+
+./amdfwtool \
+ --instance 0 --apcb ../../3rdparty/blobs/mainboard/amd/mandolin/apcb.bin \
+ \
+ \
+ \
+ \
+ --apob-base 0x9f00000 \
+ \
+ --apob-nv-size 0x1000 \
+ --bios-bin amd_biospsp.img \
+ --bios-bin-dest 8078000 \
+ --bios-uncomp-size 0x8000 \
+ \
+ \
+ --combo-capable \
+ --token-unlock \
+ --flashsize 0x00800000 \
+ --location 0xff820000 \
+ --config sample.txt \
+ --output amdfw.rom
diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c
new file mode 100644
index 0000000..03f1a7f
--- /dev/null
+++ b/util/amdfwtool/data_parse.c
@@ -0,0 +1,457 @@
+#include <stdio.h>
+#include <regex.h>
+#include <string.h>
+
+#include "amdfwtool.h"
+
+/* TODO: a empty line does not matched. */
+static const char blank_or_comment_regex[] =
+ /* a blank line */
+ "(^[[:space:]]*$)" "|" /* or ... */
+ /* a line consisting of: optional whitespace followed by */
+ "(^[[:space:]]*"
+ /* a '#' character and optionally, additional characters */
+ "#.*$)";
+static regex_t blank_or_comment_expr;
+
+static const char entries_line_regex[] =
+ /* optional whitespace */
+ "^[[:space:]]*"
+ /* followed by a chunk of nonwhitespace for macro field */
+ "([^[:space:]]+)"
+ /* followed by one or more whitespace characters */
+ "[[:space:]]+"
+ /* followed by a chunk of nonwhitespace for filename field */
+ "([^[:space:]]+)"
+ /* followed by optional whitespace */
+ "[[:space:]]*$";
+static regex_t entries_line_expr;
+
+static const char entries_subprog_line_regex[] =
+ /* optional whitespace */
+ "^[[:space:]]*"
+ /* followed by a chunk of nonwhitespace for macro field */
+ "([^[:space:]]+)"
+ /* followed by one or more whitespace characters */
+ "[[:space:]]+"
+ /* followed by a chunk of nonwhitespace for filename field */
+ "([^[:space:]]+)"
+ /* followed by one or more whitespace characters */
+ "[[:space:]]+"
+ /* followed by a chunk of nonwhitespace for filename field */
+ "([^[:space:]]+)"
+ /* followed by optional whitespace */
+ "[[:space:]]*$";
+static regex_t entries_subprog_line_expr;
+
+void compile_reg_expr(int cflags, const char *expr, regex_t *reg)
+{
+ static const size_t ERROR_BUF_SIZE = 256;
+ char error_msg[ERROR_BUF_SIZE];
+ int result;
+
+ if ((result = regcomp(reg, expr, cflags)) != 0) {
+ regerror(result, reg, error_msg, ERROR_BUF_SIZE);
+ printf("%s\n", error_msg);
+ exit(1);
+ }
+}
+
+extern amd_fw_entry amd_psp_fw_table[];
+extern amd_bios_entry amd_bios_table[];
+void find_register_fw_filename(char *fw_name, char *filename, uint8_t subprog)
+{
+ unsigned int fw_type, fw_invalid, fw, entry_size;
+ void *tableptr;
+ uint8_t /* subprog = 0, */instance = 0;
+
+ printf("fw_name=%s, fn=%s, subprog=%d\n", fw_name, filename, subprog);
+ if (strcmp(fw_name, "PSPBTLDR_FILE") == 0) {
+ fw_type = AMD_FW_PSP_BOOTLOADER;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+// printf("fw_type=%x, size=%x\n", fw_type, entry_size);
+ } else if (strcmp(fw_name, "AMD_PUBKEY_FILE") == 0) {
+ fw_type = AMD_FW_PSP_PUBKEY;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+// printf("fw_type=%x, size=%x\n", fw_type, entry_size);
+ } else if (strcmp(fw_name, "PUBSIGNEDKEY_FILE") == 0) {
+ fw_type = AMD_FW_PSP_RTM_PUBKEY;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SMUFW1_SUB1_FILE") == 0) {
+ fw_type = AMD_FW_PSP_SMU_FIRMWARE;
+ subprog = 1;
+ instance = 0;
+ fw_invalid = AMD_FW_INVALID;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SMUFW1_SUB2_FILE") == 0) {
+ fw_type = AMD_FW_PSP_SMU_FIRMWARE;
+ subprog = 2;
+ instance = 0;
+ fw_invalid = AMD_FW_INVALID;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SMUFW2_SUB1_FILE") == 0) {
+ fw_type = AMD_FW_PSP_SMU_FIRMWARE2;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 1;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SMUFW2_SUB2_FILE") == 0) {
+ fw_type = AMD_FW_PSP_SMU_FIRMWARE2;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 2;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SEC_DBG_KEY_FILE") == 0) {
+ fw_type = AMD_FW_PSP_SECURED_DEBUG;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL0_FILE") == 0) {
+ fw_type = AMD_ABL0;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL1_FILE") == 0) {
+ fw_type = AMD_ABL1;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL2_FILE") == 0) {
+ fw_type = AMD_ABL2;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL3_FILE") == 0) {
+ fw_type = AMD_ABL3;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL4_FILE") == 0) {
+ fw_type = AMD_ABL4;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL5_FILE") == 0) {
+ fw_type = AMD_ABL5;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL6_FILE") == 0) {
+ fw_type = AMD_ABL6;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_ABL7_FILE") == 0) {
+ fw_type = AMD_ABL7;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSPSCUREOS_FILE") == 0) {
+ fw_type = AMD_FW_PSP_SECURED_OS;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSPTRUSTLETS_FILE") == 0) {
+ fw_type = AMD_FW_PSP_TRUSTLETS;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SEC_DEBUG_FILE") == 0) {
+ fw_type = AMD_DEBUG_UNLOCK;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_IKEK_FILE") == 0) {
+ fw_type = AMD_WRAPPED_IKEK;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SECG1_FILE") == 0) {
+ fw_type = AMD_SEC_GASKET;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 1;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_SECG2_FILE") == 0) {
+ fw_type = AMD_SEC_GASKET;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 2;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_MP2FW1_FILE") == 0) {
+ fw_type = AMD_MP2_FW;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 1;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_MP2FW2_FILE") == 0) {
+ fw_type = AMD_MP2_FW;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 2;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_DRIVERS_FILE") == 0) {
+ fw_type = AMD_DRIVER_ENTRIES;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_S0I3_FILE") == 0) {
+ fw_type = AMD_S0I3_DRIVER;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else if (strcmp(fw_name, "PSP_WHITELIST_FILE") == 0) {
+ fw_type = AMD_FW_PSP_WHITELIST;
+ fw_invalid = AMD_FW_INVALID;
+ subprog = 0;
+ instance = 0;
+ tableptr = (void *)amd_psp_fw_table;
+ entry_size = sizeof (amd_fw_entry);
+ } else {
+ fw_type = AMD_FW_INVALID;
+// return ;
+ /* TODO: Add more */
+ }
+
+// printf("fw_type=%x, size=%x\n", fw_type, entry_size);
+ printf("Search and fill the filename\n");
+ /* Search and fill the filename */
+ while (*(unsigned int *)tableptr != fw_invalid) {
+ if (*(unsigned int *)tableptr == fw_type &&
+ ((amd_bios_entry *)tableptr)->subpr == subprog) {
+ printf("type=%d,", *(unsigned int *)tableptr);
+ printf("found, fn=%s\n", filename);
+ ((amd_fw_entry *)tableptr)->filename = filename;
+ break;
+ } else {
+// printf("not found type=%d\n", *(unsigned int *)tableptr);
+ }
+ tableptr += entry_size;
+ }
+ printf("\n");
+ printf("Search and fill the filename 2\n\n");
+ #if 1
+ if (strcmp(fw_name, "PSP_PMUI_FILE1") == 0) {
+ fw_type = AMD_BIOS_PMUI;
+ subprog = 0;
+ instance = 1;
+ } else if (strcmp(fw_name, "PSP_PMUI_FILE2") == 0) {
+ fw_type = AMD_BIOS_PMUI;
+ subprog = 0;
+ instance = 4;
+ } else if (strcmp(fw_name, "PSP_PMUI_FILE3") == 0) {
+ fw_type = AMD_BIOS_PMUI;
+ subprog = 1;
+ instance = 1;
+ } else if (strcmp(fw_name, "PSP_PMUI_FILE4") == 0) {
+ fw_type = AMD_BIOS_PMUI;
+ subprog = 1;
+ instance = 4;
+ } else if (strcmp(fw_name, "PSP_PMUD_FILE1") == 0) {
+ fw_type = AMD_BIOS_PMUD;
+ subprog = 0;
+ instance = 1;
+ } else if (strcmp(fw_name, "PSP_PMUD_FILE2") == 0) {
+ fw_type = AMD_BIOS_PMUD;
+ subprog = 0;
+ instance = 4;
+ } else if (strcmp(fw_name, "PSP_PMUD_FILE3") == 0) {
+ fw_type = AMD_BIOS_PMUD;
+ subprog = 1;
+ instance = 1;
+ } else if (strcmp(fw_name, "PSP_PMUD_FILE4") == 0) {
+ fw_type = AMD_BIOS_PMUD;
+ subprog = 1;
+ instance = 4;
+ } else if (strcmp(fw_name, "PSP_MP2CFG_FILE") == 0) {
+ fw_type = AMD_BIOS_MP2_CFG;
+ subprog = 0;
+ instance = 0;
+ } else {
+ fw_type = AMD_BIOS_INVALID;
+ }
+ tableptr = (void *)amd_bios_table;
+ if (fw_type != AMD_BIOS_INVALID) {
+ while (*(unsigned int *)tableptr != AMD_BIOS_INVALID) {
+ //printf("%x,%x,%x\n", *(unsigned int *)tableptr, ((amd_bios_entry *)tableptr)->subpr, ((amd_bios_entry *)tableptr)->inst);
+ if (*(unsigned int *)tableptr == fw_type &&
+ ((amd_bios_entry *)tableptr)->subpr == subprog &&
+ ((amd_bios_entry *)tableptr)->inst == instance) {
+ ((amd_bios_entry *)tableptr)->filename = filename;
+ //((amd_bios_entry *)tableptr)->subpr = subprog;
+ //((amd_bios_entry *)tableptr)->inst = instance;
+ printf("type=%x,", *(unsigned int *)tableptr);
+ printf("found, fn=%s\n", filename);
+ break;
+ }
+ tableptr += sizeof (amd_bios_entry);
+ }
+ }
+
+ printf("Search and fill the filename 3\n\n");
+ if (strcmp(fw_name, "PSP_SOFTFUSE") == 0) {
+ fw_type = AMD_PSP_FUSE_CHAIN;
+ } else {
+ fw_type = AMD_BIOS_INVALID;
+ }
+ /* char *filename */
+ printf("Search and fill the filename 3.1\n\n");
+ tableptr = (void *)amd_psp_fw_table;
+ if (fw_type != AMD_BIOS_INVALID) {
+ while (*(unsigned int *)tableptr != AMD_BIOS_INVALID) {
+ printf("%x,%x,%x\n", *(unsigned int *)tableptr, ((amd_bios_entry *)tableptr)->subpr, ((amd_bios_entry *)tableptr)->inst);
+ if (*(unsigned int *)tableptr == fw_type) {
+ //((amd_bios_entry *)tableptr)->filename = filename;
+ //((amd_bios_entry *)tableptr)->subpr = subprog;
+ ((amd_fw_entry *)tableptr)->other = strtoull(filename, NULL, 16);
+ printf("type=%x,", *(unsigned int *)tableptr);
+ printf("found, fuse=%llx\n", ((amd_fw_entry *)tableptr)->other);
+ break;
+ }
+ tableptr += sizeof (amd_fw_entry);
+ }
+ }
+ printf("fuse written=[] %x\n", amd_psp_fw_table[16].other);
+
+ printf("Search and fill the filename 3.9\n\n");
+
+#endif
+
+}
+
+unsigned int read_line(char **config, char **oneline)
+{
+ char *ptr = *config;
+ char *line_start;
+ int num;
+
+// printf("read_line %c\n", **config);
+ if (*ptr == NULL) return -1;
+
+ line_start = ptr;
+ while (*ptr != '\n' && *ptr != NULL) {
+ ptr ++;
+ }
+
+ num = ptr - line_start;
+ *oneline = malloc(num+1);
+
+ memcpy (*oneline, line_start, num);
+ *(*oneline + num) = '\0';
+ ptr ++; /* skip enter. */
+ //*oneline = ptr;
+// printf("readline = %s\n", *oneline);
+ *config = ptr;
+ return 0;
+}
+#define N_MATCHES 4
+void process_config(char *config, char *dir)
+{
+// char line [ /* LINE_BUF_SIZE */128];
+ char *oneline, *current, *path_filename;
+ regmatch_t match[N_MATCHES];
+ uint8_t subprog = 0;
+
+ compile_reg_expr(REG_EXTENDED | REG_NEWLINE, blank_or_comment_regex, &blank_or_comment_expr);
+ compile_reg_expr(REG_EXTENDED | REG_NEWLINE, entries_line_regex, &entries_line_expr);
+ compile_reg_expr(REG_EXTENDED | REG_NEWLINE, entries_subprog_line_regex, &entries_subprog_line_expr);
+
+ /* TODO: temp */
+ //strcpy (line, "PSPBTLDR_FILE PspBootLoader_prod_RV.sbin\n\0");
+// strcpy (line, "AMD_PUBKEY_FILE AmdPubKeyRV.bin\n\0");
+
+ /* Get a line */
+ current = config;
+ while (read_line(&current, &oneline) != -1) {
+ /* get line */
+ /* blank comment */
+// printf("%d\n", __LINE__);
+ if (!regexec(&blank_or_comment_expr, oneline, 0, NULL, 0)){
+ printf("skip comment and blank\n");
+ continue;
+ }
+
+// printf("%d\n", __LINE__);
+ if (regexec(&entries_line_expr, oneline, 3, match, 0) == 0) {
+ printf("matched entry\n");
+ printf("%d, %d, %d\n", match[0].rm_eo, match[1].rm_eo, match[2].rm_eo);
+ printf("%d, %d, %d\n", match[0].rm_so, match[1].rm_so, match[2].rm_so);
+ oneline[match[1].rm_eo] = '\0';
+ oneline[match[2].rm_eo] = '\0';
+ } else if (regexec(&entries_subprog_line_expr, oneline, 4, match, 0) == 0) {
+ printf("matched subprog entry\n");
+ printf("%d, %d, %d\n", match[0].rm_eo, match[1].rm_eo, match[2].rm_eo, match[3].rm_eo);
+ printf("%d, %d, %d\n", match[0].rm_so, match[1].rm_so, match[2].rm_so, match[3].rm_so);
+ oneline[match[1].rm_eo] = '\0';
+ oneline[match[2].rm_eo] = '\0';
+ oneline[match[3].rm_eo] = '\0';
+ subprog = oneline[match[3].rm_so] - '0';
+ } else {
+ printf("no match\n");
+ continue;
+ }
+// printf("%d\n", __LINE__);
+// printf("%d\n", __LINE__);
+
+// printf("%s, %s\n", &(oneline[match[1].rm_so]), &(oneline[match[2].rm_so]));
+ path_filename = malloc(256);
+ strcpy(path_filename, dir);
+ strcat(path_filename, "/");
+ strcat(path_filename, &(oneline[match[2].rm_so]));
+ find_register_fw_filename(&(oneline[match[1].rm_so]), path_filename, subprog);
+
+ }
+
+ printf("fuse written=[] %x\n", amd_psp_fw_table[16].other);
+
+}
diff --git a/util/amdfwtool/sample.txt b/util/amdfwtool/sample.txt
new file mode 100644
index 0000000..8c3edcc
--- /dev/null
+++ b/util/amdfwtool/sample.txt
@@ -0,0 +1,45 @@
+# sample
+# PSP
+# type file subprog
+AMD_PUBKEY_FILE AmdPubKeyRV.bin
+PSPBTLDR_FILE PspBootLoader_prod_RV.sbin
+PUBSIGNEDKEY_FILE RtmPubSignedRV.key
+PSP_SMUFW1_SUB1_FILE SmuFirmwareRV2.csbin
+PSP_SMUFW1_SUB2_FILE SmuFirmwarePCO.csbin
+PSP_SMUFW2_SUB1_FILE SmuFirmware2RV2.csbin
+PSP_SMUFW2_SUB2_FILE SmuFirmware2PCO.csbin
+PSPSCUREOS_FILE psp_os_combined_prod_RV.sbin
+PSPTRUSTLETS_FILE dr_ftpm_prod_RV.csbin
+PSP_SEC_DBG_KEY_FILE RavenSecureDebug_PublicKey.bin
+PSPSCUREOS_FILE psp_os_combined_prod_RV.sbin
+PSP_ABL0_FILE AgesaBootloader0_prod_RV.csbin
+PSP_ABL1_FILE AgesaBootloader1_prod_RV.csbin
+PSP_ABL2_FILE AgesaBootloader2_prod_RV.csbin
+PSP_ABL3_FILE AgesaBootloader3_prod_RV.csbin
+PSP_ABL4_FILE AgesaBootloader4_prod_RV.csbin
+PSP_ABL5_FILE AgesaBootloader5_prod_RV.csbin
+PSP_ABL6_FILE AgesaBootloader6_prod_RV.csbin
+PSP_ABL7_FILE AgesaBootloader7_prod_RV.csbin
+PSP_SEC_DEBUG_FILE secure_unlock_prod_RV.sbin
+PSP_IKEK_FILE PspIkekRV.bin
+PSP_SECG1_FILE security_policy_RV2_FP5_AM4.sbin
+PSP_SECG2_FILE security_policy_PCO_FP5_AM4.sbin
+PSP_MP2FW1_FILE MP2I2CFWRV2.sbin
+PSP_MP2FW2_FILE MP2I2CFWPCO.sbin
+PSP_MP2CFG_FILE MP2FWConfig.sbin
+PSP_DRIVERS_FILE drv_sys_prod_RV.sbin
+PSP_SOFTFUSE 0x0000000010000001
+PSP_S0I3_FILE dr_agesa_prod_RV.sbin
+#PSP_APOBNV_BASE
+#PSP_APOBNV_SIZE
+#
+## BDT
+#PSP_APCB0_FILE apcb.bin
+PSP_PMUI_FILE1 Appb_Rv_1D_Ddr4_Udimm_Imem.csbin
+PSP_PMUI_FILE2 Appb_Rv_2D_Ddr4_Imem.csbin
+PSP_PMUI_FILE3 Appb_Rv2_1D_ddr4_Udimm_Imem.csbin
+PSP_PMUI_FILE4 Appb_Rv2_2D_ddr4_Udimm_Imem.csbin
+PSP_PMUD_FILE1 Appb_Rv_1D_Ddr4_Udimm_Dmem.csbin
+PSP_PMUD_FILE2 Appb_Rv_2D_Ddr4_Dmem.csbin
+PSP_PMUD_FILE3 Appb_Rv2_1D_ddr4_Udimm_Dmem.csbin
+PSP_PMUD_FILE4 Appb_Rv2_2D_ddr4_Udimm_Dmem.csbin

To view, visit change 42859. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Icae73d0730106aab687486e555ba947796e5e757
Gerrit-Change-Number: 42859
Gerrit-PatchSet: 1
Gerrit-Owner: Bao Zheng <fishbaozi@gmail.com>
Gerrit-Reviewer: Zheng Bao
Gerrit-MessageType: newchange