log-handler: Add a config option for log size.

Allow a configuration option to specify a log size. The parameter takes and
interprets common size suffixes k/M/G. 1kB = 1024B, 1MB=1024kB, 1GB=1024MB.
Default unit is byte. If "B" is specified at the end it will be ignored.

Tested:
Tested that "logsize = 567kB" correctly sets up a 567KB log buffer.
Tested that invalid/overflow values will be ignored and 16KB will be used.
Tested that if log size smaller than pagesize is rounded up.

Change-Id: I2fb50462c6ff7873130be80f7d57ef8065acc5da
Signed-off-by: Kun Yi <kunyi731@gmail.com>
diff --git a/log-handler.c b/log-handler.c
index 149806c..88ea27b 100644
--- a/log-handler.c
+++ b/log-handler.c
@@ -41,8 +41,7 @@
 
 
 static const char *default_filename = LOCALSTATEDIR "/log/obmc-console.log";
-
-static const size_t logsize = 16 * 1024;
+static const size_t default_logsize = 16 * 1024;
 
 static struct log_handler *to_log_handler(struct handler *handler)
 {
@@ -129,17 +128,26 @@
 }
 
 static int log_init(struct handler *handler, struct console *console,
-		struct config *config __attribute__((unused)))
+		struct config *config)
 {
 	struct log_handler *lh = to_log_handler(handler);
-	const char *filename;
+	const char *filename, *logsize_str;
+	size_t logsize;
 	int rc;
 
 	lh->console = console;
-	lh->maxsize = logsize;
 	lh->pagesize = 4096;
 	lh->size = 0;
 
+	logsize_str = config_get_value(config, "logsize");
+	rc = config_parse_logsize(logsize_str, &logsize);
+	if (logsize_str != NULL && rc) {
+		logsize = default_logsize;
+		warn("Invalid logsize. Default to %ukB",
+                     (unsigned int)(logsize >> 10));
+	}
+	lh->maxsize = logsize <= lh->pagesize ? lh->pagesize + 1 : logsize;
+
 	filename = config_get_value(config, "logfile");
 	if (!filename)
 		filename = default_filename;