Skip to content

Commit 992dfef

Browse files
blueos_startup_update: add support for platform-specific patches
1 parent 041a82e commit 992dfef

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

core/tools/blueos_startup_update/blueos_startup_update.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import re
7+
from enum import Enum
78
import time
89
from typing import List, Optional, Tuple
910

@@ -43,6 +44,37 @@
4344
cmdline_file = None
4445

4546

47+
class CpuType(str, Enum):
48+
PI4 = "Raspberry Pi 4 (BCM2711)"
49+
PI5 = "Raspberry Pi 5 (BCM2712)"
50+
Other = "Other"
51+
52+
53+
class HostOs(str, Enum):
54+
Bookworm = "Debian(Raspberry Pi OS?) 12 (Bookworm)"
55+
Bullseye = "Debian(Raspberry Pi OS?) 11 (Bullseye)"
56+
Other = "Other"
57+
58+
59+
def get_cpu_type() -> CpuType:
60+
with open("/proc/cpuinfo", "r", encoding="utf-8") as f:
61+
for line in f:
62+
if "Raspberry Pi 4" in line:
63+
return CpuType.PI4
64+
if "Raspberry Pi 5" in line:
65+
return CpuType.PI5
66+
return CpuType.Other
67+
68+
69+
def get_host_os() -> HostOs:
70+
os_release = load_file("/etc/os-release")
71+
if "bookworm" in os_release:
72+
return HostOs.Bookworm
73+
if "bullseye" in os_release:
74+
return HostOs.Bullseye
75+
return HostOs.Other
76+
77+
4678
# Copyright 2016-2022 Paul Durivage
4779
# Licensed under the Apache License, Version 2.0 (the "License");
4880
# Based on: https://gist.github.com/angstwad/bf22d1822c38a92ec0a9
@@ -433,21 +465,34 @@ def main() -> int:
433465
logger.error("Ignoring host computer configuration for now.")
434466
return 0
435467

468+
host_os = get_host_os()
469+
logger.info(f"Host OS: {host_os}")
470+
host_cpu = get_cpu_type()
471+
logger.info(f"Host CPU: {host_cpu}")
472+
436473
# TODO: parse tag as semver and check before applying patches
437474
patches_to_apply = [
438475
update_startup,
439-
update_cgroups,
440-
update_dwc2,
441-
update_navigator_overlays,
442476
ensure_user_data_structure_is_in_place,
443477
ensure_nginx_permissions,
444478
create_dns_conf_host_link,
445479
]
446480

447-
logger.info(
448-
"The following patches will be applied if needed:",
449-
[patch_to_apply.__name__ for patch_to_apply in patches_to_apply],
450-
)
481+
# this will always be pi4 as pi5 is not supported
482+
if host_os == HostOs.Bullseye:
483+
patches_to_apply.extend([update_navigator_overlays])
484+
485+
if host_cpu == CpuType.PI4 or CpuType.PI5:
486+
patches_to_apply.extend(
487+
[
488+
update_cgroups,
489+
update_dwc2,
490+
]
491+
)
492+
493+
logger.info("The following patches will be applied if needed:")
494+
for patch in patches_to_apply:
495+
logger.info(patch.__name__)
451496

452497
patches_requiring_restart = [patch.__name__ for patch in patches_to_apply if patch()]
453498
if patches_requiring_restart:

0 commit comments

Comments
 (0)