From 19828c52e5b50de79739e2c206382be74e596847 Mon Sep 17 00:00:00 2001 From: Stephane Desneux Date: Wed, 30 Nov 2016 23:53:02 +0100 Subject: group build files into folder INSTALL Change-Id: Ib76d53f9ff0aed21f12ebd7aac66c1e877bea4a5 Signed-off-by: Stephane Desneux --- INSTALL/config/bashrc | 191 +++++++++++++++++++++++++ INSTALL/firstrun.sh | 37 +++++ INSTALL/image.conf | 19 +++ INSTALL/setup.d/10_base | 64 +++++++++ INSTALL/setup.d/20_worker_base | 63 ++++++++ INSTALL/setup.d/30_tools | 12 ++ INSTALL/setup.d/99_cleanup | 18 +++ INSTALL/setup_image.sh | 104 ++++++++++++++ INSTALL/tools/bmaptools/bmap-tools_3.3_all.deb | Bin 0 -> 38198 bytes INSTALL/tools/scripts/install_sdk | 46 ++++++ INSTALL/tools/scripts/mksdcard | 126 ++++++++++++++++ INSTALL/tools/scripts/run_xnbd_server | 16 +++ INSTALL/wait_for_net.sh | 19 +++ 13 files changed, 715 insertions(+) create mode 100644 INSTALL/config/bashrc create mode 100644 INSTALL/firstrun.sh create mode 100644 INSTALL/image.conf create mode 100644 INSTALL/setup.d/10_base create mode 100644 INSTALL/setup.d/20_worker_base create mode 100755 INSTALL/setup.d/30_tools create mode 100644 INSTALL/setup.d/99_cleanup create mode 100755 INSTALL/setup_image.sh create mode 100644 INSTALL/tools/bmaptools/bmap-tools_3.3_all.deb create mode 100644 INSTALL/tools/scripts/install_sdk create mode 100755 INSTALL/tools/scripts/mksdcard create mode 100755 INSTALL/tools/scripts/run_xnbd_server create mode 100755 INSTALL/wait_for_net.sh (limited to 'INSTALL') diff --git a/INSTALL/config/bashrc b/INSTALL/config/bashrc new file mode 100644 index 0000000..27da492 --- /dev/null +++ b/INSTALL/config/bashrc @@ -0,0 +1,191 @@ +# Sample .bashrc for SuSE Linux +# Copyright (c) SuSE GmbH Nuernberg + +# There are 3 different types of shells in bash: the login shell, normal shell +# and interactive shell. Login shells read ~/.profile and interactive shells +# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all +# settings made here will also take effect in a login shell. +# +# NOTE: It is recommended to make language settings in ~/.profile rather than +# here, since multilingual X sessions would not work properly if LANG is over- +# ridden in every subshell. + +# Some applications read the EDITOR variable to determine your favourite text +# editor. So uncomment the line below and enter the editor of your choice :-) +#export EDITOR=/usr/bin/vim +#export EDITOR=/usr/bin/mcedit + +# For some news readers it makes sense to specify the NEWSSERVER variable here +#export NEWSSERVER=your.news.server + +# If you want to use a Palm device with Linux, uncomment the two lines below. +# For some (older) Palm Pilots, you might need to set a lower baud rate +# e.g. 57600 or 38400; lowest is 9600 (very slow!) +# +#export PILOTPORT=/dev/pilot +#export PILOTRATE=115200 + +test -s ~/.alias && . ~/.alias || true + +if [ "$PS1" ]; then + function set_bash_prompt { + # save rc + local RC=$? + + function color { + echo -n "\[" + for k in $*; do + case $k in + bold) tput bold 2>/dev/null;; + none) tput sgr0 2>/dev/null;; + *) tput setaf $k 2>/dev/null;; + esac + done + echo -n "\]" + } + + local DARK_RED=$(color 1) + local DARK_GREEN=$(color 2) + local BROWN=$(color 3) + local DARK_BLUE=$(color 4) + local GRAY=$(color 7) + + local RED=$(color bold 1) + local GREEN=$(color bold 2) + local YELLOW=$(color bold 3) + local BLUE=$(color bold 4) + local MAGENTA=$(color bold 5) + local WHITE=$(color bold 7) + + local COLOR_NONE=$(color none) + + function is_git_repository { + git branch >/dev/null 2>&1 + } + + function set_git_branch { + # Capture the output of the "git status" command. + git_status="$(git status 2> /dev/null)" + + # Set color based on clean/staged/dirty. + if [[ ${git_status} =~ "working directory clean" ]]; then + state="${GREEN}" + elif [[ ${git_status} =~ "Changes to be committed" ]]; then + state="${YELLOW}" + else + state="${RED}" + fi + + # Set arrow icon based on status against remote. + remote_pattern="Your branch is (ahead|behind)" + if [[ ${git_status} =~ ${remote_pattern} ]]; then + if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then + remote="${YELLOW}↑" + elif [[ ${BASH_REMATCH[1]} == "behind" ]]; then + remote="${YELLOW}↓" + fi + else + remote="" + fi + diverge_pattern="Your branch and (.*) have diverged" + if [[ ${git_status} =~ ${diverge_pattern} ]]; then + remote="${RED}↕" + fi + + # Get the name of the branch. + branch=$(a=$(git rev-parse --abbrev-ref HEAD 2>/dev/null); [[ $? == 0 ]] && echo $a || echo "") + + # Set the final branch string. + BRANCH="${state}(${branch})${remote}${COLOR_NONE}" + } + + function set_prompt_symbol () { + mark="\$" + if [[ "`id -u`" -eq 0 ]]; then + mark="#" + fi + + if [[ $1 -eq 0 ]]; then + PROMPT_SYMBOL=$mark + elif [[ $1 -eq 127 ]]; then + PROMPT_SYMBOL="${MAGENTA}${mark}${COLOR_NONE}" + else + PROMPT_SYMBOL="${RED}${mark}${COLOR_NONE}" + fi + } + + # Set the PROMPT_SYMBOL variable. We do this first so we don't lose the + # return value of the last command. + set_prompt_symbol $RC + + local usercol=$BLUE + local hostcol=$GREEN + local dircol=$YELLOW + if [ "`id -u`" -eq 0 ]; then + usercol=$RED + hostcol=$RED + dircol=$RED + fi + + # Set the BRANCH variable. + if is_git_repository ; then + set_git_branch + else + BRANCH='' + fi + + # Set the bash prompt variable. + PS1="\[\$(ppwd \l)\][$(date +%H:%M:%S)] ${usercol}\u${COLOR_NONE}@${hostcol}\h${COLOR_NONE}:${dircol}\w${COLOR_NONE}${BRANCH}${PROMPT_SYMBOL} " + } + + if [[ "$(type -t ppwd)" != "function" ]]; then + if [[ "$TERM" =~ xterm ]]; then + _tsl=$(echo -en '\e]2;') + _isl=$(echo -en '\e]1;') + _fsl=$(echo -en '\007') + _sc=$(tput sc 2>/dev/null) + _rc=$(tput rc 2>/dev/null) + TS1="$_sc$_tsl%s@%s:%s$_fsl$_isl%s$_fsl$_rc" + unset _tsl _isl _fsl _sc _rc + function ppwd () { + local dir + local -i width + test -n "$TS1" || return; + dir="$(dirs +0)" + let width=${#dir}-18 + test ${#dir} -le 18 || dir="...${dir#$(printf "%.*s" $width "$dir")}" + local host + host=$(uname -n) + host=${host//.*/} + printf "$TS1" "$USER" "$host" "$dir" "$host" + } + else + function ppwd () { true; } + fi + fi + + PROMPT_COMMAND=set_bash_prompt + + function rcd () { + [ "${1:0:1}" == "/" ] && { cd $1; } || { cd $(pwd -P)/$1; } + } + + alias ll="ls -l" + alias lr="ls -ltr" + alias la="ls -al" + alias egrep='egrep --color=auto' + alias fgrep='fgrep --color=auto' + alias grep='grep --color=auto' + +fi + +# force locale +#export LANG=en_US.UTF-8 +#export LANGUAGE=$LANG +#export LC_ALL=$LANG +#export LC_PAPER=$LANG +#export LC_MONETARY=$LANG +#export LC_NUMERIC=$LANG +#export LC_MEASUREMENT=$LANG +#export LC_TIME=$LANG + diff --git a/INSTALL/firstrun.sh b/INSTALL/firstrun.sh new file mode 100644 index 0000000..2b70a92 --- /dev/null +++ b/INSTALL/firstrun.sh @@ -0,0 +1,37 @@ +#!/bin/bash -x + +# fail at first error ! +set -e + +# redirect outputs to log +LOGFILE=/var/log/firstrun.log +exec >$LOGFILE 2>&1 + +echo $(date +"%Y%m%d %H:%M:%S") Starting firstrun script + +# source same file with .conf extension +. ${0%.sh}.conf + +# run the scripts found in /root/firstrun.d + +for x in /root/firstrun.d/*; do + case $(basename $x) in + [0-9][0-9]_*) + echo "--------------------- start script $x ---------------------" + . $x + echo "--------------------- end of script $x ---------------------" + ;; + *) + ;; + esac + +done + +######################### cleanup ##################### + +# remove firstrun +rm -rf /root/firstrun.* +rm -rf /etc/systemd/system/multi-user.target.wants/firstrun.* +systemctl daemon-reload + +rm -f $LOGFILE diff --git a/INSTALL/image.conf b/INSTALL/image.conf new file mode 100644 index 0000000..27e173f --- /dev/null +++ b/INSTALL/image.conf @@ -0,0 +1,19 @@ +FIRSTRUN=no + +TIMEZONE=Europe/Paris + +XDT_DIR=/xdt + +DEVUSER=devel +DEVUSER_UID=1664 +DEVUSER_PASSWORD=$DEVUSER +DEVUSER_HOME=/home/$DEVUSER + +XDT_META=$XDT_DIR/meta +XDT_DOWNLOADCACHE=$XDT_DIR/downloads +XDT_SSTATECACHE=$XDT_DIR/sstate-cache +XDT_CCACHE=$XDT_DIR/ccache +XDT_BUILD=$XDT_DIR/build +XDT_WORKSPACE=$XDT_DIR/workspace +XDT_SOURCES=$XDT_DIR/sources +XDT_SDK=$XDT_DIR/sdk diff --git a/INSTALL/setup.d/10_base b/INSTALL/setup.d/10_base new file mode 100644 index 0000000..59dab07 --- /dev/null +++ b/INSTALL/setup.d/10_base @@ -0,0 +1,64 @@ +#!/bin/bash + +# add backports and testing repositories +echo "deb http://http.debian.net/debian jessie-backports main contrib" >>/etc/apt/sources.list +echo "deb http://http.debian.net/debian testing main contrib" >>/etc/apt/sources.list + +# setup network retries for apt +echo "Acquire::Retries 5;" >/etc/apt/apt.conf.d/99NetRetries + +# upgrade distro +apt-get update -y +apt-get dist-upgrade -y + +apt-get install -y passwd sudo openssh-server openssh-client vim systemd logrotate ifupdown locales +apt-get remove -y exim4 exim4-base exim4-config exim4-daemon-light +apt-get autoremove -y + +# remove some useless systemd services +for sysdir in /lib/systemd /etc/systemd; do + for pattern in tty udev; do + find $sysdir -name "*${pattern}*" -exec rm -rf {} \; || : + done +done +rm -f /lib/systemd/system/sysinit.target.wants/proc-sys-fs-binfmt_misc.automount + +cp $INSTDIR/config/bashrc /etc/skel/.bash_aliases # sourced by .bashrc for new users + +# copy files for root account (already created) +find /etc/skel -type f -exec cp -av {} /root \; + +# workaround bug on dbus if host runs selinux +mkdir -p /etc/selinux/targeted/contexts/ +echo '' >/etc/selinux/targeted/contexts/dbus_contexts + +# remount selinux ro to workaround bug in apt-get +cat </etc/rc.local +#!/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. + +if [ -d /sys/fs/selinux ]; then + mount -o remount,ro /sys/fs/selinux +fi + +exit 0 +EOF + +# generate locale and set to default +echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen +/usr/sbin/locale-gen +echo "LANG=en_US.UTF-8" >>/etc/default/locale + + + + diff --git a/INSTALL/setup.d/20_worker_base b/INSTALL/setup.d/20_worker_base new file mode 100644 index 0000000..eef5639 --- /dev/null +++ b/INSTALL/setup.d/20_worker_base @@ -0,0 +1,63 @@ +#!/bin/bash + +# install prereqs for bitbake plus other pkgs +apt-get install -y gawk wget git git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev cpio libzip2 lsb-release python3 + +# add some cool base tools +apt-get install -y vim-gtk man tree xz-utils tar + +# for gerrit +apt-get install -y git-review gitg + +# screen, xterm for bitbake devshell +# libncurses5-dev for kernel 'make menuconfig' +apt-get install -y ccache curl screen xterm libncurses5-dev + +# for toaster +apt-get install -y python-pip +pip install "Django==1.6" "South==0.8.4" "argparse==1.2.1" "wsgiref==0.1.2" "beautifulsoup4>=4.4.0" + +# for network boot through tftp+nbd +apt-get install -y tftpd-hpa xnbd-server +# adjust config file to have the server point to bitbake images deployment dir +sed -i -e "s#^\(TFTP_DIRECTORY=\).*\$#\1\"$XDT_BUILD/tmp/deploy/images\"#" /etc/default/tftpd-hpa + +# update xterm resources to have truetype fonts and utf-8 +cat <>/etc/X11/app-defaults/XTerm + +!iotbzh: enable truetype fonts and UTF-8 encoding +*VT100*faceName: mono +*VT100*faceSize: 13 +*VT100*locale: true +EOF + +# add the build user +useradd -c "Builder" -d $DEVUSER_HOME -G sudo -m -U -s /bin/bash -u $DEVUSER_UID $DEVUSER +echo $DEVUSER:$DEVUSER_PASSWORD | chpasswd + +# generate an extra environment file sourced by bashrc +for k in DEVUSER DEVUSER_UID DEVUSER_HOME \ + XDT_DIR \ + XDT_META XDT_DOWNLOADCACHE XDT_SSTATECACHE XDT_CCACHE XDT_BUILD XDT_WORKSPACE XDT_SOURCES XDT_SDK \ + ; do + v=${!k} # get value + [[ "${v:0:1}" == "/" ]] && mkdir -p $v # create dir only if value starts with "/" + echo "export $k=$v" >>/etc/xdtrc +done + +mkdir -p $DEVUSER_HOME/bin +cat <<'EOF' >>$DEVUSER_HOME/.bashrc + +# added by worker image creation script (docker-image-builder) +export PATH=~/bin:$PATH +[[ -f /etc/xdtrc ]] && . /etc/xdtrc + +EOF + +# copy meta init script in ~devel/bin: +wget -O $DEVUSER_HOME/bin/prepare_meta https://raw.githubusercontent.com/iotbzh/agl-manifest/master/prepare_meta +chmod +x $DEVUSER_HOME/bin/* + +chown -R $DEVUSER:$DEVUSER $XDT_DIR +chown -R $DEVUSER:$DEVUSER $DEVUSER_HOME + diff --git a/INSTALL/setup.d/30_tools b/INSTALL/setup.d/30_tools new file mode 100755 index 0000000..486daba --- /dev/null +++ b/INSTALL/setup.d/30_tools @@ -0,0 +1,12 @@ +#!/bin/bash + +apt-get install -y python-lzma python-gpgme pbzip2 pigz lzop + +dpkg -i \ + $INSTDIR/tools/bmaptools/bmap-tools*.deb + +mkdir -p /usr/local/bin +for x in $INSTDIR/tools/scripts/*; do + install --mode=755 $x /usr/local/bin/ +done + diff --git a/INSTALL/setup.d/99_cleanup b/INSTALL/setup.d/99_cleanup new file mode 100644 index 0000000..3cea352 --- /dev/null +++ b/INSTALL/setup.d/99_cleanup @@ -0,0 +1,18 @@ +#!/bin/bash + +apt-get autoremove -y + +# remove big useless files +rm -rf /usr/lib/x86_64-linux-gnu/dri/*.so +rm -rf /usr/lib/perl/5.*/auto/Encode/JP/JP.so +rm -rf /usr/lib/perl/5.*/auto/Encode/KR/KR.so +rm -rf /usr/lib/perl/5.*/auto/Encode/CN/CN.so +rm -rf /usr/lib/perl/5.*/auto/Encode/TW/TW.so + +# keep doc ? +#rm -rf /usr/share/doc +#rm -rf /usr/share/man +#rm -rf /usr/share/locale + + + diff --git a/INSTALL/setup_image.sh b/INSTALL/setup_image.sh new file mode 100755 index 0000000..00a0a50 --- /dev/null +++ b/INSTALL/setup_image.sh @@ -0,0 +1,104 @@ +#!/bin/bash -x + +### this script is called when building the docker image: it's executing in a temp container + +echo "------------------------ Starting $(basename $0) -----------------------" + +function debug() { + set +x + echo "-------------------------" + echo "Command failed." + echo "Running sleep for 1 day. To proceed:" + echo "* run 'killall sleep' to continue" + echo "* run 'killall -9 sleep' to abort the build" + sig=0 + sleep 86400 || sig=$? + # if killed -9, then abort + [[ $sig == 137 ]] && exit 1 # abort + set -x + return 0 # continue +} +trap debug ERR # on error, run a sleep tp debug container + +# get the INSTALL dir (the one where we were launched) +INSTDIR=$(cd $(dirname $0) && pwd -P) +echo "Detected container install dir = $INSTDIR" + +################################## variables ################################# + +# source variables in conf file +. $INSTDIR/image.conf + +################################## install docker endpoint ##################### + +# install the entrypoint script in /usr/bin +install --mode=755 $INSTDIR/wait_for_net.sh /usr/bin/ + +################################## install first-run service ################### +# all operations requiring runnning daemons (inc. systemd) must be run at first +# container instanciation + +if [[ "$FIRSTRUN" == "yes" ]]; then + install --mode=755 $INSTDIR/firstrun.sh /root/firstrun.sh + install --mode=644 $INSTDIR/image.conf /root/firstrun.conf + [[ -d $INSTDIR/firstrun.d ]] && cp -a $INSTDIR/firstrun.d /root/ + mkdir -p /etc/systemd/system/multi-user.target.wants/ + cat </etc/systemd/system/multi-user.target.wants/firstrun.service +[Unit] +Description=Firstrun service +After=network.target + +[Service] +Type=oneshot +ExecStart=-/bin/bash -c /root/firstrun.sh +TimeoutSec=0 +StandardInput=null +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +EOF +fi + +# helper func to install a firstrun hook +function firstrun_add() { + script=$1 + level=${2:-50} + name=${3:-$(basename $script)} + + mkdir -p /root/firstrun.d + cp $script /root/firstrun.d/${level}_$name +} + +################################## adjust system timezone ############################ + +ln -sf ../usr/share/zoneinfo/$TIMEZONE /etc/localtime + +################################## run other scripts in turn ############## + +for script in $INSTDIR/setup.d/*; do + case $(basename $script) in + [0-9][0-9]_*) + echo "--------------------- start script $script ---------------------" + . $script + echo "--------------------- end of script $script ---------------------" + ;; + *) + ;; + esac +done + +############################### cleanup ################################### + +cd / +apt-get clean # clean apt caches +rm -rf /var/lib/apt/lists/* +rm -rf $INSTDIR # yes, I can auto-terminate myself ! + +# cleanup /tmp without removing the dir +for x in $(find /tmp -mindepth 1); do + rm -rf $x || true +done + +echo "------------------------ $(basename $0) finished -----------------------" + diff --git a/INSTALL/tools/bmaptools/bmap-tools_3.3_all.deb b/INSTALL/tools/bmaptools/bmap-tools_3.3_all.deb new file mode 100644 index 0000000..115aa44 Binary files /dev/null and b/INSTALL/tools/bmaptools/bmap-tools_3.3_all.deb differ diff --git a/INSTALL/tools/scripts/install_sdk b/INSTALL/tools/scripts/install_sdk new file mode 100644 index 0000000..7de6023 --- /dev/null +++ b/INSTALL/tools/scripts/install_sdk @@ -0,0 +1,46 @@ +#!/bin/bash + +INSTALLER=$1 +[[ -f $INSTALLER ]] || { echo "Usage: $(basename $0) " >&2; exit 1; } + +. /etc/xdtrc + +# run the snapshot build procedure +rm -rf $XDT_SDK &>/dev/null || { echo "$XDT_SDK already exists but can't be removed. Using sudo..."; sudo rm -rf $XDT_SDK || exit 1 ; } +mkdir -p $XDT_SDK 2>/dev/null || { echo "Giving rights on /xdt to $USER"; sudo chown -R $DEVUSER:$DEVUSER $XDT_DIR; mkdir -p $XDT_SDK; } +$INSTALLER -y -d $XDT_SDK + +#### create a link at SDK default location +# extract script part of installer +offset=$(grep -na -m1 "^MARKER:$" $INSTALLER | cut -d':' -f1) +eval $(head -n $offset $INSTALLER | grep ^DEFAULT_INSTALL_DIR= ) + +PARENT_INSTALL_DIR=$(dirname $DEFAULT_INSTALL_DIR) + +mkdir -p $PARENT_INSTALL_DIR 2>/dev/null || sudo mkdir -p $PARENT_INSTALL_DIR +ln -sf $XDT_SDK $DEFAULT_INSTALL_DIR 2>/dev/null || sudo ln -sf $XDT_SDK $DEFAULT_INSTALL_DIR + + +# remove proprietary files installed in /usr/local/ (arm sysroot) +rm -rfv $XDT_SDK/sysroots/cortex*/usr/local + +# cleanup +pushd $XDT_SDK/sysroots/*-poky-* + + find . -type d -name "*.debug" | while read dir; do + echo "Removing debug dir: $dir" + rm -rf $dir + done + + echo "Removing sources in /usr/src" + rm -rf usr/src + + for dir in bin sbin usr/bin usr/local/bin usr/sbin; do + echo "Removing binaries in $dir" + find $dir -type f -exec file -i '{}' \; | grep 'x-executable;' | grep 'charset=binary' | cut -f1 -d':' | while read file; do + rm -fv $file + done + done + +popd + diff --git a/INSTALL/tools/scripts/mksdcard b/INSTALL/tools/scripts/mksdcard new file mode 100755 index 0000000..d93328e --- /dev/null +++ b/INSTALL/tools/scripts/mksdcard @@ -0,0 +1,126 @@ +#!/bin/bash + +# Copyright (C) 2015 "IoT.bzh" +# Authors: Jose Bollo, Stephane Desneux, Yannick Gicquel +# +# 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 . + +set -e + +usage() { + echo "Usage: $0 [size in GB]" >&2 + echo " is usually located in \$builddir/tmp/deploy/images" >&2 + exit 1 +} + +IMGTAR=$1 +[[ ! -f $IMGTAR ]] && { echo "Invalid image archive" >&2; usage; } + +OUTPUT=$2 + +if [[ -z $OUTPUT ]]; then + echo "Invalid output file/dir." >&2 + usage +elif [[ -d $OUTPUT ]]; then + # output is a dir, use input file for name + OUTPUT=$OUTPUT/$(basename $IMGTAR .rootfs.tar.bz2).raw +fi + + +SIZE=${3:-2} # size in giga + +initdisk() { + local size=$1 file=$2 ; #size is in giga + { + head -c 446 /dev/zero + printf '\x00\x00\x00\x00\x83\x00\x00\x00\x01\x00\x00\x00' + printf $(printf %08x $(( ( (size * 1073741824) - 1) / 512 )) | + sed 's:\(..\)\(..\)\(..\)\(..\):\\x\4\\x\3\\x\2\\x\1:') + head -c 48 /dev/zero + printf '\x55\xAA' + } > $file + dd if=/dev/zero of=$file bs=1 count=0 seek=${size}G +} + +make_image() { + local imgtar=$1 + local ydir=$(dirname $imgtar) + local image=$2 + local size=$3 + local tmpd=/tmp/dir$$ + echo + echo + echo "Creating the image $image ..." + [[ -f $image ]] && rm $image + [[ -f $image.tar.xz ]] && rm $image.tar.xz + initdisk $size $image + [[ ! -e /dev/loop-control ]] && sudo mknod /dev/loop-control c 10 237 + for i in $(seq 0 9); do + [[ ! -b /dev/loop$i ]] && sudo mknod /dev/loop$i b 7 $i + done + local loop=$(sudo losetup -f) + sudo losetup -o 512 $loop $image + sudo mke2fs -t ext3 $loop + sudo mkdir $tmpd + sudo mount $loop $tmpd + echo "Extracting image tarball..." + sudo tar-1.28 pjxf $imgtar -C $tmpd --xattrs-include='*' + sudo cp $ydir/uImage+dtb $tmpd/boot + sudo umount $loop + sudo losetup -d $loop + sudo rmdir $tmpd + + if which bmaptool &>/dev/null; then + echo "Creating bitmap file..." + bmaptool create -o $image.bmap $image + fi + +# echo "Creating compressed image $image.bz2 ..." +# BZIP2=$(which pbzip2 2>/dev/null || which bzip2 2>/dev/null) +# $BZIP2 -f -c $image >$image.bz2 + + echo "Creating compressed image $image.xz..." + xz -0 -T 0 -f -c $image >$image.xz + + rm $image + + echo "done" + echo + echo + echo + echo + echo + echo "Image $image created!" + echo + echo "On Porter board, this image can be booted with the following uboot environment:" + + cat <<'EOF' +--- +setenv bootargs_console 'console=ttySC6,38400 ignore_loglevel' +setenv bootargs_video 'vmalloc=384M video=HDMI-A-1:1920x1080-32@60' +setenv bootargs_root 'root=/dev/mmcblk0p1 rootdelay=3 rw rootfstype=ext3 rootwait' +setenv bootmmc '1:1' +setenv bootcmd_sd 'ext4load mmc ${bootmmc} 0x40007fc0 boot/uImage+dtb' +setenv bootcmd 'setenv bootargs ${bootargs_console} ${bootargs_video} ${bootargs_root}; run bootcmd_sd; bootm 0x40007fc0' +saveenv +--- +EOF + + echo + echo "NB: replace bootmmc value '1:1' with '0:1' or '2:1' to access the good slot" + echo " use 'ext4ls mmc XXX:1' to test access" +} + +make_image $IMGTAR $OUTPUT $SIZE + diff --git a/INSTALL/tools/scripts/run_xnbd_server b/INSTALL/tools/scripts/run_xnbd_server new file mode 100755 index 0000000..190301d --- /dev/null +++ b/INSTALL/tools/scripts/run_xnbd_server @@ -0,0 +1,16 @@ +#!/bin/bash + +. /etc/xdtrc + +MACHINE=${1:-porter} +IMAGE=${2:-${XDT_BUILD}/tmp/deploy/images/${MACHINE}/agl-demo-platform-crosssdk-${MACHINE}.ext4} + +echo "Using MACHINE=$MACHINE IMAGE=$IMAGE" + +[[ ! -f $IMAGE ]] && { echo "Invalid image $IMAGE"; exit 1; } + +REALIMG=$(realpath $IMAGE) +[[ ! -f ${REALIMG}.bak ]] && cp -v ${REALIMG} ${REALIMG}.bak + +sudo systemctl restart tftpd-hpa +sudo xnbd-server --target --lport 10809 $IMAGE diff --git a/INSTALL/wait_for_net.sh b/INSTALL/wait_for_net.sh new file mode 100755 index 0000000..354e76a --- /dev/null +++ b/INSTALL/wait_for_net.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +### this script is used as entrypoint of the docker container to wait for network to be up ### + +IFACE="veth0 eth0" + +function wait_net() { + for i in $IFACE; do + [[ "$(cat /sys/class/net/$i/operstate 2>/dev/null)" == "up" ]] && return 1 + done + return 0 +} + +while wait_net; do + sleep 1 +done + +[[ $# > 0 ]] && exec "$@" +exec /bin/bash -l -- cgit