一、rootfs制作命令
small系统的rootfs制作脚本为build/ohos/packages/fs_process.py,制作的命令为
build/ohos/packages/fs_process.py
–product dayu900
–root-path /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/
–out-path /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900
–log-path /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/build.log
–product-path /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/vendor/hihope/dayu900
二、fs_process.py文件解析
该文件主要就是class Packer的解析,因此解析每一个接口即可
2.1 init解析
源代码如下
def __init__(self, packer_args) -> None:
self.config = Config() # 该类在build/hb/resources/config.py
self.replace_items = {
r'${product_name}': self.config.product,
r'${root_path}': self.config.root_path,
r'${out_path}': self.config.out_path
}
self.packing_process = [
self.mv_usr_libs, self.create_fs_dirs, self.fs_link,
self.fs_filemode, self.fs_make_cmd, self.fs_tear_down
]
self.fs_cfg = None
self.chmod_dirs = []
源代码功能
初始化参数
源代码解析
●调用Config类获取product_name、root_path、out_path
Config类是通过解析ohos_config.json文件获取了上面的相关参数,该文件在编译开始或者执行hb set时自动生成并位于代码根目录下
●self.replace_items解析结果如下
○ p r o d u c t n a m e : d a y u 900 ○ {product_name}: dayu900 ○ productname:dayu900○{root_path}: /home/wen_fei/OpenHarmony/dayu900-v4.0-release
○${out_path}: /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900
2.2 fs_make解析
源代码如下
def fs_make(self, cmd_args):
fs_cfg_path = os.path.join(self.config.product_path, 'fs.yml')
if not os.path.isfile(fs_cfg_path):
LogUtil.hb_info(f'{fs_cfg_path} not found, stop packing fs. '
'If the product does not need to be packaged, ignore it.')
return
if self.config.fs_attr is None:
LogUtil.hb_info('component compiling, no need to pack fs')
return
fs_cfg_list = IoUtil.read_yaml_file(fs_cfg_path)
for fs_cfg in fs_cfg_list:
self.fs_cfg = self.fs_attr_process(fs_cfg)
if self.fs_cfg.get('fs_dir_name', None) is None:
continue
for fs_process_func in self.packing_process:
fs_process_func()
源代码功能
设置self.fs_cfg并调用处理函数
源代码解析
●获取fs_cfg_path文件:/home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/vendor/hihope/dayu900/fs.yml
●通过IoUtil.read_yaml_file接口解析fs_cfg_path文件获得fs_cfg为
●调用self.packing_process中的6个函数并执行
self.mv_usr_libs
self.create_fs_dirs
self.fs_link
self.fs_filemode
self.fs_make_cmd
self.fs_tear_down
2.3 mv_usr_libs解析
源代码如下
def mv_usr_libs(self):
src_path = self.config.out_path
libs = [lib for lib in os.listdir(src_path) if self.is_lib(lib)]
target_path = os.path.join(src_path, 'usr', 'lib')
os.makedirs(target_path, exist_ok=True)
for lib in libs:
source_file = os.path.join(src_path, lib)
target_file = os.path.join(target_path, lib)
print("[wwx1101856]: source_file: {}, target_file: {}".format(source_file, target_file))
shutil.move(source_file, target_file)
源代码功能
移动so文件到${src_path}/usr/lib目录下