From: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
Cc: treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: Re: [flasher PATCH V2 1/4] Add crc32 verification of the flash image
Date: Fri, 6 Dec 2013 20:56:38 +0100 [thread overview]
Message-ID: <20131206195637.GB923@mithrandir> (raw)
In-Reply-To: <1386351334-25766-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1577 bytes --]
On Fri, Dec 06, 2013 at 10:35:33AM -0700, Stephen Warren wrote:
[...]
> diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
[...]
> @@ -125,6 +129,19 @@ def func_flash():
> if args.debug:
> print 'flash_img_size %d 0x%x' % (flash_img_size, flash_img_size)
>
> + imgf = file(flash_img, 'rb')
> + imgd = imgf.read()
> + imgf.close()
> + flash_img_crc32 = binascii.crc32(imgd)
> + if args.debug:
> + print 'flash_img_crc32 %x' % flash_img_crc32
> + flash_img_crc32_bs = (
> + ((flash_img_crc32 & 0xff) << 24) |
> + ((flash_img_crc32 & 0xff00) << 8) |
> + ((flash_img_crc32 & 0xff0000) >> 8) |
> + ((flash_img_crc32 & 0xff000000) >> 24)
> + )
I would've thought that Python actually supported byteswapping with some
function, but it seems not (or at least not trivially). One could do
something like this:
a = array.array('I', [crc])
a.byteswap()
crc = a[0]
But with the array module you apparently can't force 32-bit values. 'I'
will be at least 2, but 4 on 32-bit and 64-bit systems, 'L' will be 64
bits on 64-bit systems and 32 bits on 32-bit systems it seems. You could
check a.itemsize to determine the right type code. I suppose we won't be
running on anything but 32- or 64-bit systems for a while, but it still
said there's no support for sized types there.
It could possibly be done with the struct module as well, but that would
likely end up much more verbose too, so:
Reviewed-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2013-12-06 19:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-06 17:35 [flasher PATCH V2 1/4] Add crc32 verification of the flash image Stephen Warren
[not found] ` <1386351334-25766-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-12-06 17:35 ` [flasher PATCH V2 3/4] Allow overriding environment variables during flashing Stephen Warren
[not found] ` <1386351334-25766-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-12-06 19:57 ` Thierry Reding
2013-12-06 19:56 ` Thierry Reding [this message]
2013-12-06 20:01 ` [flasher PATCH V2 1/4] Add crc32 verification of the flash image Stephen Warren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131206195637.GB923@mithrandir \
--to=thierry.reding-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
--cc=swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox