Skip to content

Commit

Permalink
Revert "sg2042 build euler"
Browse files Browse the repository at this point in the history
This reverts commit 02affc1.
  • Loading branch information
xingxg2022 authored Oct 24, 2023
1 parent 482d3b4 commit 993d50a
Showing 1 changed file with 2 additions and 241 deletions.
243 changes: 2 additions & 241 deletions scripts/envsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,17 @@ RV_LTP_OUTPUT_DIR=$RV_OUTPUT_DIR/ltp
RV_DISTRO_DIR=$RV_TOP_DIR/distro_riscv
RV_UBUNTU_DISTRO=ubuntu
RV_FEDORA_DISTRO=fedora
RV_EULER_DISTRO=euler

RV_UBUNTU_OFFICIAL_IMAGE=ubuntu-22.04.3-preinstalled-server-riscv64+unmatched.img
DOWNLOAD_RV_UBUNTU_OFFICIAL_IMAGE="wget https://cdimage.ubuntu.com/releases/22.04/release/$RV_UBUNTU_OFFICIAL_IMAGE.xz"
UNCOMPRESS_RV_UBUNTU_OFFICIAL_IMAGE="unxz $RV_UBUNTU_OFFICIAL_IMAGE.xz"

RV_FEDORA_OFFICIAL_IMAGE=fedora-disk-server_sophgo_sg2042-f38-20230523-014306.n.0-sda.raw
DOWNLOAD_RV_FEDORA_OFFICIAL_IMAGE="wget https://repo.openeuler.org/openEuler-preview/RISC-V/openEuler-22.03-V1-riscv64/Unmatched/openEuler-22.03-V1-riscv64-unmatched-xfce.img.tar.zst"
DOWNLOAD_RV_FEDORA_OFFICIAL_IMAGE="wget http://openkoji.iscas.ac.cn/kojifiles/work/tasks/8061/1418061/$RV_FEDORA_OFFICIAL_IMAGE.xz"
UNCOMPRESS_RV_FEDORA_OFFICIAL_IMAGE="unxz $RV_FEDORA_OFFICIAL_IMAGE.xz"

RV_EULER_OFFICIAL_IMAGE=openEuler-23.03-V1-base-sg2042-preview.img
DOWNLOAD_RV_EULER_OFFICIAL_IMAGE="wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/SG2042/$RV_EULER_OFFICIAL_IMAGE.zst"
UNCOMPRESS_RV_EULER_OFFICIAL_IMAGE="unzstd $RV_EULER_OFFICIAL_IMAGE.zst"

RV_UBUNTU_SOPHGO_IMAGE=ubuntu-sophgo.img
RV_FEDORA_SOPHGO_IMAGE=fedora-sophgo.img
RV_EULER_SOPHGO_IMAGE=euler-sophgo.img

RV_DEB_INSTALL_DIR=$RV_OUTPUT_DIR/bsp-debs
RV_RPM_INSTALL_DIR=$RV_OUTPUT_DIR/bsp-rpms
Expand Down Expand Up @@ -141,26 +135,21 @@ function show_rv_functions()
echo "build_rv_kernel -build linuxboot kernel"
echo "build_rv_ubuntu_kernel -build ubuntu kernel"
echo "build_rv_fedora_kernel -build fedora kernel"
echo "build_rv_euler_kernel -build euler kernel"
echo "build_rv_ramfs -build buildroot"
echo "build_rv_uroot -build u-root for linuxboot"
echo "build_rv_ltp -build ltp"
echo "build_rv_ubuntu_perf_tool -build ubuntu perf tool source package"
echo "build_rv_fedora_perf_tool -build fedora perf tool source package"
echo "build_rv_euler_perf_tool -build euler perf tool source package"
echo "build_rv_firmware -build firmware(zsbl,sbi,kernel,uroot,uboot,grub2)"
echo "build_rv_firmware_bin -build firmware bin"
echo "build_rv_firmware_image -build firmware image"
echo "build_rv_firmware_package -build firmware package"
echo "build_rv_ubuntu_distro -dowload ubuntu image from offical"
echo "build_rv_fedora_distro -download fedora image from offical"
echo "build_rv_euler_distro -download euler image from offical"
echo "build_rv_ubuntu_image -only build sophgo ubuntu image"
echo "build_rv_fedora_image -only build sophgo fedora image"
echo "build_rv_euler_image -only build sophgo euler image"
echo "build_rv_ubuntu -build sophgo ubuntu image"
echo "build_rv_fedora -build sophgo fedora image"
echo "build_rv_euler -build sophgo euler image"
echo "build_rv_all -build all bin and image(default: ubuntu)"
echo ""
echo "clean_rv_gcc -clean gcc obj files"
Expand All @@ -171,7 +160,6 @@ function show_rv_functions()
echo "clean_rv_kernel -clean linuxboot kernel obj files"
echo "clean_rv_ubuntu_kernel -clean ubuntu kernel obj files"
echo "clean_rv_fedora_kernel -clean fedora kernel obj files"
echo "clean_rv_euler_kernel -clean euler kernel obj files"
echo "clean_rv_ramfs -clean buildroot obj files"
echo "clean_rv_uroot -clean uroot obj files"
echo "clean_rv_ltp -clean ltp obj files"
Expand All @@ -183,10 +171,8 @@ function show_rv_functions()
echo "clean_rv_firmware_package -clean firmware package"
echo "clean_rv_ubuntu_distro -clean ubuntu image"
echo "clean_rv_fedora_distro -clean fedora image"
echo "clean_rv_euler_distro -clean fedora image"
echo "clean_rv_ubuntu_image -clean ubuntu image"
echo "clean_rv_fedora_image -clean fedora image"
echo "clean_rv_euler_image -clean euler image"
echo "clean_rv_ubuntu -clean ubuntu image"
echo "clean_rv_fedora -clean feodra image"
echo "clean_rv_all -clean all bin and image(default: ubuntu)"
Expand Down Expand Up @@ -570,69 +556,6 @@ EOT
popd
}

