jade_ota.py: move firmware fetching code into its own function
What changed, and why it matters
This commit simply rearranges existing code in a Python helper script used for firmware updates. It moves the logic that decides where to fetch firmware from into a new function, without changing what the code actually does. There is no security issue visible in this change.
No security action required. Treat as routine code cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors jade_ota.py by extracting the firmware-selection/fetching block from the __main__ section into a new get_firmware(args) function. The original code is copied verbatim into the new function and the call site is replaced with fwlen, patchlen, fwhash, fwcmp = get_firmware(args). No logic, control flow, validation, or cryptographic handling was altered.
Changed components
jade_ota.pyInspect captured patch +31 / −25
diff --git a/jade_ota.py b/jade_ota.py
index a7588dd..ac1e06d 100755
--- a/jade_ota.py
+++ b/jade_ota.py
@@ -244,6 +244,36 @@ def get_bleid(jade):
return has_radio, id
+# Get the firmware file to OTA
+def get_firmware(args):
+ if args.downloadfw:
+ fwlen, patchlen, fwhash, fwcmp = download_file(args.hwtarget, args.writecompressed,
+ args.release)
+ elif args.downloadgdk:
+ fwlen, patchlen, fwhash, fwcmp = download_file_gdk(args.hwtarget, args.writecompressed,
+ args.release)
+ elif args.fwfile:
+ assert not args.writecompressed
+ fwlen, patchlen, fwhash, fwcmp = get_local_compressed_fwfile(args.fwfile)
+ else:
+ # Default case, as 'uncompressed fw file' has a default value if not passed explicitly
+ fwlen, patchlen, fwhash, fwcmp = get_local_uncompressed_fwfile(args.fwfile_uncompressed,
+ args.writecompressed)
+
+ if fwcmp is None:
+ logger.error('No firmware available')
+ sys.exit(2)
+
+ logger.info(f'Got fw {"patch" if patchlen else "file"} of length {len(fwcmp)} '
+ f'with expected uncompressed final fw length {fwlen}')
+
+ if fwhash is not None:
+ logger.info(f'Final fw hash: {fwhash}')
+ fwhash = bytes.fromhex(fwhash)
+
+ return fwlen, patchlen, fwhash, fwcmp
+
+
# Takes the compressed firmware data to upload, the expected length of the
# final (uncompressed) firmware, the length of the uncompressed diff/patch
# (if this is a patch to apply to the current running firmware), and whether
@@ -454,31 +484,7 @@ if __name__ == '__main__':
if args.writecompressed and not os.path.isdir(COMP_FW_DIR):
os.mkdir(COMP_FW_DIR)
- # Get the file to OTA
- if args.downloadfw:
- fwlen, patchlen, fwhash, fwcmp = download_file(args.hwtarget, args.writecompressed,
- args.release)
- elif args.downloadgdk:
- fwlen, patchlen, fwhash, fwcmp = download_file_gdk(args.hwtarget, args.writecompressed,
- args.release)
- elif args.fwfile:
- assert not args.writecompressed
- fwlen, patchlen, fwhash, fwcmp = get_local_compressed_fwfile(args.fwfile)
- else:
- # Default case, as 'uncompressed fw file' has a default value if not passed explicitly
- fwlen, patchlen, fwhash, fwcmp = get_local_uncompressed_fwfile(args.fwfile_uncompressed,
- args.writecompressed)
-
- if fwcmp is None:
- logger.error('No firmware available')
- sys.exit(2)
-
- logger.info(f'Got fw {"patch" if patchlen else "file"} of length {len(fwcmp)} '
- f'with expected uncompressed final fw length {fwlen}')
-
- if fwhash is not None:
- logger.info(f'Final fw hash: {fwhash}')
- fwhash = bytes.fromhex(fwhash)
+ fwlen, patchlen, fwhash, fwcmp = get_firmware(args)
# If ble, start the agent to supply the required passkey for authentication
# and encryption - don't bother if not.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.