mirror of
https://gitee.com/openharmony/update_packaging_tools
synced 2024-11-23 06:40:03 +00:00
Signed-off-by: unknown <zhangchun39@huawei.com>
This commit is contained in:
commit
6e2fcafe93
@ -58,6 +58,7 @@ HASH_INFO_FMT = "<3HI"
|
||||
HASH_DATA_HEADER_FMT = "<32sHI"
|
||||
HASH_DATA_ADDR_FMT = "<2I"
|
||||
|
||||
|
||||
class CreateHash(object):
|
||||
"""
|
||||
Create the component hash data
|
||||
@ -128,7 +129,8 @@ class CreateHash(object):
|
||||
component_len = os.path.getsize(component.file_path)
|
||||
block_num = component_len // HASH_BLOCK_SIZE
|
||||
component_name = component.component_addr.decode().ljust(COMPONENT_NAME_SIZE, "\0")
|
||||
UPDATE_LOGGER.print_log("calc component hash component name:%s %d" % (component_name,len(component_name)))
|
||||
UPDATE_LOGGER.print_log(
|
||||
"calc component hash component name:%s %d" % (component_name, len(component_name)))
|
||||
total_block = block_num + 1 if component_len % HASH_BLOCK_SIZE > 0 else block_num
|
||||
self.hashdata += struct.pack(HASH_DATA_HEADER_FMT, component_name.encode(),
|
||||
total_block, component_len)
|
||||
@ -193,25 +195,27 @@ class CreateHash(object):
|
||||
return True
|
||||
|
||||
def parse_print_hashdata(self, save_path):
|
||||
hash_check_file_p = open(os.path.join(save_path + "hash_check_file_parse"), "wb+")
|
||||
hash_check_fd = os.open(os.path.join(save_path + "hash_check_file_parse"), os.O_RDWR | os.O_CREAT, 0o755)
|
||||
with os.fdopen(hash_check_fd, "wb+") as hash_check_file_p:
|
||||
hash_check_file_p.write(("hash info:").encode())
|
||||
hash_check_file_p.write((HashType(self.hash_type.value).name + ' ' + str(self.hash_digest_size) + \
|
||||
' ' + str(self.component_num) + ' ' + str(self.block_size) + '\n').encode())
|
||||
hash_check_file_p.write(("%s %s %s %s\n" % (
|
||||
HashType(self.hash_type.value).name, str(self.hash_digest_size),
|
||||
str(self.component_num), str(self.block_size))).encode())
|
||||
|
||||
offset = 0
|
||||
for i in range(0, self.component_num):
|
||||
hash_check_file_p.write((self.hashdata_list[offset][0] + '\n').encode())
|
||||
hash_check_file_p.write((str(self.hashdata_list[offset][1]) + ' ' + \
|
||||
str(self.hashdata_list[offset][2]) + '\n').encode())
|
||||
hash_check_file_p.write(("%s\n" % (self.hashdata_list[offset][0])).encode())
|
||||
hash_check_file_p.write(("%s %s\n" % (
|
||||
str(self.hashdata_list[offset][1]), str(self.hashdata_list[offset][2]))).encode())
|
||||
for j in range(0, self.hashdata_list[offset][1]):
|
||||
index = offset + 1
|
||||
hashdata_hexstr = "".join("%02x" % b for b in self.hashdata_list[j + index][2])
|
||||
hash_check_file_p.write((str(self.hashdata_list[j + index][0]) + ' ' + \
|
||||
str(self.hashdata_list[j + index][1]) + ' ' + hashdata_hexstr + \
|
||||
'\n').encode())
|
||||
hash_check_file_p.write(("%s" % (
|
||||
str(self.hashdata_list[j + index][0]), str(self.hashdata_list[j + index][1]),
|
||||
hashdata_hexstr)).encode())
|
||||
|
||||
offset += (1 + self.hashdata_list[offset][1])
|
||||
|
||||
signdata_hexstr = "".join("%02x" % b for b in self.signdata)
|
||||
hash_check_file_p.write(("hash sign:").encode())
|
||||
hash_check_file_p.write(signdata_hexstr.encode())
|
||||
hash_check_file_p.close()
|
@ -355,7 +355,7 @@ class CreatePackage(object):
|
||||
self.hash_info_offset += len(hash_check_data.hashinfo_value + hash_check_data.hashdata)
|
||||
|
||||
except IOError:
|
||||
UPDATE_LOGGER.print_log("Add hash check data failed", log_type=UPDATE_LOGGER.ERROR_LOG)
|
||||
UPDATE_LOGGER.print_log("Add hash check data failed!", log_type=UPDATE_LOGGER.ERROR_LOG)
|
||||
return False
|
||||
self.sign_header(SIGN_ALGO_RSA, hash_check_data, package_file)
|
||||
self.component_offset = self.hash_info_offset
|
||||
|
44
utils.py
44
utils.py
@ -25,11 +25,11 @@ from collections import OrderedDict
|
||||
import xmltodict
|
||||
import zipfile
|
||||
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from log_exception import UPDATE_LOGGER
|
||||
from build_pkcs7 import sign_ota_package
|
||||
from copy import copy
|
||||
from ctypes import cdll
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from log_exception import UPDATE_LOGGER
|
||||
|
||||
operation_path = os.path.dirname(os.path.realpath(__file__))
|
||||
PRODUCT = 'hi3516'
|
||||
@ -127,19 +127,8 @@ class ExtInit:
|
||||
return False
|
||||
|
||||
|
||||
@singleton
|
||||
class OptionsManager:
|
||||
"""
|
||||
Options management class
|
||||
"""
|
||||
|
||||
class BaseOptionsManager:
|
||||
def __init__(self):
|
||||
self.init = ExtInit()
|
||||
self.parser = argparse.ArgumentParser()
|
||||
|
||||
# Own parameters
|
||||
self.product = None
|
||||
|
||||
# Entry parameters
|
||||
self.source_package = None
|
||||
self.target_package = None
|
||||
@ -157,6 +146,23 @@ class OptionsManager:
|
||||
|
||||
self.make_dir_path = None
|
||||
|
||||
|
||||
@singleton
|
||||
class OptionsManager(BaseOptionsManager):
|
||||
"""
|
||||
Options management class
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.init = ExtInit()
|
||||
self.parser = argparse.ArgumentParser()
|
||||
|
||||
# Own parameters
|
||||
self.product = None
|
||||
|
||||
|
||||
# Parsed package parameters
|
||||
self.target_package_dir = None
|
||||
self.target_package_config_dir = None
|
||||
@ -340,7 +346,6 @@ def parse_update_config(xml_path):
|
||||
difference_list.append(component['@compAddr'])
|
||||
OPTIONS_MANAGER.incremental_img_name_list.append(split_img_name(component['#text']))
|
||||
|
||||
UPDATE_LOGGER.print_log('XML file parsing completed!')
|
||||
ret_params = [head_list, comp_dict, whole_list, difference_list, package_version, full_image_path_list]
|
||||
return ret_params
|
||||
|
||||
@ -618,9 +623,7 @@ def get_update_info():
|
||||
os.path.join(OPTIONS_MANAGER.target_package_config_dir,
|
||||
BOARD_LIST_PATH)))
|
||||
if board_list_content is False:
|
||||
UPDATE_LOGGER.print_log(
|
||||
"Get board list content failed!",
|
||||
log_type=UPDATE_LOGGER.ERROR_LOG)
|
||||
UPDATE_LOGGER.print_log("Get board list content failed!", log_type=UPDATE_LOGGER.ERROR_LOG)
|
||||
return False
|
||||
OPTIONS_MANAGER.board_list_content = board_list_content
|
||||
|
||||
@ -636,11 +639,10 @@ def get_update_info():
|
||||
OPTIONS_MANAGER.target_package_version, \
|
||||
OPTIONS_MANAGER.full_image_path_list = \
|
||||
parse_update_config(xml_file_path)
|
||||
UPDATE_LOGGER.print_log("XML file parsing completed!")
|
||||
if head_info_list is False or component_info_dict is False or \
|
||||
full_img_list is False or incremental_img_list is False:
|
||||
UPDATE_LOGGER.print_log(
|
||||
"Get parse update config xml failed!",
|
||||
log_type=UPDATE_LOGGER.ERROR_LOG)
|
||||
UPDATE_LOGGER.print_log("Get parse update config xml failed!", log_type=UPDATE_LOGGER.ERROR_LOG)
|
||||
return False
|
||||
OPTIONS_MANAGER.head_info_list, OPTIONS_MANAGER.component_info_dict, \
|
||||
OPTIONS_MANAGER.full_img_list, OPTIONS_MANAGER.incremental_img_list = \
|
||||
|
Loading…
Reference in New Issue
Block a user