<p>Richard Spiegel has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/28144">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">soc/amd/common/block: Port vendorcode's LibAmdLocateImage<br><br>In preparation to removing AmdLib, function LibAmdLocateImage() has to be<br>ported to be used by agesawrapper. The most important aspect of this porting<br>is that it has to obey coreboot format, specifically 8 character tab and 80<br>characters max. This required breaking the function in 2 (to solve<br>indentation) and rename some variables to shorter names.<br><br>One important aspect was breaking<br>(AMD_MODULE_HEADER*)(((AMD_IMAGE_HEADER *) CurrentPtr)->ModuleInfoOffset)<br><br>into:<br>image_ptr = (AMD_IMAGE_HEADER *) current_ptr;<br>if (validate_image((void *)image_ptr->ModuleInfoOffset,<br><br>and, within validate_image completed by:<br>AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain;<br><br>BUG=b:112625809<br>TEST=Build grunt, functionality tested in next commit.<br><br>Change-Id: I0d1e8b966cf7606fdb15a95de5771f835f07b2bc<br>Signed-off-by: Richard Spiegel <richard.spiegel@silverbackltd.com><br>---<br>A src/soc/amd/common/block/image/Kconfig<br>A src/soc/amd/common/block/image/Makefile.inc<br>A src/soc/amd/common/block/image/image.c<br>A src/soc/amd/common/block/include/amdblocks/image.h<br>M src/soc/amd/stoneyridge/Kconfig<br>5 files changed, 97 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/44/28144/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/soc/amd/common/block/image/Kconfig b/src/soc/amd/common/block/image/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..9f0f9ea</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/amd/common/block/image/Kconfig</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+config SOC_AMD_COMMON_BLOCK_IMAGE</span><br><span style="color: hsl(120, 100%, 40%);">+   bool</span><br><span style="color: hsl(120, 100%, 40%);">+  default n</span><br><span style="color: hsl(120, 100%, 40%);">+     help</span><br><span style="color: hsl(120, 100%, 40%);">+    This option builds in the image find functions.</span><br><span>diff --git a/src/soc/amd/common/block/image/Makefile.inc b/src/soc/amd/common/block/image/Makefile.inc</span><br><span>new file mode 100644</span><br><span>index 0000000..91701e5</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/amd/common/block/image/Makefile.inc</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_IMAGE),y)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-y += image.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += image.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+endif</span><br><span>diff --git a/src/soc/amd/common/block/image/image.c b/src/soc/amd/common/block/image/image.c</span><br><span>new file mode 100644</span><br><span>index 0000000..288afce</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/amd/common/block/image/image.c</span><br><span>@@ -0,0 +1,60 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Silverback, ltd.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <agesa_headers.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <amdblocks/image.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Check if the image has the desired module. */</span><br><span style="color: hsl(120, 100%, 40%);">+static bool validate_image(void *module_chain, const char module_signature[8])</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain;</span><br><span style="color: hsl(120, 100%, 40%);">+       uint64_t signature = *(uint64_t *)module_signature;</span><br><span style="color: hsl(120, 100%, 40%);">+   char *checking_str;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((mod_ptr != NULL) &&</span><br><span style="color: hsl(120, 100%, 40%);">+     (MODULE_SIGNATURE == *(uint32_t *)&mod_ptr->ModuleHeaderSignature)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                checking_str = (char *)&mod_ptr->ModuleIdentifier;</span><br><span style="color: hsl(120, 100%, 40%);">+             if (signature == *(uint64_t *)checking_str)</span><br><span style="color: hsl(120, 100%, 40%);">+                   return true;</span><br><span style="color: hsl(120, 100%, 40%);">+          mod_ptr = (AMD_MODULE_HEADER *)mod_ptr->NextBlock;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+     return false;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Find an image that has the desired module. The image is aligned within</span><br><span style="color: hsl(120, 100%, 40%);">+ * a given range.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void *find_image(const void *start_address, const void *end_address,</span><br><span style="color: hsl(120, 100%, 40%);">+                       uint32_t alignment, const char name[8])</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t *current_ptr = (uint8_t *)start_address;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t *start = (uint8_t *)start_address;</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t *end = (uint8_t *)end_address;</span><br><span style="color: hsl(120, 100%, 40%);">+        AMD_IMAGE_HEADER *image_ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        while ((current_ptr >= start) && (current_ptr < end)) {</span><br><span style="color: hsl(120, 100%, 40%);">+         if (IMAGE_SIGNATURE == *((uint32_t *)current_ptr)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                  image_ptr = (AMD_IMAGE_HEADER *) current_ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                       /* Check if the image has the desired module */</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (validate_image((void *)image_ptr->ModuleInfoOffset,</span><br><span style="color: hsl(120, 100%, 40%);">+                                       name))</span><br><span style="color: hsl(120, 100%, 40%);">+                             return current_ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+           }</span><br><span style="color: hsl(120, 100%, 40%);">+             current_ptr += alignment;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/soc/amd/common/block/include/amdblocks/image.h b/src/soc/amd/common/block/include/amdblocks/image.h</span><br><span>new file mode 100644</span><br><span>index 0000000..3e03e10</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/amd/common/block/include/amdblocks/image.h</span><br><span>@@ -0,0 +1,24 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Silverback, ltd.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef __AMD_IMAGE_H__</span><br><span style="color: hsl(120, 100%, 40%);">+#define __AMD_IMAGE_H__</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void *find_image(const void *start_address, const void *end_address,</span><br><span style="color: hsl(120, 100%, 40%);">+                     uint32_t alignment, const char name[8]);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* __AMD_IMAGE_H__ */</span><br><span>diff --git a/src/soc/amd/stoneyridge/Kconfig b/src/soc/amd/stoneyridge/Kconfig</span><br><span>index 2716c8c..38cb268 100644</span><br><span>--- a/src/soc/amd/stoneyridge/Kconfig</span><br><span>+++ b/src/soc/amd/stoneyridge/Kconfig</span><br><span>@@ -49,6 +49,7 @@</span><br><span>        select SOC_AMD_COMMON_BLOCK</span><br><span>  select SOC_AMD_COMMON_BLOCK_PCI</span><br><span>      select SOC_AMD_COMMON_BLOCK_PI</span><br><span style="color: hsl(120, 100%, 40%);">+        select SOC_AMD_COMMON_BLOCK_IMAGE</span><br><span>    select SOC_AMD_COMMON_BLOCK_PSP</span><br><span>      select SOC_AMD_COMMON_BLOCK_CAR</span><br><span>      select SOC_AMD_COMMON_BLOCK_S3 if HAVE_ACPI_RESUME</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/28144">change 28144</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/28144"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I0d1e8b966cf7606fdb15a95de5771f835f07b2bc </div>
<div style="display:none"> Gerrit-Change-Number: 28144 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Spiegel <richard.spiegel@silverbackltd.com> </div>