Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt yocto-4.3, add edk2 build #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 56 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,81 @@

## 构建

### 准备源码
### 1.准备源码

运行以下命令,克隆相关软件仓库:

```
mkdir -p loong-yocto/downloads
cd loong-yocto
git clone https://github.com/openembedded/bitbake.git
git clone https://github.com/openembedded/openembedded-core.git
git clone https://git.yoctoproject.org/poky.git
git clone https://github.com/loongarch64/meta-loongarch.git
基于WSL2 Debian构建,安装相关包,**使用非root用户编译**
``` shell
sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev python3-subunit mesa-common-dev zstd liblz4-tool file locales tmux
```

- `downloads` 目录用于保存下载的软件源代码,可在多次构建之间共享。

### 构建发行版

`build.sh` 默认会构建 `OpenEmbedded` 发行版,同时也支持构建 `Poky` 发行版。

可通过设置环境变量 `DISTRO` 来明确指定发行版,比如:
a.克隆poky仓库,进入目录

``` shell
cd ~
git clone https://github.com/yoctoproject/poky.git
cd poky
```
cd loong-yocto
./meta-loongarch/build.sh # Default, to build OpenEmbedded distro
DISTRO=openembedded-core ./meta-loongarch/build.sh # Build the OpenEmbedded Distro
DISTRO=poky ./meta-loongarch/build.sh # Build the Poky Distro
b.基于yocto-4.3适配, 切换到对应tag
``` shell
git checkout -b loong yocto-4.3
```

### 构建目标

`build.sh` 脚本默认构建目标为 `core-image-minimal`, 可支持以下公共目标:
c.克隆loongarch bsp层
``` shell
git clone https://github.com/otomam/meta-loongarch.git
```

### 2.构建发行版
a.配置构建环境,使用loongarch的配置文件
``` shell
export TEMPLATECONF=$PWD/meta-loongarch/conf/templates/default
. oe-init-build-env
```
a.构建镜像
``` shell
bitbake core-image-minimal
``````
可选:
- core-image-minimal
- core-image-full-cmdline
- core-image-sato
- core-image-weston
- meta-toolchain
- meta-ide-support

要指定编译不同的目标,可通过设置环境变量 `TARGET` 来完成,比如:
#### 构建报错

##### 例如构建llvm-native报错
```shell
| g++: fatal error: Killed signal terminated program cc1plus
| compilation terminated.
```
cd loong-yocto
TARGET=core-image-full-cmdline ./meta-loongarch/build.sh
+ 可以单独编译并查看详细输出
```

## 调试

在编译发生错误时,可在 `build.sh` 脚本后面指定 build file,针对单一目标来构建,方便检查错误和调试。

当前支持以下几种用法:

bitbake llvm-native -v -D
```
./meta-loongarch/build.sh openembedded-core/meta/recipes-kernel/linux/linux-yocto_6.1.bb
./meta-loongarch/build.sh openembedded-core/meta/recipes-kernel/linux/linux-yocto_6.1.bb do_fetch
./meta-loongarch/build.sh openembedded-core/meta/recipes-kernel/linux/linux-yocto_6.1.bb:do_kernel_version_sanity_check
+ 这是在构建时内存不足导致的,可以单独构建或重复构建,或者根据实际情况减少并行编译的任务数或线程
```
# ./build/local.conf
BB_NUMBER_THREADS ='8'
PARALLEL_MAKE = "-j 8"
```

## 提示
### 3.虚拟机运行
+ **不带nographic参数可以同时看到串口输出和图形窗口**
``` shell
runqemu nographic serialstdio
```
+ **默认用户root,无密码**

qemu-system-longarch64需要bios。目前,edk2-loongarch提供了它的二进制代码。未来应更改为从上游拉取生成。Poky有ovmf配方,但目前还不支持loongarch。
##### 遇到报错
``` shell
runqemu - ERROR - Error: There are no available tap devices to use for networking,
runqemu - ERROR - and I see /etc/runqemu-nosudo exists, so I am not going to try creating
runqemu - ERROR - a new one with sudo.
```
##### 运行以下命令
``` shell
sudo ../scripts/runqemu-gen-tapdevs 1000 4
```
+ 作用:**Creating 4 tap devices for GID: 1000**
131 changes: 0 additions & 131 deletions build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion conf/layer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ BBFILE_PATTERN_meta-loongarch = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-loongarch = "6"

LAYERDEPENDS_meta-loongarch = "core"
LAYERSERIES_COMPAT_meta-loongarch = "mickledore"
LAYERSERIES_COMPAT_meta-loongarch = "nanbield mickledore"
13 changes: 13 additions & 0 deletions conf/templates/default/bblayers.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
##OEROOT##/meta \
##OEROOT##/meta-poky \
##OEROOT##/meta-yocto-bsp \
##OEROOT##/meta-loongarch \
"
19 changes: 19 additions & 0 deletions conf/templates/default/conf-notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

