暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

s32g - 编译制作启动镜像

囧囧妹 2022-07-23
719

点击上方蓝字【囧囧妹】一起学习,一起成长!

一、基于Yocto编译Linux BSP

1)安装repo工具

mkdir ~/bin

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo

chmod a+x ~/bin/repo

PATH=${PATH}:~/bin


2)配置自己的Git环境变量

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

 


3)下载Yocto开发环境

mkdir fsl-auto-yocto-bsp

cd fsl-auto-yocto-bsp

python3 home/djnakata/bin/repo init -u https://source.codeaurora.org/external/autobsps32/auto_yocto_bsp -b release/bsp30.0 --repo-url='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'


python3 home/djnakata/bin/repo sync


下载完Yocto开发环境之后,接着进行编译


4)编译

建立Yocto编译环境(只需要第一次执行)

       ./sources/meta-alb/scripts/host-prepare.sh


创建编译目录并指定所需要运行的平台

       source nxp-setup-alb.sh -m s32g274ardb2


 启动bitbake编译命令    

       bitbake fsl-image-base


    编译完毕之后,所需的目标文件存放在build_s32g274ardb2/tmp/deploy/images/s32g274ardb2下面


二、单独编译U-Boot (非Yocto,需要单独下载arm build toolchains)

1) 下载源代码

git clone https://source.codeaurora.org/external/autobsps32/u-boot

cd u-boot

git checkout -b bsp30.0-2020.04 bsp30.0-2020.04


2)编译

make CROSS_COMPILE=/path/to/your/toolchain/dir/bin/aarch64-none-linux-gnu-  s32g274ardb2

_defconfig


make CROSS_COMPILE=/path/to/your/toolchain/dir/bin/aarch64-none-linux-gnu-


三、单独编译Linux Kernel(非Yocto,需要单独下载arm build toolchains)

1) 下载源代码

git clone https://source.codeaurora.org/external/autobsps32/linux

cd linux


git checkout -b bsp30.0-5.10.41-rt bsp30.0-5.10.41-rt


2)编译

make ARCH=arm64 CROSS_COMPILE=/path/to/your/toolchain/dir/bin/aarch64-none-linux-gnu- s32gen1_defconfig


make ARCH=arm64 CROSS_COMPILE=/path/to/your/toolchain/dir/bin/aarch64-none-linux-gnu-


编译好的image位于arch/arm64/boot目录下面,dtb文件位于arch/arm64/boot/dts/freescale目录下面


四、制作Boot镜像

1. SD卡方式

1) 如果是从Yocto进行编译,编译完成的image文件fsl-image-base-s32g274ardb2.sdcard位于build_s32g274ardb2/tmp/deploy/images/s32g274ardb2


然后使用dd命令进行burn up


sudo dd if=./fsl-image-base-s32g274ardb2.sdcard of=/dev/sdd bs=1M && sync


2) 如果想手动进行拷贝,需执行如下操作:


SD卡将分为两个分区:一个用于放置kernel与DTB文件;一个用于放置根文件系统, 如下:

sudo fdisk dev/sdd


Welcome to fdisk (util-linux 2.31.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.



Command (m for help): p

Disk dev/sdd: 14.5 GiB, 15552479232 bytes, 30375936 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes 512 bytes

I/O size (minimum/optimal): 512 bytes 512 bytes

Disklabel type: dos

Disk identifier: 0x1a3401e2


Command (m for help): n

Partition type

   p   primary (0 primary, 0 extended, 4 free)

   e   extended (container for logical partitions)

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-30375935, default 2048): 8192

Last sector, +sectors or +size{K,M,G,T,P} (8192-30375935, default 30375935): +255M


Created a new partition 1 of type 'Linux' and of size 255 MiB.


Command (m for help): p

Disk dev/sdd: 14.5 GiB, 15552479232 bytes, 30375936 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes 512 bytes

I/O size (minimum/optimal): 512 bytes 512 bytes

Disklabel type: dos

Disk identifier: 0x1a3401e2


Device     Boot Start    End Sectors  Size Id Type

/dev/sdd1        8192 530431  522240  255M 83 Linux


Command (m for help): n

