野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 375|回复: 2

[经验\资料] 鲁班猫4移植UEFI+grub引导

[复制链接]
发表于 2025-12-14 15:53:57 | 显示全部楼层 |阅读模式
本帖最后由 OrionisLi 于 2025-12-16 00:58 编辑

0x01 效果展示
uefi.png
图1-1 鲁班猫4UEFI界面
grub.png
图1-2 grub引导选择界面
目前完成测试的是Ubuntu 24.04和Ubuntu 22.04。
缺点是……内核没有主线支持(或者说有,但支持不太行),在制作完base之后需要手动安装BSP内核和固件。


0x02 需要准备什么

1. Ubuntu 22.04/24.04/25.04/26.04随便一个,不要太低。ArchLinux可以用后期制作镜像,但编译UEFI还是建议使用Ubuntu

2. 一个可以连接国际互联网的工具(在这里不做详细介绍)

3. 一张16GB以上的Class 10以上的SD卡(装一个救援系统在上面)

4. 串口调试软件和UART/TTL调试板(看日志用,看看会亖在哪一步)

5. 鲁班猫4(……没啥好说的)

6. 一根TypeC转USB数据线或者TypeC充电线(一定要带数据传输功能,建议直接把手机充电线薅下来用)

7. 镊子或别的又长又尖的东西(如果加散热模组了需要用镊子或者别的东西戳MaskRom按键)【可选】

8. 脑子

9. Google/Bing,Not Baidu(没错!我就在嘲讽百度

0x03 制作镜像
编译好的可以直接clone下来刷写:https://github.com/LemonFan-maker/LBC4-uefi-emmc-boot
1. 安装依赖
sudo apt-get install -y \
    acpica-tools \
    binutils-aarch64-linux-gnu \
    build-essential \
    device-tree-compiler \
    gettext \
    git \
    gcc-aarch64-linux-gnu \
    libc6-dev-arm64-cross \
    python3 \
    python3-pyelftools \
    uuid-dev
剩下的还差啥直接bing问问吧,我忘记了。

2. 拉取仓库
https://github.com/LemonFan-maker/edk2-rk3588-lubancat4
https://github.com/rockchip-linux/rkbin
https://github.com/u-boot/u-boot
之后需要cd edk2-rk3588-lubancat4 && git submodule update --init --recursive

3. 编译
1)编译UEFI
cd edk2-rk3588-lubancat4 && ./build.sh -d lbc-4 && cp ./workspace/BL33_AP_UEFI.Fv ./
2)编译Kernel
./build.sh kernel
只需要跑到DTB完成即可。
cp <SDK绝对路径>/<编译的kernel>/arch/arm64/boot/dts/rockchip/rk3588s-lubancat-4.dtb ./
3)编译uboot
制作配置
make rock5a-rk3588s_defconfig && make menuconfig
搜索CONFIG_SYS_MALLOC_F_LEN,设置为0x80000
搜索CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN,设置为0x1000000
export ROCKCHIP_TPL=../rkbin/bin/rk35/rk3588_ddr_lp4_2112MHz_lp5_2400MHz_v1.19.bin
export BL31=../rkbin/bin/rk35/rk3588_bl31_v1.51.elf
make CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc) &&cp idbloader.img ../

4. 复制一个文件
cp <鲁班猫SDK绝对路径>/rkbin/bin/rk35/rk3588_bl31_v1.48.elf ./ && cp ./rkbin/bin/rk35/rk3588_bl32_v1.20.bin ./
制作一个loader文件:
cd rkbin
./tools/boot_merger RKBOOT/RK3588MINIALL.ini
cp rk3588_spl_loader_v1.19.113.bin ../
现在../应该有rk3588_spl_loader_v1.19.113.bin、rk3588_bl31_v1.48.elf、rk3588_bl32_v1.20.bin、idbloader.img、rk3588s-lubancat-4.dtb、BL33_AP_UEFI.Fv

5. 切割
readelf -l rk3588_bl31_v1.48.elf

