All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
To: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@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, 06 Dec 2013 13:01:28 -0700	[thread overview]
Message-ID: <52A22D18.309@wwwdotorg.org> (raw)
In-Reply-To: <20131206195637.GB923@mithrandir>

On 12/06/2013 12:56 PM, Thierry Reding wrote:
> 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:

Thanks. I did wonder about using the struct module, but I also figured
that since I'd already written the conversion, and struct would be
more complex, I wouldn't bother.

I'll push out the whole 4-patch series in a second.

      reply	other threads:[~2013-12-06 20:01 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   ` [flasher PATCH V2 1/4] Add crc32 verification of the flash image Thierry Reding
2013-12-06 20:01     ` Stephen Warren [this message]

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=52A22D18.309@wwwdotorg.org \
    --to=swarren-3lzwwm7+weoh9zmkesr00q@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.