Partition type

   p   primary (1 primary, 0 extended, 3 free)

   e   extended (container for logical partitions)

Select (default p): p

Partition number (2-4, default 2): 2

First sector (2048-30375935, default 2048): 530432   

Last sector, +sectors or +size{K,M,G,T,P} (530432-30375935, default 30375935): 


Created a new partition 2 of type 'Linux' and of size 14.2 GiB.


Command (m for help): p

Disk dev/sdd: 14.5 GiB, 15552479232 bytes, 30375936 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes 512 bytes

I/O size (minimum/optimal): 512 bytes 512 bytes

Disklabel type: dos

Disk identifier: 0x1a3401e2


Device     Boot  Start      End  Sectors  Size Id Type

/dev/sdd1         8192   530431   522240  255M 83 Linux

/dev/sdd2       530432 30375935 29845504 14.2G 83 Linux


Command (m for help): t

Partition number (1,2, default 2): 1

Hex code (type L to list all codes): c


Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.


Command (m for help): t

Partition number (1,2, default 2): 2

Hex code (type L to list all codes): 83


Changed type of partition 'Linux' to 'Linux'.


Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

 


格式化新的两个分区,如下:

   sudo mkfs.vfat -n boot dev/sdd1


   sudo mkfs.ext3 -L rootfs dev/sdd2


拷贝Image到SD卡的相应分区中,如下:

   cd build_s32g274ardb2/tmp/deploy/images/s32g274ardb2


   sudo dd if=u-boot.s32 of=/dev/sdd conv=notrunc bs=256 count=1 seek=0


   sudo dd if=u-boot.s32 of=/dev/sdd conv=notrunc bs=512 seek=1 skip=1 (写u-boot到/dev/sdd)


   sudo mount dev/sdd1 media/


   sudo cp Image media (拷贝kernel image到/dev/sdd1)


   sudo cp fsl-s32g274a-rdb2.dtb media/fsl-s32g274a-rdb2.dtb (拷贝dtb文件到/dev/sdd1)


   sudo umount media


   sudo mount dev/sdd2 media


   sudo tar xf fsl-image-base-s32g274ardb2.tar.gz -C media  (拷贝根文件系统到/dev/sdd2)


   sudo umount media


2.QSPI方式

执行bitbake fsl-image-flash


生成.flashimage后缀的文件,整个进行烧写, 如下:


=> run flashbootargs

=> sf probe 6:0

=> setenv image fsl-image-flash-s32g274ardb2.flashimage

=> setenv loadaddr 0x85000000

=> run loadimage

=> sf erase ${uboot_flashaddr} +${filesize}

=> sf write ${loadaddr} ${uboot_flashaddr} ${filesize}


或者拷贝编译后生成的u-boot.s32, Image, fsl-s32g274a-rdb2.dtb,fsl-image-base-s32g274ardb2.cpio.gz.u-boot到SD卡中,然后在uboot命令行,通过如下命令进行烧写:


=> run flashbootargs

=> sf probe 6:0


1)u-boot


=> setenv image u-boot.s32


=> run loadimage


=> sf erase ${uboot_flashaddr} +${filesize}


=> sf write ${loadaddr} ${uboot_flashaddr} ${filesize}


2) linux kernel


=> setenv image Image


=> run loadimage


=> sf erase ${kernel_flashaddr} +${kernel_maxsize}


=> sf write ${loadaddr} ${kernel_flashaddr} ${kernel_maxsize}


3) Linux DTS


=> setenv image ${fdt_file}


=> run loadimage


=> sf erase ${fdt_flashaddr} +${fdt_maxsize}


=> sf write ${loadaddr} ${fdt_flashaddr} ${fdt_maxsize}


4) Linux filesystem


=> setenv Image fsl-image-base-s32g274ardb2.cpio.gz.u-boot


=> run loadimage

=> sf erase ${ramdisk_flashaddr} +${ramdisk_maxsize}

重新开机,然后使用QSPI的方式启动

原文链接:https://blog.csdn.net/RushDJ/article/details/125163399



觉得不错,点击“分享”,“赞”,“在看”传播给更多热爱嵌入式的小伙伴吧!

文章转载自囧囧妹,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论