function build_rv_euler_kernel()
{
local RV_KERNEL_CONFIG=${VENDOR}_${CHIP}_euler_defconfig
local err

pushd $RV_KERNEL_SRC_DIR
make ARCH=riscv CROSS_COMPILE=$RISCV64_LINUX_CROSS_COMPILE $RV_KERNEL_CONFIG
err=$?
if [ $err -ne 0 ]; then
echo "making kernel config failed"
popd
return $err
fi

if [ "$CHIP_NUM" = "multi" ];then
sed -i 's/# CONFIG_SOPHGO_MULTI_CHIP_CLOCK_SYNC is not set/CONFIG_SOPHGO_MULTI_CHIP_CLOCK_SYNC=y/' .config
fi

if [ -e ~/.rpmmacros ]; then
mv ~/.rpmmacros ~/.rpmmacros.orig
fi

# following lines must not be started with space or tab.
cat >> ~/.rpmmacros << "EOT"
%_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}.%%{ARCH}.rpm
EOT

make -j$(nproc) ARCH=riscv CROSS_COMPILE=$RISCV64_LINUX_CROSS_COMPILE LOCALVERSION="" rpm-pkg
ret=$?
rm ~/.rpmmacros
if [ -e ~/.rpmmacros.orig ]; then
mv ~/.rpmmacros.orig ~/.rpmmacros
fi
if [ $ret -ne 0 ]; then
echo "making rpm package failed"
make ARCH=riscv CROSS_COMPILE=$RISCV64_LINUX_CROSS_COMPILE distclean
rm kernel-[0-9]*.tar.gz
rm -rf $HOME/rpmbuild
popd
return $ret
fi

if [ ! -d $RV_RPM_INSTALL_DIR ]; then
mkdir -p $RV_RPM_INSTALL_DIR
else
rm -f $RV_RPM_INSTALL_DIR/kernel-*.rpm
fi