### Shell environment set up for builds. ###

You can now run 'bitbake <target>'

Common targets are:
core-image-minimal
core-image-full-cmdline
core-image-sato
core-image-weston
meta-toolchain
meta-ide-support

You can also run generated qemu images with a command like 'runqemu qemuloongarch64'.

Other commonly useful commands are:
- 'devtool' and 'recipetool' handle common recipe tasks
- 'bitbake-layers' handles common layer tasks
- 'oe-pkgdata-util' handles common target package tasks
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#MACHINE ?= "edgerouter"
#
# This sets the default machine to be qemux86-64 if no other machine is selected:
MACHINE ??= "qemux86-64"
MACHINE ??= "qemuloongarch64"

# These are some of the more commonly used values. Looking at the files in the
# meta/conf/machine directory, or the conf/machine directory of any additional layers
Expand Down Expand Up @@ -143,7 +143,8 @@ DISTRO ?= "poky"
# "debug-tweaks" - make an image suitable for development
# e.g. ssh root access has a blank password
# There are other application targets that can be used here too, see
# meta/classes/image.bbclass and meta/classes/core-image.bbclass for more details.
# meta/classes-recipe/image.bbclass and
# meta/classes-recipe/core-image.bbclass for more details.
# We default to enabling the debugging tweaks.
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"

Expand All @@ -162,7 +163,7 @@ USER_CLASSES ?= "buildstats"
# The build system can test booting virtual machine images under qemu (an emulator)
# after any root filesystems are created and run tests against those images. It can also
# run tests against any SDK that are built. To enable this uncomment these lines.
# See classes/test{image,sdk}.bbclass for further details.
# See meta/classes-recipe/test{image,sdk}.bbclass for further details.
#IMAGE_CLASSES += "testimage testsdk"
#TESTIMAGE_AUTO:qemuall = "1"

Expand Down Expand Up @@ -227,15 +228,21 @@ BB_DISKMON_DIRS ??= "\
# Yocto Project SState Mirror
#
# The Yocto Project has prebuilt artefacts available for its releases, you can enable
# use of these by uncommenting the following lines. This will mean the build uses
# use of these by uncommenting some of the following lines. This will mean the build uses
# the network to check for artefacts at the start of builds, which does slow it down
# equally, it will also speed up the builds by not having to build things if they are
# initially but it will then speed up the builds by not having to build things if they are
# present in the cache. It assumes you can download something faster than you can build it
# which will depend on your network.
# Note: For this to work you also need hash-equivalence passthrough to the matching server
# There is a choice between our sstate server directly and a faster content delivery network
# (CDN) kindly provided by JSDelivr, uncomment one of the SSTATE_MIRRORS lines, not both.
# Using the CDN rather than the yoctoproject.org address is suggested/preferred.
#
#BB_HASHSERVE_UPSTREAM = "hashserv.yocto.io:8687"
#SSTATE_MIRRORS ?= "file://.* http://sstate.yoctoproject.org/all/PATH;downloadfilename=PATH"
#SSTATE_MIRRORS ?= "file://.* http://cdn.jsdelivr.net/yocto/sstate/all/PATH;downloadfilename=PATH"
#
###SSTATE_MIRRORS ?= "file://.* http://sstate.yoctoproject.org/all/PATH;downloadfilename=PATH"


#
# Qemu configuration
Expand Down Expand Up @@ -280,7 +287,7 @@ PACKAGECONFIG:append:pn-qemu-system-native = " sdl"
# this doesn't mean anything to you.
CONF_VERSION = "2"

IMAGE_INSTALL:append = " edk2-loongarch"
EXTRA_IMAGEDEPENDS:append:qemuloongarch64 = " edk2-loongarch-native"
KERNEL_IMAGETYPE:qemuloongarch64 = "vmlinux.efi"
QB_DEFAULT_BIOS:qemuloongarch64 = "QEMU_EFI.fd"
EXTRA_IMAGEDEPENDS:remove:qemuloongarch64 = "u-boot"
Expand All @@ -289,4 +296,4 @@ QB_OPT_APPEND:qemuloongarch64 = "-device virtio-tablet-pci -device virtio-keyboa
QB_MEM:qemuloongarch64 = "-m 1024"
QB_NETWORK_DEVICE:qemuloongarch64 = "-device virtio-net-pci,netdev=net0,mac=@MAC@"
QB_ROOTFS_OPT:qemuloongarch64 = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-pci,drive=disk0"
QB_GRAPHICS:qemuloongarch64 = "-device virtio-vga -device qemu-xhci -device usb-kbd -device usb-mouse"
QB_GRAPHICS:qemuloongarch64 = "-device virtio-vga -device qemu-xhci -device usb-kbd -device usb-mouse"
Loading