From 2b591388ff9e2bfebe7898c894b6fcafb353acb4 Mon Sep 17 00:00:00 2001
From: victor <taehoon@falinux.com>
Date: Thu, 14 Mar 2019 10:51:42 +0900
Subject: [PATCH] =?UTF-8?q?=EB=9D=BC=EC=A6=88=EB=B2=A0=EB=A6=AC=20?=
 =?UTF-8?q?=ED=8C=8C=EC=9D=B4=203=20=EB=B6=80=ED=8A=B8=EB=A1=9C=EB=8D=94?=
 =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 go/src/fullcycle/analog-kernel/parser/parse.go | 113 +++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/go/src/fullcycle/analog-kernel/parser/parse.go b/go/src/fullcycle/analog-kernel/parser/parse.go
index 5edb704..2117a35 100644
--- a/go/src/fullcycle/analog-kernel/parser/parse.go
+++ b/go/src/fullcycle/analog-kernel/parser/parse.go
@@ -30,6 +30,10 @@ var parseFuncList = []func(chan string, chan jsonObject){
 	parseBootloaderBoard,
 	parseBootloaderRstStat,
 	parseBootloaderNet,
+	parseBootloaderBootcode,
+	parseBootloaderRead,
+	parseBootloaderCommandLine,
+	parseBootloaderLoad,
 }
 
 var reTimestamp = regexp.MustCompile(`^\[[[:blank:]]*[[:digit:]]+\.[[:digit:]]+[[:blank:]]*\]`)
@@ -731,6 +735,115 @@ func parseBootloaderNet(lines chan string, chanOutput chan jsonObject) {
 	chanOutput <- m
 }
 
+func parseBootloaderBootcode(lines chan string, chanOutput chan jsonObject) {
+	m := make(jsonObject)
+	m["type"] = "bootloader_bootcode"
+	m["value"] = ""
+
+	rLine := regexp.MustCompile(`^Raspberry Pi Bootcode`)
+	for line := range lines {
+		if rLine.MatchString(line) {
+			m["value"] = line
+			break
+		}
+	}
+
+	chanOutput <- m
+}
+
+func parseBootloaderRead(lines chan string, chanOutput chan jsonObject) {
+	const (
+		FIND_NAME = iota
+		FIND_SIZE
+	)
+
+	state := FIND_NAME
+	elements := make(map[string]string)
+	name := ""
+
+	rLine := regexp.MustCompile(`brfs: File read: ([[:print:]]+)`)
+	for line := range lines {
+		if rLine.MatchString(line) {
+			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
+				switch state {
+				case FIND_NAME:
+					name = sub[1]
+					state = FIND_SIZE
+				case FIND_SIZE:
+					elements[name] = sub[1]
+					state = FIND_NAME
+				}
+			}
+		}
+	}
+
+	list := make([]jsonObject, 0)
+	for name, size := range elements {
+		list = append(list, jsonObject{"name": name, "size": size})
+	}
+
+	m := make(jsonObject)
+	m["type"] = "bootloader_read"
+	m["list"] = list
+
+	chanOutput <- m
+}
+
+func parseBootloaderCommandLine(lines chan string, chanOutput chan jsonObject) {
+	m := make(jsonObject)
+	m["type"] = "bootloader_command_line"
+	m["value"] = ""
+
+	const (
+		FIND_HEADER = iota
+		FIND_LINE
+		DONE
+	)
+
+	state := FIND_HEADER
+
+	rLine := regexp.MustCompile(`Read command line from file`)
+	rValue := regexp.MustCompile(`[[:graph:]]+ ([[:print:]]+)`)
+	for line := range lines {
+		switch state {
+		case FIND_HEADER:
+			if rLine.MatchString(line) {
+				state = FIND_LINE
+			}
+		case FIND_LINE:
+			if sub := rValue.FindStringSubmatch(line); len(sub) > 1 {
+				m["value"] = sub[1]
+				state = DONE
+			}
+		}
+
+		if state == DONE {
+			break
+		}
+	}
+
+	chanOutput <- m
+}
+
+func parseBootloaderLoad(lines chan string, chanOutput chan jsonObject) {
+	list := make([]jsonObject, 0)
+
+	rLine := regexp.MustCompile(`Loading '([[:print:]]+)' to (0x[[:xdigit:]]+) size (0x[[:xdigit:]]+)`)
+	for line := range lines {
+		if rLine.MatchString(line) {
+			if sub := rLine.FindStringSubmatch(line); len(sub) > 3 {
+				list = append(list, jsonObject{"name": sub[1], "address": sub[2], "size": sub[3]})
+			}
+		}
+	}
+
+	m := make(jsonObject)
+	m["type"] = "bootloader_load"
+	m["list"] = list
+
+	chanOutput <- m
+}
+
 func removeBrackets(s string) string {
 	for strings.HasPrefix(s, "(") && strings.HasSuffix(s, ")") {
 		openCount := strings.Count(s, "(")
-- 
2.1.4