From: Artem Bityutskiy Date: Mon, 6 May 2013 14:25:39 +0000 (+0300) Subject: BmapCreate: generate bmap file checksum X-Git-Tag: v2.3~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f0e3bd8d68fbee33e3c6e501cde88d0c83647e1;p=tools%2Fbmap-tools.git BmapCreate: generate bmap file checksum I got a bug report recently and the investigation showed that it is caused by corrupted bmap file. Once the user re-downloaded the bmap file, the problem was solved. This patch tries to improve robustness by protecting the bmap file with SHA1 checksum. At the very end we calculate the SHA1 checksum of the entire bmap file with the in-file SHA1 value = all zeroes, and put the result to the bmap file. In order to verify the checksum, we will have to substitute the SHA1 checksum with all zeroes again and calculate SHA1 of the file. Change-Id: Ia8f109c8238a0e5e2e609f53255a699b35d72cde Signed-off-by: Artem Bityutskiy --- diff --git a/bmaptools/BmapCreate.py b/bmaptools/BmapCreate.py index e85c2e3..531da7e 100644 --- a/bmaptools/BmapCreate.py +++ b/bmaptools/BmapCreate.py @@ -129,6 +129,7 @@ class BmapCreate: self._mapped_count_pos1 = None self._mapped_count_pos2 = None + self._sha1_pos = None self._f_image_needs_close = False self._f_bmap_needs_close = False @@ -186,6 +187,14 @@ class BmapCreate: xml = "%s \n\n" % mapped_count # pylint: disable=C0301 + xml += " \n" + xml += " " + + self._f_bmap.write(xml) + self._sha1_pos = self._f_bmap.tell() + + xml = "0" * 40 + " \n\n" xml += " \n" @@ -211,6 +220,11 @@ class BmapCreate: self._f_bmap.seek(self._mapped_count_pos2) self._f_bmap.write("%u" % self.mapped_cnt) + self._f_bmap.seek(0) + sha1 = hashlib.sha1(self._f_bmap.read()).hexdigest() + self._f_bmap.seek(self._sha1_pos) + self._f_bmap.write("%s" % sha1) + def _calculate_sha1(self, first, last): """ A helper function which calculates SHA1 checksum for the range of blocks of the image file: from block 'first' to block 'last'. """