61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package uboot
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func (c BootEnvConfig) Validate() error {
|
|
switch c.BootSource {
|
|
case "usb", "emmc":
|
|
default:
|
|
return fmt.Errorf("invalid boot source %q", c.BootSource)
|
|
}
|
|
|
|
switch c.BootPart {
|
|
case "A", "B":
|
|
default:
|
|
return fmt.Errorf("invalid boot part %q", c.BootPart)
|
|
}
|
|
|
|
if c.BootDisk < 0 {
|
|
return fmt.Errorf("invalid boot disk %d", c.BootDisk)
|
|
}
|
|
if c.RootfsAPartNum <= 0 {
|
|
return fmt.Errorf("invalid rootfs A part %d", c.RootfsAPartNum)
|
|
}
|
|
if c.RootfsBPartNum <= 0 {
|
|
return fmt.Errorf("invalid rootfs B part %d", c.RootfsBPartNum)
|
|
}
|
|
if c.DataPartNum <= 0 {
|
|
return fmt.Errorf("invalid data part %d", c.DataPartNum)
|
|
}
|
|
if strings.TrimSpace(c.LinuxRootPrefix) == "" {
|
|
return fmt.Errorf("linux root prefix is required")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c BootEnvConfig) bootCmdOrDefault() string {
|
|
if s := strings.TrimSpace(c.BootCmd); s != "" {
|
|
return s
|
|
}
|
|
return compactUBootScript(defaultBootCmdTemplate)
|
|
}
|
|
|
|
func compactUBootScript(s string) string {
|
|
lines := strings.Split(s, "\n")
|
|
out := make([]string, 0, len(lines))
|
|
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" || strings.HasPrefix(line, "#") {
|
|
continue
|
|
}
|
|
out = append(out, line)
|
|
}
|
|
|
|
return strings.Join(out, " ")
|
|
}
|