forked from Hyperion/HyperionOS
NC firmware update (thanks spsf). opencomputers now uses mutiple gpus to speed up rendering and now has net drivers. currently working on kernel memory protections to prevent malicious kernel drivers. spm does not work on opencomputers, this is a known issue i am working on fixing it :D sorry for the slow development.
This commit is contained in:
1 parent
fbaafc7cff
commit
ef4b856ee6
89 files changed
+3955
-563
No files matched your search
@@ -1,7 +1,8 @@
|
||||
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Usage:
|
||||
python build.py <target> [--arch cct|oc|ac] [--release|--dev]
|
||||
python build.py <target> [--arch cct|oc|ac|nc] [--release|--dev] [--ext PATH]
|
||||
|
||||
Targets:
|
||||
build
|
||||
@@ -18,6 +19,11 @@ Arch flags:
|
||||
--arch cct
|
||||
--arch oc
|
||||
--arch ac
|
||||
--arch nc
|
||||
|
||||
External build roots:
|
||||
--ext PATH
|
||||
--ext PATH --ext PATH
|
||||
|
||||
Release flags:
|
||||
--release
|
||||
@@ -28,7 +34,6 @@ import sys
|
||||
import shutil
|
||||
import argparse
|
||||
import subprocess
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
@@ -42,7 +47,8 @@ PROD_ROOT = PROJECT_ROOT / "prod"
|
||||
ARCH_BOOT_DIR = {
|
||||
"cct": Path("boot") / "cct",
|
||||
"oc": Path("boot") / "oc",
|
||||
"ac": Path("boot") / "ac"
|
||||
"ac": Path("boot") / "ac",
|
||||
"nc": Path("boot") / "nc"
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +59,7 @@ def clean():
|
||||
else:
|
||||
print("Nothing to clean.")
|
||||
|
||||
|
||||
def cleanprod():
|
||||
if PROD_ROOT.exists():
|
||||
print(f"Removing {PROD_ROOT} ...")
|
||||
@@ -69,6 +76,7 @@ def has_minify_header(path: Path) -> bool:
|
||||
return True
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@@ -78,17 +86,34 @@ def minify_file(src: Path) -> str:
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f" ! luamin failed: {result.stderr.strip()}", file=sys.stderr)
|
||||
print(
|
||||
f" ! luamin failed: {result.stderr.strip()}",
|
||||
file=sys.stderr
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
return result.stdout
|
||||
|
||||
|
||||
def compress_lz4(data: bytes) -> bytes:
|
||||
import lz4.frame
|
||||
return lz4.frame.compress(data)
|
||||
|
||||
|
||||
def process_root(src_root: Path, out_root: Path, minify: bool, micro: bool, arch:Union[str, None], prod:bool):
|
||||
def process_root(
|
||||
src_root: Path,
|
||||
out_root: Path,
|
||||
minify: bool,
|
||||
micro: bool,
|
||||
arch: Union[str, None],
|
||||
prod: bool
|
||||
):
|
||||
if not src_root.is_dir():
|
||||
print(f"Skipping missing build root: {src_root}")
|
||||
return
|
||||
|
||||
print(f"Building from {src_root}")
|
||||
print(f"Output to {out_root}")
|
||||
print()
|
||||
@@ -99,10 +124,10 @@ def process_root(src_root: Path, out_root: Path, minify: bool, micro: bool, arch
|
||||
|
||||
if pkg_dir.name[:18] == "Hyperion-firmware-":
|
||||
if pkg_dir.name != f"Hyperion-firmware-{arch}":
|
||||
if prod != True:
|
||||
if not prod:
|
||||
continue
|
||||
|
||||
data_dir=pkg_dir / "data"
|
||||
data_dir = pkg_dir / "data"
|
||||
|
||||
if not data_dir.is_dir():
|
||||
continue
|
||||
@@ -113,12 +138,13 @@ def process_root(src_root: Path, out_root: Path, minify: bool, micro: bool, arch
|
||||
if not src.is_file():
|
||||
continue
|
||||
|
||||
rel = src.relative_to(data_dir)
|
||||
|
||||
rel = src.relative_to(data_dir)
|
||||
|
||||
dst = out_root / rel
|
||||
|
||||
if prod:
|
||||
dst = out_root / pkg_dir.name / rel
|
||||
|
||||
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
print(f" Processing: {src.relative_to(src_root)}")
|
||||
@@ -126,13 +152,22 @@ def process_root(src_root: Path, out_root: Path, minify: bool, micro: bool, arch
|
||||
if has_minify_header(src):
|
||||
if minify:
|
||||
print(" > Minifying")
|
||||
|
||||
content = minify_file(src)
|
||||
|
||||
if micro:
|
||||
print(" > LZ4 compressing")
|
||||
compressed = compress_lz4(content.encode("utf-8"))
|
||||
|
||||
compressed = compress_lz4(
|
||||
content.encode("utf-8")
|
||||
)
|
||||
|
||||
dst.write_bytes(compressed)
|
||||
else:
|
||||
dst.write_text(content, encoding="utf-8")
|
||||
dst.write_text(
|
||||
content,
|
||||
encoding="utf-8"
|
||||
)
|
||||
else:
|
||||
print(" > Copying")
|
||||
shutil.copy2(src, dst)
|
||||
@@ -144,50 +179,138 @@ def process_root(src_root: Path, out_root: Path, minify: bool, micro: bool, arch
|
||||
|
||||
|
||||
def install_bootloader(arch: str, release: bool):
|
||||
boot_dir = BUILD_ROOT / "root" / ARCH_BOOT_DIR[arch]
|
||||
eeprom = boot_dir / "eeprom"
|
||||
boot_dir = BUILD_ROOT / "root" / ARCH_BOOT_DIR[arch]
|
||||
eeprom = boot_dir / "eeprom"
|
||||
|
||||
eeprom_dst_name = "startup.lua" if release else "eeprom"
|
||||
eeprom_dst_name = "uefi.lua" if arch=="ac" else eeprom_dst_name
|
||||
print(f" Installing: eeprom -> Build/{eeprom_dst_name}")
|
||||
shutil.copy2(eeprom, BUILD_ROOT / eeprom_dst_name)
|
||||
|
||||
if arch=="cct":
|
||||
with open(BUILD_ROOT / "root/boot/fstab", "r") as file:
|
||||
content=file.read()
|
||||
with open(BUILD_ROOT / "root/boot/fstab", "w") as file:
|
||||
file.write("U root;/\n"+content)
|
||||
if arch == "ac":
|
||||
eeprom_dst_name = "uefi.lua"
|
||||
|
||||
if arch != "nc":
|
||||
print(
|
||||
f" Installing: eeprom -> Build/{eeprom_dst_name}"
|
||||
)
|
||||
|
||||
shutil.copy2(
|
||||
eeprom,
|
||||
BUILD_ROOT / eeprom_dst_name
|
||||
)
|
||||
else:
|
||||
print(
|
||||
" Installing: eeprom -> Build/eeprom (reference only)"
|
||||
)
|
||||
|
||||
shutil.copy2(
|
||||
eeprom,
|
||||
BUILD_ROOT / "eeprom"
|
||||
)
|
||||
|
||||
if arch == "cct":
|
||||
fstab = BUILD_ROOT / "root" / "boot" / "fstab"
|
||||
|
||||
with open(fstab, "r") as file:
|
||||
content = file.read()
|
||||
|
||||
with open(fstab, "w") as file:
|
||||
file.write("U root;/\n" + content)
|
||||
|
||||
if arch == "nc":
|
||||
fstab = BUILD_ROOT / "root" / "boot" / "fstab"
|
||||
|
||||
with open(fstab, "r") as file:
|
||||
content = file.read()
|
||||
|
||||
with open(fstab, "w") as file:
|
||||
file.write("U 0:root;/\n" + content)
|
||||
|
||||
|
||||
def run_build(minify: bool, micro: bool, include_test: bool, arch: Union[str, None], release: bool, prod: bool):
|
||||
def run_build(
|
||||
minify: bool,
|
||||
micro: bool,
|
||||
include_test: bool,
|
||||
arch: Union[str, None],
|
||||
release: bool,
|
||||
prod: bool,
|
||||
ext_roots: list[Path]
|
||||
):
|
||||
clean()
|
||||
BUILD_ROOT.mkdir()
|
||||
|
||||
if prod:
|
||||
cleanprod()
|
||||
PROD_ROOT.mkdir()
|
||||
|
||||
|
||||
out_root = BUILD_ROOT / "root" if arch else BUILD_ROOT
|
||||
|
||||
process_root(SRC_ROOT, out_root, minify, micro, arch, False)
|
||||
# Main source root.
|
||||
process_root(
|
||||
SRC_ROOT,
|
||||
out_root,
|
||||
minify,
|
||||
micro,
|
||||
arch,
|
||||
False
|
||||
)
|
||||
|
||||
if prod:
|
||||
process_root(SRC_ROOT, PROD_ROOT, minify, micro, arch, True)
|
||||
|
||||
process_root(
|
||||
SRC_ROOT,
|
||||
PROD_ROOT,
|
||||
minify,
|
||||
micro,
|
||||
arch,
|
||||
True
|
||||
)
|
||||
|
||||
# Additional external build roots.
|
||||
for ext_root in ext_roots:
|
||||
process_root(
|
||||
ext_root,
|
||||
out_root,
|
||||
minify,
|
||||
micro,
|
||||
arch,
|
||||
False
|
||||
)
|
||||
|
||||
if prod:
|
||||
process_root(
|
||||
ext_root,
|
||||
PROD_ROOT,
|
||||
minify,
|
||||
micro,
|
||||
arch,
|
||||
True
|
||||
)
|
||||
|
||||
# Test source root.
|
||||
if include_test:
|
||||
process_root(TEST_ROOT, out_root, minify, micro)
|
||||
process_root(
|
||||
TEST_ROOT,
|
||||
out_root,
|
||||
minify,
|
||||
micro,
|
||||
arch,
|
||||
False
|
||||
)
|
||||
|
||||
if arch:
|
||||
print("Installing bootloader files ...")
|
||||
|
||||
install_bootloader(arch, release)
|
||||
|
||||
print()
|
||||
|
||||
boot_root = out_root / "boot"
|
||||
disk_root = BUILD_ROOT / "$"
|
||||
boot_root.rename(disk_root)
|
||||
|
||||
|
||||
boot_root.rename(disk_root)
|
||||
|
||||
|
||||
def _make_firstboot_kmod(users):
|
||||
lines = []
|
||||
|
||||
lines.append("local kernel = ...")
|
||||
lines.append("local auth = kernel.auth")
|
||||
lines.append("")
|
||||
@@ -198,30 +321,47 @@ def _make_firstboot_kmod(users):
|
||||
|
||||
if username == "root":
|
||||
lines.append("do")
|
||||
lines.append(" local ok, err = auth.setPassword(0, '" + p + "')")
|
||||
lines.append(
|
||||
" local ok, err = auth.setPassword(0, '" + p + "')"
|
||||
)
|
||||
lines.append(" if ok then")
|
||||
lines.append(" kernel.log('FIRSTBOOT: root password set')")
|
||||
lines.append(
|
||||
" kernel.log('FIRSTBOOT: root password set')"
|
||||
)
|
||||
lines.append(" else")
|
||||
lines.append(" kernel.log('FIRSTBOOT: root password error: ' .. tostring(err), 'ERROR')")
|
||||
lines.append(
|
||||
" kernel.log('FIRSTBOOT: root password error: ' .. tostring(err), 'ERROR')"
|
||||
)
|
||||
lines.append(" end")
|
||||
lines.append("end")
|
||||
else:
|
||||
lines.append("do")
|
||||
lines.append(" local uid, err = auth.newUser('" + u + "', '" + p + "')")
|
||||
lines.append(
|
||||
" local uid, err = auth.newUser('" + u + "', '" + p + "')"
|
||||
)
|
||||
lines.append(" if uid then")
|
||||
lines.append(" kernel.log('FIRSTBOOT: created user " + u + " uid=' .. tostring(uid))")
|
||||
lines.append(
|
||||
" kernel.log('FIRSTBOOT: created user " + u + " uid=' .. tostring(uid))"
|
||||
)
|
||||
lines.append(" else")
|
||||
lines.append(" kernel.log('FIRSTBOOT: failed to create user " + u + ": ' .. tostring(err), 'ERROR')")
|
||||
lines.append(
|
||||
" kernel.log('FIRSTBOOT: failed to create user " + u + ": ' .. tostring(err), 'ERROR')"
|
||||
)
|
||||
lines.append(" end")
|
||||
lines.append("end")
|
||||
|
||||
lines.append("")
|
||||
|
||||
lines.append("do")
|
||||
lines.append(" local ok, err = pcall(function()")
|
||||
lines.append(" kernel.vfs.remove('/lib/modules/Hyperion/50_firstboot_users.kmod')")
|
||||
lines.append(
|
||||
" kernel.vfs.remove('/lib/modules/Hyperion/50_firstboot_users.kmod')"
|
||||
)
|
||||
lines.append(" end)")
|
||||
lines.append(" if not ok then")
|
||||
lines.append(" kernel.log('FIRSTBOOT: could not self-delete: ' .. tostring(err), 'WARN')")
|
||||
lines.append(
|
||||
" kernel.log('FIRSTBOOT: could not self-delete: ' .. tostring(err), 'WARN')"
|
||||
)
|
||||
lines.append(" end")
|
||||
lines.append("end")
|
||||
|
||||
@@ -230,29 +370,94 @@ def _make_firstboot_kmod(users):
|
||||
|
||||
def inject_makeusers(users, arch):
|
||||
base = BUILD_ROOT / "$" if arch else BUILD_ROOT
|
||||
kmod_path = base / "lib" / "modules" / "Hyperion" / "50_firstboot_users.kmod"
|
||||
|
||||
kmod_path = (
|
||||
base
|
||||
/ "lib"
|
||||
/ "modules"
|
||||
/ "Hyperion"
|
||||
/ "50_firstboot_users.kmod"
|
||||
)
|
||||
|
||||
kmod_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
kmod_path.write_text(_make_firstboot_kmod(users), encoding="utf-8")
|
||||
print(" Wrote first-boot user setup -> " + str(kmod_path.relative_to(BUILD_ROOT)))
|
||||
|
||||
kmod_path.write_text(
|
||||
_make_firstboot_kmod(users),
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
print(
|
||||
" Wrote first-boot user setup -> "
|
||||
+ str(kmod_path.relative_to(BUILD_ROOT))
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="HyperionOS build script")
|
||||
parser.add_argument("target", choices=["build", "build-mini", "build-micro", "build-test", "build-mini-test", "build-micro-test", "clean", "prod", "prod-mini"])
|
||||
parser.add_argument("--arch", choices=["cct", "oc", "ac"], default=None,
|
||||
help="Target architecture")
|
||||
parser.add_argument("--release", dest="release", action="store_true", default=True,
|
||||
help="Release build: eeprom placed as startup.lua (default)")
|
||||
parser.add_argument("--dev", dest="release", action="store_false",
|
||||
help="Dev build: boot.lua and eeprom copied unchanged")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="HyperionOS build script"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--makeuser", metavar=("USERNAME", "PASSWORD"), nargs=2, action="append",
|
||||
"target",
|
||||
choices=[
|
||||
"build",
|
||||
"build-mini",
|
||||
"build-micro",
|
||||
"build-test",
|
||||
"build-mini-test",
|
||||
"build-micro-test",
|
||||
"clean",
|
||||
"prod",
|
||||
"prod-mini"
|
||||
]
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--arch",
|
||||
choices=["cct", "oc", "ac", "nc"],
|
||||
default=None,
|
||||
help="Target architecture"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--release",
|
||||
dest="release",
|
||||
action="store_true",
|
||||
default=True,
|
||||
help="Release build: eeprom placed as startup.lua (default)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--dev",
|
||||
dest="release",
|
||||
action="store_false",
|
||||
help="Dev build: boot.lua and eeprom copied unchanged"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--ext",
|
||||
metavar="PATH",
|
||||
type=Path,
|
||||
action="append",
|
||||
default=[],
|
||||
help=(
|
||||
"Additional external build root. "
|
||||
"Can be specified multiple times."
|
||||
)
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--makeuser",
|
||||
metavar=("USERNAME", "PASSWORD"),
|
||||
nargs=2,
|
||||
action="append",
|
||||
default=[],
|
||||
help=(
|
||||
"Pre-create a user on first boot (dev builds only). "
|
||||
"May be specified multiple times. "
|
||||
"Example: --makeuser root secretpass --makeuser alice alicepass"
|
||||
),
|
||||
"Example: --makeuser root secretpass "
|
||||
"--makeuser alice alicepass"
|
||||
)
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
@@ -264,23 +469,44 @@ def main():
|
||||
clean()
|
||||
return
|
||||
|
||||
prod = "prod" in args.target
|
||||
minify = "mini" in args.target or "micro" in args.target
|
||||
micro = "micro" in args.target
|
||||
# Resolve external roots relative to the current working directory.
|
||||
ext_roots = []
|
||||
|
||||
for path in args.ext:
|
||||
path = path.expanduser().resolve()
|
||||
|
||||
if not path.is_dir():
|
||||
parser.error(f"External build root does not exist: {path}")
|
||||
|
||||
ext_roots.append(path)
|
||||
|
||||
prod = "prod" in args.target
|
||||
minify = "mini" in args.target or "micro" in args.target
|
||||
micro = "micro" in args.target
|
||||
include_test = "test" in args.target
|
||||
|
||||
if micro:
|
||||
import lz4.block
|
||||
|
||||
run_build(minify=minify, micro=micro, include_test=include_test, arch=args.arch, release=args.release, prod=prod)
|
||||
run_build(
|
||||
minify=minify,
|
||||
micro=micro,
|
||||
include_test=include_test,
|
||||
arch=args.arch,
|
||||
release=args.release,
|
||||
prod=prod,
|
||||
ext_roots=ext_roots
|
||||
)
|
||||
|
||||
if args.makeuser:
|
||||
print("Injecting first-boot user setup ...")
|
||||
inject_makeusers(args.makeuser, args.arch)
|
||||
|
||||
inject_makeusers(
|
||||
args.makeuser,
|
||||
args.arch
|
||||
)
|
||||
|
||||
print()
|
||||
|
||||
print("Build complete.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
Reference in new issue
Block a user