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

WIP: add loongarch support #86

Open
wants to merge 5 commits 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
2 changes: 2 additions & 0 deletions meta/classes-recipe/kernel-arch.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ valid_archs = "alpha cris ia64 \
sh sh64 um h8300 \
parisc s390 v850 \
avr32 blackfin \
loongarch64 \
microblaze \
nios2 arc riscv xtensa"

Expand All @@ -34,6 +35,7 @@ def map_kernel_arch(a, d):
elif re.match('aarch64_be$', a): return 'arm64'
elif re.match('aarch64_ilp32$', a): return 'arm64'
elif re.match('aarch64_be_ilp32$', a): return 'arm64'
elif re.match('loongarch(32|64|)$', a): return 'loongarch'
elif re.match('mips(isa|)(32|64|)(r6|)(el|)$', a): return 'mips'
elif re.match('mcf', a): return 'm68k'
elif re.match('riscv(32|64|)(eb|)$', a): return 'riscv'
Expand Down
4 changes: 4 additions & 0 deletions meta/classes-recipe/siteinfo.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def siteinfo_data_for_machine(arch, os, d):
"i686": "endian-little bit-32 ix86-common",
"ia64": "endian-little bit-64",
"lm32": "endian-big bit-32",
"loongarch32": "endian-little bit-32 loongarch",
"loongarch64": "endian-little bit-64 loongarch",
"m68k": "endian-big bit-32",
"microblaze": "endian-big bit-32 microblaze-common",
"microblazeel": "endian-little bit-32 microblaze-common",
Expand Down Expand Up @@ -97,6 +99,8 @@ def siteinfo_data_for_machine(arch, os, d):
"arm-linux-musleabi": "arm-linux",
"armeb-linux-gnueabi": "armeb-linux",
"armeb-linux-musleabi": "armeb-linux",
"loongarch32-linux": "loongarch32-linux",
"loongarch64-linux": "loongarch64-linux",
"microblazeel-linux" : "microblaze-linux",
"microblazeel-linux-musl" : "microblaze-linux",
"mips-linux-musl": "mips-linux",
Expand Down
3 changes: 3 additions & 0 deletions meta/conf/distro/include/default-distrovars.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ DISTRO_FEATURES_DEFAULT:remove:arc = "seccomp"
# seccomp is not yet ported to microblaze
DISTRO_FEATURES_DEFAULT:remove:microblaze = "seccomp"

# seccomp is not yet ported to loongarch64
DISTRO_FEATURES_DEFAULT:remove:loongarch64 = "seccomp"

DISTRO_FEATURES_DEFAULT ?= "acl alsa bluetooth debuginfod ext2 ipv4 ipv6 pcmcia usbgadget usbhost wifi xattr nfs zeroconf pci 3g nfc x11 vfat seccomp"
DISTRO_FEATURES ?= "${DISTRO_FEATURES_DEFAULT}"
IMAGE_FEATURES ?= ""
Expand Down
2 changes: 2 additions & 0 deletions meta/conf/machine-sdk/loongarch64.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SDK_ARCH = "loongarch64"
ABIEXTENSION:class-nativesdk = ""
7 changes: 7 additions & 0 deletions meta/conf/machine/include/loongarch/arch-loongarch.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# LoongArch Architecture definition

DEFAULTTUNE ?= "loongarch64"

TUNE_ARCH = "${TUNE_ARCH:tune-${DEFAULTTUNE}}"
TUNE_PKGARCH = "${TUNE_PKGARCH:tune-${DEFAULTTUNE}}"
TUNE_CCARGS:append = "${@bb.utils.contains('TUNE_FEATURES', 'loongarch64', ' -march=la464 -mabi=lp64d', ' ', d)}"
35 changes: 35 additions & 0 deletions meta/conf/machine/include/loongarch/qemuloongarch.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PREFERRED_PROVIDER_virtual/bootloader ?= "u-boot"

