Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
firmware
FFS Gluon
Commits
7f14b431
Commit
7f14b431
authored
Dec 11, 2023
by
David Bauer
Browse files
Options
Downloads
Patches
Plain Diff
contrib: add script for validating image-size
parent
321cd5b1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/check-image-size.py
+146
-0
146 additions, 0 deletions
contrib/check-image-size.py
with
146 additions
and
0 deletions
contrib/check-image-size.py
0 → 100755
+
146
−
0
View file @
7f14b431
#!/usr/bin/env python3
import
argparse
import
json
import
sys
from
enum
import
Enum
# Enum Class for checking image size
class
ImageSizeCheck
(
Enum
):
OK
=
"
OK
"
TOO_BIG
=
"
TOO_BIG
"
IGNORED
=
"
IGNORED
"
UNKNOWN
=
"
UNKNOWN
"
# Some devices pad their images to IMAGE_SIZE and apply a firmware header.
# Exclude this from the image size check.
excluded_devices
=
[
"
tplink_cpe210-v1
"
,
"
tplink_cpe210-v2
"
,
"
tplink_cpe210-v3
"
,
"
tplink_cpe220-v3
"
,
"
tplink_cpe510-v1
"
,
"
tplink_cpe510-v2
"
,
"
tplink_cpe510-v3
"
,
"
tplink_cpe710-v1
"
,
"
tplink_wbs210-v1
"
,
"
tplink_wbs210-v2
"
,
"
tplink_wbs510-v1
"
]
def
open_json
(
file_path
):
with
open
(
file_path
,
'
r
'
)
as
f
:
return
json
.
load
(
f
)
def
load_openwrt_profile_json
(
json_path
):
profiles
=
[]
profile_json
=
open_json
(
json_path
)
for
profile_name
,
profile_data
in
profile_json
[
"
profiles
"
].
items
():
device_profile
=
{
"
name
"
:
profile_name
,
}
if
"
image
"
in
profile_data
.
get
(
"
file_size_limits
"
,
{}):
device_profile
[
"
max_image_size
"
]
=
profile_data
[
"
file_size_limits
"
][
"
image
"
]
for
image
in
profile_data
[
"
images
"
]:
if
image
[
"
type
"
]
!=
"
sysupgrade
"
:
continue
if
"
size
"
in
image
:
device_profile
[
"
image_size
"
]
=
image
[
"
size
"
]
profiles
.
append
(
device_profile
)
return
profiles
def
check_image_size_below_limit
(
profile
,
overhead
=
0
):
# Skip devices that pad their images
if
profile
[
"
name
"
]
in
excluded_devices
:
return
ImageSizeCheck
.
IGNORED
if
"
max_image_size
"
in
profile
and
"
image_size
"
in
profile
:
if
profile
[
"
image_size
"
]
+
(
overhead
*
1024
)
>
profile
[
"
max_image_size
"
]:
return
ImageSizeCheck
.
TOO_BIG
else
:
return
ImageSizeCheck
.
OK
return
ImageSizeCheck
.
UNKNOWN
def
print_github_actions_warning
(
message
):
print
(
'
::warning::{}
'
.
format
(
message
))
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
(
description
=
'
Check image size of OpenWrt profiles
'
)
parser
.
add_argument
(
'
profile_json
'
,
help
=
'
Path to profile.json
'
,
nargs
=
'
+
'
)
parser
.
add_argument
(
'
--github-actions
'
,
help
=
'
Generate warnings for use with GitHub Actions
'
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
--overhead
'
,
type
=
int
,
help
=
'
Additional size to add to the image size in kilobyte
'
,
default
=
0
)
args
=
parser
.
parse_args
()
if
args
.
profile_json
is
None
:
print
(
'
Error: profile.json not specified
'
)
sys
.
exit
(
1
)
# Load all profile.json files
profiles
=
[]
for
profile_file
in
args
.
profile_json
:
profiles
.
extend
(
load_openwrt_profile_json
(
profile_file
))
# Initialize results with all available ImageSizeCheck values
results
=
{}
for
check_result
in
ImageSizeCheck
:
results
[
check_result
]
=
[]
for
profile
in
profiles
:
check_result
=
check_image_size_below_limit
(
profile
,
args
.
overhead
)
results
[
check_result
].
append
(
profile
)
for
check_result
,
profiles
in
results
.
items
():
if
len
(
profiles
)
==
0
:
continue
# Group by result type for GitHub Actions
if
args
.
github_actions
:
print
(
'
::group::{}
'
.
format
(
check_result
.
value
))
for
profile
in
profiles
:
if
check_result
==
ImageSizeCheck
.
TOO_BIG
:
msg
=
'
Image size of profile {} is too big ({} > {})
'
.
format
(
profile
[
"
name
"
],
profile
[
"
image_size
"
]
+
(
args
.
overhead
*
1024
),
profile
[
"
max_image_size
"
])
if
args
.
github_actions
:
print_github_actions_warning
(
msg
)
else
:
print
(
"
Warning: {}
"
.
format
(
msg
))
elif
check_result
==
ImageSizeCheck
.
UNKNOWN
:
msg
=
'
Image size of profile {} is unknown
'
.
format
(
profile
[
"
name
"
])
print
(
msg
)
elif
check_result
==
ImageSizeCheck
.
IGNORED
:
msg
=
'
Image size of profile {} is ignored (Image size {})
'
.
format
(
profile
[
"
name
"
],
profile
.
get
(
"
image_size
"
,
"
unknown
"
))
print
(
msg
)
else
:
msg
=
'
Image size of profile {} is OK ({} < {})
'
.
format
(
profile
[
"
name
"
],
profile
[
"
image_size
"
]
+
(
args
.
overhead
*
1024
),
profile
[
"
max_image_size
"
])
print
(
msg
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment