mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
make_can_boot_descriptor:Add padding argument
This commit is contained in:
committed by
Daniel Agar
parent
360c3781f3
commit
f4e9672fde
@@ -47,6 +47,9 @@ if(NOT "${PX4_BOARD_LABEL}" MATCHES "canbootloader")
|
|||||||
set(HW_MINOR ${uavcanblid_hw_version_minor})
|
set(HW_MINOR ${uavcanblid_hw_version_minor})
|
||||||
set(SW_MAJOR ${uavcanblid_sw_version_major})
|
set(SW_MAJOR ${uavcanblid_sw_version_major})
|
||||||
set(SW_MINOR ${uavcanblid_sw_version_minor})
|
set(SW_MINOR ${uavcanblid_sw_version_minor})
|
||||||
|
if("${uavcanbl_padding}" STREQUAL "")
|
||||||
|
set(uavcanbl_padding 4)
|
||||||
|
endif()
|
||||||
|
|
||||||
math(EXPR HWBOARD_ID "(${HW_MAJOR} << 8) + ${HW_MINOR}")
|
math(EXPR HWBOARD_ID "(${HW_MAJOR} << 8) + ${HW_MINOR}")
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ if(NOT "${PX4_BOARD_LABEL}" MATCHES "canbootloader")
|
|||||||
${PX4_BINARY_DIR}/${uavcan_bl_image_name}
|
${PX4_BINARY_DIR}/${uavcan_bl_image_name}
|
||||||
${PX4_BINARY_DIR}/deploy/${HWBOARD_ID}.bin
|
${PX4_BINARY_DIR}/deploy/${HWBOARD_ID}.bin
|
||||||
COMMAND
|
COMMAND
|
||||||
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_can_boot_descriptor.py -v --use-git-hash ${PX4_BOARD}.bin ${uavcan_bl_image_name}
|
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_can_boot_descriptor.py -v --padding ${uavcanbl_padding} --use-git-hash ${PX4_BOARD}.bin ${uavcan_bl_image_name}
|
||||||
COMMAND
|
COMMAND
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory deploy
|
COMMAND ${CMAKE_COMMAND} -E make_directory deploy
|
||||||
COMMAND
|
COMMAND
|
||||||
|
|||||||
@@ -120,18 +120,17 @@ class AppDescriptor(object):
|
|||||||
|
|
||||||
|
|
||||||
class FirmwareImage(object):
|
class FirmwareImage(object):
|
||||||
def __init__(self, path_or_file, mode="r"):
|
def __init__(self, path_or_file, mode="r", padding = 4):
|
||||||
|
self._padding = padding;
|
||||||
if getattr(path_or_file, "read", None):
|
if getattr(path_or_file, "read", None):
|
||||||
self._file = path_or_file
|
self._file = path_or_file
|
||||||
self._do_close = False
|
self._do_close = False
|
||||||
self._padding = 0
|
|
||||||
else:
|
else:
|
||||||
if "b" not in mode:
|
if "b" not in mode:
|
||||||
self._file = open(path_or_file, mode + "b")
|
self._file = open(path_or_file, mode + "b")
|
||||||
else:
|
else:
|
||||||
self._file = open(path_or_file, mode)
|
self._file = open(path_or_file, mode)
|
||||||
self._do_close = True
|
self._do_close = True
|
||||||
self._padding = 4
|
|
||||||
|
|
||||||
if "r" in mode:
|
if "r" in mode:
|
||||||
self._contents = BytesIO(self._file.read())
|
self._contents = BytesIO(self._file.read())
|
||||||
@@ -216,11 +215,20 @@ class FirmwareImage(object):
|
|||||||
prev_offset = self._contents.tell()
|
prev_offset = self._contents.tell()
|
||||||
self._contents.seek(0, os.SEEK_END)
|
self._contents.seek(0, os.SEEK_END)
|
||||||
self._length = self._contents.tell()
|
self._length = self._contents.tell()
|
||||||
if self._padding:
|
# Was Padding requested
|
||||||
fill = self._padding - (self._length % self._padding)
|
if self._padding != 0:
|
||||||
if fill:
|
# If so. then is the file already a multiple of the padding?
|
||||||
self._length += fill
|
if 0 == (self._length % self._padding):
|
||||||
self._padding = fill
|
# padding not needed
|
||||||
|
self._padding = 0
|
||||||
|
|
||||||
|
# Still need padding
|
||||||
|
if self._padding:
|
||||||
|
fill = self._padding - (self._length % self._padding)
|
||||||
|
if fill:
|
||||||
|
self._length += fill
|
||||||
|
#report back the fill which is the padding
|
||||||
|
self._padding = fill
|
||||||
self._contents.seek(prev_offset)
|
self._contents.seek(prev_offset)
|
||||||
|
|
||||||
return self._length
|
return self._length
|
||||||
@@ -285,6 +293,8 @@ if __name__ == "__main__":
|
|||||||
metavar="IMAGE")
|
metavar="IMAGE")
|
||||||
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
|
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
|
||||||
help="show additional firmware information on stdout")
|
help="show additional firmware information on stdout")
|
||||||
|
parser.add_option("-p", "--padding", dest="padding", type= int, default=4,
|
||||||
|
help="Padds the image to a multple of")
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
if len(args) not in (0, 2):
|
if len(args) not in (0, 2):
|
||||||
@@ -315,8 +325,8 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
bootloader_size = int(options.bootloader_size)
|
bootloader_size = int(options.bootloader_size)
|
||||||
|
|
||||||
with FirmwareImage(in_file, "rb") as in_image:
|
with FirmwareImage(in_file, "rb", 0) as in_image:
|
||||||
with FirmwareImage(out_file, "wb") as out_image:
|
with FirmwareImage(out_file, "wb", options.padding) as out_image:
|
||||||
image = in_image.read()
|
image = in_image.read()
|
||||||
out_image.write(bootloader_image)
|
out_image.write(bootloader_image)
|
||||||
out_image.write(image[bootloader_size:])
|
out_image.write(image[bootloader_size:])
|
||||||
|
|||||||
Reference in New Issue
Block a user