From 6d7fa8a083bb162aeb3fa82a8ddd1145351f2935 Mon Sep 17 00:00:00 2001 From: PT_Dreamer Date: Fri, 14 Sep 2012 23:31:13 +0100 Subject: [PATCH] Flight-Added sha1 uavo directory calculation to fw_version_info struct. --- make/firmware-defs.mk | 3 ++- make/scripts/version-info.py | 38 ++++++++++++++++++++++++++- make/templates/firmwareinfotemplate.c | 4 ++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/make/firmware-defs.mk b/make/firmware-defs.mk index 522d2e320..e77e71d2a 100644 --- a/make/firmware-defs.mk +++ b/make/firmware-defs.mk @@ -131,7 +131,8 @@ $(1).firmwareinfo.c: $(1) $(TOP)/make/templates/firmwareinfotemplate.c FORCE --outfile=$$@ \ --image=$(1) \ --type=$(2) \ - --revision=$(3) + --revision=$(3) \ + --uavodir=$(TOP)/shared/uavobjectdefinition $(eval $(call COMPILE_C_TEMPLATE, $(1).firmwareinfo.c)) diff --git a/make/scripts/version-info.py b/make/scripts/version-info.py index 8c4fe901e..12ab9895b 100644 --- a/make/scripts/version-info.py +++ b/make/scripts/version-info.py @@ -250,6 +250,40 @@ def xtrim(string, suffix, length): assert n > 0, "length of truncated string+suffix exceeds maximum length" return ''.join([string[:n], '+', suffix]) +def GetHashofDirs(directory, verbose=0): + import hashlib, os + SHAhash = hashlib.sha1() + if not os.path.exists (directory): + return -1 + + try: + for root, dirs, files in os.walk(directory): + for names in files: + if verbose == 1: + print 'Hashing', names + filepath = os.path.join(root,names) + try: + f1 = open(filepath, 'rb') + except: + # You can't open the file for some reason + f1.close() + continue + + while 1: + # Read file in as little chunks + buf = f1.read(4096) + if not buf : break + SHAhash.update(hashlib.sha1(buf).hexdigest()) + f1.close() + + except: + import traceback + # Print the stack traceback + traceback.print_exc() + return -2 + hex_stream = lambda s:",".join(['0x'+hex(ord(c))[2:].zfill(2) for c in s]) + return hex_stream(SHAhash.digest()) + def main(): """This utility uses git repository in the current working directory or from the given path to extract some info about it and HEAD commit. @@ -302,7 +336,8 @@ dependent targets. help='board type, for example, 0x04 for CopterControl'); parser.add_option('--revision', default = "", help='board revision, for example, 0x01'); - + parser.add_option('--uavodir', default = "", + help='uav object definition directory'); (args, positional_args) = parser.parse_args() if len(positional_args) != 0: parser.error("incorrect number of arguments, try --help for help") @@ -328,6 +363,7 @@ dependent targets. BOARD_TYPE = args.type, BOARD_REVISION = args.revision, SHA1 = sha1(args.image), + UAVOSHA1= GetHashofDirs(args.uavodir,0), ) if args.info: diff --git a/make/templates/firmwareinfotemplate.c b/make/templates/firmwareinfotemplate.c index b9297273e..b876b64dd 100644 --- a/make/templates/firmwareinfotemplate.c +++ b/make/templates/firmwareinfotemplate.c @@ -53,7 +53,8 @@ struct __attribute__((packed)) fw_version_info { uint8_t board_revision; uint8_t commit_tag_name[26]; uint8_t sha1sum[20]; - uint8_t pad[40]; + uint8_t uavosha1[20]; + uint8_t pad[20]; }; const struct fw_version_info fw_version_blob __attribute__((used)) __attribute__((__section__(".fw_version_blob"))) = { @@ -64,6 +65,7 @@ const struct fw_version_info fw_version_blob __attribute__((used)) __attribute__ .board_revision = ${BOARD_REVISION}, .commit_tag_name = "${FWTAG}", .sha1sum = { ${SHA1} }, + .uavosha1 = { ${UAVOSHA1} }, }; /**