aboutsummaryrefslogtreecommitdiff
path: root/lib/libnvram
diff options
context:
space:
mode:
authorThomas Huth <thuth@linux.vnet.ibm.com>2011-08-17 11:39:09 +0200
committerThomas Huth <thuth@linux.vnet.ibm.com>2011-08-19 14:57:32 +0200
commit1d41e8a29b2b6fa5283a709b6c10d0c36db99e3e (patch)
tree8f21d442845d80fdd1b73edf7c5023cdb1f59512 /lib/libnvram
parentf36326c1153fa91505456ae5be41b22a951b9812 (diff)
downloadSLOF-1d41e8a29b2b6fa5283a709b6c10d0c36db99e3e.zip
SLOF-1d41e8a29b2b6fa5283a709b6c10d0c36db99e3e.tar.gz
SLOF-1d41e8a29b2b6fa5283a709b6c10d0c36db99e3e.tar.bz2
Fixed some problems with libnvram
- On board-qemu, the logging partitions were too big (bigger than the total NVRAM size). - Fixed a compiler warning about type-punned pointers in nvram.c - When DISABLE_NVRAM is set, the fake buffer should not be accessed with cache-inhibited functions - Makefile did not generate proper dependencies Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Diffstat (limited to 'lib/libnvram')
-rw-r--r--lib/libnvram/Makefile5
-rw-r--r--lib/libnvram/nvram.c77
2 files changed, 57 insertions, 25 deletions
diff --git a/lib/libnvram/Makefile b/lib/libnvram/Makefile
index afd536f..d4e9a61 100644
--- a/lib/libnvram/Makefile
+++ b/lib/libnvram/Makefile
@@ -14,6 +14,8 @@ SRCS = nvram.c envvar.c
TOPCMNDIR ?= ../..
+include $(TOPCMNDIR)/make.rules
+
ASFLAGS = $(FLAG) $(RELEASE) $(CPUARCHDEF) -Wa,-mregnames
CPPFLAGS = -I../libc/include $(CPUARCHDEF) $(FLAG) \
-I$(INCLBRDDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I. -I../../include
@@ -43,7 +45,8 @@ depend:
$(MAKE) Makefile.dep
Makefile.dep: Makefile
-
+ $(CC) -MM $(CPPFLAGS) $(CFLAGS) $(SRCS) > Makefile.dep
+
# Include dependency file if available:
-include Makefile.dep
diff --git a/lib/libnvram/nvram.c b/lib/libnvram/nvram.c
index e9500ec..7ec12d2 100644
--- a/lib/libnvram/nvram.c
+++ b/lib/libnvram/nvram.c
@@ -30,22 +30,30 @@
void asm_cout(long Character,long UART,long NVRAM);
#if defined(DISABLE_NVRAM)
+
static volatile uint8_t nvram[NVRAM_LENGTH]; /* FAKE */
-#else
-static volatile uint8_t *nvram = (volatile uint8_t *)SB_NVRAM_adr;
-#endif
-/* This is extremely ugly, but still better than implementing
- * another sbrk() around it.
- */
-static char nvram_buffer[NVRAM_LENGTH];
-static uint8_t nvram_buffer_locked=0x00;
+#define nvram_access(type,size,name) \
+ type nvram_read_##name(unsigned int offset) \
+ { \
+ type *pos; \
+ if (offset > (NVRAM_LENGTH - sizeof(type))) \
+ return 0; \
+ pos = (type *)(nvram+offset); \
+ return *pos; \
+ } \
+ void nvram_write_##name(unsigned int offset, type data) \
+ { \
+ type *pos; \
+ if (offset > (NVRAM_LENGTH - sizeof(type))) \
+ return; \
+ pos = (type *)(nvram+offset); \
+ *pos = data; \
+ }
-/**
- * producer for nvram access functions. Since these functions are
- * basically all the same except for the used data types, produce
- * them via the following macro to keep the code from bloating.
- */
+#else /* DISABLE_NVRAM */
+
+static volatile uint8_t *nvram = (volatile uint8_t *)SB_NVRAM_adr;
#define nvram_access(type,size,name) \
type nvram_read_##name(unsigned int offset) \
@@ -65,11 +73,26 @@ static uint8_t nvram_buffer_locked=0x00;
ci_write_##size(pos, data); \
}
+#endif
+
+/*
+ * producer for nvram access functions. Since these functions are
+ * basically all the same except for the used data types, produce
+ * them via the nvram_access macro to keep the code from bloating.
+ */
+
nvram_access(uint8_t, 8, byte)
nvram_access(uint16_t, 16, word)
nvram_access(uint32_t, 32, dword)
nvram_access(uint64_t, 64, qword)
+/*
+ * This is extremely ugly, but still better than implementing
+ * another sbrk() around it.
+ */
+static char nvram_buffer[NVRAM_LENGTH];
+static uint8_t nvram_buffer_locked=0x00;
+
/**
* This function is a minimal abstraction for our temporary
* buffer. It should have been malloced, but since there is no
@@ -111,11 +134,11 @@ int nvramlog_printf(const char* fmt, ...)
char buff[256];
int count, i;
va_list ap;
-
+
va_start(ap, fmt);
count = vsprintf(buff, fmt, ap);
va_end(ap);
-
+
for (i=0; i<count; i++)
asm_cout(buff[i], 0, 1);
@@ -189,7 +212,8 @@ static int calc_used_nvram_space(void)
int walk, len;
for (walk=0; walk<NVRAM_LENGTH;) {
- if(get_partition_header_checksum(walk) !=
+ if(nvram_read_byte(walk) == 0
+ || get_partition_header_checksum(walk) !=
calc_partition_header_checksum(walk)) {
/* If there's no valid entry, bail out */
break;
@@ -234,7 +258,9 @@ partition_t get_partition(unsigned int type, char *name)
{
partition_t ret={0,-1};
int walk, len;
-
+
+ DEBUG("get_partition(%i, '%s')\n", type, name);
+
for (walk=0; walk<NVRAM_LENGTH;) {
// DEBUG("get_partition: walk=%x\n", walk);
if(get_partition_header_checksum(walk) !=
@@ -492,20 +518,23 @@ static void init_cpulog_partition(partition_t cpulog)
void reset_nvram(void)
{
partition_t cpulog0, cpulog1;
- char header[12];
+ struct {
+ uint32_t prefix;
+ uint64_t name;
+ } __attribute__((packed)) header;
DEBUG("Erasing NVRAM\n");
erase_nvram(0, NVRAM_LENGTH);
DEBUG("Creating CPU log partitions\n");
- *(uint32_t *)(char *)&(header[0]) = be32_to_cpu(LLFW_LOG_BE0_NAME_PREFIX);
- *(uint64_t *)(char *)&(header[4]) = be64_to_cpu(LLFW_LOG_BE0_NAME);
- cpulog0=create_nvram_partition(LLFW_LOG_BE0_SIGNATURE, header,
+ header.prefix = be32_to_cpu(LLFW_LOG_BE0_NAME_PREFIX);
+ header.name = be64_to_cpu(LLFW_LOG_BE0_NAME);
+ cpulog0=create_nvram_partition(LLFW_LOG_BE0_SIGNATURE, (char *)&header,
(LLFW_LOG_BE0_LENGTH*16)-PARTITION_HEADER_SIZE);
- *(uint32_t *)(char *)&(header[0]) = be32_to_cpu(LLFW_LOG_BE1_NAME_PREFIX);
- *(uint64_t *)(char *)&(header[4]) = be64_to_cpu(LLFW_LOG_BE1_NAME);
- cpulog1=create_nvram_partition(LLFW_LOG_BE1_SIGNATURE, header,
+ header.prefix = be32_to_cpu(LLFW_LOG_BE1_NAME_PREFIX);
+ header.name = be64_to_cpu(LLFW_LOG_BE1_NAME);
+ cpulog1=create_nvram_partition(LLFW_LOG_BE1_SIGNATURE, (char *)&header,
(LLFW_LOG_BE1_LENGTH*16)-PARTITION_HEADER_SIZE);
DEBUG("Initializing CPU log partitions\n");