require conf/machine/include/qemu.inc
require conf/machine/include/loongarch/tune-loongarch.inc

MACHINE_FEATURES = "screen keyboard ext2 ext3 serial"

KERNEL_IMAGETYPE = "vmlinuz"
KERNEL_IMAGETYPES += "vmlinuz"
KEEPUIMAGE = "no"

SERIAL_CONSOLES ?= "115200;ttyS0 115200;hvc0"

IMAGE_FSTYPES += "ext4 wic.qcow2"

WKS_FILE ?= "qemuloongarch.wks"

MACHINE_EXTRA_RRECOMMENDS += " kernel-modules"

#EXTRA_IMAGEDEPENDS += "opensbi"

UBOOT_ENTRYPOINT_loongarch32 = "0x80400000"
UBOOT_ENTRYPOINT_loongarch64 = "0x80200000"

# qemuboot options
QB_KERNEL_CMDLINE_APPEND = "earlycon=sbi"
QB_MACHINE = "-machine virt"
QB_DEFAULT_BIOS = "fw_jump.elf"
QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
QB_NETWORK_DEVICE = "-device virtio-net-device,netdev=net0,mac=@MAC@"
QB_ROOTFS_OPT = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
QB_SERIAL_OPT = "-device virtio-serial-device -chardev null,id=virtcon -device virtconsole,chardev=virtcon"
QB_TCPSERIAL_OPT = " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon"
# Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
QB_OPT_APPEND = " -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-device,rng=rng0"
13 changes: 13 additions & 0 deletions meta/conf/machine/include/loongarch/tune-loongarch.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require conf/machine/include/loongarch/arch-loongarch.inc

TUNEVALID[loongarch64] = "Enable 64-bit LoongArch optimizations"

TUNEVALID[littleendian] = "Little endian mode"

AVAILTUNES += "loongarch64"

# Default
TUNE_FEATURES:tune-loongarch64 = "loongarch64"
TUNE_ARCH:tune-loongarch64 = "loongarch64"
TUNE_PKGARCH:tune-loongarch64 = "loongarch64"
PACKAGE_EXTRA_ARCHS:tune-loongarch64 = "loongarch64"
11 changes: 11 additions & 0 deletions meta/conf/machine/qemuloongarch64.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#@TYPE: Machine
#@NAME: generic loongarch64 machine
#@DESCRIPTION: Machine configuration for running a generic loongarch64

require conf/machine/include/loongarch/qemuloongarch.inc

XVISOR_PLAT = "loongarch/virt64"

EXTRA_IMAGEDEPENDS += "u-boot"
UBOOT_MACHINE = "qemu-loongarch64_smode_defconfig"
UBOOT_ELF = "u-boot"
1 change: 1 addition & 0 deletions meta/conf/templates/default/local.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#
#MACHINE ?= "qemuarm"
#MACHINE ?= "qemuarm64"
#MACHINE ?= "qemuloongarch64"
#MACHINE ?= "qemumips"
#MACHINE ?= "qemumips64"
#MACHINE ?= "qemuppc"
Expand Down
2 changes: 2 additions & 0 deletions meta/lib/oe/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def machine_dict(d):
"x86_64": (62, 0, 0, True, 64),
"epiphany": (4643, 0, 0, True, 32),
"lm32": (138, 0, 0, False, 32),
"loongarch64":(258, 0, 0, True, 64),
"mips": ( 8, 0, 0, False, 32),
"mipsel": ( 8, 0, 0, True, 32),
"microblaze": (189, 0, 0, False, 32),
Expand All @@ -45,6 +46,7 @@ def machine_dict(d):
"ia64": (50, 0, 0, True, 64),
"alpha": (36902, 0, 0, True, 64),
"hppa": (15, 3, 0, False, 32),
"loongarch64":(258, 0, 0, True, 64),
"m68k": ( 4, 0, 0, False, 32),
"mips": ( 8, 0, 0, False, 32),
"mipsel": ( 8, 0, 0, True, 32),
Expand Down
1 change: 1 addition & 0 deletions meta/recipes-bsp/u-boot/u-boot-tools.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SED_CONFIG_EFI:x86-64 = ''
SED_CONFIG_EFI:arm = ''
SED_CONFIG_EFI:armeb = ''
SED_CONFIG_EFI:aarch64 = ''
SED_CONFIG_EFI:loongarch64 = ''

