Browse Source

Make mender-convert tool print more concise output

Only crucial information is presented to the user as
console output.
More verbose information is stored in the build.log.

Issues: MEN-2172

Changelog: None

Signed-off-by: Adam Podogrocki <a.podogrocki@gmail.com>
1.0.x
Adam Podogrocki 6 years ago
parent
commit
52e5263d48
  1. 8
      bbb-convert-stage-2.sh
  2. 6
      bbb-convert-stage-3.sh
  3. 59
      bbb-convert-stage-5.sh
  4. 28
      convert-stage-4.sh
  5. 150
      mender-convert
  6. 49
      mender-convert-functions.sh
  7. 7
      rpi3-convert-stage-2.sh
  8. 7
      rpi3-convert-stage-3.sh
  9. 31
      rpi3-convert-stage-5.sh

8
bbb-convert-stage-2.sh

@ -5,11 +5,11 @@ embedded_rootfs_dir=$2
uboot_backup_dir=${embedded_rootfs_dir}/opt/backup/uboot uboot_backup_dir=${embedded_rootfs_dir}/opt/backup/uboot
[ ! -d "${sdimg_boot_dir}" ] && \ [ ! -d "${sdimg_boot_dir}" ] && \
{ echo "Error: boot location not mounted."; exit 1; } { log "Error: boot location not mounted."; exit 1; }
[ ! -d "${embedded_rootfs_dir}" ] && \ [ ! -d "${embedded_rootfs_dir}" ] && \
{ echo "Error: embedded content not mounted."; exit 1; } { log "Error: embedded content not mounted."; exit 1; }
[[ ! -f $uboot_backup_dir/MLO || ! -f $uboot_backup_dir/u-boot.img ]] && \ [[ ! -f $uboot_backup_dir/MLO || ! -f $uboot_backup_dir/u-boot.img ]] && \
{ echo "Error: cannot find U-Boot related files."; exit 1; } { log "Error: cannot find U-Boot related files."; exit 1; }
set_uenv() { set_uenv() {
cat <<- 'EOF' | sudo tee --append $sdimg_boot_dir/uEnv.txt 2>&1 >/dev/null cat <<- 'EOF' | sudo tee --append $sdimg_boot_dir/uEnv.txt 2>&1 >/dev/null
@ -42,6 +42,6 @@ sudo cp ${uboot_backup_dir}/u-boot.img ${sdimg_boot_dir}
# Create U-Boot purposed uEnv.txt file. # Create U-Boot purposed uEnv.txt file.
set_uenv set_uenv
echo -e "\tDone." log "\tDone."
exit 0 exit 0

6
bbb-convert-stage-3.sh

@ -4,9 +4,9 @@ sdimg_primary_dir=$1
embedded_rootfs_dir=$2 embedded_rootfs_dir=$2
[ ! -d "${sdimg_primary_dir}" ] && \ [ ! -d "${sdimg_primary_dir}" ] && \
{ echo "Error: rootfs location not mounted."; exit 1; } { log "Error: rootfs location not mounted."; exit 1; }
[ ! -d "${embedded_rootfs_dir}" ] && \ [ ! -d "${embedded_rootfs_dir}" ] && \
{ echo "Error: embedded content not mounted."; exit 1; } { log "Error: embedded content not mounted."; exit 1; }
# Copy rootfs partition. # Copy rootfs partition.
sudo cp -ar ${embedded_rootfs_dir}/* ${sdimg_primary_dir} sudo cp -ar ${embedded_rootfs_dir}/* ${sdimg_primary_dir}
@ -15,6 +15,6 @@ sudo cp -ar ${embedded_rootfs_dir}/* ${sdimg_primary_dir}
sudo install -d -m 755 ${sdimg_primary_dir}/boot/efi sudo install -d -m 755 ${sdimg_primary_dir}/boot/efi
sudo install -d -m 755 ${sdimg_primary_dir}/data sudo install -d -m 755 ${sdimg_primary_dir}/data
echo -e "\tDone." log "\tDone."
exit 0 exit 0

59
bbb-convert-stage-5.sh

@ -44,6 +44,7 @@ device_type=
keep=0 keep=0
efi_boot=EFI/BOOT efi_boot=EFI/BOOT
EFI_STUB_VER="4.12.0" EFI_STUB_VER="4.12.0"
build_log=$output_dir/build.log
declare -a mender_disk_mappings declare -a mender_disk_mappings
@ -68,14 +69,14 @@ get_kernel_version() {
# #
# $1 - linux kernel version # $1 - linux kernel version
build_env_lock_boot_files() { build_env_lock_boot_files() {
echo -e "\tBuilding boot scripts and tools." log "\tBuilding boot scripts and tools."
local grubenv_repo_vc_dir=$grubenv_dir/.git local grubenv_repo_vc_dir=$grubenv_dir/.git
local grubenv_build_dir=$grubenv_dir/build local grubenv_build_dir=$grubenv_dir/build
mkdir -p $grubenv_dir mkdir -p $grubenv_dir
if [ ! -d $grubenv_repo_vc_dir ]; then if [ ! -d $grubenv_repo_vc_dir ]; then
git clone https://github.com/mendersoftware/grub-mender-grubenv.git $grubenv_dir git clone https://github.com/mendersoftware/grub-mender-grubenv.git $grubenv_dir >> "$build_log" 2>&1
fi fi
cd $grubenv_dir cd $grubenv_dir
@ -91,8 +92,8 @@ build_env_lock_boot_files() {
sed -i '/^kernel_imagetype/s/=.*$/='${kernel_imagetype}'/' mender_grubenv_defines sed -i '/^kernel_imagetype/s/=.*$/='${kernel_imagetype}'/' mender_grubenv_defines
sed -i '/^kernel_devicetree/s/=.*$/='${kernel_devicetree//\//\\/}'/' mender_grubenv_defines sed -i '/^kernel_devicetree/s/=.*$/='${kernel_devicetree//\//\\/}'/' mender_grubenv_defines
make --quiet make --quiet >> "$build_log" 2>&1
make --quiet DESTDIR=$grubenv_build_dir install make --quiet DESTDIR=$grubenv_build_dir install >> "$build_log" 2>&1
cd $output_dir cd $output_dir
} }
@ -100,7 +101,7 @@ build_env_lock_boot_files() {
# #
# $1 - linux kernel version # $1 - linux kernel version
build_grub_efi() { build_grub_efi() {
echo -e "\tBuilding GRUB efi file." log "\tBuilding GRUB efi file."
local grub_build_dir=$grub_dir/build local grub_build_dir=$grub_dir/build
local grub_arm_dir=$grub_build_dir/arm local grub_arm_dir=$grub_build_dir/arm
@ -112,16 +113,16 @@ build_grub_efi() {
# Build grub modules for arm platform and executables for the host. # Build grub modules for arm platform and executables for the host.
if [ ! -d $grub_repo_vc_dir ]; then if [ ! -d $grub_repo_vc_dir ]; then
git clone git://git.savannah.gnu.org/grub.git $grub_dir git clone git://git.savannah.gnu.org/grub.git $grub_dir >> "$build_log" 2>&1
fi fi
cd $grub_dir cd $grub_dir
make --quiet distclean make --quiet distclean >> "$build_log" 2>&1
if [ $(version $version) -lt $(version $EFI_STUB_VER) ]; then if [ $(version $version) -lt $(version $EFI_STUB_VER) ]; then
# To avoid error message: "plain image kernel not supported - rebuild # To avoid error message: "plain image kernel not supported - rebuild
# with CONFIG_(U)EFI_STUB enabled" - use a specific commit. # with CONFIG_(U)EFI_STUB enabled" - use a specific commit.
git checkout 9b37229f0 git checkout 9b37229f0 >> "$build_log" 2>&1
fi fi
mkdir -p $grub_arm_dir mkdir -p $grub_arm_dir
@ -130,27 +131,27 @@ build_grub_efi() {
local cores=$(nproc) local cores=$(nproc)
# First build host tools. # First build host tools.
./autogen.sh > /dev/null ./autogen.sh >> "$build_log" 2>&1
./configure --quiet CC=gcc --target=${host} --with-platform=efi --prefix=$grub_host_dir ./configure --quiet CC=gcc --target=${host} --with-platform=efi --prefix=$grub_host_dir >> "$build_log" 2>&1
make --quiet -j$cores make --quiet -j$cores >> "$build_log" 2>&1
make --quiet install make --quiet install >> "$build_log" 2>&1
# Clean workspace. # Clean workspace.
make --quiet clean make --quiet clean >> "$build_log" 2>&1
make --quiet distclean make --quiet distclean >> "$build_log" 2>&1
# Now build ARM modules. # Now build ARM modules.
./configure --quiet --host=$bootloader_toolchain --with-platform=efi \ ./configure --quiet --host=$bootloader_toolchain --with-platform=efi \
--prefix=$grub_arm_dir CFLAGS="-Os -march=armv7-a" \ --prefix=$grub_arm_dir CFLAGS="-Os -march=armv7-a" \
CCASFLAGS="-march=armv7-a" --disable-werror CCASFLAGS="-march=armv7-a" --disable-werror >> "$build_log" 2>&1
make --quiet -j$cores make --quiet -j$cores >> "$build_log" 2>&1
make --quiet install make --quiet install >> "$build_log" 2>&1
# Build GRUB EFI image. # Build GRUB EFI image.
${grub_host_dir}/bin/grub-mkimage -v -p /$efi_boot -o grub.efi --format=arm-efi \ ${grub_host_dir}/bin/grub-mkimage -v -p /$efi_boot -o grub.efi --format=arm-efi \
-d $grub_arm_dir/lib/grub/arm-efi/ boot linux ext2 fat serial part_msdos \ -d $grub_arm_dir/lib/grub/arm-efi/ boot linux ext2 fat serial part_msdos \
part_gpt normal efi_gop iso9660 configfile search loadenv test cat echo \ part_gpt normal efi_gop iso9660 configfile search loadenv test cat echo \
gcry_sha256 halt hashsum loadenv reboot &> /dev/null gcry_sha256 halt hashsum loadenv reboot >> "$build_log" 2>&1
rc=$? rc=$?
@ -182,7 +183,7 @@ set_uenv() {
# $1 - boot partition mountpoint # $1 - boot partition mountpoint
# $2 - primary partition mountpoint # $2 - primary partition mountpoint
install_files() { install_files() {
echo -e "\tInstalling GRUB files." log "\tInstalling GRUB files."
local boot_dir=$1 local boot_dir=$1
local rootfs_dir=$2 local rootfs_dir=$2
@ -197,7 +198,7 @@ install_files() {
# Make sure env, lock, lock.sha256sum files exists in working directory. # Make sure env, lock, lock.sha256sum files exists in working directory.
[[ ! -d $grubenv_efi_boot_dir/mender_grubenv1 || \ [[ ! -d $grubenv_efi_boot_dir/mender_grubenv1 || \
! -d $grubenv_efi_boot_dir/mender_grubenv2 ]] && \ ! -d $grubenv_efi_boot_dir/mender_grubenv2 ]] && \
{ echo "Error: cannot find mender grub related files."; return 1; } { log "Error: cannot find mender grub related files."; return 1; }
sudo install -d -m 755 $efi_boot_dir sudo install -d -m 755 $efi_boot_dir
@ -219,17 +220,17 @@ install_files() {
do_install_bootloader() { do_install_bootloader() {
if [ -z "${mender_disk_image}" ]; then if [ -z "${mender_disk_image}" ]; then
echo "Mender raw disk image not set. Aborting." log "Mender raw disk image not set. Aborting."
exit 1 exit 1
fi fi
if [ -z "${bootloader_toolchain}" ]; then if [ -z "${bootloader_toolchain}" ]; then
echo "ARM GCC toolchain not set. Aborting." log "ARM GCC toolchain not set. Aborting."
exit 1 exit 1
fi fi
if [ -z "${device_type}" ]; then if [ -z "${device_type}" ]; then
echo "Target device type name not set. Aborting." log "Target device type name not set. Aborting."
exit 1 exit 1
fi fi
@ -239,7 +240,7 @@ do_install_bootloader() {
fi fi
[ ! -f $mender_disk_image ] && \ [ ! -f $mender_disk_image ] && \
{ echo "$mender_disk_image - file not found. Aborting."; exit 1; } { log "$mender_disk_image - file not found. Aborting."; exit 1; }
# Map & mount Mender compliant image. # Map & mount Mender compliant image.
create_device_maps $mender_disk_image mender_disk_mappings create_device_maps $mender_disk_image mender_disk_mappings
@ -258,15 +259,15 @@ do_install_bootloader() {
sudo mount ${map_primary} ${path_primary} sudo mount ${map_primary} ${path_primary}
get_kernel_version ${path_primary} kernel_version get_kernel_version ${path_primary} kernel_version
echo -e "\tFound kernel version: $kernel_version" log "\tFound kernel version: $kernel_version"
build_env_lock_boot_files $kernel_version build_env_lock_boot_files $kernel_version
build_grub_efi $kernel_version build_grub_efi $kernel_version
rc=$? rc=$?
[[ $rc -ne 0 ]] && { echo -e "\tBuilding grub.efi failed. Aborting."; } \ [[ $rc -ne 0 ]] && { log "\tBuilding grub.efi failed. Aborting."; } \
|| { echo -e "\tBuilding grub.efi succeeded."; \ || { log "\tBuilding grub.efi succeeded."; \
install_files ${path_boot} ${path_primary}; } install_files ${path_boot} ${path_primary}; }
# Back to working directory. # Back to working directory.
@ -277,7 +278,7 @@ do_install_bootloader() {
rm -rf $output_dir/sdimg rm -rf $output_dir/sdimg
[[ $keep -eq 0 ]] && { rm -rf $grubenv_dir $grub_dir; } [[ $keep -eq 0 ]] && { rm -rf $grubenv_dir $grub_dir; }
[[ $rc -ne 0 ]] && { exit 1; } || { echo -e "\tDone."; } [[ $rc -ne 0 ]] && { exit 1; } || { log "\tDone."; }
} }
PARAMS="" PARAMS=""
@ -309,7 +310,7 @@ while (( "$#" )); do
break break
;; ;;
-*) -*)
echo "Error: unsupported option $1" >&2 log "Error: unsupported option $1"
exit 1 exit 1
;; ;;
*) *)

28
convert-stage-4.sh

@ -121,7 +121,7 @@ get_mender_files_from_upstream() {
mkdir -p $mender_dir mkdir -p $mender_dir
echo -e "\tDownloading inventory & identity scripts." log "\tDownloading inventory & identity scripts."
wget -nc -q -O $mender_dir/mender-device-identity \ wget -nc -q -O $mender_dir/mender-device-identity \
$mender_client_repo/$mender_client_revision/support/mender-device-identity $mender_client_repo/$mender_client_revision/support/mender-device-identity
@ -152,7 +152,7 @@ install_files() {
dataconfdir="mender" dataconfdir="mender"
databootdir="u-boot" databootdir="u-boot"
echo -e "\tInstalling files." log "\tInstalling files."
# Prepare 'data' partition # Prepare 'data' partition
sudo install -d -m 755 ${data_dir}/${dataconfdir} sudo install -d -m 755 ${data_dir}/${dataconfdir}
@ -165,18 +165,18 @@ install_files() {
# Prepare 'primary' partition # Prepare 'primary' partition
[ ! -d "$primary_dir/data" ] && \ [ ! -d "$primary_dir/data" ] && \
{ echo -e "\t'data' mountpoint missing. Adding"; \ { log "\t'data' mountpoint missing. Adding"; \
sudo install -d -m 755 ${primary_dir}/data; } sudo install -d -m 755 ${primary_dir}/data; }
case "$device_type" in case "$device_type" in
"beaglebone") "beaglebone")
[ ! -d "$primary_dir/boot/efi" ] && \ [ ! -d "$primary_dir/boot/efi" ] && \
{ echo -e "\t'/boot/efi' mountpoint missing. Adding"; \ { log "\t'/boot/efi' mountpoint missing. Adding"; \
sudo install -d -m 755 ${primary_dir}/boot/efi; } sudo install -d -m 755 ${primary_dir}/boot/efi; }
;; ;;
"raspberrypi3") "raspberrypi3")
[ ! -d "$primary_dir/uboot" ] && \ [ ! -d "$primary_dir/uboot" ] && \
{ echo -e "\t'/boot/efi' mountpoint missing. Adding"; \ { log "\t'/boot/efi' mountpoint missing. Adding"; \
sudo install -d -m 755 ${primary_dir}/uboot; } sudo install -d -m 755 ${primary_dir}/uboot; }
;; ;;
esac esac
@ -221,33 +221,33 @@ install_files() {
do_install_mender() { do_install_mender() {
if [ -z "${mender_disk_image}" ]; then if [ -z "${mender_disk_image}" ]; then
echo "Mender raw disk image not set. Aborting." log "Mender raw disk image not set. Aborting."
show_help show_help
fi fi
if [ -z "${mender_client}" ]; then if [ -z "${mender_client}" ]; then
echo "Mender client binary not set. Aborting." log "Mender client binary not set. Aborting."
show_help show_help
fi fi
if [ -z "${device_type}" ]; then if [ -z "${device_type}" ]; then
echo "Target device type name not set. Aborting." log "Target device type name not set. Aborting."
show_help show_help
fi fi
if [ -z "${artifact_name}" ]; then if [ -z "${artifact_name}" ]; then
echo "Artifact info not set. Aborting." log "Artifact info not set. Aborting."
show_help show_help
fi fi
if [ -z "${server_url}" ] && [ -z "${demo_host_ip}" ] && \ if [ -z "${server_url}" ] && [ -z "${demo_host_ip}" ] && \
[ -z "${tenant_token}" ]; then [ -z "${tenant_token}" ]; then
echo "No server type specified. Aborting." log "No server type specified. Aborting."
show_help show_help
fi fi
if [ -n "${server_url}" ] && [ -n "${demo_host_ip}" ]; then if [ -n "${server_url}" ] && [ -n "${demo_host_ip}" ]; then
echo "Incompatible server type choice. Aborting." log "Incompatible server type choice. Aborting."
show_help show_help
fi fi
@ -262,7 +262,7 @@ do_install_mender() {
fi fi
[ ! -f $mender_disk_image ] && \ [ ! -f $mender_disk_image ] && \
{ echo "$mender_disk_image - file not found. Aborting."; exit 1; } { log "$mender_disk_image - file not found. Aborting."; exit 1; }
# Mount rootfs partition A. # Mount rootfs partition A.
create_device_maps $mender_disk_image mender_disk_mappings create_device_maps $mender_disk_image mender_disk_mappings
@ -298,7 +298,7 @@ do_install_mender() {
rm -rf $output_dir/sdimg rm -rf $output_dir/sdimg
[[ $keep -eq 0 ]] && { rm -rf $mender_dir; } [[ $keep -eq 0 ]] && { rm -rf $mender_dir; }
echo -e "\tDone." log "\tDone."
} }
PARAMS="" PARAMS=""
@ -349,7 +349,7 @@ while (( "$#" )); do
break break
;; ;;
-*) -*)
echo "Error: unsupported option $1" >&2 log "Error: unsupported option $1"
exit 1 exit 1
;; ;;
*) *)

150
mender-convert

@ -182,10 +182,10 @@ declare -a raw_disk_mappings
declare -a supported_devices=("beaglebone" "raspberrypi3") declare -a supported_devices=("beaglebone" "raspberrypi3")
do_raw_disk_image_shrink_rootfs() { do_raw_disk_image_shrink_rootfs() {
echo -e "$step/$total Shrinking raw disk image root filesystem..." log "$step/$total Shrinking raw disk image root filesystem..."
((step++)) ((step++))
if [ -z "${raw_disk_image}" ]; then if [ -z "${raw_disk_image}" ]; then
echo "Raw disk image not set. Aborting." log "Raw disk image not set. Aborting."
return 1 return 1
fi fi
@ -202,7 +202,7 @@ do_raw_disk_image_shrink_rootfs() {
# Find first available loopback device. # Find first available loopback device.
loopdevice=($(losetup -f)) loopdevice=($(losetup -f))
[ $? -ne 0 ] && { echo "Error: inaccesible loopback device"; return 1; } [ $? -ne 0 ] && { log "Error: inaccesible loopback device"; return 1; }
# Mount appropriate partition. # Mount appropriate partition.
if [[ $count -eq 1 ]]; then if [[ $count -eq 1 ]]; then
@ -210,7 +210,7 @@ do_raw_disk_image_shrink_rootfs() {
elif [[ $count -eq 2 ]]; then elif [[ $count -eq 2 ]]; then
sudo losetup $loopdevice $raw_disk_image -o $(($rootfsstart * $sector_size)) sudo losetup $loopdevice $raw_disk_image -o $(($rootfsstart * $sector_size))
else else
echo "Error: invalid/unsupported embedded raw disk image. Aborting." log "Error: invalid/unsupported embedded raw disk image. Aborting."
return 1 return 1
fi fi
@ -220,14 +220,14 @@ do_raw_disk_image_shrink_rootfs() {
new_size_sectors=$(( $min_size_blocks * $block_size / $sector_size )) new_size_sectors=$(( $min_size_blocks * $block_size / $sector_size ))
align_partition_size new_size_sectors $sector_size align_partition_size new_size_sectors $sector_size
echo -e "\tRoot filesystem size:\ log "\tRoot filesystem size:\
\n\tminimal: $(( $min_size_blocks * $block_size )) \ \n\tminimal: $(( $min_size_blocks * $block_size )) \
\n\taligned: $(( $new_size_sectors * $sector_size ))\ \n\taligned: $(( $new_size_sectors * $sector_size ))\
\n\tsectors: $new_size_sectors" \n\tsectors: $new_size_sectors"
sudo e2fsck -y -f $loopdevice sudo e2fsck -y -f $loopdevice >> "$build_log" 2>&1
sudo resize2fs -p $loopdevice ${new_size_sectors}s sudo resize2fs -p $loopdevice ${new_size_sectors}s >> "$build_log" 2>&1
sudo e2fsck -y -f $loopdevice sudo e2fsck -y -f $loopdevice >> "$build_log" 2>&1
sudo losetup -d $loopdevice sudo losetup -d $loopdevice
sudo losetup $loopdevice $raw_disk_image sudo losetup $loopdevice $raw_disk_image
@ -242,15 +242,15 @@ do_raw_disk_image_shrink_rootfs() {
endsector=($(sudo parted $loopdevice -ms unit s print | grep "^$count" | cut -f3 -d: | sed 's/[^0-9]*//g')) endsector=($(sudo parted $loopdevice -ms unit s print | grep "^$count" | cut -f3 -d: | sed 's/[^0-9]*//g'))
sudo losetup -d $loopdevice sudo losetup -d $loopdevice
echo -e "\tRaw disk image new endsector: $endsector" log "\tRaw disk image new endsector: $endsector"
truncate -s $((($endsector+1) * $sector_size)) $raw_disk_image truncate -s $((($endsector+1) * $sector_size)) $raw_disk_image
echo -e "\tNew root filesystem size (sectors): $new_size_sectors" log "\tNew root filesystem size (sectors): $new_size_sectors"
return 0 return 0
} }
do_raw_disk_image_create_partitions() { do_raw_disk_image_create_partitions() {
echo -e "$step/$total Repartitioning raw disk image..." log "$step/$total Repartitioning raw disk image..."
((step++)) ((step++))
if [ -z "$raw_disk_image" ] || [ -z "$device_type" ] || \ if [ -z "$raw_disk_image" ] || [ -z "$device_type" ] || \
@ -260,14 +260,14 @@ do_raw_disk_image_create_partitions() {
fi fi
if [[ ! -f ${raw_disk_image} ]]; then if [[ ! -f ${raw_disk_image} ]]; then
echo "Raw disk image not found. Aborting." log "Raw disk image not found. Aborting."
return 1 return 1
fi fi
local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w) local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w)
[[ $supported -eq 0 ]] && \ [[ $supported -eq 0 ]] && \
{ echo "Error: incorrect device type. Aborting."; return 1; } { log "Error: incorrect device type. Aborting."; return 1; }
mkdir -p $output_dir && cd $output_dir mkdir -p $output_dir && cd $output_dir
@ -290,16 +290,16 @@ do_raw_disk_image_create_partitions() {
sector_size raw_disk_counts sector_size raw_disk_counts
[ -z "${prootfs_size}" ] && \ [ -z "${prootfs_size}" ] && \
{ echo -e "root filesystem size not set. Aborting."; return 1; } { log "root filesystem size not set. Aborting."; return 1; }
echo -e "\tDetected raw disk image with $raw_disk_counts partition(s)." log "\tDetected raw disk image with $raw_disk_counts partition(s)."
local mender_disk_image_size= local mender_disk_image_size=
calculate_mender_disk_size $pboot_start $pboot_size \ calculate_mender_disk_size $pboot_start $pboot_size \
$prootfs_size $data_part_size_mb \ $prootfs_size $data_part_size_mb \
$sector_size pdata_size mender_disk_image_size $sector_size pdata_size mender_disk_image_size
echo -e "\tCreating Mender disk image:\ log "\tCreating Mender disk image:\
\n\t\timage size: ${mender_disk_image_size} bytes\ \n\t\timage size: ${mender_disk_image_size} bytes\
\n\t\troot filesystem size: $((${prootfs_size} * $sector_size)) bytes\ \n\t\troot filesystem size: $((${prootfs_size} * $sector_size)) bytes\
\n\t\tdata partition size: $(($pdata_size * $sector_size)) bytes" \n\t\tdata partition size: $(($pdata_size * $sector_size)) bytes"
@ -315,7 +315,7 @@ do_raw_disk_image_create_partitions() {
create_device_maps $mender_disk_image mender_disk_mappings create_device_maps $mender_disk_image mender_disk_mappings
echo -e "$step/$total Formatting repartitioned raw disk image..." log "$step/$total Formatting repartitioned raw disk image..."
((step++)) ((step++))
make_mender_disk_filesystem ${mender_disk_mappings[@]} make_mender_disk_filesystem ${mender_disk_mappings[@]}
@ -330,7 +330,7 @@ do_raw_disk_image_create_partitions() {
rc=$? rc=$?
echo -e "$step/$total Cleaning intermediate files..." log "$step/$total Cleaning intermediate files..."
((step++)) ((step++))
# Clean and detach. # Clean and detach.
detach_device_maps ${mender_disk_mappings[@]} detach_device_maps ${mender_disk_mappings[@]}
@ -339,7 +339,7 @@ do_raw_disk_image_create_partitions() {
rm -rf $embedded_base_dir rm -rf $embedded_base_dir
rm -rf $sdimg_base_dir rm -rf $sdimg_base_dir
[ $rc -eq 0 ] || { echo -e "\nRepartitioning of $raw_disk_image image failed."; } [ $rc -eq 0 ] || { log "\nRepartitioning of $raw_disk_image image failed."; }
return $rc return $rc
} }
@ -352,19 +352,19 @@ do_make_sdimg_beaglebone() {
mount_mender_disk ${mender_disk_mappings[@]} mount_mender_disk ${mender_disk_mappings[@]}
mount_raw_disk ${raw_disk_mappings[@]} mount_raw_disk ${raw_disk_mappings[@]}
echo -e "$step/$total Setting boot partition..." log "$step/$total Setting boot partition..."
((step++)) ((step++))
stage_2_args="$sdimg_boot_dir $embedded_rootfs_dir" stage_2_args="$sdimg_boot_dir $embedded_rootfs_dir"
${tool_dir}/bbb-convert-stage-2.sh ${stage_2_args} || ret=$? ${tool_dir}/bbb-convert-stage-2.sh ${stage_2_args} || ret=$?
[[ $ret -ne 0 ]] && { echo "Aborting."; return $ret; } [[ $ret -ne 0 ]] && { log "Aborting."; return $ret; }
echo -e "$step/$total Setting root filesystem partition..." log "$step/$total Setting root filesystem partition..."
((step++)) ((step++))
stage_3_args="$sdimg_primary_dir $embedded_rootfs_dir" stage_3_args="$sdimg_primary_dir $embedded_rootfs_dir"
${tool_dir}/bbb-convert-stage-3.sh ${stage_3_args} || ret=$? ${tool_dir}/bbb-convert-stage-3.sh ${stage_3_args} || ret=$?
[[ $ret -ne 0 ]] && { echo "Aborting."; return $ret; } [[ $ret -ne 0 ]] && { log "Aborting."; return $ret; }
echo -e "$step/$total Setting file system table..." log "$step/$total Setting file system table..."
((step++)) ((step++))
set_fstab $device_type set_fstab $device_type
@ -372,7 +372,7 @@ do_make_sdimg_beaglebone() {
} }
do_make_sdimg_raspberrypi3() { do_make_sdimg_raspberrypi3() {
echo -e "$step/$total Setting boot partition..." log "$step/$total Setting boot partition..."
((step++)) ((step++))
image_boot_part=$(fdisk -l ${raw_disk_image} | grep FAT32) image_boot_part=$(fdisk -l ${raw_disk_image} | grep FAT32)
@ -380,7 +380,7 @@ do_make_sdimg_raspberrypi3() {
boot_part_end=$(echo ${image_boot_part} | awk '{print $3}') boot_part_end=$(echo ${image_boot_part} | awk '{print $3}')
boot_part_size=$(echo ${image_boot_part} | awk '{print $4}') boot_part_size=$(echo ${image_boot_part} | awk '{print $4}')
echo -e "\tExtracting boot partition from raw disk image." log "\tExtracting boot partition from raw disk image."
extract_file_from_image ${raw_disk_image} ${boot_part_start} \ extract_file_from_image ${raw_disk_image} ${boot_part_start} \
${boot_part_size} "boot.vfat" ${boot_part_size} "boot.vfat"
@ -388,7 +388,7 @@ do_make_sdimg_raspberrypi3() {
${tool_dir}/rpi3-convert-stage-2.sh ${stage_2_args} || ret=$? ${tool_dir}/rpi3-convert-stage-2.sh ${stage_2_args} || ret=$?
[[ $ret -ne 0 ]] && { return $ret; } [[ $ret -ne 0 ]] && { return $ret; }
echo -e "$step/$total Setting root filesystem partition..." log "$step/$total Setting root filesystem partition..."
((step++)) ((step++))
image_rootfs_part=$(fdisk -l ${raw_disk_image} | grep Linux) image_rootfs_part=$(fdisk -l ${raw_disk_image} | grep Linux)
@ -396,7 +396,7 @@ do_make_sdimg_raspberrypi3() {
rootfs_part_end=$(echo ${image_rootfs_part} | awk '{print $3}') rootfs_part_end=$(echo ${image_rootfs_part} | awk '{print $3}')
rootfs_part_size=$(echo ${image_rootfs_part} | awk '{print $4}') rootfs_part_size=$(echo ${image_rootfs_part} | awk '{print $4}')
echo -e "\tExtracting root filesystem partition from raw disk image." log "\tExtracting root filesystem partition from raw disk image."
extract_file_from_image ${raw_disk_image} ${rootfs_part_start} \ extract_file_from_image ${raw_disk_image} ${rootfs_part_start} \
${rootfs_part_size} "rootfs.img" ${rootfs_part_size} "rootfs.img"
@ -410,7 +410,7 @@ do_make_sdimg_raspberrypi3() {
sudo install -d -m 755 ${sdimg_primary_dir}/uboot sudo install -d -m 755 ${sdimg_primary_dir}/uboot
sudo install -d -m 755 ${sdimg_primary_dir}/data sudo install -d -m 755 ${sdimg_primary_dir}/data
echo -e "$step/$total Setting file system table..." log "$step/$total Setting file system table..."
((step++)) ((step++))
set_fstab $device_type set_fstab $device_type
@ -422,7 +422,7 @@ do_make_sdimg_raspberrypi3() {
} }
do_install_mender_to_mender_disk_image() { do_install_mender_to_mender_disk_image() {
echo -e "$step/$total Installing Mender to Mender disk image..." log "$step/$total Installing Mender to Mender disk image..."
((step++)) ((step++))
if [ -z "$mender_disk_image" ] || [ -z "$device_type" ] || \ if [ -z "$mender_disk_image" ] || [ -z "$device_type" ] || \
@ -434,7 +434,7 @@ do_install_mender_to_mender_disk_image() {
local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w) local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w)
[[ $supported -eq 0 ]] && \ [[ $supported -eq 0 ]] && \
{ echo "Error: incorrect device type. Aborting."; return 1; } { log "Error: incorrect device type. Aborting."; return 1; }
# mender-image-1.5.0 # mender-image-1.5.0
stage_4_args="-m $mender_disk_image -d $device_type -g ${mender_client} -a ${artifact_name}" stage_4_args="-m $mender_disk_image -d $device_type -g ${mender_client} -a ${artifact_name}"
@ -462,7 +462,7 @@ do_install_mender_to_mender_disk_image() {
eval set -- " ${stage_4_args}" eval set -- " ${stage_4_args}"
${tool_dir}/convert-stage-4.sh ${stage_4_args} || ret=$? ${tool_dir}/convert-stage-4.sh ${stage_4_args} || ret=$?
[[ $ret -ne 0 ]] && { echo -e "\nInstalling Mender to Mender disk image failed."; return $ret; } [[ $ret -ne 0 ]] && { log "\nInstalling Mender to Mender disk image failed."; return $ret; }
# Update test configuration file # Update test configuration file
update_test_config_file $device_type artifact-name $artifact_name update_test_config_file $device_type artifact-name $artifact_name
@ -471,7 +471,7 @@ do_install_mender_to_mender_disk_image() {
} }
do_install_bootloader_to_mender_disk_image() { do_install_bootloader_to_mender_disk_image() {
echo -e "$step/$total Installing Bootloader to Mender disk image..." log "$step/$total Installing Bootloader to Mender disk image..."
((step++)) ((step++))
if [ -z "$mender_disk_image" ] || [ -z "$device_type" ] || \ if [ -z "$mender_disk_image" ] || [ -z "$device_type" ] || \
@ -483,14 +483,14 @@ do_install_bootloader_to_mender_disk_image() {
local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w) local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w)
[[ $supported -eq 0 ]] && \ [[ $supported -eq 0 ]] && \
{ echo "Error: incorrect device type. Aborting."; return 1; } { log "Error: incorrect device type. Aborting."; return 1; }
case "$device_type" in case "$device_type" in
"beaglebone") "beaglebone")
stage_5_args="-m $mender_disk_image -d $device_type -b ${bootloader_toolchain} $keep" stage_5_args="-m $mender_disk_image -d $device_type -b ${bootloader_toolchain} $keep"
eval set -- " ${stage_5_args}" eval set -- " ${stage_5_args}"
${tool_dir}/bbb-convert-stage-5.sh ${stage_5_args}|| ret=$? ${tool_dir}/bbb-convert-stage-5.sh ${stage_5_args}|| ret=$?
[[ $ret -ne 0 ]] && { echo -e "\nInstalling Bootloader failed."; return $ret; } [[ $ret -ne 0 ]] && { log "\nInstalling Bootloader failed."; return $ret; }
# Update test configuration file # Update test configuration file
update_test_config_file $device_type distro-feature "mender-grub" \ update_test_config_file $device_type distro-feature "mender-grub" \
@ -500,7 +500,7 @@ do_install_bootloader_to_mender_disk_image() {
stage_5_args="-m $mender_disk_image -d $device_type -b ${bootloader_toolchain} $keep" stage_5_args="-m $mender_disk_image -d $device_type -b ${bootloader_toolchain} $keep"
eval set -- " ${stage_5_args}" eval set -- " ${stage_5_args}"
${tool_dir}/rpi3-convert-stage-5.sh ${stage_5_args}|| ret=$? ${tool_dir}/rpi3-convert-stage-5.sh ${stage_5_args}|| ret=$?
[[ $ret -ne 0 ]] && { echo -e "\nInstalling Bootloader failed."; return $ret; } [[ $ret -ne 0 ]] && { log "\nInstalling Bootloader failed."; return $ret; }
# Update test configuration file # Update test configuration file
update_test_config_file $device_type mount-location "\/uboot" update_test_config_file $device_type mount-location "\/uboot"
@ -511,38 +511,38 @@ do_install_bootloader_to_mender_disk_image() {
} }
do_mender_disk_image_to_artifact() { do_mender_disk_image_to_artifact() {
echo -e "$step/$total Creating Mender Artifact..." log "$step/$total Creating Mender Artifact..."
((step++)) ((step++))
if [ -z "${mender_disk_image}" ]; then if [ -z "${mender_disk_image}" ]; then
echo "Mender disk image not set. Aborting." log "Mender disk image not set. Aborting."
return 1 return 1
fi fi
if [ -z "${device_type}" ]; then if [ -z "${device_type}" ]; then
echo "Target device_type name not set. Aborting." log "Target device_type name not set. Aborting."
return 1 return 1
fi fi
if [ -z "${artifact_name}" ]; then if [ -z "${artifact_name}" ]; then
echo "Artifact name not set. Aborting." log "Artifact name not set. Aborting."
return 1 return 1
fi fi
if [ -z "${rootfs_partition_id}" ]; then if [ -z "${rootfs_partition_id}" ]; then
echo -e "\tRootfs partition id not set - 'primary' will be used by default." log "\tRootfs partition id not set - 'primary' will be used by default."
rootfs_partition_id="primary" rootfs_partition_id="primary"
fi fi
local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w) local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w)
[[ $supported -eq 0 ]] && \ [[ $supported -eq 0 ]] && \
{ echo "Error: incorrect device type. Aborting."; return 1; } { log "Error: incorrect device type. Aborting."; return 1; }
inarray=$(echo ${rootfs_partition_ids[@]} | grep -o $rootfs_partition_id | wc -w) inarray=$(echo ${rootfs_partition_ids[@]} | grep -o $rootfs_partition_id | wc -w)
[[ $inarray -eq 0 ]] && \ [[ $inarray -eq 0 ]] && \
{ echo "Error: invalid rootfs partition id provided. Aborting."; return 1; } { log "Error: invalid rootfs partition id provided. Aborting."; return 1; }
local count= local count=
local bootstart= local bootstart=
@ -557,7 +557,7 @@ do_mender_disk_image_to_artifact() {
rootfs_a_size rootfs_b_start rootfs_b_size rootfs_a_size rootfs_b_start rootfs_b_size
ret=$? ret=$?
[[ $ret -ne 0 ]] && \ [[ $ret -ne 0 ]] && \
{ echo "Error: cannot validate Mender disk image. Aborting."; return 1; } { log "Error: cannot validate Mender disk image. Aborting."; return 1; }
# Check if device type matches. # Check if device type matches.
create_device_maps $mender_disk_image mender_disk_mappings create_device_maps $mender_disk_image mender_disk_mappings
@ -567,12 +567,12 @@ do_mender_disk_image_to_artifact() {
mender_device_type=$( cat $sdimg_data_dir/mender/device_type | sed 's/[^=].*=//' ) mender_device_type=$( cat $sdimg_data_dir/mender/device_type | sed 's/[^=].*=//' )
if [ "$mender_device_type" != "$device_type" ]; then if [ "$mender_device_type" != "$device_type" ]; then
echo "Error: device types of Mender artifact & Mender not matching. Aborting." log "Error: device types of Mender artifact & Mender not matching. Aborting."
ret=1 ret=1
fi fi
if ! [ -x "$(command -v mender-artifact)" ]; then if ! [ -x "$(command -v mender-artifact)" ]; then
echo "Error: mender-artifact not found in PATH. Aborting." log "Error: mender-artifact not found in PATH. Aborting."
ret=1 ret=1
fi fi
@ -599,12 +599,12 @@ do_mender_disk_image_to_artifact() {
fsck.ext4 -fp $mender_rootfs_image &> /dev/null || ret=$? fsck.ext4 -fp $mender_rootfs_image &> /dev/null || ret=$?
[[ $ret -ne 0 ]] && \ [[ $ret -ne 0 ]] && \
{ echo -e "Error: checking $mender_rootfs_basename file system failed. Aborting."; } { log "Error: checking $mender_rootfs_basename file system failed. Aborting."; }
# Find first available loopback device. # Find first available loopback device.
loopdevice=($(sudo losetup -f || ret=$?)) loopdevice=($(sudo losetup -f || ret=$?))
[[ $ret -ne 0 ]] && \ [[ $ret -ne 0 ]] && \
{ echo -e "Error: cannot find an unused loop device. Aborting."; } { log "Error: cannot find an unused loop device. Aborting."; }
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
#Mount extracted ext4 partition to verify 'artifact_info' file content. #Mount extracted ext4 partition to verify 'artifact_info' file content.
@ -623,7 +623,7 @@ do_mender_disk_image_to_artifact() {
# Note: expected Mender Artifact name follows the scheme: # Note: expected Mender Artifact name follows the scheme:
# mender-<device_name>-<artifact_name>.mender. # mender-<device_name>-<artifact_name>.mender.
mender_artifact=${output_dir}/${mender_disk_filename}.mender mender_artifact=${output_dir}/${mender_disk_filename}.mender
echo -e "\tWriting Mender artifact to: ${mender_artifact}" log "\tWriting Mender artifact to: ${mender_artifact}"
#Create Mender artifact #Create Mender artifact
mender-artifact write rootfs-image \ mender-artifact write rootfs-image \
@ -634,8 +634,8 @@ do_mender_disk_image_to_artifact() {
ret=$? ret=$?
[[ $ret -eq 0 ]] && \ [[ $ret -eq 0 ]] && \
{ echo -e "\tCreating Mender Artifact succeeded."; } || \ { log "\tCreating Mender Artifact succeeded."; } || \
{ echo -e "\tCreating Mender Artifact failed."; } { log "\tCreating Mender Artifact failed."; }
fi fi
fi fi
@ -680,6 +680,10 @@ source ${tool_dir}/mender-convert-functions.sh
export -f create_device_maps export -f create_device_maps
export -f detach_device_maps export -f detach_device_maps
export -f mount_mender_disk export -f mount_mender_disk
export -f log
export -f logsetup
logsetup
while (( "$#" )); do while (( "$#" )); do
case "$1" in case "$1" in
@ -744,7 +748,7 @@ while (( "$#" )); do
break break
;; ;;
-*) -*)
echo "Error: unsupported option $1" >&2 log "Error: unsupported option $1"
exit 1 exit 1
;; ;;
*) *)
@ -755,7 +759,7 @@ while (( "$#" )); do
done done
[ -z "${data_part_size_mb}" ] && \ [ -z "${data_part_size_mb}" ] && \
{ echo "Default 'data' partition size set to 128MB"; data_part_size_mb=128; } { log "Default 'data' partition size set to 128MB"; data_part_size_mb=128; }
eval set -- "$PARAMS" eval set -- "$PARAMS"
@ -766,48 +770,48 @@ case "$1" in
raw-disk-image-shrink-rootfs) raw-disk-image-shrink-rootfs)
total=1 total=1
do_raw_disk_image_shrink_rootfs || rc=$? do_raw_disk_image_shrink_rootfs || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; } [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
echo -e "The rootfs partition in the raw disk image has been shrinked successfully!" log "The rootfs partition in the raw disk image has been shrinked successfully!"
echo -e "You can now convert the output raw disk image\n\t$raw_disk_image\ log "You can now convert the output raw disk image\n\t$raw_disk_image\
\nto a Mender disk image." \nto a Mender disk image."
;; ;;
raw-disk-image-create-partitions) raw-disk-image-create-partitions)
total=6 total=6
do_raw_disk_image_create_partitions || rc=$? do_raw_disk_image_create_partitions || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; } [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
echo -e "A new Mender disk image with partition layout to support Mender has been successfully created!" log "A new Mender disk image with partition layout to support Mender has been successfully created!"
echo -e "You can find the output Mender disk image at:\n\t${mender_disk_image}." log "You can find the output Mender disk image at:\n\t${mender_disk_image}."
;; ;;
install-mender-to-mender-disk-image) install-mender-to-mender-disk-image)
total=1 total=1
do_install_mender_to_mender_disk_image || rc=$? do_install_mender_to_mender_disk_image || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; } [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
echo -e "The Mender client has been successfully installed to the Mender disk image." log "The Mender client has been successfully installed to the Mender disk image."
echo -e "You can find the output Mender disk image at:\n\t${mender_disk_image}." log "You can find the output Mender disk image at:\n\t${mender_disk_image}."
;; ;;
install-bootloader-to-mender-disk-image) install-bootloader-to-mender-disk-image)
total=1 total=1
do_install_bootloader_to_mender_disk_image || rc=$? do_install_bootloader_to_mender_disk_image || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; } [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
echo -e "A bootloader configuration supporting dual A/B rootfs updates has been installed to the Mender disk image!" log "A bootloader configuration supporting dual A/B rootfs updates has been installed to the Mender disk image!"
echo -e "You can find the output Mender disk image at:\n\t${mender_disk_image}." log "You can find the output Mender disk image at:\n\t${mender_disk_image}."
;; ;;
mender-disk-image-to-artifact) mender-disk-image-to-artifact)
total=1 total=1
do_mender_disk_image_to_artifact || rc=$? do_mender_disk_image_to_artifact || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; } [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
echo -e "A Mender Artifact has been successfully extracted from your Mender disk image!" log "A Mender Artifact has been successfully extracted from your Mender disk image!"
echo -e "You can find the Mender Artifact at:\n\t$mender_artifact\nand use it to deploy updates." log "You can find the Mender Artifact at:\n\t$mender_artifact\nand use it to deploy updates."
;; ;;
from-raw-disk-image) from-raw-disk-image)
total=9 total=9
do_from_raw_disk_image || rc=$? do_from_raw_disk_image || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; } [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
echo -e "Conversion complete!" log "Conversion complete!"
echo -e "The Mender disk image you can provision your device storage with is at:\ log "The Mender disk image you can provision your device storage with is at:\
\n\t${mender_disk_image}." \n\t${mender_disk_image}."
echo -e "The Mender root file system partition is at:\n\t${mender_rootfs_image}." log "The Mender root file system partition is at:\n\t${mender_rootfs_image}."
echo -e "The Mender Artifact you can upload to your Mender server to deploy to your devices is at:\ log "The Mender Artifact you can upload to your Mender server to deploy to your devices is at:\
\n\t${mender_artifact}." \n\t${mender_artifact}."
;; ;;
*) *)

