Preserve Full USB packet logging and verify packaged firmware
This commit is contained in:
1 parent
d07537f6aa
commit
7c65314266
10 files changed
+508
-6
No files matched your search
@@ -67,6 +67,11 @@ def parse_args() -> argparse.Namespace:
|
||||
metavar="CAPABILITY=TEXT",
|
||||
help="Require TEXT to be present in the linked image.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--expect-application", action="append", default=[],
|
||||
metavar="CAPABILITY=TEXT",
|
||||
help="Require TEXT in the packaged firmware.bin or DFU application, not ELF metadata.",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -74,6 +79,16 @@ def stable_unique(values: list[str]) -> list[str]:
|
||||
return list(dict.fromkeys(value for value in values if value))
|
||||
|
||||
|
||||
def read_application(args):
|
||||
if args.firmware_bin is not None:
|
||||
return args.firmware_bin.read_bytes()
|
||||
if args.dfu_package is not None:
|
||||
with zipfile.ZipFile(args.dfu_package) as package:
|
||||
app = json.loads(package.read("manifest.json"))["manifest"]["application"]
|
||||
return package.read(app["bin_file"])
|
||||
raise ValueError("application checks require --firmware-bin or --dfu-package")
|
||||
|
||||
|
||||
def verify_ota_artifacts(args, methods):
|
||||
"""Check the actual update medium; source/seeder support cannot qualify."""
|
||||
if not methods:
|
||||
@@ -138,21 +153,31 @@ def main() -> int:
|
||||
|
||||
checks = []
|
||||
malformed = False
|
||||
for expectation in args.expect:
|
||||
application = b""
|
||||
if args.expect_application:
|
||||
try:
|
||||
application = read_application(args)
|
||||
except (OSError, ValueError, KeyError, zipfile.BadZipFile) as exc:
|
||||
print(f"capability check: cannot read packaged application: {exc}", file=sys.stderr)
|
||||
malformed = True
|
||||
expectations = [(value, image, "linked image") for value in args.expect]
|
||||
expectations += [(value, application, "packaged application") for value in args.expect_application]
|
||||
for expectation, content, source in expectations:
|
||||
if "=" not in expectation:
|
||||
print(
|
||||
f"capability check: malformed --expect {expectation!r}",
|
||||
f"capability check: malformed expectation {expectation!r}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
malformed = True
|
||||
continue
|
||||
capability, needle = expectation.split("=", 1)
|
||||
present = bool(needle) and needle.encode("utf-8") in image
|
||||
present = bool(needle) and needle.encode("utf-8") in content
|
||||
checks.append(
|
||||
{
|
||||
"capability": capability,
|
||||
"evidence": needle,
|
||||
"present": present,
|
||||
"source": source,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -203,7 +228,7 @@ def main() -> int:
|
||||
print(
|
||||
"capability check failed: "
|
||||
f"{check['capability']} promised but {check['evidence']!r} "
|
||||
f"is absent from {args.image}",
|
||||
f"is absent from the {check['source']}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 1
|
||||
|
||||
@@ -12,6 +12,10 @@ compiler/linker inputs remain untouched. On Windows, existing include
|
||||
directories are also rewritten to shorter 8.3 aliases without changing their
|
||||
order. This keeps GCC's expanded ``cc1plus`` command below the CreateProcess
|
||||
limit.
|
||||
|
||||
Full profiles that promise USB packet logging also remove inherited disables
|
||||
before PlatformIO parses the flags. PlatformIO emits all ``-U`` options after
|
||||
``-D`` options, so appending a define alone cannot enable an inherited disable.
|
||||
"""
|
||||
|
||||
Import("env") # noqa: F821
|
||||
@@ -125,6 +129,29 @@ def deduplicate_overlay(build_flags, overlay):
|
||||
return serialize_flags(unique), len(flags) - len(unique)
|
||||
|
||||
|
||||
def require_packet_logging(build_flags):
|
||||
"""Make the selected Full logging contract survive ParseFlags ordering.
|
||||
|
||||
Touch only this macro: other defines, undefines, quoted strings, and
|
||||
option/argument pairs retain their semantics. A later artifact check also
|
||||
proves that packet logging survived other scripts and link-time removal.
|
||||
"""
|
||||
retained = []
|
||||
for flag in logical_flags(build_flags):
|
||||
if flag[0] is not COMMAND_FLAG:
|
||||
if flag[0] in {"-D", "-U"} and len(flag) == 2:
|
||||
macro = flag[1]
|
||||
elif flag[0].startswith(("-D", "-U")):
|
||||
macro = flag[0][2:]
|
||||
else:
|
||||
macro = ""
|
||||
if macro.split("=", 1)[0] == "MESH_PACKET_LOGGING":
|
||||
continue
|
||||
retained.append(flag)
|
||||
retained.append(("-DMESH_PACKET_LOGGING=1",))
|
||||
return serialize_flags(retained)
|
||||
|
||||
|
||||
def resolved_path(value, project_dir, expander=None):
|
||||
"""Resolve a SCons path node/string without requiring SCons in tests."""
|
||||
if hasattr(value, "get_abspath"):
|
||||
@@ -217,12 +244,18 @@ if os.environ.get("MESHCORE_ESP32_FULL_BUILD") == "1":
|
||||
cleaned, removed = deduplicate_overlay(
|
||||
original, os.environ.get("PLATFORMIO_BUILD_FLAGS", "")
|
||||
)
|
||||
if removed:
|
||||
logging_required = os.environ.get("MESHCORE_REQUIRE_PACKET_LOGGING") == "1"
|
||||
if logging_required:
|
||||
cleaned = require_packet_logging(cleaned)
|
||||
if removed or logging_required:
|
||||
env.Replace(BUILD_FLAGS=cleaned) # noqa: F821
|
||||
if removed:
|
||||
print(
|
||||
"ESP32 FULL build: removed %d repeated external build flags"
|
||||
% removed
|
||||
)
|
||||
if logging_required:
|
||||
print("ESP32 FULL build: USB packet logging required; inherited disables removed")
|
||||
if (
|
||||
os.name == "nt"
|
||||
and os.environ.get("MESHCORE_COMPANION_RADIO_FULL") == "1"
|
||||
|
||||
Reference in new issue
Block a user