do_compile () {
# Yes, this is crazy. If you build on a system with git < 2.14 from scratch, the tree will
Expand Down
5 changes: 3 additions & 2 deletions meta/recipes-devtools/binutils/binutils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ GPROFNG_ALTS:aarch64 = "${GPROFNGS}"
LDGOLD_ALTS ?= "ld.gold dwp"
LDGOLD_ALTS:riscv64 = ""
LDGOLD_ALTS:riscv32 = ""
LDGOLD_ALTS:loongarch64 = ""
LDGOLD_ALTS:libc-glibc:mipsarch = ""

USE_ALTERNATIVES_FOR = " \
Expand Down Expand Up @@ -198,6 +199,6 @@ ALTERNATIVE_PRIORITY = "100"
ALTERNATIVE:${PN}:class-target = "${USE_ALTERNATIVES_FOR}"

python () {
if bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', True, False, d) and bb.utils.contains_any('TARGET_ARCH', 'riscv32 riscv64', True, False, d):
bb.fatal("Gold linker does not _yet_ support RISC-V architecture please remove ld-is-gold from DISTRO_FEATURES")
if bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', True, False, d) and bb.utils.contains_any('TARGET_ARCH', 'riscv32 riscv64 loongarch64', True, False, d):
bb.fatal("Gold linker does not _yet_ support RISC-V and LoongArch architecture please remove ld-is-gold from DISTRO_FEATURES")
}
2 changes: 2 additions & 0 deletions meta/recipes-devtools/meson/meson_1.0.0.bb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def generate_native_link_template(d):
loader = 'ld-linux-aarch64.so.1'
elif 'ppc64le' in build_arch:
loader = 'ld64.so.2'
elif 'loongarch64' in build_arch:
loader = 'ld-linux-loongarch-lp64d.so.1'

if loader:
val += ['-Wl,--dynamic-linker=@{OECORE_NATIVE_SYSROOT}${base_libdir_native}/' + loader]
Expand Down
2 changes: 1 addition & 1 deletion meta/recipes-devtools/qemu/qemu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ do_install_ptest() {
}

# QEMU_TARGETS is overridable variable
QEMU_TARGETS ?= "arm aarch64 i386 mips mipsel mips64 mips64el ppc ppc64 ppc64le riscv32 riscv64 sh4 x86_64"
QEMU_TARGETS ?= "arm aarch64 i386 loongarch64 mips mipsel mips64 mips64el ppc ppc64 ppc64le riscv32 riscv64 sh4 x86_64"

EXTRA_OECONF = " \
--prefix=${prefix} \
Expand Down
2 changes: 1 addition & 1 deletion meta/recipes-kernel/linux/linux-yocto-dev.bb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PACKAGECONFIG[dt-validation] = ",,python3-dtschema-native"
# we need the wrappers if validation isn't in the packageconfig
DEPENDS += "${@bb.utils.contains('PACKAGECONFIG', 'dt-validation', '', 'python3-dtschema-wrapper-native', d)}"

COMPATIBLE_MACHINE = "^(qemuarmv5|qemuarm|qemuarm64|qemux86|qemuppc|qemumips|qemumips64|qemux86-64|qemuriscv32|qemuriscv64)$"
COMPATIBLE_MACHINE = "^(qemuarmv5|qemuarm|qemuarm64|qemux86|qemuppc|qemumips|qemumips64|qemux86-64|qemuriscv32|qemuriscv64|qemuloongarch64)$"

KERNEL_DEVICETREE:qemuarmv5 = "versatile-pb.dtb"

Expand Down
4 changes: 3 additions & 1 deletion meta/recipes-kernel/linux/linux-yocto_6.1.bb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ KBRANCH:qemuriscv64 ?= "v6.1/standard/base"
KBRANCH:qemuriscv32 ?= "v6.1/standard/base"
KBRANCH:qemux86 ?= "v6.1/standard/base"
KBRANCH:qemux86-64 ?= "v6.1/standard/base"
KBRANCH:qemuloongarch64 ?= "v6.1/standard/base"
KBRANCH:qemumips64 ?= "v6.1/standard/mti-malta64"

SRCREV_machine:qemuarm ?= "45f7cca5081d3cb4ad4fae8e158cd58ea4db6c1f"
SRCREV_machine:qemuarm64 ?= "404168c1ce77179a34bb9959a18b594a9f7105d3"
SRCREV_machine:qemuloongarch64 ?= "404168c1ce77179a34bb9959a18b594a9f7105d3"
SRCREV_machine:qemumips ?= "eb204027dbb98317d002250cc594de30ecc62b90"
SRCREV_machine:qemuppc ?= "404168c1ce77179a34bb9959a18b594a9f7105d3"
SRCREV_machine:qemuriscv64 ?= "404168c1ce77179a34bb9959a18b594a9f7105d3"
Expand Down Expand Up @@ -51,7 +53,7 @@ KCONF_BSP_AUDIT_LEVEL = "1"

KERNEL_DEVICETREE:qemuarmv5 = "versatile-pb.dtb"

COMPATIBLE_MACHINE = "^(qemuarm|qemuarmv5|qemuarm64|qemux86|qemuppc|qemuppc64|qemumips|qemumips64|qemux86-64|qemuriscv64|qemuriscv32)$"
COMPATIBLE_MACHINE = "^(qemuarm|qemuarmv5|qemuarm64|qemux86|qemuppc|qemuppc64|qemumips|qemumips64|qemux86-64|qemuriscv64|qemuriscv32|qemuloongarch64)$"

# Functionality flags
KERNEL_EXTRA_FEATURES ?= "features/netfilter/netfilter.scc"
Expand Down
11 changes: 11 additions & 0 deletions meta/site/loongarch64-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# general
ac_cv_alignof_guint32=4
ac_cv_alignof_guint64=8
ac_cv_alignof_unsigned_long=8

# glib-2.0
glib_cv_stack_grows=${glib_cv_stack_grows=no}
glib_cv_uscore=${glib_cv_uscore=no}

# startup-notification
lf_cv_sane_realloc=${lf_cv_sane_realloc=yes}
3 changes: 3 additions & 0 deletions scripts/lib/wic/canned-wks/qemuloongarch.wks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# short-description: Create qcow2 image for LoongArch QEMU machines

part / --source rootfs --fstype=ext4 --label root --align 4096 --size 5G
4 changes: 3 additions & 1 deletion scripts/runqemu
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ class BaseConfig(object):
"""attempt to determine the appropriate qemu-system binary"""
mach = self.get('MACHINE')
if not mach:
search = '.*(qemux86-64|qemux86|qemuarm64|qemuarm|qemumips64|qemumips64el|qemumipsel|qemumips|qemuppc).*'
search = '.*(qemux86-64|qemux86|qemuarm64|qemuarm|qemuloongarch64|qemumips64|qemumips64el|qemumipsel|qemumips|qemuppc).*'
if self.rootfs:
match = re.match(search, self.rootfs)
if match:
Expand All @@ -1336,6 +1336,8 @@ class BaseConfig(object):
qbsys = 'x86_64'
elif mach == 'qemuppc':
qbsys = 'ppc'
elif mach == 'qemuloongarch64':
qbsys = 'loongarch64'
elif mach == 'qemumips':
qbsys = 'mips'
elif mach == 'qemumips64':
Expand Down