Allow building deltas with boot image only (no rootfs) 83/311583/3
authorAntoni <a.adaszkiewi@samsung.com>
Wed, 22 May 2024 14:21:36 +0000 (16:21 +0200)
committerAntoni <a.adaszkiewi@samsung.com>
Wed, 22 May 2024 14:57:41 +0000 (16:57 +0200)
update-info-builder.py was extended for more verbose logging

Change-Id: I4ea0be05bbf281fff1e503cd008aa8c2b50fc62d

mk_delta/common/bin/mk_delta.sh
mk_delta/common/bin/update-info-builder.py

index fa93831d756a78f7e7f01611080020d96bb9f0fb..3dfe3ebe5e0b5e9e14212318768cf15f4503fc0b 100755 (executable)
@@ -430,19 +430,22 @@ fi
 cd ${DELTA_DIR}
 cp ${COMMON_BINDIR}/unpack.sh ./
 
-if [ ! -r "${EXTRACTED_FILES_DIR}"/${UPGRADE_APPLY_BIN} ]; then
-       fn_extract_files_from_partition rootfs.img
-else
-       cp "${EXTRACTED_FILES_DIR}"/${UPGRADE_APPLY_BIN} .
-       cp "${EXTRACTED_FILES_DIR}"/${UPGRADE_APPLY_DELTAFS_BIN} .
-       cp "${EXTRACTED_FILES_DIR}"/${UPGRADE_SUPPORT_DIR}/* .
-       cp "${EXTRACTED_FILES_DIR}"/${DELTA_VERIFIER_BIN} .
-       cp "${EXTRACTED_FILES_DIR}"/${BLKID_PRINT_BIN} .
-       cp "${EXTRACTED_FILES_DIR}"/${RESIZE_DYNPARTS_BIN} .
-       cp "${EXTRACTED_FILES_DIR}"/${COPY_BLOCKDEV_BIN} .
+if fn_get_tar_file_names rootfs.img "${OLD_TAR_DIR}"; then
+       # If this binary was not extracted, it means no rootfs related files were,
+       # and we need to extract them now
+       if [ ! -r "${EXTRACTED_FILES_DIR}"/${UPGRADE_APPLY_BIN} ]; then
+               fn_extract_files_from_partition rootfs.img
+       else
+               cp "${EXTRACTED_FILES_DIR}"/${UPGRADE_APPLY_BIN} .
+               cp "${EXTRACTED_FILES_DIR}"/${UPGRADE_APPLY_DELTAFS_BIN} .
+               cp "${EXTRACTED_FILES_DIR}"/${UPGRADE_SUPPORT_DIR}/* .
+               cp "${EXTRACTED_FILES_DIR}"/${DELTA_VERIFIER_BIN} .
+               cp "${EXTRACTED_FILES_DIR}"/${BLKID_PRINT_BIN} .
+               cp "${EXTRACTED_FILES_DIR}"/${RESIZE_DYNPARTS_BIN} .
+               cp "${EXTRACTED_FILES_DIR}"/${COPY_BLOCKDEV_BIN} .
+       fi
 fi
 
-
 if [ ! -r "${HAL_TARG_NAME}" ]; then
        # Check if there is hal.img provided
        # If not then ok, just the update-info.ini file will not contain model_name information
index 0ff4de513726f86ae1a0788ade5d763eb93bf86f..c24970f13a0e6122078ef195085656c801ed79ef 100755 (executable)
@@ -42,6 +42,49 @@ TIZEN_PREFIX = "tizen.org"
 SYSTEM_PREFIX = os.path.join(TIZEN_PREFIX, "system")
 BUILD_PREFIX = "TZ_BUILD_"
 
+class ConfigFilesExistanceVerfier:
+    def __init__(self, hal_model_config_path, rootfs_model_config_path, tizen_build_config_path):
+        self.hal_model_config_path = hal_model_config_path
+        self.rootfs_model_config_path = rootfs_model_config_path
+        self.tizen_build_config_path = tizen_build_config_path
+
+        self.hal_model_config_exists = os.path.exists(hal_model_config_path) and os.path.isfile(hal_model_config_path)
+        self.rootfs_model_config_exists = os.path.exists(rootfs_model_config_path) and os.path.isfile(rootfs_model_config_path)
+        self.tizen_build_config_exists = os.path.exists(tizen_build_config_path) and os.path.isfile(tizen_build_config_path)
+
+    # rootfs_model_config and tizen_build_config have to be either both found, or both missing.
+    # hal_model_config doesn't have to be found, unless both rootfs_model_config and tizen_build_config are missing
+    def check_if_proper_combination_exists(self):
+        self.is_combination_proper = True
+        self.message = ""
+
+        if self.rootfs_model_config_exists ^ self.tizen_build_config_exists:
+            if not self.rootfs_model_config_exists:
+                self.message = f'One of config files from rootfs.img not found. Missing file: {self.rootfs_model_config_path}'
+            else:
+                self.message = f'One of config files from rootfs.img not found. Missing file: {self.tizen_build_config_path}'
+
+            self.is_combination_proper = False
+            return
+
+        if self.hal_model_config_exists:
+            if self.rootfs_model_config_exists:
+                self.message = f'Config files from both hal.img and rootfs.img will be used'
+            else:
+                self.message = f'Config file from only hal.img will be used'
+        else:
+            if self.rootfs_model_config_exists:
+                self.message = f'Config files form only rootfs.img will be used'
+            else:
+                self.message = f'No config files were found.'
+                self.is_combination_proper = False
+
+    def inform_about_combination(self):
+        if self.is_combination_proper:
+            print(f'{self.message}')
+        else:
+            print(f'{self.message}', file=sys.stderr)
+
 
 # following three could be simpler, but this way its easier in case we add more variables to check
 def generate_hal_model_config_set(full_type):
@@ -113,7 +156,7 @@ def get_dict_from_xml_file(path, set_info):
     return None
 
 
-def generate_main_dict(args):
+def generate_main_dict(args, config_files_existance_verifier):
     main_dict = {}
 
     hal_set = generate_hal_model_config_set(args.full_type)
@@ -122,7 +165,7 @@ def generate_main_dict(args):
 
     # hal.img is not required. On the other hand, if it is available, the
     # resulting update-info.cfg file will also contain information from hal.img
-    if hal_set and os.path.exists(args.hal_model_config_path):
+    if hal_set and config_files_existance_verifier.hal_model_config_exists:
         hal_dict = get_dict_from_xml_file(args.hal_model_config_path, hal_set)
         if not hal_dict:
             print(f'{args.hal_model_config_path}: error parsing file', file=sys.stderr)
@@ -130,7 +173,8 @@ def generate_main_dict(args):
 
         main_dict.update(hal_dict)
 
-    if rootfs_set:
+    # Similarly to the comment above, rootfs.img is not required.
+    if rootfs_set and config_files_existance_verifier.rootfs_model_config_exists:
         rootfs_dict = get_dict_from_xml_file(args.rootfs_model_config_path, rootfs_set)
         if not rootfs_dict:
             print(f'{args.rootfs_model_config_path}: error parsing file', file=sys.stderr)
@@ -138,7 +182,7 @@ def generate_main_dict(args):
 
         main_dict.update(rootfs_dict)
 
-    if tizen_set:
+    if tizen_set and config_files_existance_verifier.tizen_build_config_exists:
         tizen_dict = get_dict_from_text_file(args.tizen_build_config_path, tizen_set)
         if not tizen_dict:
             print(f'{args.tizen_build_config_path}: error parsing file', file=sys.stderr)
@@ -170,12 +214,18 @@ def main():
     if os.path.exists(args.output_file):
         parser.error(f'{args.output_file} already exists!')
 
-    for file in [args.rootfs_model_config_path, args.tizen_build_config_path]:
-        if not (os.path.exists(file) and os.path.isfile(file)):
-            parser.error(f'{file} is not a valid path!')
-
     print('--- Generate update info file ---')
-    update_data = generate_main_dict(args)
+
+    config_files_existance_verifier = \
+        ConfigFilesExistanceVerfier(args.hal_model_config_path, args.rootfs_model_config_path, args.tizen_build_config_path)
+
+    config_files_existance_verifier.check_if_proper_combination_exists()
+    config_files_existance_verifier.inform_about_combination()
+
+    if not config_files_existance_verifier.is_combination_proper:
+        raise Exception
+
+    update_data = generate_main_dict(args, config_files_existance_verifier)
     if not update_data:
         # TODO make this exception more verbose
         raise Exception