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, "(")