Elf 文件类型为 EXEC (可执行文件)
Entry point 0x40000
There are 4 program headers, starting at offset 64

程序头:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000010000 0x0000000000040000 0x0000000000040000
                 0x000000000003203c 0x000000000007e000  RWE    0x10000
  LOAD           0x0000000000050000 0x00000000000f0000 0x00000000000f0000
                 0x0000000000006000 0x0000000000006000  R      0x10000
  LOAD           0x0000000000060000 0x00000000ff100000 0x00000000ff100000
                 0x0000000000009000 0x0000000000009000  RWE    0x10000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10

Section to Segment mapping:
  段节...
   00     ro .data stacks .bss xlat_table
   01     .ddr_m0_bin
   02     .text_pmusram
   03     

按照三个LOAD的位置切割:
dd if=bl31.elf of=bl31_0x40000.bin bs=1 skip=$((0x10000)) count=$((0x3203c))
dd if=bl31.elf of=bl31_0xf0000.bin bs=1 skip=$((0x50000)) count=$((0x6000))
dd if=bl31.elf of=bl31_0xff100000.bin bs=1 skip=$((0x60000)) count=$((0x9000))
得到三个bl31_0x*的文件。

6. 拼接
mainline_uefi.its文件

/dts-v1/;

/ {
    description = "LubanCat 4 UEFI for Mainline SPL";
    #address-cells = <1>;

    images {
        /* UEFI 本体 */
        uefi {
            description = "UEFI Firmware";
            data = /incbin/("./BL33_AP_UEFI.Fv");
            type = "standalone";
            arch = "arm64";
            os = "U-Boot";
            compression = "none";
            load = <0x00200000>;
        };
        /* ATF (BL31) - Main */
        atf-1 {
            description = "ARM Trusted Firmware - Main";
            data = /incbin/("./bl31_0x40000.bin");
            type = "firmware";
            arch = "arm64";
            os = "arm-trusted-firmware";
            compression = "none";
            load = <0x00040000>;
            entry = <0x00040000>;
        };

        atf-2 {
            description = "ARM Trusted Firmware - PMU";
            data = /incbin/("./bl31_0xf0000.bin");
            type = "firmware";
            arch = "arm64";
            os = "arm-trusted-firmware";
            compression = "none";
            load = <0x000f0000>;
        };

        atf-3 {
            description = "ARM Trusted Firmware - M0";
            data = /incbin/("./bl31_0xff100000.bin");
            type = "firmware";
            arch = "arm64";
            os = "arm-trusted-firmware";
            compression = "none";
            load = <0xff100000>;
        };

        /* OP-TEE节点 */
        optee {
            description = "OP-TEE";
            data = /incbin/("./rk3588_bl32_v1.20.bin");
            type = "firmware";
            arch = "arm64";
            os = "tee";
            compression = "none";
            load = <0x08400000>;
            entry = <0x08400000>;
        };

        /* DTB */
        fdt {
            description = "RK3588 DTB";
            data = /incbin/("./rk3588s-lubancat-4.dtb");
            type = "flat_dt";
            arch = "arm64";
            compression = "none";
            load = <0x04000000>;
        };
    };

    configurations {
        default = "conf";
        conf {
            description = "LubanCat 4 Boot";
            firmware = "atf-1";
            /* 加入"optee" */
            loadables = "optee", "atf-2", "atf-3", "fdt", "uefi";
        };
    };
};


mkimage -f mainline_uefi.its u-boot.itb生成镜像。

7. 烧录
sudo rkdeveloptool db ./rk3588_spl_loader_v1.19.113.bin

sudo rkdeveloptool wl 64 idbloader.img && sudo rkdeveloptool wl 0x4000 u-boot.itb && sudo rkdeveloptool rd

烧录完之后直接在串口软件中看日志,应该是可以直接进入UEFI界面的。
原理下次有机会再聊。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2026-1-27 05:46 , Processed in 0.078564 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表