重命名 makesd_c73 为 makesd

This commit is contained in:
HuaweiAscend
2020-07-27 09:58:31 +08:00
committed by Gitee
parent bef05d3548
commit 2f6f941c74
3 changed files with 0 additions and 0 deletions
View File
+467
View File
@@ -0,0 +1,467 @@
#
# =======================================================================
#
# Copyright (C) 2018, Hisilicon Technologies Co., Ltd. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1 Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2 Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3 Neither the names of the copyright holders nor the names of the
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# =======================================================================
#
'''common installation'''
import os
import platform
import signal
import subprocess
import time
import yaml
import sys
NETWORK_CARD_DEFAULT_IP="192.168.0.2"
USB_CARD_DEFAULT_IP="192.168.1.2"
VERSION_INFO_URL = "https://raw.githubusercontent.com/Ascend/tools/master/versioninfo.yaml"
CURRENT_PATH = os.path.dirname(
os.path.realpath(__file__))
SD_CARD_MAKING_PATH = os.path.join(CURRENT_PATH, "sd_card_making")
MIN_DISK_SIZE = 7 * 1024 * 1024 * 1024
MAKING_SD_CARD_COMMAND = "bash {path}/make_ubuntu_sd.sh " + " {dev_name}" + \
" {pkg_path} {ubuntu_file_name}" + \
" " + NETWORK_CARD_DEFAULT_IP + " " + USB_CARD_DEFAULT_IP + \
" > {log_path}/make_ubuntu_sd.log "
def execute(cmd, timeout=3600, cwd=None):
'''execute os command'''
# print(cmd)
is_linux = platform.system() == 'Linux'
if not cwd:
cwd = os.getcwd()
process = subprocess.Popen(cmd, cwd=cwd, bufsize=32768, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True,
preexec_fn=os.setsid if is_linux else None)
t_beginning = time.time()
# cycle times
time_gap = 0.01
str_std_output = ""
while True:
str_out = str(process.stdout.read().decode())
str_std_output = str_std_output + str_out
if process.poll() is not None:
break
seconds_passed = time.time() - t_beginning
if timeout and seconds_passed > timeout:
if is_linux:
os.kill(process.pid, signal.SIGTERM)
else:
process.terminate()
return False, process.stdout.readlines()
time.sleep(time_gap)
str_std_output = str_std_output.strip()
# print(str_std_output)
std_output_lines_last = []
std_output_lines = str_std_output.split("\n")
for i in std_output_lines:
std_output_lines_last.append(i)
if process.returncode != 0 or "Traceback" in str_std_output:
return False, std_output_lines_last
return True, std_output_lines_last
def print_process(string, is_finished=False):
if string == "" or string is None or is_finished:
print(".......... .......... .......... .......... 100%", end='\r')
print("")
else:
string = string.split(".......... ", 1)[1]
string = string.split("%")[0] + "%"
print(string, end='\r')
def execute_wget(cmd, timeout=86400, cwd=None):
'''execute os command'''
# print(cmd)
is_linux = platform.system() == 'Linux'
if not cwd:
cwd = os.getcwd()
process = subprocess.Popen(cmd, cwd=cwd, bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True,
preexec_fn=os.setsid if is_linux else None)
t_beginning = time.time()
# cycle times
time_gap = 0.01
str_std_output = ""
process_str = ""
while True:
str_out = str(process.stdout.readline())
if "......" in str_out:
process_str = str_out
print_process(process_str)
str_std_output = str_std_output + str_out
if process.poll() is not None:
break
seconds_passed = time.time() - t_beginning
if timeout and seconds_passed > timeout:
if is_linux:
os.kill(process.pid, signal.SIGTERM)
else:
process.terminate()
print("")
return False
time.sleep(time_gap)
if process.returncode != 0 or "Traceback" in str_std_output:
print("")
return False
print_process(process_str, True)
return True
def check_sd(dev_name):
ret, disk = execute(
"fdisk -l 2>/dev/null | grep \"Disk {dev_name}:\"".format(dev_name=dev_name))
if not ret or len(disk) > 1:
print(
"[ERROR] Can not get disk, please use fdisk -l to check available disk name!")
return False
ret, mounted_list = execute("df -h")
if not ret:
print("[ERROR] Can not get mounted disk list!")
return False
unchanged_disk_list = []
for each_mounted_disk in mounted_list:
disk_name = each_mounted_disk.split()[0]
disk_type = each_mounted_disk.split()[5]
if disk_type == "/boot" or disk_type == "/":
unchanged_disk_list.append(disk_name)
unchanged_disk = " ".join(unchanged_disk_list)
disk_size_str = disk[0].split(", ")[1]
disk_size_str = disk_size_str.split()[0]
disk_size = int(disk_size_str)
if dev_name not in unchanged_disk and disk_size >= MIN_DISK_SIZE:
return True
print("[ERROR] Invalid SD card or size is less then 8G, please check SD Card.")
return False
def parse_download_info(ascend_version):
version_info_file_name = os.path.basename(VERSION_INFO_URL)
version_info_path = os.path.join(
CURRENT_PATH, version_info_file_name)
ret = execute_wget("wget -O {name} {url} --no-check-certificate".format(
name=version_info_path, url=VERSION_INFO_URL))
if not ret or not os.path.exists(version_info_path):
print(
"[ERROR] Can not download versioninfo.yaml, please check your network connection.")
execute("rm -rf {path}".format(path=version_info_path))
return False, "", "", ""
version_info_file = open(
version_info_path, 'r', encoding='utf-8')
version_info_dict = yaml.load(
version_info_file)
ascend_version_dict = version_info_dict.get("mini_developerkit")
if ascend_version == "" or ascend_version == ascend_version_dict.get("latest_version"):
ascend_developerkit_url = ascend_version_dict.get("url")
ascend_sd_making_url = ascend_version_dict.get("sd_making_url")
ubuntu_version = ascend_version_dict.get(
"compatibility").get("ubuntu")[0]
else:
version_list = ascend_version_dict.get("archived_versions")
for each_version in version_list:
if ascend_version == each_version.get("version"):
ascend_developerkit_url = each_version.get("url")
ascend_sd_making_url = each_version.get("sd_making_url")
ubuntu_version = each_version.get(
"compatibility").get("ubuntu")[0]
break
ubuntu_version_dict = version_info_dict.get("ubuntu")
for each_version in ubuntu_version_dict:
if ubuntu_version == each_version.get("version"):
ubuntu_url = each_version.get("url")
break
version_info_file.close()
if ascend_developerkit_url == "" or ascend_sd_making_url == "" or ubuntu_url == "":
return False, "", "", ""
return True, ascend_developerkit_url, ascend_sd_making_url, ubuntu_url
def check_minirc_run_package():
#check driver package
ret, paths = execute(
"find {path} -name \"Ascend310-driver-*.tar.gz\"".format(path=CURRENT_PATH))
if not ret:
print("[ERROR]Can not find driver run package in current path")
return False
if len(paths) > 1:
print("[ERROR]Too many driver packages, please delete redundant packages.")
return False
#check aicpu_kernel package
ret, paths = execute(
"find {path} -name \"Ascend310-aicpu_kernels-*.tar.gz\"".format(path=CURRENT_PATH))
if not ret:
print("[ERROR]Can not find aicpu_kernels package in current path")
return False
if len(paths) > 1:
print("[ERROR]Too many aicpu_kernels packages, please delete redundant packages.")
return False
#check acl package
ret, paths = execute(
"find {path} -name \"Ascend310-acllib-*.run\"".format(path=CURRENT_PATH))
if not ret:
print("[ERROR]Can not find acllib run package in current path")
return False
if len(paths) > 1:
print("[ERROR]Too many acllib run packages, please delete redundant packages.")
return False
def process_local_installation(dev_name):
ret = check_minirc_run_package
if not ret:
return False
confirm_tips = "Please make sure you have installed dependency packages:" + \
"\n\t apt-get install -y qemu-user-static binfmt-support gcc-aarch64-linux-gnu g++-aarch64-linux-gnu\n" + \
"Please input Y: continue, other to install them:"
confirm = input(confirm_tips)
confirm = confirm.strip()
if confirm != "Y" and confirm != "y":
return False
execute("rm -rf {path}_log/*".format(path=SD_CARD_MAKING_PATH))
execute("mkdir -p {path}_log".format(path=SD_CARD_MAKING_PATH))
log_path = "{path}_log".format(path=SD_CARD_MAKING_PATH)
ret, paths = execute(
"find {path} -name \"Ascend310-driver-*.tar\"".format(path=CURRENT_PATH))
if not ret:
print("[ERROR] Can not fine driver run package in current path")
return False
if len(paths) > 1:
print(
"[ERROR] Too many mini driver run packages, please delete redundant packages.")
return False
ascend_driver_path = paths[0]
ascend_driver_file_name = os.path.basename(ascend_driver_path)
ret, paths = execute(
"find {path} -name \"make-ubuntu-sd.sh\"".format(path=CURRENT_PATH))
if not ret:
print("[ERROR] Can not fine make_ubuntu_sd.sh in current path")
return False
ret, paths = execute(
"find {path} -name \"ubuntu*server*arm*.iso\"".format(path=CURRENT_PATH))
if not ret:
print("[ERROR] Can not fine ubuntu\ package in current path")
return False
if len(paths) > 1:
print("[ERROR] Too many ubuntu packages, please delete redundant packages.")
return False
ubuntu_path = paths[0]
ubuntu_file_name = os.path.basename(ubuntu_path)
print("Step: Start to make SD Card. It need some time, please wait...")
print("Command:")
print(MAKING_SD_CARD_COMMAND.format(path=CURRENT_PATH, dev_name=dev_name, pkg_path=CURRENT_PATH,
ubuntu_file_name=ubuntu_file_name, log_path=log_path))
execute(MAKING_SD_CARD_COMMAND.format(path=CURRENT_PATH, dev_name=dev_name, pkg_path=CURRENT_PATH,
ubuntu_file_name=ubuntu_file_name, log_path=log_path))
ret = execute("grep Success {log_path}/make_ubuntu_sd.result".format(log_path=log_path))
if not ret[0]:
print("[ERROR] Making SD Card failed, please check %s/make_ubuntu_sd.log for details!" % log_path)
return False
return True
def process_internet_installation(dev_name, ascend_version):
print("Step: Downloading version information...")
ret = parse_download_info(ascend_version)
if not ret[0]:
print("Can not find valid versions, please try to get valid version: python3 sd_card_making.py list")
return False
ascend_developerkit_url = ret[1]
ascend_sd_making_url = ret[2]
ubuntu_url = ret[3]
execute("rm -rf {path}_log/*".format(path=SD_CARD_MAKING_PATH))
execute("mkdir -p {path}_log".format(path=SD_CARD_MAKING_PATH))
log_path = "{path}_log".format(path=SD_CARD_MAKING_PATH)
print("Step: Downloading developerkit package...")
ascend_developerkit_file_name = os.path.basename(ascend_developerkit_url)
ascend_developerkit_path = os.path.join(
CURRENT_PATH, ascend_developerkit_file_name)
if os.path.exists(ascend_developerkit_path):
print("%s is already downloaded, skip to download it." %
ascend_developerkit_path)
else:
ret = execute_wget("wget -O {name} {url} --no-check-certificate".format(
name=ascend_developerkit_path, url=ascend_developerkit_url))
if not ret or not os.path.exists(ascend_developerkit_path):
print("[ERROR] Download develperkit package failed, Please check %s connection." %
ascend_developerkit_url)
execute("rm -rf {path}".format(path=ascend_developerkit_path))
return False
print("Step: Downloading SD Card making scripts...")
ascend_sd_making_file_name = os.path.basename(ascend_sd_making_url)
ascend_sd_making_path = os.path.join(
CURRENT_PATH, ascend_sd_making_file_name)
ret = execute_wget("wget -O {name} {url} --no-check-certificate".format(
name=ascend_sd_making_path, url=ascend_sd_making_url))
if not ret or not os.path.exists(ascend_developerkit_path):
print("[ERROR] Download SD Card making scripts failed, Please check %s connection." %
ascend_sd_making_url)
execute("rm -rf {path}".format(path=ascend_sd_making_path))
return False
print("Step: Downloading Ubuntu iso...")
ubuntu_file_name = os.path.basename(ubuntu_url)
ubuntu_path = os.path.join(CURRENT_PATH, ubuntu_file_name)
if os.path.exists(ubuntu_path):
print("%s is already downloaded, skip to download it." % ubuntu_path)
else:
ret = execute_wget(
"wget -O {name} {url} --no-check-certificate".format(name=ubuntu_path, url=ubuntu_url))
if not ret or not os.path.exists(ascend_developerkit_path):
print(
"[ERROR] Download Ubuntu iso failed, Please check %s connection." % ubuntu_url)
execute("rm -rf {path}".format(path=ubuntu_path))
return False
print("Step: Installing system dependency...")
ret = execute(
"apt-get install -y qemu-user-static binfmt-support gcc-aarch64-linux-gnu g++-aarch64-linux-gnu")
if not ret[0]:
print("[ERROR] Install system dependency failed, please check:" +
"\n\tapt-get install -y qemu-user-static binfmt-support gcc-aarch64-linux-gnu g++-aarch64-linux-gnu\n\tapt-get install -y qemu-user-static binfmt-support gcc-aarch64-linux-gnu g++-aarch64-linux-gnu")
print("Step: Start to make SD Card. It need some time, please wait...")
execute(MAKING_SD_CARD_COMMAND.format(path=CURRENT_PATH, dev_name=dev_name,
pkg_path=CURRENT_PATH, ubuntu_file_name=ubuntu_file_name,
ascend_developerkit_file_name=ascend_developerkit_file_name,
log_path=log_path))
ret = execute("grep Success {log_path}/make_ubuntu_sd.result".format(log_path=log_path))
if not ret[0]:
print("[ERROR] Making SD Card failed, please check %s/make_ubuntu_sd.log for details!" % log_path)
return False
return True
def print_usage():
print("Usage: ")
print("\t[internet]: python3 make_sd_card.py internet [SD Name]")
print("\t Use latest version to make SD card.")
print("\t[internet]: python3 make_sd_card.py internet [SD Name] [Version]")
print("\t Use given version to make SD card.")
print("\t[local ]: python3 make_sd_card.py local [SD Name]")
print("\t Use local given packages to make SD card.")
def main():
'''sd card making'''
command = ""
dev_name = ""
version = ""
if (len(sys.argv) >= 3):
command = sys.argv[1]
dev_name = sys.argv[2]
if (len(sys.argv) >= 4):
version = sys.argv[3]
if command == "internet" and (len(sys.argv) == 3 or len(sys.argv) == 4):
print("Begin to make SD Card...")
elif command == "local" and len(sys.argv) == 3:
print("Begin to make SD Card...")
else:
print("Invalid Command!")
print_usage()
exit(-1)
ret = check_sd(dev_name)
if not ret:
exit(-1)
if command == "internet":
result = process_internet_installation(dev_name, version)
else:
result = process_local_installation(dev_name)
if result:
print("Make SD Card successfully!")
exit(0)
else:
exit(-1)
if __name__ == '__main__':
main()
+826
View File
@@ -0,0 +1,826 @@
#!/bin/bash
#
# =======================================================================
#
# Copyright (C) 2018, Hisilicon Technologies Co., Ltd. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1 Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2 Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3 Neither the names of the copyright holders nor the names of the
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# =======================================================================
set -x
# ************************Variable*********************************************
ScriptPath="$( cd "$(dirname "$0")" ; pwd -P )""/"
DEV_NAME=$1
#********************** UPDATE TO FIX ISSUE REGARDING /dev/mmc* MOUNTED SD CARD **********
if [[ $DEV_NAME == /dev/mmc* ]]
then
echo "Partion naming with p-prefix"
p1="p1"
p2="p2"
p3="p3"
else
echo "Partition naming without p-prefix"
p1="1"
p2="2"
p3="3"
fi
#####################################################################################
ISO_FILE_DIR=$2
ISO_FILE=$3
DRIVER_PACKAGE=$(ls Ascend310-driver-*.tar.gz)
AICPU_KERNELS_PACKAGE=$(ls Ascend310-aicpu_kernels-*.tar.gz)
ACLLIB_PACKAGE=$(ls Ascend-acllib-*.run)
NETWORK_CARD_DEFAULT_IP=$4
USB_CARD_DEFAULT_IP=$5
LogPath=${ScriptPath}"sd_card_making_log/"
TMPDIR_SD_MOUNT=${LogPath}"sd_mount_dir"
TMPDIR_SD2_MOUNT=${LogPath}"sd_mount_dir2"
TMPDIR_SD3_MOUNT=${LogPath}"sd_mount_dir3"
TMPDIR_DATE=${LogPath}"no_touch_make_sd_dir"
USER_NAME="HwHiAiUser"
USER_PWD="HwHiAiUser:\$6\$klSpdQ1K\$4Gm/7HxehX.YSum4Wf3IDFZ3v5L.clybUpGNGaw9zAh3rqzqB4mWbxvSTFcvhbjY/6.tlgHhWsbtbAVNR9TSI/:17795:0:99999:7:::"
ROOT_PWD="root:\$6\$klSpdQ1K\$4Gm/7HxehX.YSum4Wf3IDFZ3v5L.clybUpGNGaw9zAh3rqzqB4mWbxvSTFcvhbjY/6.tlgHhWsbtbAVNR9TSI/:17795:0:99999:7:::"
MINIRC_LOGROTATE_DIR="/etc/crob.minirc/"
SYSLOG_MAXSIZE="1000M"
SYSLOG_ROTATE="4"
KERNLOG_MAXSIZE="1000M"
KERNLOG_ROTATE="4"
# end
# ************************Cleanup*********************************************
# Description: files cleanup
# ******************************************************************************
function filesClean()
{
df -h | grep "${TMPDIR_DATE}"
if [ $? -eq 0 ];then
umount ${TMPDIR_DATE}
fi
rm -rf ${TMPDIR_DATE}
df -h | grep "${LogPath}squashfs-root/cdtmp"
if [ $? -eq 0 ];then
umount ${LogPath}squashfs-root/cdtmp
fi
rm -rf ${LogPath}squashfs-root
rm -rf ${LogPath}filesystem.squashfs
df -h | grep "${TMPDIR_SD_MOUNT}"
if [ $? -eq 0 ];then
umount ${TMPDIR_SD_MOUNT}
fi
rm -rf ${TMPDIR_SD_MOUNT}
df -h | grep "${TMPDIR_SD2_MOUNT}"
if [ $? -eq 0 ];then
umount ${TMPDIR_SD2_MOUNT}
fi
rm -rf ${TMPDIR_SD2_MOUNT}
df -h | grep "${TMPDIR_SD3_MOUNT}"
if [ $? -eq 0 ];then
umount ${TMPDIR_SD3_MOUNT}
fi
rm -rf ${TMPDIR_SD3_MOUNT}
rm -rf ${LogPath}driver
}
#end
# ************************check ip****************************************
# Description: check ip valid or not
# $1: ip
# ******************************************************************************
function checkIpAddr()
{
ip_addr=$1
echo ${ip_addr} | grep "^[0-9]\{1,3\}\.\([0-9]\{1,3\}\.\)\{2\}[0-9]\{1,3\}$" > /dev/null
if [ $? -ne 0 ]
then
return 1
fi
for num in `echo ${ip_addr} | sed "s/./ /g"`
do
if [ $num -gt 255 ] || [ $num -lt 0 ]
then
return 1
fi
done
return 0
}
# **************check network card and usb card ip******************************
# Description: check network card and usb card ip
# ******************************************************************************
function checkIps()
{
if [[ ${NETWORK_CARD_DEFAULT_IP}"X" == "X" ]];then
NETWORK_CARD_DEFAULT_IP="192.168.0.2"
fi
checkIpAddr ${NETWORK_CARD_DEFAULT_IP}
if [ $? -ne 0 ];then
echo "Failed: Invalid network card ip."
return 1
fi
NETWORK_CARD_GATEWAY=`echo ${NETWORK_CARD_DEFAULT_IP} | sed -r 's/([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+/\1.1/g'`
if [[ ${USB_CARD_DEFAULT_IP}"X" == "X" ]];then
USB_CARD_DEFAULT_IP="192.168.1.2"
fi
checkIpAddr ${USB_CARD_DEFAULT_IP}
if [ $? -ne 0 ];then
echo "Failed: Invalid usb card ip."
return 1
fi
return 0
}
# ************************umount SD Card****************************************
# Description: check sd card mount, if mounted, umount it
# ******************************************************************************
function checkSDCard()
{
paths=`df -h | grep "$DEV_NAME" | awk -F ' ' '{print $6}'`
for path in $paths
do
echo "umount $path"
umount $path
if [ $? -ne 0 ];then
echo "Failed: umount $path failed!"
return 1
fi
done
return 0
}
#end
# ************************Extract ubuntufs from iso*****************************
# Description: mount iso file , extract root filesystem from squashfs, after
# execute function it will create squashfs-root/ in "./"
# ******************************************************************************
function ubuntufsExtract()
{
mkdir ${TMPDIR_DATE}
mount -o loop ${ISO_FILE_DIR}/${ISO_FILE} ${TMPDIR_DATE}
cp ${TMPDIR_DATE}/install/filesystem.squashfs ${LogPath}
if [[ $? -ne 0 ]];then
echo "Failed: Copy 'filesystem.squashfs' fail!"
return 1;
fi
cd ${LogPath}
unsquashfs filesystem.squashfs
if [[ $? -ne 0 ]];then
echo "Failed: Unsquashfs 'filesystem.squashfs' fail!"
return 1;
fi
#Return to the bin directory
cd ${ScriptPath}
return 0
}
# end
# *****************configure syslog and kernlog**************************************
# Description: configure syslog and kernlog
# ******************************************************************************
function configure_syslog_and_kernlog()
{
if [ ! -d ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR} ];then
mkdir -p ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR}
fi
echo "" > ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR}minirc_logrotate
echo "" > ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR}minirc_logrotate.conf
cat > ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR}minirc_logrotate << EOF
#!/bin/bash
#Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "\${logfile}" ] && echo "\"\${logfile}\" \${date}"
done >> status.clean
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate ${MINIRC_LOGROTATE_DIR}minirc_logrotate.conf
EOF
cat > ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR}minirc_logrotate.conf << EOF
# see "main logrotate" for details
# use the syslog group by default, since this is the owing group
# of /var/log/syslog.
su root syslog
# create new (empty) log files after rotating old ones
create
/var/log/syslog
{
rotate ${SYSLOG_ROTATE}
weekly
maxsize ${SYSLOG_MAXSIZE}
missingok
notifempty
compress
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
/var/log/kern.log
{
rotate ${SYSLOG_ROTATE}
weekly
maxsize ${SYSLOG_MAXSIZE}
missingok
notifempty
compress
}
EOF
chmod 755 ${LogPath}squashfs-root/${MINIRC_LOGROTATE_DIR}minirc_logrotate
echo "*/30 * * * * root cd / && run-parts --report ${MINIRC_LOGROTATE_DIR}" >> ${LogPath}squashfs-root/etc/crontab
if [ -f ${LogPath}squashfs-root/etc/rsyslog.d/50-default.conf ];then
sed -i 's/*.*;auth,authpriv.none/*.*;auth,authpriv,kern.none/g' ${LogPath}squashfs-root/etc/rsyslog.d/50-default.conf
fi
echo 'LogLevel=emerg' >> /etc/systemd/system.conf
echo 'MaxLevelStore=emerg' >> /etc/systemd/journald.conf
echo 'MaxLevelSyslog=emerg' >> /etc/systemd/journald.conf
echo 'MaxLevelKMsg=emerg' >> /etc/systemd/journald.conf
echo 'MaxLevelConsole=emerg' >> /etc/systemd/journald.conf
echo 'MaxLevelWall=emerg' >> /etc/systemd/journald.conf
}
# ************************Configure ubuntu**************************************
# Description: install ssh, configure user/ip and so on
# ******************************************************************************
function configUbuntu()
{
# 1. configure image sources
mkdir -p ${LogPath}squashfs-root/cdtmp
mount -o bind ${TMPDIR_DATE} ${LogPath}squashfs-root/cdtmp
echo "
#!/bin/bash
DRIVER_PACKAGE=\$1
username=\$2
password=\$3
root_pwd=\$4
# 1. apt install deb
mv /etc/apt/sources.list /etc/apt/sources.list.bak
touch /etc/apt/sources.list
echo \"deb file:/cdtmp bionic main restricted\" > /etc/apt/sources.list
locale-gen zh_CN.UTF-8 en_US.UTF-8 en_HK.UTF-8
apt-get update
echo \"make_sd_process: 5%\"
apt-get install openssh-server -y
apt-get install tar -y
apt-get install vim -y
echo \"make_sd_process: 10%\"
apt-get install gcc -y
apt-get install zlib -y
apt-get install python2.7 -y
apt-get install python3 -y
apt-get install pciutils -y
apt-get install strace -y
apt-get install nfs-common -y
apt-get install sysstat -y
apt-get install libelf1 -y
apt-get install libpython2.7 -y
apt-get install libnuma1 -y
echo \"make_sd_process: 20%\"
apt-get install dmidecode -y
apt-get install rsync -y
apt-get install net-tools -y
echo \"make_sd_process: 25%\"
mv /etc/apt/sources.list.bak /etc/apt/sources.list
# 2. set username
useradd -m \${username} -d /home/\${username} -s /bin/bash
sed -i \"/^\${username}:/c\\\\\${password}\" /etc/shadow
sed -i \"/^root:/c\\\\\${root_pwd}\" /etc/shadow
# 3. config host
echo 'davinci-mini' > /etc/hostname
echo '127.0.0.1 localhost' > /etc/hosts
echo '127.0.1.1 davinci-mini' >> /etc/hosts
# 4. config ip
echo \"
network:
version: 2
# renderer: NetworkManager
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [${NETWORK_CARD_DEFAULT_IP}/24]
gateway4: ${NETWORK_CARD_GATEWAY}
nameservers:
addresses: [255.255.0.0]
usb0:
dhcp4: no
addresses: [${USB_CARD_DEFAULT_IP}/24]
gateway4: ${NETWORK_CARD_GATEWAY}
\" > /etc/netplan/01-netcfg.yaml
# 5. auto-run minirc_cp.sh and minirc_sys_init.sh when start ubuntu
echo \"#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will \"exit 0\" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
cd /var/
/bin/bash /var/minirc_boot.sh /opt/mini/${DRIVER_PACKAGE}
/bin/bash /var/acllib_install.sh >/var/1.log
/bin/bash /var/aicpu_kernels_install.sh >>/var/1.log
exit 0
\" > /etc/rc.local
chmod 755 /etc/rc.local
echo \"RuntimeMaxUse=50M\" >> /etc/systemd/journald.conf
echo \"SystemMaxUse=50M\" >> /etc/systemd/journald.conf
echo \"export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/acllib/lib64\" >> /home/HwHiAiUser/.bashrc
exit
# end" > ${LogPath}squashfs-root/chroot_install.sh
chmod 750 ${LogPath}squashfs-root/chroot_install.sh
# 2. add user and install software
# execute in ./chroot_install.sh
chroot ${LogPath}squashfs-root /bin/bash -c "./chroot_install.sh ${DRIVER_PACKAGE} ${USER_NAME} '"${USER_PWD}"' '"${ROOT_PWD}"'"
if [[ $? -ne 0 ]];then
echo "Failed: qemu is broken or the version of qemu is not compatible!"
return 1;
fi
#configure syslog and kern log
configure_syslog_and_kernlog
umount ${LogPath}squashfs-root/cdtmp
rm -rf ${LogPath}squashfs-root/cdtmp
rm ${LogPath}squashfs-root/chroot_install.sh
return 0
}
# end
# ************************Format SDcard*****************************************
# Description: format to ext3 filesystem and three partition
# ******************************************************************************
function formatSDcard()
{
if [[ $(fdisk -l 2>/dev/null | grep "^${DEV_NAME}" | wc -l) -gt 1 ]];then
for i in $(fdisk -l 2>/dev/null | grep "^${DEV_NAME}" | awk -F ' ' '{print $1}'); do
echo "d
w" | fdisk ${DEV_NAME}
done
else
echo "d
w" | fdisk ${DEV_NAME}
fi
umount ${DEV_NAME} 2>/dev/null
echo "n
+5G
n
+1G
n
w" | fdisk ${DEV_NAME}
partprobe
fdisk -l
sleep 5
checkSDCard
if [ $? -ne 0 ];then
return 1
fi
echo "y
" | mkfs.ext3 -L ubuntu_fs ${DEV_NAME}$p1 # updated by aman
if [[ $? -ne 0 ]];then
echo "Failed: Format SDcard1 failed!"
return 1;
fi
echo "make_sd_process: 30%"
checkSDCard
if [ $? -ne 0 ];then
return 1
fi
echo "y
" | mkfs.ext3 -L ubuntu_fs ${DEV_NAME}$p2 # updated by aman
if [[ $? -ne 0 ]];then
echo "Failed: Format SDcard2 failed!"
return 1;
fi
echo "make_sd_process: 35%"
checkSDCard
if [ $? -ne 0 ];then
return 1
fi
echo "y
" | mkfs.ext3 -L ubuntu_fs ${DEV_NAME}$p3 # updated by aman
if [[ $? -ne 0 ]];then
echo "Failed: Format SDcard3 failed!"
return 1;
fi
echo "make_sd_process: 45%"
return 0
}
#end
# ************************Copy files to SD**************************************
# Description: copy rar and root filesystem to SDcard
# ******************************************************************************
function preInstallDriver()
{
echo "start pre install driver"
mkdir -p ${LogPath}squashfs-root/opt/mini
chmod 755 ${LogPath}squashfs-root/opt/mini
# 1. copy third party file
tar zxf ${ISO_FILE_DIR}/${DRIVER_PACKAGE} -C ${LogPath} driver/scripts/minirc_install_phase1.sh
cp ${LogPath}driver/scripts/minirc_install_phase1.sh ${LogPath}squashfs-root/opt/mini/
if [[ $? -ne 0 ]];then
echo "Failed: Copy minirc_install_phase1.sh to filesystem failed!"
return 1
fi
chmod +x ${LogPath}/driver/scripts/minirc_install_phase1.sh
echo "make_sd_process: 75%"
tar -zxf ${ISO_FILE_DIR}/${DRIVER_PACKAGE} -C ${LogPath} driver/scripts/minirc_boot.sh
cp ${LogPath}driver/scripts/minirc_boot.sh ${LogPath}squashfs-root/var/
if [[ $? -ne 0 ]];then
echo "Failed: Copy minirc_boot.sh to filesystem failed!"
return 1
fi
tar -zxf ${ISO_FILE_DIR}/${DRIVER_PACKAGE} -C ${LogPath} driver/extend_rootfs/perf
cp ${LogPath}driver/extend_rootfs/perf ${LogPath}squashfs-root/usr/bin/perf
if [[ $? -ne 0 ]];then
echo "Failed: Copy perf.sh to filesystem failed!"
return 1
fi
chmod +x ${LogPath}squashfs-root/usr/bin/perf
echo "make_sd_process: 80%"
# 2. copy root filesystem
if [[ ${arch} =~ "x86" ]];then
rm ${LogPath}squashfs-root/usr/bin/qemu-aarch64-static
fi
#install $DRIVER_PACKAGE
mkdir -p ${LogPath}mini_pkg_install/opt/mini
cp ${ISO_FILE_DIR}/${DRIVER_PACKAGE} ${LogPath}mini_pkg_install/opt/mini/
chmod +x ${LogPath}squashfs-root/opt/mini/minirc_install_phase1.sh
${LogPath}driver/scripts/minirc_install_phase1.sh ${LogPath}mini_pkg_install
res=$(echo $?)
if [[ ${res} != "0" ]];then
echo "Install ${DRIVER_PACKAGE} fail, error code:${res}"
echo "Failed: Install ${DRIVER_PACKAGE} failed!"
return 1
fi
}
function generateAclLibInstallShell()
{
echo "
#!/bin/bash
chown HwHiAiUser:HwHiAiUser /home/HwHiAiUser/${ACLLIB_PACKAGE}
echo \"y
y
\" | su HwHiAiUser -c \"/home/HwHiAiUser/${ACLLIB_PACKAGE} --run\"
rm -f /home/HwHiAiUser/${ACLLIB_PACKAGE}
exit 0
" >${LogPath}squashfs-root/var/acllib_install.sh
chmod 750 ${LogPath}squashfs-root/var/acllib_install.sh
}
function installAclLib()
{
echo "start install acl lib"
cp -f ${ISO_FILE_DIR}/$ACLLIB_PACKAGE ${LogPath}squashfs-root/home/HwHiAiUser/
chmod 750 ${LogPath}squashfs-root/home/HwHiAiUser/$ACLLIB_PACKAGE
generateAclLibInstallShell
echo "install acl lib end"
}
function genAicpuKernInstShell()
{
echo "
#!/bin/bash
cd /home/HwHiAiUser/aicpu_kernels_device/
chmod 750 *.sh
chmod 750 scripts/*.sh
scripts/install.sh --run
rm -rf /home/HwHiAiUser/aicpu_kernels_device
exit 0
" >${LogPath}squashfs-root/var/aicpu_kernels_install.sh
chmod 750 ${LogPath}squashfs-root/var/aicpu_kernels_install.sh
}
function installAicpuKernels()
{
tar zxf ${ISO_FILE_DIR}/${AICPU_KERNELS_PACKAGE} -C ${LogPath}squashfs-root/home/HwHiAiUser/
genAicpuKernInstShell
}
function copyFilesToSDcard()
{
cp -a ${LogPath}squashfs-root/* ${TMPDIR_SD_MOUNT}
if [[ $? -ne 0 ]];then
echo "Failed: Copy root filesystem to SDcard failed!"
return 1
fi
cp -rf ${TMPDIR_SD_MOUNT}/home/* ${TMPDIR_SD3_MOUNT}/
#rm -rf ${TMPDIR_SD_MOUNT}/home/*
cp -rf ${TMPDIR_SD_MOUNT}/var/log/* ${TMPDIR_SD2_MOUNT}/
#rm -rf ${TMPDIR_SD_MOUNT}/var/log/*
echo "make_sd_process: 90%"
return 0
}
function preInstallMinircPackage()
{
preInstallDriver
if [ $? -ne 0 ];then
echo "Pre install driver package failed"
return 1
fi
echo "pre install driver end"
installAclLib
if [ $? -ne 0 ];then
echo "Pre install acllib package failed"
return 1
fi
echo "pre install acl lib end"
installAicpuKernels
if [ $? -ne 0 ];then
echo "Pre install aicpu_kernels package failed"
return 1
fi
echo "pre install aicpu end"
rm -rf ${LogPath}mini_pkg_install/opt
cp -rf ${LogPath}mini_pkg_install/* ${LogPath}squashfs-root/
if [[ $? -ne 0 ]];then
echo "Failed: Copy mini_pkg_install to filesystem failed!"
return 1
fi
echo "pre install drvier finished"
echo "make_sd_process: 85%"
rm -rf ${LogPath}mini_pkg_install
copyFilesToSDcard
if [ $? -ne 0 ];then
echo "Copy file to sdcard failed"
return 1
fi
}
# end
# ************************Make sysroot**************************************
# Description: copy aarch64 gnu libs
# ******************************************************************************
function make_sysroot()
{
echo "make sysroot start"
if [ ! -d /usr/aarch64-linux-gnu/ ]; then
mkdir -p /usr/aarch64-linux-gnu/
fi
if [ ! -d /usr/lib/aarch64-linux-gnu/ ]; then
mkdir -p /usr/lib/aarch64-linux-gnu/
fi
cp -rdp ${LogPath}squashfs-root/usr/include /usr/aarch64-linux-gnu/
echo "make_sd_process: 95%"
cp -rdp ${LogPath}squashfs-root/usr/lib/aarch64-linux-gnu/* /usr/lib/aarch64-linux-gnu/
echo "make_sd_process: 98%"
cp -rdp ${LogPath}squashfs-root/lib/aarch64-linux-gnu /lib/
if [ ! -f /usr/lib/aarch64-linux-gnu/libz.so ]; then
ln -s /lib/aarch64-linux-gnu/libz.so.1 /usr/lib/aarch64-linux-gnu/libz.so
fi
ln -s /usr/aarch64-linux-gnu/include/sys /usr/include/sys
ln -s /usr/aarch64-linux-gnu/include/bits /usr/include/bits
ln -s /usr/aarch64-linux-gnu/include/gnu /usr/include/gnu
echo "make sysroot end"
}
# ########################Begin Executing######################################
# ************************Check args*******************************************
function main()
{
echo "make_sd_process: 2%"
if [[ $# -lt 4 ]];then
echo "Failed: Number of parameter illegal! Usage: $0 <dev fullname> <img path> <iso fullname> <mini filename>"
return 1;
fi
# ***************check network and usb card ip**********************************
checkIps
if [ $? -ne 0 ];then
return 1
fi
# ************************umount dev_name***************************************
checkSDCard
if [ $? -ne 0 ];then
return 1
fi
# ************************Extract ubuntufs**************************************
# output:squashfs-root/
ubuntufsExtract
if [ $? -ne 0 ];then
return 1
fi
# end
# ************************Check architecture************************************
arch=$(uname -m)
if [[ ${arch} =~ "x86" ]];then
cp /usr/bin/qemu-aarch64-static ${LogPath}squashfs-root/usr/bin/
if [ $? -ne 0 ];then
echo "Failed: qemu-user-static or binfmt-support not found!"
return 1;
fi
chmod 755 ${LogPath}squashfs-root/usr/bin/qemu-aarch64-static
fi
# end
# ************************Configure ubuntu**************************************
echo "Process: 1/4(Configure ubuntu filesystem)"
configUbuntu
if [ $? -ne 0 ];then
return 1
fi
# end
# ************************Format SDcard*****************************************
echo "Process: 2/4(Format SDcard)"
formatSDcard
if [ $? -ne 0 ];then
return 1
fi
# ************************Copy files to SD**************************************
if [[ -d "${TMPDIR_SD_MOUNT}" ]];then
umount ${TMPDIR_SD_MOUNT} 2>/dev/null
rm -rf ${TMPDIR_SD_MOUNT}
fi
mkdir ${TMPDIR_SD_MOUNT}
mount ${DEV_NAME}$p1 ${TMPDIR_SD_MOUNT} 2>/dev/null # updated by aman
if [[ -d "${TMPDIR_SD2_MOUNT}" ]];then
umount ${TMPDIR_SD2_MOUNT} 2>/dev/null
rm -rf ${TMPDIR_SD2_MOUNT}
fi
mkdir ${TMPDIR_SD2_MOUNT}
mount ${DEV_NAME}$p2 ${TMPDIR_SD2_MOUNT} 2>/dev/null # updated by aman
echo "make_sd_process: 50%"
if [[ -d "${TMPDIR_SD3_MOUNT}" ]];then
umount ${TMPDIR_SD3_MOUNT} 2>/dev/null
rm -rf ${TMPDIR_SD3_MOUNT}
fi
mkdir ${TMPDIR_SD3_MOUNT}
mount ${DEV_NAME}$p3 ${TMPDIR_SD3_MOUNT} 2>/dev/null # updated by aman
echo "make_sd_process: 55%"
echo "Process: 3/4(Pre install each run package and copy filesystem to SDcard)"
preInstallMinircPackage
if [ $? -ne 0 ];then
return 1
fi
# end
echo "Process: 4/4(Make sysroot)"
make_sysroot
umount ${TMPDIR_SD_MOUNT} 2>/dev/null
if [[ $? -ne 0 ]];then
echo "Failed: Umount ${TMPDIR_SD_MOUNT} to SDcard failed!"
return 1
fi
umount ${TMPDIR_SD2_MOUNT} 2>/dev/null
if [[ $? -ne 0 ]];then
echo "Failed: Umount ${TMPDIR_SD2_MOUNT} to SDcard failed!"
return 1
fi
umount ${TMPDIR_SD3_MOUNT} 2>/dev/null
if [[ $? -ne 0 ]];then
echo "Failed: Umount ${TMPDIR_SD3_MOUNT} to SDcard failed!"
return 1
fi
echo "Finished!"
return 0
}
main $*
ret=$?
#clean files
echo "make sd car finished ,clean files"
filesClean
if [[ ret -ne 0 ]];then
echo "Failed" > ${LogPath}/make_ubuntu_sd.result
exit 1
fi
echo "Success" > ${LogPath}/make_ubuntu_sd.result
exit 0
# end