From 8bfe4ea9bca626e442f7cd7b0a4b70b72f3f14be Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Mon, 9 Sep 2024 15:06:06 +0800 Subject: [PATCH] =?utf8?q?=E7=94=9F=E6=88=90=E5=9B=BA=E4=BB=B6=E5=8C=85?= =?utf8?q?=E6=97=B6=EF=BC=8C=E5=90=8C=E6=97=B6=E6=9B=B4=E6=96=B0=20filesch?= =?utf8?q?ecksum.txt=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../fd230/create_fs_checksumfile.py | 80 +++++++++++++++++++ code/sdk/build/script/cmake_builder.py | 8 ++ 3 files changed, 89 insertions(+) create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/create_fs_checksumfile.py diff --git a/.gitignore b/.gitignore index 2a5b10553..9356ae11b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 000000000..7556cf92f --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/create_fs_checksumfile.py @@ -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 + + + + diff --git a/code/sdk/build/script/cmake_builder.py b/code/sdk/build/script/cmake_builder.py index da0c9812e..9d0e78ae1 100755 --- a/code/sdk/build/script/cmake_builder.py +++ b/code/sdk/build/script/cmake_builder.py @@ -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) -- 2.17.1