龙芯俱乐部开源技术社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 2732|回复: 5

龍芯派從源碼構建linux from scratch

[复制链接]

46

主题

115

帖子

4146

积分

论坛元老

Rank: 8Rank: 8

积分
4146
发表于 2019-6-24 05:49:58 | 显示全部楼层 |阅读模式
學習孫海勇的《手把手教你構建自己的linux系統》。方案是直接在根目錄建臨時系統後,然後把主系統刪掉,最後編譯目標系統。
4.1.1
su
export SYSDIR=/
mkdir -pv ${SYSDIR}/sources
mkdir -pv ${SYSDIR}/build
chmod -v a+wt ${SYSDIR}/{sources,build}
mkdir -pv ${SYSDIR}/tools
ln -sv ${SYSDIR}/tools /

4.1.2
groupadd mylinux
useradd -s /bin/bash -g mylinux -m -k /dev/null mylinux
passwd mylinux
8位密碼
chown -v mylinux ${SYSDIR}/tools
chown -v mylinux ${SYSDIR}/sources
chown -v mylinux ${SYSDIR}/build
su - mylinux

4.1.3
cat > ~/.bash_profile << "EOF"
exec env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$ ' /bin/bash
EOF
cat > ~/.bashrc << "EOF"
set +h
umask 022
SYSDIR=/
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
DOWNLOADDIR=${SYSDIR}/sources
BUILDDIR=${SYSDIR}/build
export SYSDIR LC_ALL PATH DOWNLOADDIR BUILDDIR
EOF
source ~/.bash_profile
檢查
export
cat > ${BUILDDIR}/test.c << "EOF"
#include <stdio.h>
main()
{
  printf("OK\n");
  return 0;
}
EOF
測試
gcc ${BUILDDIR}/test.c
./a.out
rm a.out

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

46

主题

115

帖子

4146

积分

论坛元老

Rank: 8Rank: 8

积分
4146
 楼主| 发表于 2019-6-25 20:17:46 | 显示全部楼层
4.3.1
exit
su
yum install git texinfo -y
su - mylinux
mylinux:~$ cd ${DOWNLOADDIR}
git clone --depth=1 git://cgit.loongnix.org/compiler/toolchain-fc21/binutils-2.24.git
tar -cf binutils-2.24.tar.bz2 binutils-2.24
tar xvf ${DOWNLOADDIR}/binutils-2.24.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/binutils-2.24
mkdir -pv ../binutils-build
cd ../binutils-build
CC="gcc -B/usr/bin/" ../binutils-2.24/configure --prefix=/tools --disable-nls --disable-werror
make -j2
make install
make -C ld clean
make -C ld LIB_PATH=/tools/lib
cp -v ld/ld-new /tools/bin
cd ..
rm -rf binutils-build
rm -rf binutils-2.24
popd
檢查
type ld
ls /tools/bin
gcc -v ${BUILDDIR}/test.c 2>&1 | grep Binutils
無顯示,但是去掉grep,可以看到GNU assembler version 2.24 (mips64el-unknown-linux-gnu) using BFD version version 2.24
./a.out

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

46

主题

115

帖子

4146

积分

论坛元老

Rank: 8Rank: 8

积分
4146
 楼主| 发表于 2019-6-26 19:24:55 | 显示全部楼层
4.3.2
GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
cd ${DOWNLOADDIR}
git clone --depth=1 git://cgit.loongnix.org/compiler/toolchain-fc21/gcc-4.9.3.git
tar -cf gcc-4.9.3.tar.bz2 gcc-4.9.3/
wget http://ftp.gnu.org/gnu/gmp/gmp-6.0.0a.tar.bz2
wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.bz2
wget http://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
tar xvf ${DOWNLOADDIR}/gcc-4.9.3.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/gcc-4.9.3
tar xvf ${DOWNLOADDIR}/gmp-6.0.0a.tar.bz2
mv gmp-6.0.0 gmp
tar xvf ${DOWNLOADDIR}/mpfr-3.1.2.tar.bz2
mv mpfr-3.1.2 mpfr
tar xvf ${DOWNLOADDIR}/mpc-1.0.2.tar.gz
mv mpc-1.0.2 mpc
mkdir -pv ../gcc-build
cd ../gcc-build
CC="gcc -B/usr/bin/" ../gcc-4.9.3/configure --prefix=/tools --disable-nls --disable-multilib --enable-shared --enable-languages=c
make bootstrap -j2
make install
ln -vs gcc /tools/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.9.3
檢查
type gcc
ls -l /tools/bin/cc | awk -F/tools/bin/ `{prin $2}'
無返回,但是ls -l /tools/bin/cc 返回/tools/bin/cc -> gcc
ls /tools/bin/$(uname -m)*
gcc -v ${BUILDDIR}/test.c 2>&1 | grep Configured


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

46

主题

115

帖子

4146

积分

论坛元老

Rank: 8Rank: 8

积分
4146
 楼主| 发表于 2019-6-28 20:44:09 | 显示全部楼层

4.4.1
cd ${DOWNLOADDIR}
git clone --depth=1 git://cgit.loongnix.org/kernel/linux-3.10.git
tar -cf linux-3.10.tar.bz2 linux-3.10/
rm -rf linux-3.10
tar xvf ${DOWNLOADDIR}/linux-3.10.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/linux-3.10
   make mrproper
   make headers_check
   make INSTALL_HDR_PATH=dest headers_install
   cp -rv dest/include/* /tools/include
   cd ..
   rm -rf linux-3.10
popd
ls /tools/include

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

46

主题

115

帖子

4146

积分

论坛元老

Rank: 8Rank: 8

积分
4146
 楼主| 发表于 2019-7-6 20:31:46 | 显示全部楼层
4.4.2
cd ${DOWNLOADDIR}
git clone --depth=1 git://cgit.loongnix.org/compiler/toolchain-fc21/glibc-2.20.git
tar -cf glibc-2.20.tar.bz2 glibc-2.20/
rm -rf glibc-2.20
tar xvf ${DOWNLOADDIR}/glibc-2.20.tar.bz2 -C ${BUILDDIR}
pushd ${BUILDDIR}/glibc-2.20
   mkdir ../glibc-build
   cd ../glibc-build
   CC="gcc -B/usr/bin -march=mips64 -mabi=64" ../glibc-2.20/configure --prefix=/tools --disable-profile --disable-add-ons --enable-kernel=3.10.0 --with-binutils=/tools/bin --without-gd --with-heasers=/tools/include --without-selinux --with-arch=loongson3a --disable-multilib --build=mips64el-redhat-linux
   make -j2
   mkdir -v /tools/etc
   touch /tools/etc/ld.so.conf
   make install
   cd ..
   rm -rf glibc-build
   rm -rf glibc-2.20
popd
/tools/lib/libc.so.6 | grep "GNU C"

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

4

主题

24

帖子

764

积分

版主

Rank: 7Rank: 7Rank: 7

积分
764
发表于 2020-2-28 16:18:59 | 显示全部楼层
好!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|龙芯俱乐部开源技术社区

GMT+8, 2024-4-19 03:48 , Processed in 0.109545 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表