[coreboot-gerrit] Change in coreboot[master]: soc/amd/common/block: Port vendorcode's LibAmdLocateImage

Richard Spiegel (Code Review) gerrit at coreboot.org
Thu Aug 16 20:27:08 CEST 2018


Richard Spiegel has uploaded this change for review. ( https://review.coreboot.org/28144


Change subject: soc/amd/common/block: Port vendorcode's LibAmdLocateImage
......................................................................

soc/amd/common/block: Port vendorcode's LibAmdLocateImage

In preparation to removing AmdLib, function LibAmdLocateImage() has to be
ported to be used by agesawrapper. The most important aspect of this porting
is that it has to obey coreboot format, specifically 8 character tab and 80
characters max. This required breaking the function in 2 (to solve
indentation) and rename some variables to shorter names.

One important aspect was breaking
(AMD_MODULE_HEADER*)(((AMD_IMAGE_HEADER *) CurrentPtr)->ModuleInfoOffset)

into:
image_ptr = (AMD_IMAGE_HEADER *) current_ptr;
if (validate_image((void *)image_ptr->ModuleInfoOffset,

and, within validate_image completed by:
AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain;

BUG=b:112625809
TEST=Build grunt, functionality tested in next commit.

Change-Id: I0d1e8b966cf7606fdb15a95de5771f835f07b2bc
Signed-off-by: Richard Spiegel <richard.spiegel at silverbackltd.com>
---
A src/soc/amd/common/block/image/Kconfig
A src/soc/amd/common/block/image/Makefile.inc
A src/soc/amd/common/block/image/image.c
A src/soc/amd/common/block/include/amdblocks/image.h
M src/soc/amd/stoneyridge/Kconfig
5 files changed, 97 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/44/28144/1

diff --git a/src/soc/amd/common/block/image/Kconfig b/src/soc/amd/common/block/image/Kconfig
new file mode 100644
index 0000000..9f0f9ea
--- /dev/null
+++ b/src/soc/amd/common/block/image/Kconfig
@@ -0,0 +1,5 @@
+config SOC_AMD_COMMON_BLOCK_IMAGE
+	bool
+	default n
+	help
+	  This option builds in the image find functions.
diff --git a/src/soc/amd/common/block/image/Makefile.inc b/src/soc/amd/common/block/image/Makefile.inc
new file mode 100644
index 0000000..91701e5
--- /dev/null
+++ b/src/soc/amd/common/block/image/Makefile.inc
@@ -0,0 +1,7 @@
+ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_IMAGE),y)
+
+romstage-y += image.c
+
+ramstage-y += image.c
+
+endif
diff --git a/src/soc/amd/common/block/image/image.c b/src/soc/amd/common/block/image/image.c
new file mode 100644
index 0000000..288afce
--- /dev/null
+++ b/src/soc/amd/common/block/image/image.c
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2018 Silverback, ltd.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <agesa_headers.h>
+#include <amdblocks/image.h>
+
+/* Check if the image has the desired module. */
+static bool validate_image(void *module_chain, const char module_signature[8])
+{
+	AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain;
+	uint64_t signature = *(uint64_t *)module_signature;
+	char *checking_str;
+
+	while ((mod_ptr != NULL) &&
+	  (MODULE_SIGNATURE == *(uint32_t *)&mod_ptr->ModuleHeaderSignature)) {
+		checking_str = (char *)&mod_ptr->ModuleIdentifier;
+		if (signature == *(uint64_t *)checking_str)
+			return true;
+		mod_ptr = (AMD_MODULE_HEADER *)mod_ptr->NextBlock;
+	}
+	return false;
+}
+
+/*
+ * Find an image that has the desired module. The image is aligned within
+ * a given range.
+ */
+void *find_image(const void *start_address, const void *end_address,
+			uint32_t alignment, const char name[8])
+{
+	uint8_t *current_ptr = (uint8_t *)start_address;
+	uint8_t *start = (uint8_t *)start_address;
+	uint8_t *end = (uint8_t *)end_address;
+	AMD_IMAGE_HEADER *image_ptr;
+
+	while ((current_ptr >= start) && (current_ptr < end)) {
+		if (IMAGE_SIGNATURE == *((uint32_t *)current_ptr)) {
+			image_ptr = (AMD_IMAGE_HEADER *) current_ptr;
+
+			/* Check if the image has the desired module */
+			if (validate_image((void *)image_ptr->ModuleInfoOffset,
+					   name))
+				return current_ptr;
+		}
+		current_ptr += alignment;
+	}
+	return NULL;
+}
diff --git a/src/soc/amd/common/block/include/amdblocks/image.h b/src/soc/amd/common/block/include/amdblocks/image.h
new file mode 100644
index 0000000..3e03e10
--- /dev/null
+++ b/src/soc/amd/common/block/include/amdblocks/image.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2018 Silverback, ltd.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#ifndef __AMD_IMAGE_H__
+#define __AMD_IMAGE_H__
+
+#include <stdint.h>
+
+void *find_image(const void *start_address, const void *end_address,
+			uint32_t alignment, const char name[8]);
+
+#endif /* __AMD_IMAGE_H__ */
diff --git a/src/soc/amd/stoneyridge/Kconfig b/src/soc/amd/stoneyridge/Kconfig
index 2716c8c..38cb268 100644
--- a/src/soc/amd/stoneyridge/Kconfig
+++ b/src/soc/amd/stoneyridge/Kconfig
@@ -49,6 +49,7 @@
 	select SOC_AMD_COMMON_BLOCK
 	select SOC_AMD_COMMON_BLOCK_PCI
 	select SOC_AMD_COMMON_BLOCK_PI
+	select SOC_AMD_COMMON_BLOCK_IMAGE
 	select SOC_AMD_COMMON_BLOCK_PSP
 	select SOC_AMD_COMMON_BLOCK_CAR
 	select SOC_AMD_COMMON_BLOCK_S3 if HAVE_ACPI_RESUME

-- 
To view, visit https://review.coreboot.org/28144
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d1e8b966cf7606fdb15a95de5771f835f07b2bc
Gerrit-Change-Number: 28144
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Spiegel <richard.spiegel at silverbackltd.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180816/40232c8e/attachment-0001.html>


More information about the coreboot-gerrit mailing list