生成固件包时,同时更新 fileschecksum.txt 文件 917/1 917/head
authorSnickerSun <snickersun@163.com>
Mon, 9 Sep 2024 07:06:06 +0000 (15:06 +0800)
committerSnickerSun <snickersun@163.com>
Mon, 9 Sep 2024 07:06:06 +0000 (15:06 +0800)
.gitignore
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/create_fs_checksumfile.py [new file with mode: 0644]
code/sdk/build/script/cmake_builder.py

index 2a5b105..9356ae1 100644 (file)
@@ -1,3 +1,4 @@
+fileschecksum.txt
 tools/string_packer/output/**
 code/sdk/deveco/**
 code/sdk/vscode/**
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/create_fs_checksumfile.py b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/create_fs_checksumfile.py
new file mode 100644 (file)
index 0000000..7556cf9
--- /dev/null
@@ -0,0 +1,80 @@
+# -*-coding:utf-8-*-    
+  
+#===============================================================================  
+# 目录对比工具(包含子目录 ),并列出
+# 1、A比B多了哪些文件  
+# 2、B比A多了哪些文件  
+# 3、二者相同的文件: md5比较
+#===============================================================================  
+  
+import os
+import sys
+import time
+import difflib
+import hashlib
+import struct
+import shutil
+
+
+def getFileMd5(filename):
+    if not os.path.isfile(filename):
+        print('file not exist: ' + filename)
+        return
+    myhash = hashlib.md5()
+    f = open(filename,'rb')
+    while True:
+        b = f.read(8096)
+        if not b :
+            break
+        myhash.update(b)
+    f.close()
+    return myhash.hexdigest()
+
+
+def getAllFiles(path):
+    flist=[]
+    for root, dirs , fs in os.walk(path):
+        for f in fs:
+            f_fullpath = os.path.join(root, f)
+            f_relativepath = f_fullpath[len(path):]
+            flist.append(f_relativepath)
+    return flist
+
+
+def create_dirs(dir_path):
+    # print(dir_path)
+    if not os.path.exists(dir_path):
+        try:
+            os.makedirs(dir_path)
+        except OSError as exc: # Guard against race condition
+            if exc.errno != errno.EEXIST:
+                raise
+# 获取文件大小
+def get_FileSize(filePath):
+    fsize = os.path.getsize(filePath)
+    return fsize
+
+target_tmp_dir=""
+filelist=[]
+target_filelist_name=""
+
+if __name__ == '__main__':
+    target_tmp_dir = sys.argv[1]+"/fs"
+    target_filelist_name=target_tmp_dir+"/system/fileschecksum.txt"
+    if os.path.exists(target_filelist_name):
+        os.remove(target_filelist_name)
+    filelist=getAllFiles(target_tmp_dir)
+    create_dirs(target_tmp_dir+"/system/")
+    with open(target_filelist_name, 'w') as file:
+        for f in filelist:
+            fullpath=target_tmp_dir+f
+            print(fullpath)
+            fmd5=getFileMd5(fullpath)
+            fsize=get_FileSize(fullpath)
+            content = "{},{},{}\n".format(f,fsize,fmd5)
+            file.write(content)
+        file.close
+
+    
+
+
index da0c981..9d0e78a 100755 (executable)
@@ -138,6 +138,14 @@ class CMakeBuilder(BuildEnvironment):
                     fs_image_path = os.path.join(root_path, 'build', 'config', 'target_config', env.get('chip'),'mk_fs_image', env.get('fs_image_path'))
                 else:
                     fs_image_path = os.path.join(root_path, 'build', 'config', 'target_config', env.get('chip'),'mk_fs_image', 'fd230')
+                # 创建文件校验表,方便检验文件完整性。
+                create_fs_checksum_script_path=os.path.join(fs_image_path, 'create_fs_checksumfile.py')
+                errcode = exec_shell([self.python_path, create_fs_checksum_script_path, fs_image_path], None, True)
+                if errcode != 0:
+                    print("creat fs checksum error!")
+                    self.print_build_result(target, errcode)
+                    sys.exit(1)
+                # 生成yaffs镜像文件
                 fs_script_path = os.path.join(fs_image_path, 'mkyaffs2tool.py')
                 output_path = env.get_output_path()
                 print(output_path)