Add checksum calc for bin file
This commit is contained in:
25
post_build.py
Normal file
25
post_build.py
Normal file
@@ -0,0 +1,25 @@
|
||||
Import("env")
|
||||
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
|
||||
|
||||
print("Current CLI targets", COMMAND_LINE_TARGETS)
|
||||
print("Current Build targets", BUILD_TARGETS)
|
||||
|
||||
def sha256sum(filename):
|
||||
with open(filename, 'rb', buffering=0) as f:
|
||||
return hashlib.file_digest(f, 'sha256').hexdigest()
|
||||
|
||||
def post_buildprog_action(source, target, env):
|
||||
source_path = Path(source[0].get_abspath())
|
||||
sha256 = sha256sum(source_path)
|
||||
print(f"Calculated SHA256: {sha256}")
|
||||
|
||||
build_dir = source_path.parent
|
||||
sha_txt_file = build_dir / "firmware.bin.sha256"
|
||||
|
||||
with Path.open(sha_txt_file, "w") as f:
|
||||
f.write(sha256)
|
||||
|
||||
env.AddPostAction("buildprog", post_buildprog_action)
|
||||
Reference in New Issue
Block a user