当前位置: 首页 > 科技观察

开始!友好的armNanoPiM1Plus移植了Openharmony标准版

时间:2023-03-21 21:30:09 科技观察

更多信息请访问:与华为官方共建的鸿蒙技术社区https://harmonyos.51cto.com首先感谢永恒666分享4412开发板子移植openharmony3.0标准版——原来移植ohos也可以这么简单!本文参考此方法在友军armNanoPiM1Plus上移植了Openharmony标准版。整理方法如下:1OpenHarmonyLinux内核移植参考:OpenHarmonyLinux内核快速移植方法1.根据BuildingU-bootandLinuxforH5/H3/H2+/zh获取NanoPiM1Plus内核,主要步骤如下:1.1安装交叉编译器下载交叉编译器arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz,然后解压编译器:$mkdir-p/opt/FriendlyARM/toolchain$tarxfarm-cortexa9-linux-gnueabihf-4.9.3。tar.xz-C/opt/FriendlyARM/toolchain/然后把编译器的路径添加到PATH中,用vi编辑vi~/.bashrc,在最后添加如下内容,建议在重启前使用如下每次终端命令方法:$exportPATH=/opt/FriendlyARM/toolchain/4.9.3/bin:$PATH$exportGCC_COLORS=auto在当前shell窗口执行~/.bashrc脚本使设置立即生效。请注意,有一个“。”空格:$.~/.bashrc这个编译器是64位的,不能在32位的Linux系统上运行。安装完成后,可以快速验证是否安装成功:$arm-linux-gcc-vgccversion4.9.3(ctng-1.21.0-229g-FA)1.2编译Linux内核下载NanoPiM1PlusLinux4.14内核源码来自编译好的ipcamera_hispark_taurus源码,并切换分支:我的ohos3.0路径是/home/soon/ohos300/,把这个路径换成你自己的$cd/home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp$gitclonehttps://github.com/friendlyarm/linux.git-bsunxi-4.14.y--depth1$mvlinuxlinux-nanopi编译确认环境没有问题:$sudoapt-getinstallu-boot-tools$cd/家/很快/ohos300/出/KERNEL_OBJ/kernel/src_tmp/linux-nanopi$touch.scmversion$makesunxi_defconfigARCH=armCROSS_COMPILE=arm-linux-$makezImagedtbsARCH=armCROSS_COMPILE=arm-linux-编译完成后会在arch/arm/boot/目录下生成zImage,并在arch中/arm/boot/dts/目录下生成一个dtb文件2.内核态基础代码的迁移从OpenHarmony3.0内核代码目录kernel/linux/linux-4.19/drivers复制如下路径代码/staging到kernel/src_tmp/linux-nanopi/drivers/staging下的out/KERNEL_OBJ/。驱动程序/staging/hilogdrivers/staging/hieventsoon@soon-u20:~/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/drivers/staging$ls-altotal224drwxrwxr-x52soonsoon4096December2922:51.drwxrwxr-x132soon12soon3940.drwxrwxr-x4soonsoon4096Dec2922:51androiddrwxrwxr-x2soonsoon4096Dec2919:24board-rw-rw-r--1soonsoon628Dec2922:51built-in.o-rw-rw-r--1soonsoon2512Dec2922:51。.o.cmddrwxrwxr-x3soonsoon409612月2919:24ccreedrwxrwxr-x2soonsoon409612月2919:24clocking-wizarddrwxrwxr-x4soonsoon409612月2919:24comedidrwxrwxr-x2soonsoon409612月2919:24dgncdrwxrwxr-x2soonsoon409612月2919:24emxx_udcdrwxrwxr-x2soonsoon409612月2922:51fbtftdrwxrwxr-x3soonsoon409612月2919:24fsl-dpaa2drwxrwxr-x4soonsoon409612月2919:24fsl-mcdrwxrwxr-x2soonsoon409612月2919:24fwserialdrwxrwxr-x2soonsoon409612月2919:24gdm724xdrwxrwxr-x2soonsoon409612月2919:24goldfishdrwxrwxr-x4soonsoon409612月2919:24greybusdrwxrwxr-x2soonsoon409612月2919:24gs_fpgabootdrwxr-xr-x2soonsoon409612月2919:49hieventdrwxr-xr-x2soonsoon409612月2919:49hilog在三方内核的drivers/staging/Kconfig文件中添加如下代码:source"drivers/staging/hilog/Kconfig"source"drivers/staging/hievent/Kconfig"在中打开对应的CONFIG控件kernelconfigitemMacros:CONFIG_HILOGandCONFIG_HIEVENTCONFIG_HILOG=yCONFIG_HI_LOG_BUFFER_SIZE=2048CONFIG_HIEVENT=y3KernelstatemandatoryfeatureHDFtransplantation3.1打HDFpatch因为patch_hdf.sh是最近上传的,如果用repo下载的话,先update/home/soon/ohos300/drivers/adapter/khdf/linux目录也可以下载下来,替换成整个仓库。update命令可以在给Linux内核打HDF补丁的时候使用下面的gitpullgitcheckoutmaster执行打补丁的shell脚本来合并HDF补丁。配置HDF补丁脚本的三个可变参数。获取patch_hdf.sh脚本。执行patch_hdf.sh脚本,依次传入三个可变参数。patch_hdf.sh脚本三个参数的含义分别为:第一个入参为项目根目录路径,第二个入参为内核目录路径,第三个入参为hdf补丁文件。./patch_hdf.sh[项目根目录路径][内核目录路径][hdf补丁文件]我这里使用的指令如下/home/soon/ohos300/drivers/adapter/khdf/linux/patch_hdf.sh\/home/soon/ohos300\/home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi\/home/soon/ohos300/kernel/linux/patches/linux-4.19/hi3516dv300_patch/hdf.patch3.2配置config提供HDF基本配置,如需其他功能,通过menuconfig打开相应的驱动开关即可。HDF补丁执行成功后,默认HDF开关是关闭的,打开HDF基本配置选项如下:CONFIG_DRIVERS_HDF=yCONFIG_HDF_SUPPORT_LEVEL=2CONFIG_DRIVERS_HDF_PLATFORM=yCONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI=yCONFIG_DRIVERS_HDF_PLATFORM_GPIO=yCONFIG_DRIVERS_HDF_PLATFORM_I2C=yCONFIG_DRIVERS_HDF_PLATFORM_UART=yCONFIG_DRIVERS_HDF_TEST=y4打开内核的一些关键配置4.1打开AndroidDrivers和AndroidBinderIPCDriverDeviceDrivers—>Android—>[]AndroidDrivers(open)[]AndroidBinderIPCDriver(open)4.2OpenSELinuxSupportrelatedconfigurationreferenceLiangzili’sarrangement,RaspberryPi4BportedOHOS3.0LTSstandardsystemcanbeinmakemenuconfigNext,use/toexecutethesearchkeywordtoseethelocationanddependenciesoftheconfigurationitems.Youcanalsorefertothearticleattachmentconfiguration.5RecompileandgeneratezImageanddtbconfigurationanddirectlyexecutethefollowingcommand:$makezImagedtbsARCH=armCROSS_COMPILE=arm-linux-Aftercompiling,zImagewillbegeneratedinarch/arm/boot/directory,andarch/arm/boot/dts/Thedtbfileisgeneratedinthedirectory.Copythesetwofilesforlateruse.2Synthesizeboot.img1.CopythebootpartitionofNanoPiM1Plusto~/ohos300/out/ohos-arm-release/packages/phone/boot/.ItcanbecopiedfromthemadeSDcard.HowtomakeanSDbootcardrefertoNanoPiM1Plus4.3.3.1BurningtoTFcard.2.替换zImage和dtb文件cp-f/home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/arch/arm/boot/zImage/home/soon/ohos300/out/ohos-arm-release/packages/phone/boot/cp-f/home/soon/ohos300/out/KERNEL_OBJ/kernel/src_tmp/linux-nanopi/arch/arm/boot/dts/sun8i-*-nanopi-*.dtb/home/soon/ohos300/out/ohos-arm-release/packages/phone/boot/3.用build_boot.py生成boot.img参考树莓派rpi3的device\rpi3\rpi3\kernel\build_kernel.py脚本,修改:#!/usr/bin/envpython3importsysimportosimportos.pathimportsubprocessimportmultiprocessingimportshutilimportpathlibbootimgsize=64*1024*1024command=sys.argv[1]output_dir=sys.argv[2]defmake_boot_img():oldpwd=os.getcwd()os.chdir(output_dir)imagefile='图像/boot.img'imagefile_tmp=imagefile+'.tmp'boot_dir='boot'withopen(imagefile_tmp,'wb')aswriter:writer.truncate(bootimgsize)subprocess.run(F'mkfs.vfat{imagefile_tmp}-nBOOT',shell=True,check=True)subprocess.run(F'mcopy-i{imagefile_tmp}{boot_dir}/*::/',shell=True,check=True)os.rename(imagefile_tmp,imagefile)os.chdir(oldpwd)command_table={'bootimg':make_boot_img,}command_table[command]()将build_boot.py放入~/ohos300执行以下命令生成boot.img,soon@soon-u20:~/ohos300$python3build_boot.pybootimg/home/soon/ohos300/out/ohos-arm-release/packages/phonemkfs.fat4.1(2017-01-24)三合一SD卡烧录img参考MakeImageFilesforH31DownloadBuildansd卡镜像环境gitclonehttps://github.com/friendlyarm/sd-fuse_h3.gitcdsd-fuse_h3wgethttp://112.124.9.243/dvdfiles/H3/images-for-eflasher/friendlycore-focal_4.14_armhf.tgztarxvzfriendly-focal_4.14tg_armhf。为之前编译的树莓派rpi3img准备system.img、vendor.img、userdata.img,删除friendlycore-focal_4.14_armhf下的.img,删除之前合并的boot.img、system.img,复制vendor.img和userdata.img到这个目录3修改partmap.txt#sd0partitionmap#flash=.:::,#supportdevice:eeprom,nand,mmc#supportfstype:2nd,boot,raw,fat,ext4,ubi##CPU=h3flash=mmc,0:boot0:raw:0x2000,0x17FE000:u-boot-sunxi-with-spl.bin;flash=mmc,0:boot:fat:0x1800000,0x4000000:boot.img;flash=mmc,0:system:ext4:0x5800000,0x20000000:system.img;flash=mmc,0:vendor:ext4:0x025800000,0x4000000:vendor.img;flash=mmc,0:userdata:ext4:0x29800000,0x12C00000:用户数据.img;4合成SD卡烧录img,在sd-fuse_h3目录下执行:sudo./mk-sd-image.shfriendlycore-focal_4.14_armhfh3-sd-friendlycore.imgsoon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3$sudo./mk-sd-image.shfriendlycore-focal_4.14_armhfh3-sd-friendlycore.img[sudo]passwordforsoon:CreatingRAWimage:out/h3-sd-friendlycore.img(7800MB)---------------------------------0+0recordsin0+0recordsout0bytescopied,0.0010239s,0.0kB/sUsingdevice:/dev/loop14--------------------------------Friendlycore-focal_4.14_armhfilesystemfusingImageroot:./friendlycore-focal_4.14_armhf--------------------------------------------------------------[/dev/loop14]capacity=7438MB,7799999488bytescurrent/dev/loop14partition:MBR.0start:0x0000100000size0x01d0da8c00kB----------------------------------------------------------解析./friendlycore-focal_4.14_armhf/partmap.txt:part.0flash=mmc,0:boot0:raw:0x2000,0x17fe000:u-boot-sunxi-with-spl.bin:[RAW]./friendlycore-focal_4.14_armhf/u-boot-sunxi-with-spl.binpart.1flash=mmc,0:boot:fat:0x1800000,0x4000000:boot.img:[MBR]./friendlycore-focal_4.14_armhf/boot.imgpart.2flash=mmc,0:system:ext4:0x5800000,0x20000000:system.img:[MBR]./friendlycore-focal_4.14_armhf/system.imgpart.3flash=mmc,0:vendor:ext4:0x25800000,0x4000000:vendor.img:[MBR]./friendlycore-focal_4.14_armhf/vendor.imgpart.4flash=mmc,0:userdata:ext4:0x29800000,0x12c00000:userdata.img:[MBR]./friendlycore-focal_4.14_armhf/用户数据.img----------------------------------------------------------------createNewmbr4:[MBR.0]开始:0x0001800000Size0x0004000000[MBR.1]开始:0x0005800000SIZE0X0020000000[MBR.2]开始:0x0025800000SIZE0X000SIZE0X000X000400000000000000000000000000000000000000000000来------------------------------------------------------------copyfrom:./friendlycore-focal_4.14_armhfto/dev/loop14[RAW.0]:2040KB|./friendlycore-focal_4.14_armhf/u-boot-sunxi-with-spl.bin>100%:done.[MBR.0]:65536KB|./friendlycore-focal_4.14_armhf/boot.img>100%:done.[MBR.1]:524288KB|./friendlycore-focal_4.14_armhf/system.img>100%:done.[MBR.2]:65536KB|./friendlycore-focal_4.14_armhf/vendor.img>100%:done.[MBR.3]:307200KB|./friendlycore-focal_4.14_armhf/userdata.img>21100%:done.--------------------------------------------------------------/dev/loop14:msdospartitions1234###trytoresize2fs:/dev/loop14p3resize2fs1.45.5(07-Jan-2020)文件系统已经准备好16384(4k)blockslong.Nothingtodo!--------------------------------Friendlycore-focal_4.14_armhfisfusedsuccessfully.Alldone.--------------------------------RAWimagesuccessfullycreated(23:44:53).-rw-r--r--1rootroot7799999488December3023:44out/h3-sd-friendlycore.imgTip:Youcancompressittosavediskspace.soon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3$将在out目录中生成imgsoon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3/out$ls-altotal964620drwxrwxr-x2soonsoon4096Dec3023:46。rw-r--r--1rootroot7799999488December3023:44h3-sd-friendlycore.imgsoon@soon-u20:~/nanopi-m1-plus/sd-fuse_h3/out$5刻录img,可以用dd或者Win32DiskImager,dd的命令如下:sudoddif=out/h3-sd-friendlycore.imgbs=1Mof=/dev/sdX更多信息请访问:与华为官方共建的鸿蒙技术社区https://harmonyos.51cto.com