49
mender-convert-functions.sh

@ -15,6 +15,7 @@ declare -a raw_disk_partitions=("boot" "rootfs")
tool_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" tool_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
files_dir=${tool_dir}/files files_dir=${tool_dir}/files
output_dir=${tool_dir}/output output_dir=${tool_dir}/output
build_log=${output_dir}/build.log
embedded_base_dir=$output_dir/embedded embedded_base_dir=$output_dir/embedded
sdimg_base_dir=$output_dir/sdimg sdimg_base_dir=$output_dir/sdimg
@ -26,6 +27,16 @@ sdimg_primary_dir=$sdimg_base_dir/primary
sdimg_secondary_dir=$sdimg_base_dir/secondary sdimg_secondary_dir=$sdimg_base_dir/secondary
sdimg_data_dir=$sdimg_base_dir/data sdimg_data_dir=$sdimg_base_dir/data
logsetup() {
echo -n "" > $build_log
exec > >(tee -a $build_log)
exec 2>&1
}
log() {
echo -e "$*"
}
# Takes following arguments: # Takes following arguments:
# #
# $1 -relative file path # $1 -relative file path
@ -51,7 +62,7 @@ get_part_number_from_device() {
echo ${1##*[0-9]p} echo ${1##*[0-9]p}
;; ;;
*) *)
echo "Could not determine partition number from $1" log "Could not determine partition number from $1"
exit 1 exit 1
;; ;;
esac esac
@ -164,7 +175,7 @@ get_image_info() {
eval $rvar_rootfssize="'$lsecondpartsize'" eval $rvar_rootfssize="'$lsecondpartsize'"
[[ $lcount -gt 2 ]] && \ [[ $lcount -gt 2 ]] && \
{ echo "Unsupported type of source image. Aborting."; return 1; } || \ { log "Unsupported type of source image. Aborting."; return 1; } || \
{ return 0; } { return 0; }
} }
@ -196,7 +207,7 @@ get_mender_disk_info() {
local lcount=${#lparts[@]} local lcount=${#lparts[@]}
if [[ $lcount -ne 4 ]]; then if [[ $lcount -ne 4 ]]; then
echo "Error: invalid Mender disk image. Aborting." log "Error: invalid Mender disk image. Aborting."
return 1 return 1
else else
local lsectorsize=($(echo "${lfdisk}" | grep '^Sector' | cut -d' ' -f4)) local lsectorsize=($(echo "${lfdisk}" | grep '^Sector' | cut -d' ' -f4))
@ -276,7 +287,7 @@ analyse_raw_disk_image() {
rootfsstart rootfssize bootflag rootfsstart rootfssize bootflag
[[ $? -ne 0 ]] && \ [[ $? -ne 0 ]] && \
{ echo "Error: invalid/unsupported raw disk image. Aborting."; exit 1; } { log "Error: invalid/unsupported raw disk image. Aborting."; exit 1; }
if [[ $count -eq 1 ]]; then if [[ $count -eq 1 ]]; then
rootfssize=$bootsize rootfssize=$bootsize
@ -327,7 +338,7 @@ calculate_mender_disk_size() {
# #
# $1 - raw disk image # $1 - raw disk image
unmount_partitions() { unmount_partitions() {
echo "Check if device is mounted..." log "Check if device is mounted..."
is_mounted=`grep ${1} /proc/self/mounts | wc -l` is_mounted=`grep ${1} /proc/self/mounts | wc -l`
if [ ${is_mounted} -ne 0 ]; then if [ ${is_mounted} -ne 0 ]; then
sudo umount ${1}?* sudo umount ${1}?*
@ -338,7 +349,7 @@ unmount_partitions() {
# #
# $1 - raw disk image # $1 - raw disk image
erase_filesystem() { erase_filesystem() {
echo "Erase filesystem..." log "Erase filesystem..."
sudo wipefs --all --force ${1}?* sudo wipefs --all --force ${1}?*
sudo dd if=/dev/zero of=${1} bs=1M count=100 sudo dd if=/dev/zero of=${1} bs=1M count=100
} }
@ -353,7 +364,7 @@ create_mender_disk() {
local bs=$(( 1024*1024 )) local bs=$(( 1024*1024 ))
local count=$(( ${lsize} / ${bs} )) local count=$(( ${lsize} / ${bs} ))
dd if=/dev/zero of=${lfile} bs=${bs} count=${count} dd if=/dev/zero of=${lfile} bs=${bs} count=${count}>> "$build_log" 2>&1
} }
# Takes following arguments: # Takes following arguments:
@ -424,7 +435,7 @@ format_mender_disk() {
w # write the partition table w # write the partition table
q # and we're done q # and we're done
EOF EOF
echo -e "\tChanges in partition table applied." log "\tChanges in partition table applied."
} }
# Takes following arguments: # Takes following arguments:
@ -444,7 +455,7 @@ verify_mender_disk() {
local no_of_parts=${#partitions[@]} local no_of_parts=${#partitions[@]}
[[ $no_of_parts -eq 4 ]] || \ [[ $no_of_parts -eq 4 ]] || \
{ echo "Error: incorrect number of partitions: $no_of_parts. Aborting."; return 1; } { log "Error: incorrect number of partitions: $no_of_parts. Aborting."; return 1; }
eval $rvar_no_of_parts=="'$no_of_parts='" eval $rvar_no_of_parts=="'$no_of_parts='"
@ -463,7 +474,7 @@ create_device_maps() {
[[ ${#mappings[@]} -eq 0 ]] \ [[ ${#mappings[@]} -eq 0 ]] \
&& { log "Error: partition mappings failed. Aborting."; exit 1; } && { log "Error: partition mappings failed. Aborting."; exit 1; }
else else
echo "Error: no device passed. Aborting." log "Error: no device passed. Aborting."
exit 1 exit 1
fi fi
@ -476,7 +487,7 @@ create_device_maps() {
detach_device_maps() { detach_device_maps() {
local mappings=($@) local mappings=($@)
[ ${#mappings[@]} -eq 0 ] && { echo -e "\tPartition mappings cleaned."; return; } [ ${#mappings[@]} -eq 0 ] && { log "\tPartition mappings cleaned."; return; }
local mapper=${mappings[0]%p*} local mapper=${mappings[0]%p*}
@ -508,10 +519,10 @@ make_mender_disk_filesystem() {
label=${mender_disk_partitions[${part_no} - 1]} label=${mender_disk_partitions[${part_no} - 1]}
if [[ part_no -eq 1 ]]; then if [[ part_no -eq 1 ]]; then
echo -e "\tCreating MS-DOS filesystem for '$label' partition." log "\tCreating MS-DOS filesystem for '$label' partition."
sudo mkfs.vfat -n ${label} $map_dev >> "$build_log" 2>&1 sudo mkfs.vfat -n ${label} $map_dev >> "$build_log" 2>&1
else else
echo -e "\tCreating ext4 filesystem for '$label' partition." log "\tCreating ext4 filesystem for '$label' partition."
sudo mkfs.ext4 -L ${label} $map_dev >> "$build_log" 2>&1 sudo mkfs.ext4 -L ${label} $map_dev >> "$build_log" 2>&1
fi fi
done done
@ -562,7 +573,7 @@ set_fstab() {
local device_type=$1 local device_type=$1
local sysconfdir="$sdimg_primary_dir/etc" local sysconfdir="$sdimg_primary_dir/etc"
[ ! -d "${sysconfdir}" ] && { echo "Error: cannot find rootfs config dir."; exit 1; } [ ! -d "${sysconfdir}" ] && { log "Error: cannot find rootfs config dir."; exit 1; }
# Erase/create the fstab file. # Erase/create the fstab file.
sudo install -b -m 644 /dev/null ${sysconfdir}/fstab sudo install -b -m 644 /dev/null ${sysconfdir}/fstab
@ -594,7 +605,7 @@ set_fstab() {
/dev/mmcblk0p4 /data auto defaults 0 0 /dev/mmcblk0p4 /data auto defaults 0 0
EOF" EOF"
echo -e "\tDone." log "\tDone."
} }
# Takes following arguments # Takes following arguments
@ -606,9 +617,9 @@ set_fstab() {
extract_file_from_image() { extract_file_from_image() {
local cmd="dd if=$1 of=${output_dir}/$4 skip=$2 bs=512 count=$3" local cmd="dd if=$1 of=${output_dir}/$4 skip=$2 bs=512 count=$3"
[ "${4##*.}" == "ext4" ] && { echo -e "\tStoring data in $4 root file system image."; } \ [ "${4##*.}" == "ext4" ] && { log "\tStoring data in $4 root file system image."; } \
|| { echo -e "\tStoring data in $4 disk image."; } || { log "\tStoring data in $4 disk image."; }
$(${cmd}) $(${cmd}>> "$build_log" 2>&1)
} }
# Takes following arguments # Takes following arguments
@ -652,7 +663,7 @@ update_test_config_file() {
local device_type=$1 local device_type=$1
[ ! -f "${files_dir}/${device_type}_variables.cfg" ] && \ [ ! -f "${files_dir}/${device_type}_variables.cfg" ] && \
{ echo "Error: test configuration file '${device_type}_variables.cfg' not found. Aborting."; return 1; } { log "Error: test configuration file '${device_type}_variables.cfg' not found. Aborting."; return 1; }
shift shift

7
rpi3-convert-stage-2.sh

@ -2,9 +2,10 @@
output_dir=$1 output_dir=$1
boot_mapping=$2 boot_mapping=$2
build_log=$output_dir/build.log
[ ! -f $output_dir/boot.vfat ] && \ [ ! -f $output_dir/boot.vfat ] && \
{ echo "Error: extracted boot partition not found. Aborting."; exit 1; } { log "Error: extracted boot partition not found. Aborting."; exit 1; }
# Make a copy of Linux kernel arguments and modify. # Make a copy of Linux kernel arguments and modify.
mcopy -on -i ${output_dir}/boot.vfat -s ::cmdline.txt ${output_dir}/cmdline.txt mcopy -on -i ${output_dir}/boot.vfat -s ::cmdline.txt ${output_dir}/cmdline.txt
@ -17,8 +18,8 @@ mcopy -on -i ${output_dir}/boot.vfat -s ::config.txt ${output_dir}/config.txt
echo -e '\nenable_uart=1\n' >> ${output_dir}/config.txt echo -e '\nenable_uart=1\n' >> ${output_dir}/config.txt
mcopy -o -i ${output_dir}/boot.vfat -s ${output_dir}/config.txt ::config.txt mcopy -o -i ${output_dir}/boot.vfat -s ${output_dir}/config.txt ::config.txt
sudo dd if=${output_dir}/boot.vfat of=/dev/mapper/${boot_mapping} bs=1M sudo dd if=${output_dir}/boot.vfat of=/dev/mapper/${boot_mapping} bs=1M >> "$build_log" 2>&1
echo -e "\tDone." log "\tDone."
exit 0 exit 0

7
rpi3-convert-stage-3.sh

@ -2,15 +2,16 @@
output_dir=$1 output_dir=$1
rootfs_mapping=$2 rootfs_mapping=$2
build_log=$output_dir/build.log
[ ! -f ${output_dir}/rootfs.img ] && \ [ ! -f ${output_dir}/rootfs.img ] && \
{ echo "Error: extracted rootfs partition not found. Aborting."; exit 1; } { log "Error: extracted rootfs partition not found. Aborting."; exit 1; }
sudo dd if=${output_dir}/rootfs.img of=/dev/mapper/${rootfs_mapping} bs=8M sudo dd if=${output_dir}/rootfs.img of=/dev/mapper/${rootfs_mapping} bs=8M >> "$build_log" 2>&1
# dd sets the original label, make sure label follows Mender naming convention. # dd sets the original label, make sure label follows Mender naming convention.
sudo e2label /dev/mapper/${rootfs_mapping} "primary" sudo e2label /dev/mapper/${rootfs_mapping} "primary"
echo -e "\tDone." log "\tDone."
exit 0 exit 0

31
rpi3-convert-stage-5.sh

@ -45,19 +45,20 @@ build_uboot_files() {
mkdir -p $bin_dir_pi mkdir -p $bin_dir_pi
echo -e "\tBuilding U-Boot related files." log "\tBuilding U-Boot related files."
if [ ! -d $uboot_repo_vc_dir ]; then if [ ! -d $uboot_repo_vc_dir ]; then
git clone https://github.com/mendersoftware/uboot-mender.git -b $branch git clone https://github.com/mendersoftware/uboot-mender.git -b $branch >> "$build_log" 2>&1
fi fi
cd $uboot_dir cd $uboot_dir
git checkout $commit git checkout $commit >> "$build_log" 2>&1
make --quiet distclean make --quiet distclean >> "$build_log"
make --quiet rpi_3_32b_defconfig && make --quiet make --quiet rpi_3_32b_defconfig >> "$build_log" 2>&1
make --quiet envtools make --quiet >> "$build_log" 2>&1
make --quiet envtools >> "$build_log" 2>&1
cat<<-'EOF' >boot.cmd cat<<-'EOF' >boot.cmd
fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
@ -69,11 +70,11 @@ build_uboot_files() {
EOF EOF
if [ ! -e $uboot_dir/tools/mkimage ]; then if [ ! -e $uboot_dir/tools/mkimage ]; then
echo "Error: cannot build U-Boot. Aborting" log "Error: cannot build U-Boot. Aborting"
return 1 return 1
fi fi
$uboot_dir/tools/mkimage -A arm -T script -C none -n "Boot script" -d "boot.cmd" boot.scr $uboot_dir/tools/mkimage -A arm -T script -C none -n "Boot script" -d "boot.cmd" boot.scr >> "$build_log" 2>&1
cp -t $bin_dir_pi $uboot_dir/boot.scr $uboot_dir/tools/env/fw_printenv $uboot_dir/u-boot.bin cp -t $bin_dir_pi $uboot_dir/boot.scr $uboot_dir/tools/env/fw_printenv $uboot_dir/u-boot.bin
return 0 return 0
@ -87,7 +88,7 @@ install_files() {
local boot_dir=$1 local boot_dir=$1
local rootfs_dir=$2 local rootfs_dir=$2
echo -e "\tInstalling U-Boot related files." log "\tInstalling U-Boot related files."
# Make a copy of Linux kernel arguments and modify. # Make a copy of Linux kernel arguments and modify.
sudo cp ${boot_dir}/cmdline.txt ${output_dir}/cmdline.txt sudo cp ${boot_dir}/cmdline.txt ${output_dir}/cmdline.txt
@ -148,12 +149,12 @@ install_files() {
do_install_bootloader() { do_install_bootloader() {
if [ -z "${mender_disk_image}" ]; then if [ -z "${mender_disk_image}" ]; then
echo "Mender raw disk image file not set. Aborting." log "Mender raw disk image file not set. Aborting."
exit 1 exit 1
fi fi
if [ -z "${bootloader_toolchain}" ]; then if [ -z "${bootloader_toolchain}" ]; then
echo "ARM GCC toolchain not set. Aborting." log "ARM GCC toolchain not set. Aborting."
exit 1 exit 1
fi fi
@ -165,12 +166,12 @@ do_install_bootloader() {
local gcc_version=$(${bootloader_toolchain}-gcc -dumpversion) local gcc_version=$(${bootloader_toolchain}-gcc -dumpversion)
if [ $(version $gcc_version) -ne $(version $GCC_VERSION) ]; then if [ $(version $gcc_version) -ne $(version $GCC_VERSION) ]; then
echo "Error: Invalid ARM GCC version ($gcc_version). Expected $GCC_VERSION. Aborting." log "Error: Invalid ARM GCC version ($gcc_version). Expected $GCC_VERSION. Aborting."
exit 1 exit 1
fi fi
[ ! -f $mender_disk_image ] && \ [ ! -f $mender_disk_image ] && \
{ echo "$mender_disk_image - file not found. Aborting."; exit 1; } { log "$mender_disk_image - file not found. Aborting."; exit 1; }
# Map & mount Mender compliant image. # Map & mount Mender compliant image.
create_device_maps $mender_disk_image mender_disk_mappings create_device_maps $mender_disk_image mender_disk_mappings
@ -193,7 +194,7 @@ do_install_bootloader() {
[[ $keep -eq 0 ]] && { rm -f ${output_dir}/config.txt ${output_dir}/cmdline.txt; [[ $keep -eq 0 ]] && { rm -f ${output_dir}/config.txt ${output_dir}/cmdline.txt;
rm -rf $uboot_dir $bin_base_dir; } rm -rf $uboot_dir $bin_base_dir; }
[[ "$rc" -ne 0 ]] && { exit 1; } || { echo -e "\tDone."; } [[ "$rc" -ne 0 ]] && { exit 1; } || { log "\tDone."; }
} }
# Conditional once we support other boards # Conditional once we support other boards
@ -226,7 +227,7 @@ while (( "$#" )); do
break break
;; ;;
-*) -*)
echo "Error: unsupported option $1" >&2 log "Error: unsupported option $1"
exit 1 exit 1
;; ;;
*) *)

Loading…
Cancel
Save