cp $HOME/rpmbuild/RPMS/riscv64/*.rpm $RV_RPM_INSTALL_DIR/
make ARCH=riscv CROSS_COMPILE=$RISCV64_LINUX_CROSS_COMPILE distclean
rm kernel-[0-9]*.tar.gz
rm -rf $HOME/rpmbuild
popd
}

function clean_rv_euler_kernel()
{
pushd $RV_KERNEL_SRC_DIR
make distclean
popd
rm -f $RV_RPM_INSTALL_DIR/kernel-*.rpm
}

function clean_rv_fedora_kernel()
{
pushd $RV_KERNEL_SRC_DIR
Expand Down Expand Up @@ -725,23 +648,6 @@ function clean_rv_fedora_distro()
rm $RV_DISTRO_DIR/$RV_FEDORA_DISTRO/$RV_FEDORA_OFFICIAL_IMAGE
}

function build_rv_euler_distro()
{
mkdir -p $RV_DISTRO_DIR/$RV_EULER_DISTRO

pushd $RV_DISTRO_DIR/$RV_EULER_DISTRO
if [ ! -f $RV_EULER_OFFICIAL_IMAGE ] ; then
$DOWNLOAD_RV_EULER_OFFICIAL_IMAGE
$UNCOMPRESS_RV_EULER_OFFICIAL_IMAGE
fi
popd
}

function clean_rv_euler_distro()
{
rm $RV_DISTRO_DIR/$RV_EULER_DISTRO/$RV_EULER_OFFICIAL_IMAGE
}

function build_rv_ubuntu_image()
{
echo build_rv_ubuntu_image
Expand Down Expand Up @@ -830,7 +736,7 @@ EOT
sudo umount $RV_OUTPUT_DIR/root/dev
sudo umount /dev/mapper/$efi_part
sudo umount /dev/mapper/$root_part
sudo kpartx -d $RV_OUTPUT_DIR/$RV_UBUNTU_SOPHGO_IMAGEs
sudo kpartx -d $RV_OUTPUT_DIR/$RV_UBUNTU_SOPHGO_IMAGE
sudo kpartx -d $RV_DISTRO_DIR/$RV_UBUNTU_DISTRO/$RV_UBUNTU_OFFICIAL_IMAGE
sudo rm -r $RV_OUTPUT_DIR/efi
sudo rm -r $RV_OUTPUT_DIR/root
Expand All @@ -843,125 +749,6 @@ function clean_rv_ubuntu_image()
rm -f $RV_OUTPUT_DIR/$RV_UBUNTU_SOPHGO_IMAGE
}

function build_rv_euler_image()
{
echo build_rv_euler_image
echo create an image file...
rm -f $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE
dd if=/dev/zero of=$RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE bs=1GiB count=10

echo create partitions...
sudo parted $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE mktable msdos
sudo parted $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE mkpart p fat32 0% 256MiB
sudo parted $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE mkpart p ext4 256MiB 100%
loops=$(sudo kpartx -av $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE | cut -d ' ' -f 3)
efi_part=$(echo $loops | cut -d ' ' -f 1)
root_part=$(echo $loops | cut -d ' ' -f 2)
sleep 3
sudo mkfs.vfat /dev/mapper/$efi_part -n EFI
sudo mkfs.ext4 /dev/mapper/$root_part

echo copy bootloader...
mkdir $RV_OUTPUT_DIR/efi
sudo mount /dev/mapper/$efi_part $RV_OUTPUT_DIR/efi
sudo mkdir -p $RV_OUTPUT_DIR/efi/riscv64

sudo cp $RV_FIRMWARE/fip.bin $RV_OUTPUT_DIR/efi/
sudo cp $RV_FIRMWARE_INSTALL_DIR/zsbl.bin $RV_OUTPUT_DIR/efi/
# sudo cp $RV_FIRMWARE_INSTALL_DIR/grub.cfg $RV_OUTPUT_DIR/efi/
# sudo cp $RV_FIRMWARE_INSTALL_DIR/grubriscv64.efi $RV_OUTPUT_DIR/efi/
sudo cp $RV_FIRMWARE_INSTALL_DIR/fw_dynamic.bin $RV_OUTPUT_DIR/efi/riscv64
sudo cp $RV_FIRMWARE_INSTALL_DIR/riscv64_Image $RV_OUTPUT_DIR/efi/riscv64
# sudo cp $RV_FIRMWARE_INSTALL_DIR/u-boot.bin $RV_OUTPUT_DIR/efi/riscv64
sudo cp $RV_FIRMWARE_INSTALL_DIR/*.dtb $RV_OUTPUT_DIR/efi/riscv64
sudo cp $RV_FIRMWARE_INSTALL_DIR/initrd.img $RV_OUTPUT_DIR/efi/riscv64
sudo touch $RV_OUTPUT_DIR/efi/BOOT

echo copy euler...
loops=$(sudo kpartx -av $RV_DISTRO_DIR/$RV_EULER_DISTRO/$RV_EULER_OFFICIAL_IMAGE | cut -d ' ' -f 3)
euler_root_part=$(echo $loops | cut -d ' ' -f 3)
echo ============ rootfs $euler_root_part
sudo dd if=/dev/mapper/$euler_root_part of=/dev/mapper/$root_part bs=256M status=progress
sudo e2fsck -f -y /dev/mapper/$root_part
sudo resize2fs /dev/mapper/$root_part
sudo e2label /dev/mapper/$root_part ROOT

echo mount root partition...
mkdir $RV_OUTPUT_DIR/root
sudo mount /dev/mapper/$root_part $RV_OUTPUT_DIR/root

sudo mount --bind /proc $RV_OUTPUT_DIR/root/proc
sudo mount --bind /sys $RV_OUTPUT_DIR/root/sys
sudo mount --bind /dev $RV_OUTPUT_DIR/root/dev
sudo mount --bind /dev/pts $RV_OUTPUT_DIR/root/dev/pts
sudo mount --bind /run/ $RV_OUTPUT_DIR/root/run
sudo mv $RV_OUTPUT_DIR/root/etc/hosts $RV_OUTPUT_DIR/root/etc/hosts-bak
sudo cp /etc/hosts $RV_OUTPUT_DIR/root/etc/
#echo add user euler:Sophgo12#
# following lines must not be started with space or tab.

# following lines must not be started with space or tab.
echo copy bsp package...
sudo cp -r $RV_RPM_INSTALL_DIR $RV_OUTPUT_DIR/root/home/

echo install linux image...
# following lines must not be started with space or tab.
sudo chroot $RV_OUTPUT_DIR/root /bin/env ROOT_PART="$root_part" /bin/bash << "EOT"
echo install dracut
echo "y" | dnf install dracut
rm -rf /lib/dracut/dracut.conf.d/99-initramfs.conf
echo install kernel
rpm -ivh --force /home/bsp-rpms/kernel-[0-9]*.riscv64.rpm
# The following command is to solve the problem of not updating the extlinux.conf file when installing kernel RPM package.
kernel_version=`ls /home/bsp-rpms/kernel-[0-9]*.riscv64.rpm | cut -d '-' -f 3 | cut -d '.' -f 1-3`
mv /boot/extlinux/extlinux.conf /boot/extlinux/extlinux.conf_bak
cat > /boot/extlinux/extlinux.conf << EOF
## /boot/extlinux/extlinux.conf
default euler_sophgo
menu title linuxboot menu
prompt 0
timeout 50
label euler_sophgo
menu label euler Sophgo in SD
linux /boot/vmlinuz-$kernel_version
initrd /boot/initramfs-$kernel_version.img
append console=ttyS0,115200 root=LABEL=ROOT rootfstype=ext4 rootwait rw earlycon selinux=0 LANG=en_US.UTF-8 nvme.use_threaded_interrupts=1 nvme_core.io_timeout=3000
EOF
exit
EOT
popd

echo cleanup...
sync
sleep 60
sudo rm $RV_OUTPUT_DIR/root/etc/hosts
sudo mv $RV_OUTPUT_DIR/root/etc/hosts-bak $RV_OUTPUT_DIR/root/etc/hosts
sudo umount $RV_OUTPUT_DIR/root/run
sudo umount $RV_OUTPUT_DIR/root/proc
sudo umount $RV_OUTPUT_DIR/root/sys
sudo umount $RV_OUTPUT_DIR/root/dev/pts
sudo umount $RV_OUTPUT_DIR/root/dev
sudo umount /dev/mapper/$efi_part
sudo umount /dev/mapper/$root_part
sudo kpartx -d $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE
sudo kpartx -d $RV_DISTRO_DIR/$RV_EULER_DISTRO/$RV_EULER_OFFICIAL_IMAGE
sudo rm -r $RV_OUTPUT_DIR/efi
#sudo umount $RV_OUTPUT_DIR/root
sudo rm -r $RV_OUTPUT_DIR/root

echo "build euler image successfully!"
}

function clean_rv_euler_image()
{
rm -rf $RV_OUTPUT_DIR/$RV_EULER_SOPHGO_IMAGE
}

function build_rv_fedora_image()
{
echo build_rv_fedora_image
Expand Down Expand Up @@ -1139,16 +926,6 @@ function clean_rv_fedora_perf_tool()
echo "clean_rv_fedora_perf_tool is not implemented"
}

function build_rv_euler_perf_tool()
{
echo "build_rv_euler_perf_tool is not implemented"
}

function clean_rv_euler_perf_tool()
{
echo "clean_rv_euler_perf_tool is not implemented"
}

function build_rv_firmware()
{
build_rv_zsbl
Expand Down Expand Up @@ -1352,22 +1129,6 @@ function clean_rv_fedora()
clean_rv_fedora_image
}

function build_rv_euler()
{
build_rv_euler_kernel
build_rv_euler_perf_tool
build_rv_euler_distro
build_rv_euler_image
}

function clean_rv_euler()
{
clean_rv_euler_kernel
clean_rv_euler_perf_tool
clean_rv_euler_distro
clean_rv_euler_image
}

function build_rv_all()
{
build_rv_firmware_bin
Expand Down

0 comments on commit 993d50a

Please sign in to comment.