vendorcode/siemens/hwilib: Drop CAR_GLOBAL_MIGRATION

TEST: BUILD_TIMELESS=1 results in identical binaries.

TODO: Is this code correct? The strncpy/strncmp current_hwi seems
wrong.

Change-Id: Icf44fee8f7f538df6c34dfbd98b852954d146896
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37026
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
This commit is contained in:
Arthur Heymans 2019-11-20 19:35:59 +01:00 committed by Patrick Georgi
parent fba9f33187
commit b6c9a5d797
1 changed files with 20 additions and 27 deletions

View File

@ -17,7 +17,6 @@
#include <string.h> #include <string.h>
#include <console/console.h> #include <console/console.h>
#include <device/mmio.h> #include <device/mmio.h>
#include <arch/early_variables.h>
#include <types.h> #include <types.h>
#include "hwilib.h" #include "hwilib.h"
@ -74,15 +73,15 @@ struct param_info {
/* Storage for pointers to the different blocks. The contents will be filled /* Storage for pointers to the different blocks. The contents will be filled
* in hwilib_find_blocks(). * in hwilib_find_blocks().
*/ */
static uint8_t *all_blocks[MAX_BLOCK_NUM] CAR_GLOBAL; static uint8_t *all_blocks[MAX_BLOCK_NUM];
/* As the length of extended block is variable, save all length to a global /* As the length of extended block is variable, save all length to a global
* variable so that they can be used later to check boundaries. * variable so that they can be used later to check boundaries.
*/ */
static uint16_t all_blk_size[MAX_BLOCK_NUM] CAR_GLOBAL; static uint16_t all_blk_size[MAX_BLOCK_NUM];
/* Storage for the cbfs file name of the currently open hwi file. */ /* Storage for the cbfs file name of the currently open hwi file. */
static char current_hwi[HWI_MAX_NAME_LEN] CAR_GLOBAL; static char current_hwi[HWI_MAX_NAME_LEN];
static uint32_t hwilib_read_bytes (const struct param_info *param, uint8_t *dst, static uint32_t hwilib_read_bytes (const struct param_info *param, uint8_t *dst,
@ -405,16 +404,14 @@ static uint32_t hwilib_read_bytes (const struct param_info *param, uint8_t *dst,
uint32_t maxlen) uint32_t maxlen)
{ {
uint8_t i = 0, *blk = NULL; uint8_t i = 0, *blk = NULL;
uint8_t **blk_ptr = car_get_var_ptr(&all_blocks[0]);
uint16_t *all_blk_size_ptr = car_get_var_ptr(&all_blk_size[0]);
if (!param || !dst) if (!param || !dst)
return 0; return 0;
/* Take the first valid block to get the parameter from */ /* Take the first valid block to get the parameter from */
do { do {
if ((param->pos[i].len) && (param->pos[i].offset) && if ((param->pos[i].len) && (param->pos[i].offset) &&
(blk_ptr[param->pos[i].blk_type])) { (all_blocks[param->pos[i].blk_type])) {
blk = blk_ptr[param->pos[i].blk_type]; blk = all_blocks[param->pos[i].blk_type];
break; break;
} }
i++; i++;
@ -425,7 +422,7 @@ static uint32_t hwilib_read_bytes (const struct param_info *param, uint8_t *dst,
*/ */
if ((!blk) || (param->pos[i].len > maxlen) || if ((!blk) || (param->pos[i].len > maxlen) ||
(param->pos[i].len + param->pos[i].offset > (param->pos[i].len + param->pos[i].offset >
all_blk_size_ptr[param->pos[i].blk_type])) all_blk_size[param->pos[i].blk_type]))
return 0; return 0;
/* We can now copy the wanted data. */ /* We can now copy the wanted data. */
memcpy(dst, (blk + param->pos[i].offset), param->pos[i].len); memcpy(dst, (blk + param->pos[i].offset), param->pos[i].len);
@ -472,9 +469,6 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
{ {
uint8_t *ptr = NULL, *base = NULL; uint8_t *ptr = NULL, *base = NULL;
uint32_t next_offset = 1; uint32_t next_offset = 1;
uint8_t **blk_ptr = car_get_var_ptr(&all_blocks[0]);
uint16_t *all_blk_size_ptr = car_get_var_ptr(&all_blk_size[0]);
char *curr_hwi_name_ptr = car_get_var_ptr(&current_hwi);
size_t filesize = 0; size_t filesize = 0;
/* Check for a valid parameter */ /* Check for a valid parameter */
@ -482,8 +476,7 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
return CB_ERR_ARG; return CB_ERR_ARG;
/* Check if this file is already open. If yes, just leave as there is /* Check if this file is already open. If yes, just leave as there is
nothing left to do here. */ nothing left to do here. */
if (curr_hwi_name_ptr && if (!strncmp((char *)&current_hwi, hwi_filename, HWI_MAX_NAME_LEN)) {
!strncmp(curr_hwi_name_ptr, hwi_filename, HWI_MAX_NAME_LEN)) {
printk(BIOS_SPEW, "HWILIB: File \"%s\" already open.\n", printk(BIOS_SPEW, "HWILIB: File \"%s\" already open.\n",
hwi_filename); hwi_filename);
return CB_SUCCESS; return CB_SUCCESS;
@ -504,15 +497,15 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
* in prior calls to this function. * in prior calls to this function.
* This way the caller do not need to "close" already opened blocks. * This way the caller do not need to "close" already opened blocks.
*/ */
memset(blk_ptr, 0, (MAX_BLOCK_NUM * sizeof (uint8_t *))); memset(all_blocks, 0, (MAX_BLOCK_NUM * sizeof (uint8_t *)));
/* Check which blocks are available by examining the length field. */ /* Check which blocks are available by examining the length field. */
base = ptr; base = ptr;
/* Fill in sizes of all fixed length blocks. */ /* Fill in sizes of all fixed length blocks. */
all_blk_size_ptr[BLK_HIB] = LEN_HIB; all_blk_size[BLK_HIB] = LEN_HIB;
all_blk_size_ptr[BLK_SIB] = LEN_SIB; all_blk_size[BLK_SIB] = LEN_SIB;
all_blk_size_ptr[BLK_EIB] = LEN_EIB; all_blk_size[BLK_EIB] = LEN_EIB;
/* Length of BLK_XIB is variable and will be filled if block is found */ /* Length of BLK_XIB is variable and will be filled if block is found */
all_blk_size_ptr[BLK_XIB] = 0; all_blk_size[BLK_XIB] = 0;
while(!(strncmp((char *)ptr, BLOCK_MAGIC, LEN_MAGIC_NUM)) && while(!(strncmp((char *)ptr, BLOCK_MAGIC, LEN_MAGIC_NUM)) &&
next_offset) { next_offset) {
uint16_t len = read16(ptr + LEN_OFFSET); uint16_t len = read16(ptr + LEN_OFFSET);
@ -520,26 +513,26 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
if ((ptr - base + len) > filesize) if ((ptr - base + len) > filesize)
break; break;
if (len == LEN_HIB) { if (len == LEN_HIB) {
blk_ptr[BLK_HIB] = ptr; all_blocks[BLK_HIB] = ptr;
next_offset = read32(ptr + NEXT_OFFSET_HIB); next_offset = read32(ptr + NEXT_OFFSET_HIB);
if (next_offset) if (next_offset)
ptr = base + next_offset; ptr = base + next_offset;
} else if (len == LEN_SIB) { } else if (len == LEN_SIB) {
blk_ptr[BLK_SIB] = ptr; all_blocks[BLK_SIB] = ptr;
next_offset = read32(ptr + NEXT_OFFSET_SIB); next_offset = read32(ptr + NEXT_OFFSET_SIB);
if (next_offset) if (next_offset)
ptr = base + next_offset; ptr = base + next_offset;
} else if (len == LEN_EIB) { } else if (len == LEN_EIB) {
/* Skip preliminary blocks */ /* Skip preliminary blocks */
if (!(read16(ptr + EIB_FEATRUE_OFFSET) & 0x01)) if (!(read16(ptr + EIB_FEATRUE_OFFSET) & 0x01))
blk_ptr[BLK_EIB] = ptr; all_blocks[BLK_EIB] = ptr;
next_offset = read32(ptr + NEXT_OFFSET_EIB); next_offset = read32(ptr + NEXT_OFFSET_EIB);
if (next_offset) if (next_offset)
ptr = base + next_offset; ptr = base + next_offset;
} else if (len >= MIN_LEN_XIB) { } else if (len >= MIN_LEN_XIB) {
blk_ptr[BLK_XIB] = ptr; all_blocks[BLK_XIB] = ptr;
next_offset = read32(ptr + NEXT_OFFSET_XIB); next_offset = read32(ptr + NEXT_OFFSET_XIB);
all_blk_size_ptr[BLK_XIB] = len; all_blk_size[BLK_XIB] = len;
if (next_offset) if (next_offset)
ptr = base + next_offset; ptr = base + next_offset;
} else { } else {
@ -547,10 +540,10 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
} }
} }
/* We should have found at least one valid block */ /* We should have found at least one valid block */
if (blk_ptr[BLK_HIB] || blk_ptr[BLK_SIB] || blk_ptr[BLK_EIB] || if (all_blocks[BLK_HIB] || all_blocks[BLK_SIB] || all_blocks[BLK_EIB] ||
blk_ptr[BLK_XIB]) { all_blocks[BLK_XIB]) {
/* Save currently opened hwi filename. */ /* Save currently opened hwi filename. */
strncpy(curr_hwi_name_ptr, hwi_filename, HWI_MAX_NAME_LEN); strncpy((char *)&current_hwi, hwi_filename, HWI_MAX_NAME_LEN);
return CB_SUCCESS; return CB_SUCCESS;
} }
else else