itopen组织
1、提供OpenHarmony优雅实用的小工具
2、手把手适配riscv + qemu + linux的三方库移植
3、未来计划riscv + qemu + ohos的三方库移植 + 小程序开发
4、一切拥抱开源,拥抱国产化
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
该文件主要就是class Packer的解析,因此解析每一个接口即可
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 = []
初始化参数
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
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目录下
def create_fs_dirs(self):
fs_path = os.path.join(self.config.out_path,
self.fs_cfg.get('fs_dir_name', 'rootfs'))
exist_ok, with_rm = self.is_incr(self.fs_cfg.get('fs_incr', None))
print("fs_path: {}".format(fs_path))
if with_rm and os.path.exists(fs_path):
shutil.rmtree(fs_path)
os.makedirs(fs_path, exist_ok=exist_ok)
self.replace_items[r'${fs_dir}'] = fs_path
for fs_dir in self.fs_cfg.get('fs_dirs', []):
source_dir = fs_dir.get('source_dir', '')
target_dir = fs_dir.get('target_dir', '')
if target_dir == '':
continue
source_path = self.fs_dirs_replace(source_dir,
self.config.out_path)
target_path = self.fs_dirs_replace(target_dir, fs_path)
if source_dir == '' or not os.path.exists(source_path):
os.makedirs(target_path, exist_ok=True)
target_mode_tuple = (target_path, fs_dir.get('dir_mode', 755))
print("[wwx1101856]: target_mode_tuple: {}".format(target_mode_tuple))
self.chmod_dirs.append(target_mode_tuple)
continue
print("[wwx1101856]: source_path: {}, target_path: {}, fs_dir: {}".format(source_path, target_path, fs_dir))
self.copy_files(source_path, target_path, fs_dir)
创建rootfs目录并根据yml的内容拷贝目录和文件到rootfs中
def fs_link(self):
fs_symlink = self.fs_cfg.get('fs_symlink', [])
for symlink in fs_symlink:
source, _ = self.replace(symlink.get('source', ''))
link_name, _ = self.replace(symlink.get('link_name', ''))
if os.path.exists(link_name):
os.remove(link_name)
os.symlink(source, link_name)
根据yml的内容创建软链接文件
def fs_filemode(self):
fs_filemode = self.fs_cfg.get('fs_filemode', [])
for filestat in fs_filemode:
file_dir = os.path.join(self.replace_items[r'${fs_dir}'],
filestat.get('file_dir', ''))
file_mode = filestat.get('file_mode', 0)
if os.path.exists(file_dir) and file_mode > 0:
self.chmod_dirs.append((file_dir, file_mode))
for file_dir, file_mode in self.chmod_dirs:
self.chmod(file_dir, file_mode)
设置目录和文件的的mode
def fs_make_cmd(self):
fs_make_cmd = self.fs_cfg.get('fs_make_cmd', [])
log_path = self.config.log_path
for cmd in fs_make_cmd:
cmd, _ = self.replace(cmd)
cmd = cmd.split(' ')
SystemUtil.exec_command(cmd, log_path=log_path)
获取制作文件系统的脚本并执行
def fs_tear_down(self):
while len(self.chmod_dirs):
tfile = self.chmod_dirs.pop()[0]
if os.path.isfile(tfile):
self.chmod(tfile, 555)
elif os.path.isdir(tfile):
self.chmod(tfile, 755)
再次检查并设置self.chmod_dirs中文件的mode,在执行fs_make_cmd时因需要会将某些文件和目录的mode修改
rootfsimg_linux.sh /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs ext4 96
总结一句话
# 如果是jffs2格式,则执行下面命令
mkfs.jffs2 -q -o /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs_jffs2.img -d /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs --pagesize=4096 --devtable /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/build/lite/make_rootfs/rootfs_linux.config
# 如果是vfat格式,则执行下面命令
dd if=/dev/zero of=/home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs_vfat.img count=xxx bs=512
mkfs.vfat /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs_vfat.img -s 4 -f 2 -S 512 > /dev/null
mcopy -i /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs_vfat.img /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs/* -/ ::/
# 如果是ext4格式,则执行下面命令
dd if=/dev/zero of=/home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs_vfat.img bs=512 count=xxx
mkfs.ext4 /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs_vfat.img
/home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/third_party/e2fsprogs/install.sh /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/third_party/e2fsprogs
/home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/third_party/e2fsprogs/e2fsprogs/contrib/populate-extfs.sh /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/out/dayu900/dayu900/rootfs /home/itopen/OpenHarmony/OpenHarmony-v4.0-Release/build/lite/make_rootfs/rootfs_linux.config
● libc++.so来源prebuilts/clang/ohos/linux-x86_64/llvm/lib/arm-linux-ohos/libc++.so
● libc.so来源third_party/musl的代码编译
来源于各个模块编译出来的库,small系统编译出来的都是so文件不是z.so文件
来源于toybox
各模块的server
其他模块编译出的可执行程序
dev_tools/bin下的可执行程序