mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
Tools: Scripts: firmware_version_decoder: add --expected-hash for running in CI
This commit is contained in:
parent
0cd5bdebfb
commit
55d8ba647c
@ -204,7 +204,7 @@ class Decoder:
|
|||||||
self.fwversion.os_name = self.unpack_string_from_pointer()
|
self.fwversion.os_name = self.unpack_string_from_pointer()
|
||||||
self.fwversion.os_hash_string = self.unpack_string_from_pointer()
|
self.fwversion.os_hash_string = self.unpack_string_from_pointer()
|
||||||
|
|
||||||
def process(self, filename) -> None:
|
def process(self, filename) -> FWVersion:
|
||||||
# We need the file open for ELFFile
|
# We need the file open for ELFFile
|
||||||
file = open(filename, "rb")
|
file = open(filename, "rb")
|
||||||
data = file.read()
|
data = file.read()
|
||||||
@ -226,7 +226,7 @@ class Decoder:
|
|||||||
|
|
||||||
# Unpack struct and print it
|
# Unpack struct and print it
|
||||||
self.unpack_fwversion()
|
self.unpack_fwversion()
|
||||||
print(self.fwversion)
|
return self.fwversion
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -242,7 +242,21 @@ if __name__ == "__main__":
|
|||||||
required=True,
|
required=True,
|
||||||
help="File that contains a valid ardupilot firmware in ELF format.",
|
help="File that contains a valid ardupilot firmware in ELF format.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--expected-hash",
|
||||||
|
dest="expected_hash",
|
||||||
|
help="Expected git hash. The script fails if this doesn't match the git hash in the binary file. Used in CI",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
decoder = Decoder()
|
decoder = Decoder()
|
||||||
decoder.process(args.file)
|
try:
|
||||||
|
firmware_data = decoder.process(args.file)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error decoding FWVersion: {type(e)}")
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
print(firmware_data)
|
||||||
|
if args.expected_hash and args.expected_hash != firmware_data.firmware_hash_string:
|
||||||
|
print(f"Git hashes don't match! expected: {args.expected_hash}, got {firmware_data.firmware_hash_string}")
|
||||||
|
exit(-1)
|
||||||
|
Loading…
Reference in New Issue
Block a user