Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
librem5-flash-image
Commits
415727cf
Commit
415727cf
authored
Dec 30, 2018
by
Guido Gunther
Browse files
flash-image: Validate checksum of downloaded image
This also uses the meta data provided with the image.
parent
af843f80
Pipeline
#72902
failed with stage
in 1 minute and 1 second
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
scripts/librem5-devkit-flash-image
View file @
415727cf
...
...
@@ -2,6 +2,7 @@
import
argparse
import
datetime
import
hashlib
import
jenkins
import
logging
import
lzma
...
...
@@ -52,6 +53,33 @@ BLOCK_SIZE = 8192
UNCOMPRESSED_SIZE
=
3600000000
class
VerifyImageException
(
Exception
):
pass
def
verify_image
(
image
,
meta
):
m
=
hashlib
.
sha256
()
size
=
int
(
meta
[
'image'
][
'size'
])
hexdigest
=
meta
[
'image'
][
'sha256sum'
]
logging
.
info
(
"Calculating sha256sum of {}"
.
format
(
image
))
bar
=
tqdm
.
tqdm
(
total
=
size
,
desc
=
'Checking'
,
leave
=
False
)
with
open
(
image
,
'rb'
)
as
f
:
while
True
:
data
=
f
.
read
(
BLOCK_SIZE
)
if
data
:
m
.
update
(
data
)
bar
.
update
(
n
=
len
(
data
))
else
:
break
bar
.
close
()
if
m
.
hexdigest
()
!=
hexdigest
:
raise
VerifyImageException
(
"Checksum of image {} "
"does not match {}"
.
format
(
m
.
hexdigest
(),
hexdigest
))
def
download_image
(
url
,
target
):
decomp
=
lzma
.
LZMADecompressor
()
logging
.
info
(
"Downloading image from {}"
.
format
(
url
))
...
...
@@ -66,7 +94,7 @@ def download_image(url, target):
uncompressed_size
=
int
(
meta
[
'image'
][
'size'
])
logging
.
debug
(
"Image size is %d"
,
uncompressed_size
)
except
requests
.
exceptions
.
HTTPError
:
logging
.
warning
(
"No meta data found, s
ize may be incorr
ec
t
"
)
logging
.
warning
(
"No meta data found, s
kipping integrity ch
ec
k
"
)
meta
=
None
uncompressed_size
=
UNCOMPRESSED_SIZE
...
...
@@ -88,6 +116,8 @@ def download_image(url, target):
download_bar
.
update
(
n
=
len
(
data
))
download_bar
.
close
()
decompress_bar
.
close
()
if
meta
:
verify_image
(
target
,
meta
)
def
find_image
(
jobname
,
type
,
dist
):
...
...
@@ -205,6 +235,9 @@ def main():
uboot_target
)
write_uuu_script
(
uuu_target
,
image_target
,
uboot_target
)
flash_image
(
uuu_target
)
except
VerifyImageException
as
e
:
logging
.
error
(
e
)
return
1
except
KeyboardInterrupt
:
logging
.
error
(
"CTRL-C pressed."
)
return
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment