x86_64平台上搭建龙芯开发环境

您的第一个版面的简单描述
回复
admin
网站管理员
帖子: 373
注册时间: 周四 3月 15, 2018 3:56 pm
来自: 广东深圳
联系:

x86_64平台上搭建龙芯开发环境

帖子 admin »

目前无法找到可以完全模拟龙芯CPU引导loongnix的方法,但是通过qemu用户模式,使用静态编译的程序可以把mips64el的指令翻译成
x86_64平台能够执行的指令。具体搭建步骤如下:

可以参考这个例子:
http://mirror.lemote.com:8000/fedora/qemu/README.txt

宿主机操作系统:Fedora 31 x86_64 workstation
IP: 192.168.1.21

(1)下载mips64el静态指令执行程序并执行:
# wget http://mirror.lemote.com:8000/fedora/qemu/qemu-mips64el
# wget http://mirror.lemote.com:8000/fedora/qe ... mt-conf.sh
# chmod 755 qemu-mips64el qemu-binfmt-conf.sh
# ./qemu-binfmt-conf.sh

(2)下载镜像并使用chroot进入开发环境,有两种方法:
方法一:
# wget http://mirror.lemote.com:8000/fedora/qe ... ini.tar.xz
# mkdir fc21-mips64el
# cd fc21-mips64el
# tar --numeric-owner -xf ../fedora-21-mips64el-mini.tar.xz
# cd ..
# cp qemu-mips64el fc21-mips64el/usr/local/bin
# vi fc21-mips64el/etc/profile.d/vte.sh
vte.sh文件内容如下:
# Copyright © 2006 Shaun McCance <shaunm@gnome.org>
# Copyright © 2013 Peter De Wachter <pdewacht@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Not bash or zsh?
[ -n "$BASH_VERSION" -o -n "$ZSH_VERSION" ] || return 0

# Not an interactive shell?
[[ $- == *i* ]] || return 0

# Not running under vte?
[ "${VTE_VERSION:-0}" -ge 3405 ] || return 0

__vte_urlencode() (
# This is important to make sure string manipulation is handled
# byte-by-byte.
LC_ALL=C
str="$1"
while [ -n "$str" ]; do
safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
printf "%s" "$safe"
str="${str#"$safe"}"
if [ -n "$str" ]; then
printf "%%%02X" "'$str"
str="${str#?}"
fi
done
)

# Print a warning so that anyone who's added this manually to his PS1 can adapt.
# The function will be removed in a later version.
__vte_ps1() {
echo -n "(__vte_ps1 is obsolete)"
}

__vte_osc7 () {
printf "\033]7;file://%s%s\a" "${HOSTNAME:-}" "$(__vte_urlencode "${PWD}")"
}

__vte_prompt_command() {
local pwd='~'
[ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
printf "\033]0;%s@%s:%s\007%s" "${USER}" "${HOSTNAME%%.*}" "${pwd}" "$(__vte_osc7)"
}

case "$TERM" in
xterm*|vte*)
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
[ -n "$ZSH_VERSION" ] && precmd_functions+=(__vte_osc7)
;;
esac

true
保存退出。

# chmod 755 fc21-mips64el/etc/profile.d/vte.sh
# mount -t proc /proc fc21-mips64el/proc
# mount --rbind /sys fc21-mips64el/sys
# mount --make-rslave fc21-mips64el/sys
# mount --rbind /dev fc21-mips64el/dev
# mount --make-rslave fc21-mips64el/dev
# test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
# mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm
# chmod 1777 /dev/shm
进入开发环境:
# chroot fc21-mips64el

方法二:下载loongnix docker镜像并解压
# docker pull loongnix/loongnix-base
# docker save loongnix/loongnix-base > loongnix.tar
# mkdir loongnix
# cd loongnix
# tar -xvf ../loongnix.tar
# mv 336ba66d9ed6e7657e4916fa47c0bdbc1109cf7d3813b2a4876ad964b273e790/layer.tar .
# rm -fr 336ba66d9ed6e7657e4916fa47c0bdbc1109cf7d3813b2a4876ad964b273e790
# rm -f 54f3526b8a11b1207c47481fcf604e419a8d72609bee8c6eeb2406fa32d95a0e.json
# rm -f manifest.json repositories
# tar -xvf layer.tar
# rm -f layer.tar
# vi etc/profile.d/vte.sh
vte.sh文件内容如下:
# Copyright © 2006 Shaun McCance <shaunm@gnome.org>
# Copyright © 2013 Peter De Wachter <pdewacht@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Not bash or zsh?
[ -n "$BASH_VERSION" -o -n "$ZSH_VERSION" ] || return 0

# Not an interactive shell?
[[ $- == *i* ]] || return 0

# Not running under vte?
[ "${VTE_VERSION:-0}" -ge 3405 ] || return 0

__vte_urlencode() (
# This is important to make sure string manipulation is handled
# byte-by-byte.
LC_ALL=C
str="$1"
while [ -n "$str" ]; do
safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
printf "%s" "$safe"
str="${str#"$safe"}"
if [ -n "$str" ]; then
printf "%%%02X" "'$str"
str="${str#?}"
fi
done
)

# Print a warning so that anyone who's added this manually to his PS1 can adapt.
# The function will be removed in a later version.
__vte_ps1() {
echo -n "(__vte_ps1 is obsolete)"
}

__vte_osc7 () {
printf "\033]7;file://%s%s\a" "${HOSTNAME:-}" "$(__vte_urlencode "${PWD}")"
}

__vte_prompt_command() {
local pwd='~'
[ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
printf "\033]0;%s@%s:%s\007%s" "${USER}" "${HOSTNAME%%.*}" "${pwd}" "$(__vte_osc7)"
}

case "$TERM" in
xterm*|vte*)
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
[ -n "$ZSH_VERSION" ] && precmd_functions+=(__vte_osc7)
;;
esac

true
保存退出。

# chmod 755 etc/profile.d/vte.sh
# cd ..
# cp qemu-mips64el loongnix/usr/local/bin
# mount -t proc /proc loongnix/proc
# mount --rbind /sys loongnix/sys
# mount --make-rslave loongnix/sys
# mount --rbind /dev loongnix/dev
# mount --make-rslave loongnix/dev
# test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
# mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm
# chmod 1777 /dev/shm

进入开发环境:
# chroot loongnix
# yum install gcc autoconf automake m4 make vim -y

(3)运行chroot图形程序
宿主机:192.168.1.21
# xhost +

chroot环境:
# export DISPLAY=:0.0
# xclock
回复