# lbkit **Repository Path**: litebmc/lbkit ## Basic Information - **Project Name**: lbkit - **Description**: litebmc配套工具链,支持litebmc集成开发环境以及dbus接口自动生成c语言代码 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-07-05 - **Last Updated**: 2025-11-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 安装lbkit lbkit由pipy包和deb&rpm两部分组成: 1. lbkit的pypi包使用python编写,负责组件编译发布、产品构建、代码自动生成、开发者测试等业务实现,以pip包形式发布到pypi.org官方仓,使用命令`pip3 install lbkit`安装。 2. lbkit的rpm或deb包,提供二进制工具、依赖管理、模型数据等,支持[deb软件仓](https://litebmc.com/ubuntu/),可使用`apt install lbkit`命令安装。 #### 在线安装 在线安装操作示例: ``` # 添加软件源,将下面这一行内容追加到/etc/apt/sources.list deb [arch=amd64] https://litebmc.com/ubuntu/ stable main # 安装gpg公钥方法一:下载litebmc.gpg并安装 wget -qO- https://litebmc.com/ubuntu/litebmc.gpg | sudo tee /etc/apt/trusted.gpg.d/litebmc.asc # 安装gpg公钥方法二:从keyserver.ubuntu.com下载ID为27B8C6BEC58DCF534A7BA35E1246430E1FC586BB的公钥 apt-key adv --keyserver keyserver.ubuntu.com --recv 27B8C6BEC58DCF534A7BA35E1246430E1FC586BB # 查找uid为ci@litebmc.com的公钥ID是否为27B8C6BEC58DCF534A7BA35E1246430E1FC586BB,确保正确导入 apt-key list | grep 27B8 # 更新索引 apt update # 安装lbkit apt install lbkit ``` ?> 暂未构建rpm软件仓,可参考下一章节构建rpm包。 ### 编译安装 `lbkit`工具的发布方法是在[lbkit代码仓](https://gitee.com/litebmc/lbkit.git)打tag标签,由CI工程自动触发版本发布。 Litebmc仅测试了ubuntu22.04系统构建deb包,其它系统安装可能需要开发者适配(欢迎贡献代码)。 如需要手工构建,可以参考以下操作示例: **openSUSE构建rpm包和pypi包** ```shell # 安装python3和python3-pip sudo zypper install python3 python3-pip # 环境准备(需要root权限) sudo ./build.py --prepare # 构建rpm包 ./build.py # 安装pip包 pip3 install output/pypi/lbkit-0.6.0-py3-none-any.whl # 安装rpm包(需要root权限) sudo rpm -ivh output/rpm/x86_64/lbkit-0.6.0-1.x86_64.rpm ``` **ubuntu 22.04构建deb包和pyp包** ```shell # 安装python3和python3-pip sudo apt install python3 python3-pip # 环境准备(需要root权限) sudo ./build.py --prepare # 构建rpm包 ./build.py # 安装pip包 pip3 install output/pypi/lbkit-0.6.0-py3-none-any.whl # 安装deb包(需要root权限) sudo dpkg -i output/deb/x86_64/lbkit_0.6.0_all.deb # 首次安装可能因依赖不存在导致失败,可以执行以下命令安装依赖 sudo apt install -f ``` `./build.py`命令支持`--version`参数,可指定软件包版本号,未指定时默认为`0.6.0`。 ## 系统初始化 #### 配置conan仓 litebmc的组件使用conan 2.0包管理器管理组件的发布、依赖、构建、集成和裁剪,安装lbkit工具时跟随主软件自动安装conan,首次使用需要配置conan: ```bash # 初始化conan(会生成文件名为default的profile文件) conan profile detect # 添加远程仓别名,按需配置 url # conan remote add litebmc # 登录conan仓,按需配置 username、password # conan remote login -p -r litebmc ,如果需要构建自己的conan仓,请参考: https://docs.conan.io/2/tutorial/conan_repositories/setting_up_conan_remotes/artifactory/artifactory_ce_cpp.html # litebmc提供了一个只读仓库,支持访客模式,无需登录 conan remote add litebmc https://art.litebmc.com/artifactory/api/conan/center ``` #### 软件源加速 系统默认的pypi仓较慢,可以选择合适的pypi软件源提升安装速度,常用的源及安装指导: 1. [华为云](https://mirrors.huaweicloud.com/mirrorDetail/5ea148ce302e67c59c8fe161?mirrorName=pypi&catalog=language) 2. [阿里云](https://mirrors.huaweicloud.com/mirrorDetail/5ea14ecab05943f36fb75ee7?mirrorName=ubuntu&catalog=os) 3. [清华源](https://mirrors.tuna.tsinghua.edu.cn/help/pypi/) deb包安装时依赖ubuntu镜像源,默认使用[官方源](https://archive.ubuntu.com)较慢,建议选择合适的ubuntu镜像源加速,可以使用以下源加速: 1. [华为云](https://mirrors.huaweicloud.com/mirrorDetail/5ea14ecab05943f36fb75ee7?mirrorName=ubuntu&catalog=os) 2. [阿里云](https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11v96owU) 3. [清华源](https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/) ## 使用指导 lbkit工具的命令为`lbkit`,可以简化为`lbk`,支持的命令包括: ```bash Code Generate commands: gen 代码自动生成. Build Component commands: build 构建组件. test 构建DT. Build Product commands: build 构建组件. Misc commands: help Shows help for a specific command. CI Robot commands: gitee Call gitee api. LiteBmcKit commands. Type "litebmc -h" for help ``` ### 产品构建 litebmc的产品构建策略存储在[litebmc/litebmc.git](https://gitee.com/litebmc/litebmc.git),下载源码后进入`litebmc/litebmc`目录,由`manifest.yml`文件承载产品的构建策略,执行`lbk build`命令即按照构建策略启动构建。 `lbk build --help`命令的帮助说明: ```bash usage: lbk [-h] [-m MANIFEST] [-s] [-pr:b PROFILE_BUILD] [-bt {debug,release,minsize}] [-r REMOTE] [-l] [-ul] [-p PRODUCT] [-t TARGET] Build LiteBMC options: -h, --help show this help message and exit -m MANIFEST, --manifest MANIFEST Specify the manifest.yml, ignored when -l is specified. -s, --from_source Build from source -pr:b PROFILE_BUILD, --profile_build PROFILE_BUILD Apply the specified profile to the build machine -bt {debug,release,minsize}, --build_type {debug,release,minsize} Set the build type -r REMOTE, --remote REMOTE specified conan server -l, --lockfile using conan.lock -ul, --update_lockfile update conan.lock -p PRODUCT, --product PRODUCT product name, default product is `default` -t TARGET, --target TARGET build target: * default ``` 说明: * `-m`: 指定manifest.yml文件,默认为当前目录下的`manifest.yml`文件,一般无需指定。 * `-s`: 强制从源码构建依赖组件。 * `-pr:b`: 构建工具的profile文件,默认为`default`。 * `-bt`: 构建类型,支持debug、release、minsize。 ?> 参考: [Building for multiple configurations: Release, Debug, Static and Shared](https://docs.conan.io/2.0/tutorial/consuming_packages/different_configurations.html) * `-r`: 指定conan仓,构建时将从此仓下载recipes。 * `-l`: 指定lock文件,可以固化构建时的依赖,如果首次生成或需要更新时请使用`-ul`参数 * `-ul`: 更新lock文件 * `-p`: manifest.yml文件的`products`配置项可以支持多种软件包配置,可通过`-p`参数指定需要构建的产品配置,默认为`default` * `-t`: 构建目标,目标定义在`/usr/share/litebmc/targets/`目录,用于编排构建任务,默认为default。 !> 产品manifest.yml文件必须配置名为default的产品包。 构建qemu产品包的命令示例: ```bash # 克隆litebmc仓源码 git clone https://gitee.com/litebmc/litebmc.git # 进入qemu镜像配置目录 cd litebmc/litebmc # 查看构建策略配置文件 ls manifest.yml # 启动构建 lbk build # 生成的文件在.temp/output目录 cd .temp/output # 运行仿真镜像(注意,请安装qemu-efi-aarch64工具: apt install qemu-efi-aarch64) qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 4 -m 512m -bios u-boot.bin -netdev user,id=eth0,hostfwd=tcp::2022-:22 -device virtio-net-device,netdev=eth0 -drive id=nvme,if=none,file=./qemu.img,format=raw -device nvme,drive=nvme,serial=nvme1 ``` `lbk build`构建有几个关键阶段说明: 1. 下载manifest.yml的`download`描述的资源。 2. 解压manifest.yml的`toolchain`描述的构建工具,包括`compiler`编译器、`sysroot`和`profile`,其中profile描述了交叉编译工具链的详细信息。 3. 编译和安装manifest.yml的`dependencies`描述的conan包,并将每个conan包的打包文件复制到rootfs中。 4. 集成uboot\kernel\rootfs构建出可用的目标镜像,目标镜像使用product的chip_model描述,当前仅支持`qemu_arm64`和`rk3506`两种,镜像关联的配置可以见schema文件`/usr/share/litebmc/schema/pdf.v1.json`说明。 !> qemu镜像构建时会向~/.conan2/profile安装名为`litebmc`的profile文件,组件构建时可以使用`-pr litebmc`参数指定使用qemu的构建工具完成交叉编译。 !> 构建工具安装在`.temp/tools/compiler`目录,删除.temp将导致交叉编译工具不可用。 构建rk3506产品包(luckfox lyra plus B)的命令示例: ```bash # 克隆litebmc仓源码 git clone https://gitee.com/litebmc/litebmc.git # 进入rk3506镜像配置目录 cd litebmc/rk3506 # 查看构建策略配置文件 ls manifest.yml # 启动构建 lbk build # 生成的文件在.temp/output/目录 ls .temp/output/firmware.img ``` ?> 参考lockfox官方指南完成镜像烧录: [镜像烧录](https://wiki.luckfox.com/zh/Luckfox-Lyra/Image-flashing/) ### 组件构建 组件构建的命令是`lbk build`,需要在组件源码目录执行,因为构建时需要记录源码的scm信息(含源码url和commit id),要求组件使用git管理源码并正确初始化`.git`。 可以使用`lbk build --help`查看组件构建的帮助: ```bash usage: lbk [-h] [-t BUILD_TYPE] [-pr PROFILE] [-pr:b PROFILE_BUILD] [-ur] [-up] [-s] [-r REMOTE] [-c CHANNEL] [-o PKG_OPTIONS] [-cv CODEGEN_VERSION] Build component options: -h, --help show this help message and exit -t BUILD_TYPE, --build_type BUILD_TYPE Build type(Same as conan's settings.build_type), only Debug,Release can be accepted -pr PROFILE, --profile PROFILE Apply the specified profile to the host machine, default value: default -pr:b PROFILE_BUILD, --profile_build PROFILE_BUILD Apply the specified profile to the build machine, default value: default -ur, --upload_recipe Upload recipe to remote -up, --upload_package Upload package to remote -s, --from_source Build all depencencies component from source -r REMOTE, --remote REMOTE Conan仓别名(等同conan的-r选项) -c CHANNEL, --channel CHANNEL Provide a channel if not specified in mds/package.yml default value: dev -o PKG_OPTIONS, --pkg_options PKG_OPTIONS Define options values (host machine), e.g.: -o pkg/*:shared=True -cv CODEGEN_VERSION, --codegen_version CODEGEN_VERSION must less than or equal to 5.4, default: 5.4 codegen versions: - 5.3: compatible with lb_base/[>=0.8.5 <0.9.0], 支持32位操作系统 - 5.4: compatible with lb_base/[>=0.9.0 <0.10.0], LBInterface增加alias ``` 其中: * `-t`: 构建类型,只支持debug和release,release包 参考: [Building for multiple configurations: Release, Debug, Static and Shared](https://docs.conan.io/2.0/tutorial/consuming_packages/different_configurations.html) * `-pr`:指定conan构建的profile文件,如构建 [产品仓](https://gitee.com/litebmc/litebmc.git)的litebmc产品包时会自动安装profile文件`litebmc`,就可以使用`-pr litebmc`指定产品配置的profile文件完成交叉编译。 参考:[profile官方文档](https://docs.conan.io/2/reference/config_files/profiles.html) * `-ur`: 将构建出的软件recipe发布到`-r`参数指定的conan仓 ?> lbkit的官方仓只上传了组件的recipe,由开发者在本地环境自动从源码构建了package * `-up`: 将构建出的软件recipe和package发布到`-r`参数指定的conan仓。 * `-c`: 完整的conan包名格式为`name/version@user/channel`,如`lb_base/0.3.0@litebmc/stable`。 `-c` 参数指定软件包的`channel`,默认为`dev`。 如果指定为`release`时将忽略`@user/channel`部分,包名为`name/version`,如`lb_base/0.3.0`。 * `-o`: conan包使用`options`控制组件的特性,如是否构建共享库、使能某个特性等,lbkit使用`-o`向组件传递特性,如`-o glib/*:shared=False`将控制glib组件编译出静态库。 ?> 参考 [conan options](https://docs.conan.io/2/reference/conanfile/attributes.html#options) * `-cv`: 自动生成工具的版本号,此版本号将向所有组件包括dbus接口组件传递,用于在构建过程中自动生成C代码。 ?> litebmc的dbus接口组件包中不包含c代码,在编译时会调用自动生成工具完成代码生成,使用版本号控制生成的代码。 组件构建示例: ```bash git clone https://gitee.com/litebmc/lb_example_app.git cd lb_example_app # 构建lb_base x86_64包,使用profile文件为`default` lbk build -c release # 查看构建制品文件,结果示例:.temp/rootfs/opt/litebmc/apps/lb_example_app/lb_example_app: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=8a6064a058ce2cb6a2b15e6536cb08a24e3f09aa, for GNU/Linux 3.2.0, with debug_info, not stripped file .temp/rootfs/opt/litebmc/apps/lb_example_app/lb_example_app # 构建lb_base arm64包,使用profile文件为产品构建时安装的qemu arm64编译器配置`litebmc` lbk build -c release -pr litebmc # 查看构建制品文件,结果示例: .temp/rootfs/opt/litebmc/apps/lb_example_app/lb_example_app: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 6.1.0, with debug_info, not stripped file .temp/rootfs/opt/litebmc/apps/lb_example_app/lb_example_app # 构建lb_base arm包,使用profile文件为产品构建时安装的rk3506 arm编译器配置`rk3506` lbk build -c release -pr rk3506 # 查年构建制品文件,结果示例:.temp/rootfs/opt/litebmc/apps/lb_example_app/lb_example_app: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, with debug_info, not stripped file .temp/rootfs/opt/litebmc/apps/lb_example_app/lb_example_app # 发布lb_base包 lbk build -c release -ur ``` ### 组件测试 组件测试的命令是`lbk test`,命令参数基本与`lbk build`相同,可以使用`lbk test --help`查看帮助。 ```bash If you just want to execute the binary program, run the -e parameter usage: lbk [-h] [-t BUILD_TYPE] [-pr PROFILE] [-pr:b PROFILE_BUILD] [-ur] [-up] [-s] [-r REMOTE] [-c CHANNEL] [-o PKG_OPTIONS] [-cv CODEGEN_VERSION] Build component options: -h, --help show this help message and exit -t BUILD_TYPE, --build_type BUILD_TYPE Build type(Same as conan's settings.build_type), only Debug,Release can be accepted -pr PROFILE, --profile PROFILE Apply the specified profile to the host machine, default value: default -pr:b PROFILE_BUILD, --profile_build PROFILE_BUILD Apply the specified profile to the build machine, default value: default -ur, --upload_recipe Upload recipe to remote -up, --upload_package Upload package to remote -s, --from_source Build all depencencies component from source -r REMOTE, --remote REMOTE Conan仓别名(等同conan的-r选项) -c CHANNEL, --channel CHANNEL Provide a channel if not specified in mds/package.yml default value: dev -o PKG_OPTIONS, --pkg_options PKG_OPTIONS Define options values (host machine), e.g.: -o pkg/*:shared=True -cv CODEGEN_VERSION, --codegen_version CODEGEN_VERSION must less than or equal to 5.4, default: 5.4 codegen versions: - 5.3: compatible with lb_base/[>=0.8.5 <0.9.0], 支持32位操作系统 - 5.4: compatible with lb_base/[>=0.9.0 <0.10.0], LBInterface增加alias ``` ?> 可以指定`-e`参数仅运行`package.yml`文件的`package_info.bins`配置项指定的可执行程序,参考示例 [lb_example_app的package.yml配置](https://gitee.com/litebmc/lb_example_app/blob/master/metadata/package.yml) 组件测试示例: ```bash git clone https://gitee.com/litebmc/lb_example_app.git cd lb_example_app # 执行组件测试 lbk test ```