#!/bin/bash # # Copyright 2017-2019 NXP # # SPDX-License-Identifier: BSD-3-Clause # # Author: Shengzhou Liu set -e ARCH=`uname -m` FIVERSION=1.9.1909 DISTRO_SVR_URL=http://www.nxp.com/lgfiles/sdk/lsdk1909 usage () { cat < ] [ -b ] [ -r ] [ -f ] [ -d ] [ -m ] OPTION: -i, --instruction Instruction to execute, valid argument as below: 'auto' Automatically partition and format the target storage drive, then download and install distro images 'pf' Only partition and format the target storage drive without installing distro images 'download' Only download distro images without installation 'install' Only install the specified image, can be omitted by default 'list' Show the list of supported machines and installation invironment 'mksdcard' Create sdcard.img including composite firmware and distro images -b, --bootpart Boot partition image to be programmed into SD/USB/SATA storage drive -r, --rootfs The first distro rootfs image by default to be programmed into target storage drive -R, --rootfs2 The second distro rootfs image for dual distros installation -d, --device Device name of the target SD/USB/SATA storage drive in Linux -p, --partition Specify configurable partitions of target disk, default as "-p 4P=100M:1G:6G:-1" if not specified -f, --firmware Composite firmware to be programmed into SD card -F, --force Force partition and format target disk regardless of the data in disk -e, --efi Used for the case of UEFI as bootloader instead of U-BOot, valid argument: dtb or acpi -m, --machine Target machine name to specify the name of composite firmware for automatical deployment -u, --url Specify URL of distro webserver to override the default one for automatically downloading distro -v, --version Print version info -h, --help Print help info Examples: - Automatically download and install LSDK distro images to target storage drive on host machine or ARM board: $ flex-installer -i auto -m ls1046ardb -d /dev/mmcblk0 (default latest LSDK distro) $ flex-installer -i auto:lsdk1906 -m lx2160ardb -d /dev/sdx (specify LSDK version) You can specify one or several of '-b -r -R -f -u ' options to override the default settings - Install local distro images with single distro: $ flex-installer -b bootpartition_arm64_lts_4.19.tgz -r rootfs_lsdk1906_LS_arm64_main.tgz -f firmware_ls1046ardb_uboot_sdboot.img -d /dev/sdx - Install local distro images with dual distros: $ flex-installer -b bootpartition_arm64_lts_4.19.tgz -r rootfs_lsdk1906_LS_arm64_main.tgz -R rootfs_buildroot_LS_arm64_devel.tgz -f -d /dev/sdx (run 'setenv devpart_root 3;boot' in U-Boot to boot the second distro from partition 3) - On ARM board running TinyDistro, first partition target disk, then download local distro images onto board and install as below: $ flex-installer -i pf -d /dev/mmcblk0 (or /dev/sdx) $ cd /run/media/mmcblk0p3 (or sdx3) and download distro images to this partition via wget or scp $ flex-installer -b bootpartition_arm64_lts_xx.tgz -r rootfs_lsdk1906_LS_arm64_main.tgz -d /dev/mmcblk0 (or /dev/sdx) - Only download disto images: $ flex-installer -i download -m ls1046ardb - only install composite firmware: $ flex-installer -f firmware_lx2160ardb_uboot_sdboot.img -d /dev/mmcblk0 (or /dev/sdx) - Install distro into sdcard.img with loop device $ flex-installer -i mksdcard -m ls1046ardb Note: '-e dtb' or '-e acpi' option is needed if UEFI is used as bootloader, no need in case of U-Boot. EOF exit } check_disk_capacity() { disksize=$[ `sudo fdisk -ls /dev/$devname` / 1000000 ] if [ $disksize -ge 15 ] || [ ${devname:0:4} = loop ]; then print_n "/dev/$devname: $disksize GB" else print_e "The capacity of /dev/$devname $disksize GB is not enough, 32 GB or above is recommended" exit fi } search_dev() { devlist=`ls /dev/sd?` for dev in $devlist; do sdx=`udevadm info -q all -n $dev | grep ID_BUS` disksize=$[ `sudo fdisk -ls $dev` / 1000000 ] if [ $1 = usb ] ; then if [ ${sdx:10:3} = usb ]; then devusb=${dev:5:3} echo "USB disk: $devusb $disksize GB" break fi elif [ $1 = sata ]; then if [ ${sdx:10:3} = ata ]; then devsata=${dev:5:3} echo "SATA disk: $devsata $disksize GB" break fi fi done } get_device_name_in_tinydistro() { # for automation test with '-d sd|usb|sata' instead of '-d /dev/sdx' in tiny distro by searching the first available device on remote board if [ "$mediadevice" = "sd" ]; then if [ ! -b /dev/mmcblk0 ]; then echo "SD/MMC device is not available"; exit else devname=mmcblk0 fi elif [ "$mediadevice" = "usb" ] ; then search_dev usb devname=$devusb if [ -z "$devname" ] ; then echo "USB device is not available"; exit fi elif [ "$mediadevice" = "sata" ] ; then search_dev sata devname=$devsata if [ -z "$devname" ] ; then echo "SATA device is not available"; exit fi elif echo "$mediadevice" | grep /; then devname=${mediadevice##*/} fi if [ ${devname:0:6} = mmcblk ] || [ ${devname:0:4} = loop ]; then devpartname=${devname}p else devpartname=$devname fi } get_device_name_on_host() { devname=${mediadevice##*/} if [ ${devname:0:6} = mmcblk ] || [ ${devname:0:4} = loop ]; then devpartname=${devname}p else devpartname=$devname fi } umount_device() { sudo umount /dev/${devpartname}* 1>/dev/null 2>&1 || true mntlist=`cat /proc/mounts | grep /dev/${devpartname} | cut -d' ' -f1 | tr '\n' ' '` for mntp in $mntlist; do sudo fuser -k $mntp || true sudo umount $mntp || true done } mount_device() { for ((i=1; i<=$pnum; i++)); do if [ -n "$extendedpart" ] && [ $i = $extendedpart ]; then continue; fi sudo mkdir -p $mntdir/${devpartname}$i if ! mount | grep ${devpartname}$i; then sudo mount /dev/${devpartname}$i $mntdir/${devpartname}$i 1>/dev/null 2>&1 || true fi done } program_firmware_to_sd() { # $1: firmware file, $2: startblock, $3: device if [ ! -b $3 ]; then echo device $device not found exit fi if [ ! -r $1 ]; then echo firmware $1 not found exit fi sudo dd if=$1 of=$3 bs=512 seek=$2 print_d "Program $1 into $3 startblock=$2" } get_partition_number() { [ -z "$diskpartition" ] && print_e "Please specify partition settings" && exit if ! [[ $diskpartition =~ ^[2-9]+[P=]+[0-9]+[G,M]* ]] || \ echo $diskpartition | tr -d '[0-9] [:,-]' | grep -E '[^P,M,G]'; then print_e "Error: the number of partitions should be >= 2 and the unit of size is G or M" print_w "Correct example: '-p 5P=100M:1G:6G:8G:-1', '-1' indicates the end sector of last partition" exit fi pnum=`echo $diskpartition | cut -d= -f1` pnum=${pnum%?} } partition_format_disk() { [ -z "$force_install" ] && check_distro_in_disk print_n "Partitioning /dev/$devname ..." optimal_io_size=$(sudo cat /sys/block/$devname/queue/optimal_io_size) minimum_io_size=$(sudo cat /sys/block/$devname/queue/minimum_io_size) [ "$optimal_io_size" = "0" ] && aligntype=minimal || aligntype=optimal [ $pnum -le 2 ] && parttable=gpt || parttable=msdos umount_device sudo parted -a $aligntype -s /dev/$devname mklabel $parttable for ((i=1; i<=$pnum; i++)); do eval n_p$i=`echo $1 | cut -d: -f$i` [ $i = 1 ] && n_p1=`echo $n_p1 | cut -d= -f2` n_p=`eval echo '${n_p'"$i"'}'` [ ${n_p: -1} = G ] && n_p=${n_p%?} && n_p=$[ $n_p * 1024 ] [ ${n_p: -1} = M ] && n_p=${n_p%?} [ ${n_p: -2} = -1 ] && eval e_p$i=100% [ $i = 1 ] && s_p1=$RESERVEDRAW && e_p1=$[ $s_p1 + $n_p ] && umount_device && \ sudo parted -a $aligntype -s /dev/$devname mkpart primary ${s_p1}MiB ${e_p1}MiB && continue n=$[ i-1 ] && a_e_p=`eval echo '${e_p'"$n"'}'` eval s_p$i=$[ $a_e_p + 1 ] && s_p=`eval echo '${s_p'"$i"'}'` [ ${n_p: -2} = -1 ] && eval e_p$i=100% || eval e_p$i=$[ $s_p + $n_p ] e_p=`eval echo '${e_p'"$i"'}'` if [ $pnum -le 4 ]; then parttype=primary elif [ $i -le 3 ]; then parttype=primary elif [ $i -eq 4 ]; then parttype=extended end=100% umount_device sudo parted -a $aligntype -s /dev/$devname mkpart $parttype ${s_p}MiB $end s_p=$[ $s_p + 1 ] parttype=logical extendedpart=4 else parttype=logical fi [ $e_p != 100% ] && end=${e_p}MiB || end=${e_p} umount_device sudo parted -a $aligntype -s /dev/$devname mkpart $parttype ${s_p}MiB $end done print_n "Formatting partitions ..." [ -f /usr/bin/man ] && man ext4 | grep -q metadata_csum && metadataopt=",^metadata_csum" if [ $ARCH = x86_64 -o $ARCH = i686 ] && [ -f /usr/bin/man ] && ! man ext4 | grep -q metadata_csum; then metadataopt="" else metadataopt=",^metadata_csum" fi for ((i=1; i<=$pnum; i++)); do if [ $i = "$bootpartnum" ]; then umount_device sudo mkfs.ext4 -F -q -b 4096 -L boot -O ^64bit$metadataopt $bootdev || true elif [ $i = "$efipartnum" ]; then if [ "$enable_efi" = "y" ]; then # in case of UEFI as Bootloader umount_device sudo mkfs.vfat -n EFI $efidev || true else # for misc metadata or other uses in case of U-Boot as Bootloader umount_device sudo mkfs.ext4 -F -q -b 4096 -L misc $efidev || true fi else if [ $i = "$syspartnum" ]; then label=system elif [ $i = "$backuppartnum" ]; then label=backup elif [ $i = "$userpartnum" ]; then label=userdata else label=data$i fi umount_device [ $i != "$extendedpart" ] && sudo mkfs.ext4 -F -q -O ^huge_file,^64bit$metadataopt -b 4096 -L $label /dev/${devpartname}$i || true fi done mount_device sudo parted -s /dev/$devname print print_d "partition and format /dev/$devname" } flex_install_distro() { # install composite firmware if [ -n "$firmware" -o $instruction = auto ] && [ -f $firmware_n ]; then umount_device program_firmware_to_sd $firmware_n 8 /dev/$devname mount_device fi # install boot partition if [ -n "$bootpart" -o $instruction = auto ] && [ -d $bootpart_n -o -f $bootpart_n ]; then echo "Installing boot partition, please wait ..." [ $bootparttype = dir ] && sudo cp -rfp $bootpart_n/* $bootpartition [ $bootparttype = tgz ] && sudo tar xf $bootpart_n -C $bootpartition print_d "boot partition installation" fi # install system rootfs if [ -n "$rootfs" -o $instruction = auto ] && [ -d $rootfs_n -o -f $rootfs_n ]; then echo "Installing system rootfs partition, please wait ..." case $rfstype in dir) sudo cp -rfp $rootfs_n/* $syspartition;; tgz) sudo tar xf $rootfs_n -C $syspartition;; ext) dd if=$rootfs_n of=$sysdev bs=4M && sync;; *) echo format $rfstype is not supported; exit esac [ -d $syspartition/debootstrap ] && sudo rm -rf $syspartition/debootstrap print_d "rootfs partition installation" fi # install the second rootfs for dual OS if '-R' option is specified if [ -n "$rootfs2" ] && [ -d $rootfs2_n -o -f $rootfs2_n ]; then echo Installing the second rootfs, please wait ... [ $rfs2type = dir ] && sudo cp -rfp $rootfs2_n/* $backuppart [ $rfs2type = tgz ] && sudo tar xf $rootfs2_n -C $backuppartition [ -d $backuppartition/debootstrap ] && sudo rm -rf $backuppartition/debootstrap print_d "Install $rootfs2" fi if [ -n "$userdata" ]; then echo "Installing userdata, please wait ..." sudo tar xf $userdata -C $userpartition print_d "userdata partition installation" fi [ -n "$bootpart" -o -n "$rootfs" -o -n "$rootfs2" -o $instruction = auto ] && echo sync data, please wait ... && sync [ $distrotype = android ] && print_d "Android installation finished" && exit [ $instruction != auto ] && [ -z "$rootfs" -a -z "$rootfs2" ] && return if [ -n "$rootfs" -o $instruction = auto ]; then [ -n "$rootfs2" ] && partlist="$syspartition $backuppartition" || partlist=$syspartition for curpart in $partlist; do echo setting PARTUUID ... fstabfile=$curpart/etc/fstab uuid_boot=`lsblk -l --output UUID $bootdev | grep -` [ -n "$userpartnum" ] && uuid_user=`lsblk -l --output UUID $userdev | grep -` sudo chmod 666 $fstabfile if ! grep '^/dev/root' $fstabfile; then sudo echo "/dev/root / ext4 errors=remount-ro 0 1" >> $fstabfile fi [ -d $curpart/boot ] || mkdir -p $curpart/boot sudo echo "UUID=$uuid_boot /boot ext4 defaults 0 2" >> $fstabfile [ -n "$userpartnum" ] && sudo echo "UUID=$uuid_user /userdata ext4 defaults 0 2" >> $fstabfile sudo chmod 644 $fstabfile test -f $curpart/etc/apt/apt.conf && sudo rm -f $curpart/etc/apt/apt.conf done fi if [ "$enable_efi" = "y" ]; then # configure grub.cfg for UEFI if [ -f $bootpartition/grub/${machine}_grub.cfg ]; then partuuid_boot=`lsblk -l --output PARTUUID $bootdev | grep -` partuuid_sys=`lsblk -l --output PARTUUID $sysdev | grep -` sudo touch $bootpartition/$partuuid_boot grep -r -l partuuid_boot $bootpartition/grub | sudo xargs sed -i "s/partuuid_boot/$partuuid_boot/g" grep -r -l partuuid_sys $bootpartition/grub | sudo xargs sed -i "s/partuuid_sys/$partuuid_sys/g" if [ "$enable_acpi" = "y" ] && grep -q 'console=ttyAMA0,115200' $bootpartition/grub/${machine}_grub.cfg; then grep -l 'console=ttyAMA0,115200' $bootpartition/grub/${machine}_grub.cfg | \ sudo xargs sed -i "s/console=ttyAMA0,115200/acpi=force/g" fi fi if ! mount | grep ${devpartname}$efipartnum; then sudo mount $efidev $efipartition fi sudo mkdir -p $efipartition/EFI/BOOT if [ -f $bootpartition/grub/${machine}_grub.cfg ]; then sudo cp $bootpartition/grub/${machine}_grub.cfg $efipartition/EFI/BOOT/grub.cfg fi if [ -f $bootpartition/grub/BOOTAA64.EFI ]; then sudo cp $bootpartition/grub/BOOTAA64.EFI $efipartition/EFI/BOOT/ fi if grep -q U-Boot $syspartition/etc/buildinfo; then sudo sed -i '3d' $syspartition/etc/buildinfo fi fi if [ -n "$rootfs" -o $instruction = auto ] && [ -d $rootfs_n -o -f $rootfs_n ]; then if grep -q $uuid_boot $fstabfile; then [ $ARCH = aarch64 -o $ARCH = armv7l ] && [ `pwd` = $backuppartition ] && cd - umount_device || true print_n "Installation completed successfully" else print_e "Installation failed" fi fi } check_distro_in_disk() { if ! mount | grep -q $backuppartition; then sudo mount $backupdev $backuppartition || true; fi if ! mount | grep -q $syspartition; then sudo mount $sysdev $syspartition || true; fi for tdir in $backuppartition $syspartition; do if [ -d $tdir/var/lib ]; then print_w "\nWARNING: Appears $tdir contains an existing file system, formatting this partition might cause loss of data on it" read -t 40 -n 1 -p "Do you want to format this partition now? [y/n] " rdresult && echo "" [ -z "$rdresult" ] && rdresult=n [ "$rdresult" != y -a "$rdresult" != Y -a "$rdresult" != n -a "$rdresult" != N ] && echo $rdresult is invalid, valid: y or n && exit if [ $rdresult = n -o $rdresult = N ]; then print_w "\nPlease backup important data in $tdir if necessary," print_w "then rerun it by selecting 'y' with confirmation of formatting this partition!" showpart=n; exit fi fi done } check_images_format() { if [ -d $bootpart_n ]; then bootparttype=dir elif file -L $bootpart_n | grep -q 'gzip compressed'; then bootparttype=tgz elif file -L $bootpart_n | grep -q 'UUID='; then bootparttype=ext elif [ $instruction != auto ] && [ -n "$bootpart" ] && [ ! -f $bootpart ]; then print_e "Not found $bootpart"; exit else bootparttype=unknown fi if [ -d $rootfs_n ]; then rfstype=dir elif file -L $rootfs_n | grep -q 'gzip compressed'; then rfstype=tgz elif file -L $rootfs_n | grep -q 'UUID='; then rfstype=ext elif [ $instruction != auto ] && [ -n "$rootfs" ] && [ ! -f $rootfs ]; then print_e "Not found $rootfs"; exit else rfstype=unknown fi if [ -d $rootfs2_n ]; then rfs2type=dir elif file -L $rootfs2_n | grep -q 'gzip compressed'; then rfs2type=tgz elif file -L $rootfs2_n | grep -q 'UUID='; then rfs2type=ext elif [ $instruction != auto ] && [ -n "$rootfs2" ] && [ ! -f $rootfs2 ]; then print_e "Not found $rootfs2"; exit else rfs2type=unknown fi } check_network_access() { if echo $url | grep -q //; then remoteserver=$(echo $url | cut -d/ -f3) else remoteserver=$(echo $url | cut -d/ -f1) fi retcode=$(curl -I -m 10 -o /dev/null -s -w %{http_code} $remoteserver) || true if [ ${retcode:0:1} != 2 -a ${retcode:0:1} != 3 ]; then print_e "ERROR: HTTP returned $retcode, unable to access $remoteserver to fetch distro image" print_e "Please check your network to ensure $remoteserver is accessable via HTTP from this machine" print_e "Please check HTTP proxy settings if needed in your environment" exit fi } check_http_request() { retcode=$(curl -I -m 10 -o /dev/null -s -w %{http_code} $1) || true if [ "$retcode" != 200 -a "$retcode" != 000 ]; then print_e "The requested URL $1 returned error $retcode" exit fi } download_distro() { check_http_request $bootpart_url if [ -n "$machine" ] && [ "$machine" != ls2088ardb -a "$machine" != ls1012ardb -a "$machine" != ls1012afrwy ]; then if [ -f ${firmware_url##*/} ]; then \ echo -e "${firmware_url##*/} already exists ..." && uselocalimg=y else echo -e "\n Downloading $firmware_url ..." && curl -R -O -f $firmware_url; if [ $? != 0 ]; then print_w "Not found $firmware_url" fi fi fi && \ if [ -f ${bootpart_url##*/} ]; then \ echo -e "${bootpart_url##*/} already exists ..." && uselocalimg=y else echo -e "\n Downloading $bootpart_url ..." && curl -R -O -f $bootpart_url fi && \ if [ -f ${rootfs_url##*/} ]; then \ echo -e "${rootfs_url##*/} already exists ..." && uselocalimg=y else echo -e "\n Downloading $rootfs_url ..." && curl -R -O -f $rootfs_url fi && \ if [ -n "$rootfs2" ]; then if [ -f ${rootfs2_url##*/} ]; then \ echo -e "${rootfs2_url##*/} already exists ..." && uselocalimg=y else echo -e "\n Downloading $rootfs2_url ..." && curl -R -O -f $rootfs2_url fi fi if [ $? != 0 ]; then print_e "Failed to download distro images" exit elif [ "$uselocalimg" != y ]; then print_n "Downloaded distro images successfully" fi } print_e() { echo -e "${RED} $1 ${NC}" } print_n() { echo -e "${green} $1 ${NC}" } print_w() { echo -e "${YELLOW} $1 ${NC}" } print_d() { echo -e "${GREEN} $1 [Done] ${NC}" } RED='\e[1;31m' GREEN='\e[1;32m' green='\e[0;32m' YELLOW='\e[1;33m' NC='\e[0m' if [ -z "$1" -o "$1" = "--help" ] ; then usage; exit fi ARGS=`getopt -a -o m:f:b:r:R:u:p:d:s:i:e:hvF -l machine:,firmware:,bootpart:,rootfs:,rootfs2:,url:,partition:,device:,efi:,startblock:,instruction:,help,version,force -- "$@"` [ $? -ne 0 ] && usage eval set -- "${ARGS}" while true do case "$1" in -m|--machine) machine=$2 shift;; -f|--firmware) firmware=$2 echo firmware = $firmware shift;; -s|--startblock) startblock=$2 echo startblock = $startblock shift;; -b|--bootpart) bootpart=$2 echo bootpart = $bootpart shift;; -r|--rootfs) rootfs=$2 echo rootfs = $rootfs shift;; -R|--rootfs2) rootfs2=$2 echo rootfs2 = $rootfs2 shift;; -p|--partition) diskpartition=$2 echo diskpartition = $diskpartition shift;; -u|--url) url=$2 echo URL = $url shift;; -d|--device) mediadevice=$2 shift;; -i|instruction) if [ ${2:0:5} = auto: ]; then distrover=$(echo $2 | cut -d: -f2) echo distroversion: $distrover elif [ ${2:0:3} = pf: ]; then distrotype=$(echo $2 | cut -d: -f2) fi instruction=$(echo $2 | cut -d: -f1) shift;; -e|--efi) enable_efi=y echo "'-e' option is enabled for UEFI instead of U-Boot" [ "$2" = dtb ] && echo dtb is used for UEFI [ "$2" = acpi ] && enable_acpi=y && echo ACPI is enabled shift;; -v|--version) echo flex-installer version: $FIVERSION exit;; -h|--help) usage;; -F|--force) force_install=y;; --) shift break;; esac shift done if [ -n "$instruction" ] && [ $instruction != auto -a $instruction != pf -a $instruction != download \ -a $instruction != install -a $instruction != list -a $instruction != mksdcard ]; then print_e "Invalid instruction $instruction, valid: auto, pf, download, install, list, mksdcard" exit fi default_machine_list='ls1012ardb ls1012afrwy ls1021atwr ls1028ardb ls1043ardb ls1046ardb ls1046afrwy ls1088ardb_pb ls2088ardb lx2160ardb ' if [ "$instruction" = list ]; then print_n "\nSupported machine list:" print_n " $default_machine_list" print_n "\nSupported invironment of installation:" print_n " Linux host PC, ARM board running LSDK distro, ARM board running TinyLinux" exit fi [ -z "$distrotype" ] && distrotype=linux [ -z "$instruction" ] && instruction=null if [ -z "$mediadevice" ] && [ $instruction != download -a $instruction != mksdcard ]; then print_e "Please specify '-d '" exit fi [ $instruction = mksdcard -a -z "$mediadevice" ] && mediadevice=`sudo losetup -f` if [ $ARCH = x86_64 -o $ARCH = i686 ] && [ $instruction != download ]; then if [ ! -b $mediadevice ]; then print_e "$mediadevice does not exist on this host machine" exit fi get_device_name_on_host else [ $instruction != download ] && get_device_name_in_tinydistro fi [ -n "$distrover" ] && distroversion=$distrover || distroversion=lsdk${FIVERSION:4:4} default_linux_version=4.19 RESERVEDRAW=68 DEFAULT_LINUX_PARTITION="4P=100M:1G:6G:-1" DEFAULT_LOOP_SDCARD_PARTITION="4P=30M:1G:50M:-1" DEFAULT_ANDROID_PARTITION="4P=1G:2G:2G:-1" if [ $distrotype = android ]; then bootpartnum=1; syspartnum=2; backuppartnum=3; userpartnum=4 [ -z "$diskpartition" ] && diskpartition=$DEFAULT_ANDROID_PARTITION elif [ "${devname:0:4}" = loop ]; then bootpartnum=2; syspartnum=4; backuppartnum=3; efipartnum=1 [ -z "$diskpartition" ] && diskpartition=$DEFAULT_LOOP_SDCARD_PARTITION else bootpartnum=2; syspartnum=4; backuppartnum=3; efipartnum=1 [ -z "$diskpartition" ] && diskpartition=$DEFAULT_LINUX_PARTITION fi get_partition_number if [ $instruction = auto -o $instruction = mksdcard ]; then if [ -z "$machine" ] || ! echo "$default_machine_list" | grep -q "$machine "; then print_w "Please specify correct '-m '" print_n "Valid machine name: $default_machine_list" exit fi fi mntdir=/run/media bootdev=/dev/${devpartname}$bootpartnum sysdev=/dev/${devpartname}$syspartnum backupdev=/dev/${devpartname}$backuppartnum bootpartition=$mntdir/${devpartname}${bootpartnum} syspartition=$mntdir/${devpartname}${syspartnum} backuppartition=$mntdir/${devpartname}${backuppartnum} [ -n "$efipartnum" ] && efidev=/dev/${devpartname}$efipartnum && efipartition=$mntdir/${devpartname}${efipartnum} [ -n "$userpartnum" ] && userdev=/dev/${devpartname}$userpartnum && userpartition=$mntdir/${devpartname}${userpartnum} [ "$machine" = "ls1021atwr" ] && tgtarch=arm32 || tgtarch=arm64 for i in $bootpartition $syspartition $backuppartition $efipartition $userpartition; do sudo mkdir -p $i done [ -n "$bootpart" ] && bootpart_n=$bootpart || bootpart_n=bootpartition_LS_${tgtarch}_lts_${default_linux_version}.tgz [ -n "$firmware" ] && firmware_n=$firmware || firmware_n=firmware_${machine}_uboot_sdboot.img [ -n "$rootfs" ] && rootfs_n=$rootfs || rootfs_n=rootfs_${distroversion}_LS_${tgtarch}_main.tgz [ -n "$rootfs2" ] && rootfs2_n=$rootfs2 if [ -z "$url" -a -z "$distrover" ]; then url=$DISTRO_SVR_URL elif [ -z "$url" -a -n "$distrover" ]; then url=${DISTRO_SVR_URL%/*}/$distrover fi rootfs_url=$url/$rootfs_n rootfs2_url=$url/$rootfs2_n bootpart_url=$url/$bootpart_n firmware_url=$url/$firmware_n if [ $instruction = auto ]; then if [ ! -f /usr/bin/curl ]; then print_e "not found curl, please install curl package" exit fi check_disk_capacity partition_format_disk $diskpartition if [ $ARCH = aarch64 -o $ARCH = armv7l ]; then if grep -q Tiny /etc/issue; then cd $backuppartition; fi fi check_network_access download_distro check_images_format flex_install_distro elif [ $instruction = pf ]; then check_disk_capacity partition_format_disk $diskpartition elif [ $instruction = download ]; then check_network_access download_distro elif [ $instruction = null -o $instruction = install ] && \ [ -n "$bootpart" -o -n "$rootfs" -o -n "$rootfs2" -o "$firmware" ]; then if [ "$enable_efi" = "y" ] && [ -z "$machine" ]; then print_e "Please specify '-m ' for UEFI installation" exit fi if [ "$ARCH" = "x86_64" -o "$ARCH" = "i686" ] || [[ `cat /etc/issue | grep 'NXP LSDK lsdk'` ]]; then partition_format_disk $diskpartition fi check_images_format flex_install_distro elif [ $instruction = mksdcard ]; then if mount|grep $mntdir/$devname; then sudo umount $mntdir/$devname* 1>/dev/null 2>&1 || true; fi print_n "Creating ${machine}_sdcard.img, waiting ..." [ -f ${machine}_sdcard.img ] && echo Using the existing ${machine}_sdcard.img || \ dd if=/dev/zero of=${machine}_sdcard.img bs=1M count=4000 loopdev=$(sudo losetup -j ${machine}_sdcard.img | cut -d' ' -f1) if [ -n "$loopdev" ]; then for lpn in $loopdev; do sudo losetup -d ${lpn::-1} done fi sudo losetup /dev/$devname ${machine}_sdcard.img flex-installer -i auto -m $machine -d /dev/$devname sudo losetup -d /dev/$devname else print_e "Incorrect usage, run 'flex-installer -h' to see help info" fi