lib/stage_cache: Add debug messages for failures

Communicate additional status to the console when the save and load
functions do not function as expected.  The most likely scenario for
an error is when using a cache that is external to cbmem, and restricted
in size.

Change-Id: Ic9a709c11152b3b9cb40abfc204151f9636b5a4c
Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com>
Reviewed-on: https://review.coreboot.org/23517
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Marshall Dawson 2018-01-30 15:54:52 -07:00 committed by Martin Roth
parent 8cc5fdec90
commit 0876caa473
2 changed files with 33 additions and 8 deletions

View File

@ -17,6 +17,7 @@
#include <cbmem.h> #include <cbmem.h>
#include <stage_cache.h> #include <stage_cache.h>
#include <string.h> #include <string.h>
#include <console/console.h>
/* Stage cache uses cbmem. */ /* Stage cache uses cbmem. */
void stage_cache_add(int stage_id, const struct prog *stage) void stage_cache_add(int stage_id, const struct prog *stage)
@ -25,15 +26,21 @@ void stage_cache_add(int stage_id, const struct prog *stage)
void *c; void *c;
meta = cbmem_add(CBMEM_ID_STAGEx_META + stage_id, sizeof(*meta)); meta = cbmem_add(CBMEM_ID_STAGEx_META + stage_id, sizeof(*meta));
if (meta == NULL) if (meta == NULL) {
printk(BIOS_ERR, "Error: Can't add %x metadata to cbmem\n",
CBMEM_ID_STAGEx_META + stage_id);
return; return;
}
meta->load_addr = (uintptr_t)prog_start(stage); meta->load_addr = (uintptr_t)prog_start(stage);
meta->entry_addr = (uintptr_t)prog_entry(stage); meta->entry_addr = (uintptr_t)prog_entry(stage);
meta->arg = (uintptr_t)prog_entry_arg(stage); meta->arg = (uintptr_t)prog_entry_arg(stage);
c = cbmem_add(CBMEM_ID_STAGEx_CACHE + stage_id, prog_size(stage)); c = cbmem_add(CBMEM_ID_STAGEx_CACHE + stage_id, prog_size(stage));
if (c == NULL) if (c == NULL) {
printk(BIOS_ERR, "Error: Can't add stage_cache %x to cbmem\n",
CBMEM_ID_STAGEx_CACHE + stage_id);
return; return;
}
memcpy(c, prog_start(stage), prog_size(stage)); memcpy(c, prog_start(stage), prog_size(stage));
} }
@ -49,13 +56,19 @@ void stage_cache_load_stage(int stage_id, struct prog *stage)
prog_set_entry(stage, NULL, NULL); prog_set_entry(stage, NULL, NULL);
meta = cbmem_find(CBMEM_ID_STAGEx_META + stage_id); meta = cbmem_find(CBMEM_ID_STAGEx_META + stage_id);
if (meta == NULL) if (meta == NULL) {
printk(BIOS_ERR, "Error: Can't find %x metadata in cbmem\n",
CBMEM_ID_STAGEx_META + stage_id);
return; return;
}
e = cbmem_entry_find(CBMEM_ID_STAGEx_CACHE + stage_id); e = cbmem_entry_find(CBMEM_ID_STAGEx_CACHE + stage_id);
if (e == NULL) if (e == NULL) {
printk(BIOS_ERR, "Error: Can't find stage_cache %x in cbmem\n",
CBMEM_ID_STAGEx_CACHE + stage_id);
return; return;
}
c = cbmem_entry_start(e); c = cbmem_entry_start(e);
size = cbmem_entry_size(e); size = cbmem_entry_size(e);

View File

@ -68,8 +68,11 @@ void stage_cache_add(int stage_id, const struct prog *stage)
imd = imd_get(); imd = imd_get();
e = imd_entry_add(imd, CBMEM_ID_STAGEx_META + stage_id, sizeof(*meta)); e = imd_entry_add(imd, CBMEM_ID_STAGEx_META + stage_id, sizeof(*meta));
if (e == NULL) if (e == NULL) {
printk(BIOS_DEBUG, "Error: Can't add %x metadata to imd\n",
CBMEM_ID_STAGEx_META + stage_id);
return; return;
}
meta = imd_entry_at(imd, e); meta = imd_entry_at(imd, e);
@ -79,8 +82,11 @@ void stage_cache_add(int stage_id, const struct prog *stage)
e = imd_entry_add(imd, CBMEM_ID_STAGEx_CACHE + stage_id, e = imd_entry_add(imd, CBMEM_ID_STAGEx_CACHE + stage_id,
prog_size(stage)); prog_size(stage));
if (e == NULL) if (e == NULL) {
printk(BIOS_DEBUG, "Error: Can't add stage_cache %x to imd\n",
CBMEM_ID_STAGEx_CACHE + stage_id);
return; return;
}
c = imd_entry_at(imd, e); c = imd_entry_at(imd, e);
@ -97,15 +103,21 @@ void stage_cache_load_stage(int stage_id, struct prog *stage)
imd = imd_get(); imd = imd_get();
e = imd_entry_find(imd, CBMEM_ID_STAGEx_META + stage_id); e = imd_entry_find(imd, CBMEM_ID_STAGEx_META + stage_id);
if (e == NULL) if (e == NULL) {
printk(BIOS_DEBUG, "Error: Can't find %x metadata in imd\n",
CBMEM_ID_STAGEx_META + stage_id);
return; return;
}
meta = imd_entry_at(imd, e); meta = imd_entry_at(imd, e);
e = imd_entry_find(imd, CBMEM_ID_STAGEx_CACHE + stage_id); e = imd_entry_find(imd, CBMEM_ID_STAGEx_CACHE + stage_id);
if (e == NULL) if (e == NULL) {
printk(BIOS_DEBUG, "Error: Can't find stage_cache %x in imd\n",
CBMEM_ID_STAGEx_CACHE + stage_id);
return; return;
}
c = imd_entry_at(imd, e); c = imd_entry_at(imd, e);
size = imd_entry_size(imd, e); size = imd_entry_size(imd, e);