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
[ ! -d "${sdimg_boot_dir}" ] && \
{ echo "Error: boot location not mounted."; exit 1; }
{ log "Error: boot location not mounted."; exit 1; }
[ ! -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 ]] && \
{ echo "Error: cannot find U-Boot related files."; exit 1; }
{ log "Error: cannot find U-Boot related files."; exit 1; }
set_uenv() {
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.
set_uenv
echo -e "\tDone."
log "\tDone."
exit 0

6
bbb-convert-stage-3.sh

@ -4,9 +4,9 @@ sdimg_primary_dir=$1
embedded_rootfs_dir=$2
[ ! -d "${sdimg_primary_dir}" ] && \
{ echo "Error: rootfs location not mounted."; exit 1; }
{ log "Error: rootfs location not mounted."; exit 1; }
[ ! -d "${embedded_rootfs_dir}" ] && \
{ echo "Error: embedded content not mounted."; exit 1; }
{ log "Error: embedded content not mounted."; exit 1; }
# Copy rootfs partition.
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}/data
echo -e "\tDone."
log "\tDone."
exit 0

59
bbb-convert-stage-5.sh

@ -44,6 +44,7 @@ device_type=
keep=0
efi_boot=EFI/BOOT
EFI_STUB_VER="4.12.0"
build_log=$output_dir/build.log
declare -a mender_disk_mappings
@ -68,14 +69,14 @@ get_kernel_version() {
#
# $1 - linux kernel version
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_build_dir=$grubenv_dir/build
mkdir -p $grubenv_dir
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
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_devicetree/s/=.*$/='${kernel_devicetree//\//\\/}'/' mender_grubenv_defines
make --quiet
make --quiet DESTDIR=$grubenv_build_dir install
make --quiet >> "$build_log" 2>&1
make --quiet DESTDIR=$grubenv_build_dir install >> "$build_log" 2>&1
cd $output_dir
}
@ -100,7 +101,7 @@ build_env_lock_boot_files() {
#
# $1 - linux kernel version
build_grub_efi() {
echo -e "\tBuilding GRUB efi file."
log "\tBuilding GRUB efi file."
local grub_build_dir=$grub_dir/build
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.
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
cd $grub_dir
make --quiet distclean
make --quiet distclean >> "$build_log" 2>&1
if [ $(version $version) -lt $(version $EFI_STUB_VER) ]; then
# To avoid error message: "plain image kernel not supported - rebuild
# with CONFIG_(U)EFI_STUB enabled" - use a specific commit.
git checkout 9b37229f0
git checkout 9b37229f0 >> "$build_log" 2>&1
fi
mkdir -p $grub_arm_dir
@ -130,27 +131,27 @@ build_grub_efi() {
local cores=$(nproc)
# First build host tools.
./autogen.sh > /dev/null
./configure --quiet CC=gcc --target=${host} --with-platform=efi --prefix=$grub_host_dir
make --quiet -j$cores
make --quiet install
./autogen.sh >> "$build_log" 2>&1
./configure --quiet CC=gcc --target=${host} --with-platform=efi --prefix=$grub_host_dir >> "$build_log" 2>&1
make --quiet -j$cores >> "$build_log" 2>&1
make --quiet install >> "$build_log" 2>&1
# Clean workspace.
make --quiet clean
make --quiet distclean
make --quiet clean >> "$build_log" 2>&1
make --quiet distclean >> "$build_log" 2>&1
# Now build ARM modules.
./configure --quiet --host=$bootloader_toolchain --with-platform=efi \
--prefix=$grub_arm_dir CFLAGS="-Os -march=armv7-a" \
CCASFLAGS="-march=armv7-a" --disable-werror
make --quiet -j$cores
make --quiet install
CCASFLAGS="-march=armv7-a" --disable-werror >> "$build_log" 2>&1
make --quiet -j$cores >> "$build_log" 2>&1
make --quiet install >> "$build_log" 2>&1
# Build GRUB EFI image.
${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 \
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=$?
@ -182,7 +183,7 @@ set_uenv() {
# $1 - boot partition mountpoint
# $2 - primary partition mountpoint
install_files() {
echo -e "\tInstalling GRUB files."
log "\tInstalling GRUB files."
local boot_dir=$1
local rootfs_dir=$2
@ -197,7 +198,7 @@ install_files() {
# Make sure env, lock, lock.sha256sum files exists in working directory.
[[ ! -d $grubenv_efi_boot_dir/mender_grubenv1 || \
! -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
@ -219,17 +220,17 @@ install_files() {
do_install_bootloader() {
if [ -z "${mender_disk_image}" ]; then
echo "Mender raw disk image not set. Aborting."
log "Mender raw disk image not set. Aborting."
exit 1
fi
if [ -z "${bootloader_toolchain}" ]; then
echo "ARM GCC toolchain not set. Aborting."
log "ARM GCC toolchain not set. Aborting."
exit 1
fi
if [ -z "${device_type}" ]; then
echo "Target device type name not set. Aborting."
log "Target device type name not set. Aborting."
exit 1
fi
@ -239,7 +240,7 @@ do_install_bootloader() {
fi
[ ! -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.
create_device_maps $mender_disk_image mender_disk_mappings
@ -258,15 +259,15 @@ do_install_bootloader() {
sudo mount ${map_primary} ${path_primary}
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_grub_efi $kernel_version
rc=$?
[[ $rc -ne 0 ]] && { echo -e "\tBuilding grub.efi failed. Aborting."; } \
|| { echo -e "\tBuilding grub.efi succeeded."; \
[[ $rc -ne 0 ]] && { log "\tBuilding grub.efi failed. Aborting."; } \
|| { log "\tBuilding grub.efi succeeded."; \
install_files ${path_boot} ${path_primary}; }
# Back to working directory.
@ -277,7 +278,7 @@ do_install_bootloader() {
rm -rf $output_dir/sdimg
[[ $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=""
@ -309,7 +310,7 @@ while (( "$#" )); do
break
;;
-*)
echo "Error: unsupported option $1" >&2
log "Error: unsupported option $1"
exit 1
;;
*)

28
convert-stage-4.sh

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

150
mender-convert

@ -182,10 +182,10 @@ declare -a raw_disk_mappings
declare -a supported_devices=("beaglebone" "raspberrypi3")
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++))
if [ -z "${raw_disk_image}" ]; then
echo "Raw disk image not set. Aborting."
log "Raw disk image not set. Aborting."
return 1
fi
@ -202,7 +202,7 @@ do_raw_disk_image_shrink_rootfs() {
# Find first available loopback device.
loopdevice=($(losetup -f))
[ $? -ne 0 ] && { echo "Error: inaccesible loopback device"; return 1; }
[ $? -ne 0 ] && { log "Error: inaccesible loopback device"; return 1; }
# Mount appropriate partition.
if [[ $count -eq 1 ]]; then
@ -210,7 +210,7 @@ do_raw_disk_image_shrink_rootfs() {
elif [[ $count -eq 2 ]]; then
sudo losetup $loopdevice $raw_disk_image -o $(($rootfsstart * $sector_size))
else
echo "Error: invalid/unsupported embedded raw disk image. Aborting."
log "Error: invalid/unsupported embedded raw disk image. Aborting."
return 1
fi
@ -220,14 +220,14 @@ do_raw_disk_image_shrink_rootfs() {
new_size_sectors=$(( $min_size_blocks * $block_size / $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\taligned: $(( $new_size_sectors * $sector_size ))\
\n\tsectors: $new_size_sectors"
sudo e2fsck -y -f $loopdevice
sudo resize2fs -p $loopdevice ${new_size_sectors}s
sudo e2fsck -y -f $loopdevice
sudo e2fsck -y -f $loopdevice >> "$build_log" 2>&1
sudo resize2fs -p $loopdevice ${new_size_sectors}s >> "$build_log" 2>&1
sudo e2fsck -y -f $loopdevice >> "$build_log" 2>&1
sudo losetup -d $loopdevice
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'))
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
echo -e "\tNew root filesystem size (sectors): $new_size_sectors"
log "\tNew root filesystem size (sectors): $new_size_sectors"
return 0
}
do_raw_disk_image_create_partitions() {
echo -e "$step/$total Repartitioning raw disk image..."
log "$step/$total Repartitioning raw disk image..."
((step++))
if [ -z "$raw_disk_image" ] || [ -z "$device_type" ] || \
@ -260,14 +260,14 @@ do_raw_disk_image_create_partitions() {
fi
if [[ ! -f ${raw_disk_image} ]]; then
echo "Raw disk image not found. Aborting."
log "Raw disk image not found. Aborting."
return 1
fi
local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w)
[[ $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
@ -290,16 +290,16 @@ do_raw_disk_image_create_partitions() {
sector_size raw_disk_counts
[ -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=
calculate_mender_disk_size $pboot_start $pboot_size \
$prootfs_size $data_part_size_mb \
$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\troot filesystem size: $((${prootfs_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
echo -e "$step/$total Formatting repartitioned raw disk image..."
log "$step/$total Formatting repartitioned raw disk image..."
((step++))
make_mender_disk_filesystem ${mender_disk_mappings[@]}
@ -330,7 +330,7 @@ do_raw_disk_image_create_partitions() {
rc=$?
echo -e "$step/$total Cleaning intermediate files..."
log "$step/$total Cleaning intermediate files..."
((step++))
# Clean and detach.
detach_device_maps ${mender_disk_mappings[@]}
@ -339,7 +339,7 @@ do_raw_disk_image_create_partitions() {
rm -rf $embedded_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
}
@ -352,19 +352,19 @@ do_make_sdimg_beaglebone() {
mount_mender_disk ${mender_disk_mappings[@]}
mount_raw_disk ${raw_disk_mappings[@]}
echo -e "$step/$total Setting boot partition..."
log "$step/$total Setting boot partition..."
((step++))
stage_2_args="$sdimg_boot_dir $embedded_rootfs_dir"
${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++))
stage_3_args="$sdimg_primary_dir $embedded_rootfs_dir"
${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++))
set_fstab $device_type
@ -372,7 +372,7 @@ do_make_sdimg_beaglebone() {
}
do_make_sdimg_raspberrypi3() {
echo -e "$step/$total Setting boot partition..."
log "$step/$total Setting boot partition..."
((step++))
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_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} \
${boot_part_size} "boot.vfat"
@ -388,7 +388,7 @@ do_make_sdimg_raspberrypi3() {
${tool_dir}/rpi3-convert-stage-2.sh ${stage_2_args} || ret=$?
[[ $ret -ne 0 ]] && { return $ret; }
echo -e "$step/$total Setting root filesystem partition..."
log "$step/$total Setting root filesystem partition..."
((step++))
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_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} \
${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}/data
echo -e "$step/$total Setting file system table..."
log "$step/$total Setting file system table..."
((step++))
set_fstab $device_type
@ -422,7 +422,7 @@ do_make_sdimg_raspberrypi3() {
}
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++))
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)
[[ $supported -eq 0 ]] && \
{ echo "Error: incorrect device type. Aborting."; return 1; }
{ log "Error: incorrect device type. Aborting."; return 1; }
# mender-image-1.5.0
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}"
${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_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() {
echo -e "$step/$total Installing Bootloader to Mender disk image..."
log "$step/$total Installing Bootloader to Mender disk image..."
((step++))
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)
[[ $supported -eq 0 ]] && \
{ echo "Error: incorrect device type. Aborting."; return 1; }
{ log "Error: incorrect device type. Aborting."; return 1; }
case "$device_type" in
"beaglebone")
stage_5_args="-m $mender_disk_image -d $device_type -b ${bootloader_toolchain} $keep"
eval set -- " ${stage_5_args}"
${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_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"
eval set -- " ${stage_5_args}"
${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_config_file $device_type mount-location "\/uboot"
@ -511,38 +511,38 @@ do_install_bootloader_to_mender_disk_image() {
}
do_mender_disk_image_to_artifact() {
echo -e "$step/$total Creating Mender Artifact..."
log "$step/$total Creating Mender Artifact..."
((step++))
if [ -z "${mender_disk_image}" ]; then
echo "Mender disk image not set. Aborting."
log "Mender disk image not set. Aborting."
return 1
fi
if [ -z "${device_type}" ]; then
echo "Target device_type name not set. Aborting."
log "Target device_type name not set. Aborting."
return 1
fi
if [ -z "${artifact_name}" ]; then
echo "Artifact name not set. Aborting."
log "Artifact name not set. Aborting."
return 1
fi
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"
fi
local supported=$(echo ${supported_devices[@]} | grep -o $device_type | wc -w)
[[ $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 -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 bootstart=
@ -557,7 +557,7 @@ do_mender_disk_image_to_artifact() {
rootfs_a_size rootfs_b_start rootfs_b_size
ret=$?
[[ $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.
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/[^=].*=//' )
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
fi
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
fi
@ -599,12 +599,12 @@ do_mender_disk_image_to_artifact() {
fsck.ext4 -fp $mender_rootfs_image &> /dev/null || ret=$?
[[ $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.
loopdevice=($(sudo losetup -f || ret=$?))
[[ $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
#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:
# mender-<device_name>-<artifact_name>.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
mender-artifact write rootfs-image \
@ -634,8 +634,8 @@ do_mender_disk_image_to_artifact() {
ret=$?
[[ $ret -eq 0 ]] && \
{ echo -e "\tCreating Mender Artifact succeeded."; } || \
{ echo -e "\tCreating Mender Artifact failed."; }
{ log "\tCreating Mender Artifact succeeded."; } || \
{ log "\tCreating Mender Artifact failed."; }
fi
fi
@ -680,6 +680,10 @@ source ${tool_dir}/mender-convert-functions.sh
export -f create_device_maps
export -f detach_device_maps
export -f mount_mender_disk
export -f log
export -f logsetup
logsetup
while (( "$#" )); do
case "$1" in
@ -744,7 +748,7 @@ while (( "$#" )); do
break
;;
-*)
echo "Error: unsupported option $1" >&2
log "Error: unsupported option $1"
exit 1
;;
*)
@ -755,7 +759,7 @@ while (( "$#" )); do
done
[ -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"
@ -766,48 +770,48 @@ case "$1" in
raw-disk-image-shrink-rootfs)
total=1
do_raw_disk_image_shrink_rootfs || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; }
echo -e "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\
[[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
log "The rootfs partition in the raw disk image has been shrinked successfully!"
log "You can now convert the output raw disk image\n\t$raw_disk_image\
\nto a Mender disk image."
;;
raw-disk-image-create-partitions)
total=6
do_raw_disk_image_create_partitions || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; }
echo -e "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}."
[[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
log "A new Mender disk image with partition layout to support Mender has been successfully created!"
log "You can find the output Mender disk image at:\n\t${mender_disk_image}."
;;
install-mender-to-mender-disk-image)
total=1
do_install_mender_to_mender_disk_image || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; }
echo -e "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}."
[[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
log "The Mender client has been successfully installed to the Mender disk image."
log "You can find the output Mender disk image at:\n\t${mender_disk_image}."
;;
install-bootloader-to-mender-disk-image)
total=1
do_install_bootloader_to_mender_disk_image || rc=$?
[[ $rc -ne 0 ]] && { echo -e "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!"
echo -e "You can find the output Mender disk image at:\n\t${mender_disk_image}."
[[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
log "A bootloader configuration supporting dual A/B rootfs updates has been installed to the Mender disk image!"
log "You can find the output Mender disk image at:\n\t${mender_disk_image}."
;;
mender-disk-image-to-artifact)
total=1
do_mender_disk_image_to_artifact || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; }
echo -e "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."
[[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
log "A Mender Artifact has been successfully extracted from your Mender disk image!"
log "You can find the Mender Artifact at:\n\t$mender_artifact\nand use it to deploy updates."
;;
from-raw-disk-image)
total=9
do_from_raw_disk_image || rc=$?
[[ $rc -ne 0 ]] && { echo -e "Check $build_log for details."; exit 1; }
echo -e "Conversion complete!"
echo -e "The Mender disk image you can provision your device storage with is at:\
[[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; }
log "Conversion complete!"
log "The Mender disk image you can provision your device storage with is at:\
\n\t${mender_disk_image}."
echo -e "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 root file system partition is at:\n\t${mender_rootfs_image}."
log "The Mender Artifact you can upload to your Mender server to deploy to your devices is at:\
\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 )"
files_dir=${tool_dir}/files
output_dir=${tool_dir}/output
build_log=${output_dir}/build.log
embedded_base_dir=$output_dir/embedded
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_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:
#
# $1 -relative file path
@ -51,7 +62,7 @@ get_part_number_from_device() {
echo ${1##*[0-9]p}
;;
*)
echo "Could not determine partition number from $1"
log "Could not determine partition number from $1"
exit 1
;;
esac
@ -164,7 +175,7 @@ get_image_info() {
eval $rvar_rootfssize="'$lsecondpartsize'"
[[ $lcount -gt 2 ]] && \
{ echo "Unsupported type of source image. Aborting."; return 1; } || \
{ log "Unsupported type of source image. Aborting."; return 1; } || \
{ return 0; }
}
@ -196,7 +207,7 @@ get_mender_disk_info() {
local lcount=${#lparts[@]}
if [[ $lcount -ne 4 ]]; then
echo "Error: invalid Mender disk image. Aborting."
log "Error: invalid Mender disk image. Aborting."
return 1
else
local lsectorsize=($(echo "${lfdisk}" | grep '^Sector' | cut -d' ' -f4))
@ -276,7 +287,7 @@ analyse_raw_disk_image() {
rootfsstart rootfssize bootflag
[[ $? -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
rootfssize=$bootsize
@ -327,7 +338,7 @@ calculate_mender_disk_size() {
#
# $1 - raw disk image
unmount_partitions() {
echo "Check if device is mounted..."
log "Check if device is mounted..."
is_mounted=`grep ${1} /proc/self/mounts | wc -l`
if [ ${is_mounted} -ne 0 ]; then
sudo umount ${1}?*
@ -338,7 +349,7 @@ unmount_partitions() {
#
# $1 - raw disk image
erase_filesystem() {
echo "Erase filesystem..."
log "Erase filesystem..."
sudo wipefs --all --force ${1}?*
sudo dd if=/dev/zero of=${1} bs=1M count=100
}
@ -353,7 +364,7 @@ create_mender_disk() {
local bs=$(( 1024*1024 ))
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:
@ -424,7 +435,7 @@ format_mender_disk() {
w # write the partition table
q # and we're done
EOF
echo -e "\tChanges in partition table applied."
log "\tChanges in partition table applied."
}
# Takes following arguments:
@ -444,7 +455,7 @@ verify_mender_disk() {
local no_of_parts=${#partitions[@]}
[[ $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='"
@ -463,7 +474,7 @@ create_device_maps() {
[[ ${#mappings[@]} -eq 0 ]] \
&& { log "Error: partition mappings failed. Aborting."; exit 1; }
else
echo "Error: no device passed. Aborting."
log "Error: no device passed. Aborting."
exit 1
fi
@ -476,7 +487,7 @@ create_device_maps() {
detach_device_maps() {
local mappings=($@)
[ ${#mappings[@]} -eq 0 ] && { echo -e "\tPartition mappings cleaned."; return; }
[ ${#mappings[@]} -eq 0 ] && { log "\tPartition mappings cleaned."; return; }
local mapper=${mappings[0]%p*}
@ -508,10 +519,10 @@ make_mender_disk_filesystem() {
label=${mender_disk_partitions[${part_no} - 1]}
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
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
fi
done
@ -562,7 +573,7 @@ set_fstab() {
local device_type=$1
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.
sudo install -b -m 644 /dev/null ${sysconfdir}/fstab
@ -594,7 +605,7 @@ set_fstab() {
/dev/mmcblk0p4 /data auto defaults 0 0
EOF"
echo -e "\tDone."
log "\tDone."
}
# Takes following arguments
@ -606,9 +617,9 @@ set_fstab() {
extract_file_from_image() {
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."; } \
|| { echo -e "\tStoring data in $4 disk image."; }
$(${cmd})
[ "${4##*.}" == "ext4" ] && { log "\tStoring data in $4 root file system image."; } \
|| { log "\tStoring data in $4 disk image."; }
$(${cmd}>> "$build_log" 2>&1)
}
# Takes following arguments
@ -652,7 +663,7 @@ update_test_config_file() {
local device_type=$1
[ ! -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

7
rpi3-convert-stage-2.sh

@ -2,9 +2,10 @@
output_dir=$1
boot_mapping=$2
build_log=$output_dir/build.log
[ ! -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.
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
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

7
rpi3-convert-stage-3.sh

@ -2,15 +2,16 @@
output_dir=$1
rootfs_mapping=$2
build_log=$output_dir/build.log
[ ! -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.
sudo e2label /dev/mapper/${rootfs_mapping} "primary"
echo -e "\tDone."
log "\tDone."
exit 0

31
rpi3-convert-stage-5.sh

@ -45,19 +45,20 @@ build_uboot_files() {
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
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
cd $uboot_dir
git checkout $commit
git checkout $commit >> "$build_log" 2>&1
make --quiet distclean
make --quiet rpi_3_32b_defconfig && make --quiet
make --quiet envtools
make --quiet distclean >> "$build_log"
make --quiet rpi_3_32b_defconfig >> "$build_log" 2>&1
make --quiet >> "$build_log" 2>&1
make --quiet envtools >> "$build_log" 2>&1
cat<<-'EOF' >boot.cmd
fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
@ -69,11 +70,11 @@ build_uboot_files() {
EOF
if [ ! -e $uboot_dir/tools/mkimage ]; then
echo "Error: cannot build U-Boot. Aborting"
log "Error: cannot build U-Boot. Aborting"
return 1
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
return 0
@ -87,7 +88,7 @@ install_files() {
local boot_dir=$1
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.
sudo cp ${boot_dir}/cmdline.txt ${output_dir}/cmdline.txt
@ -148,12 +149,12 @@ install_files() {
do_install_bootloader() {
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
fi
if [ -z "${bootloader_toolchain}" ]; then
echo "ARM GCC toolchain not set. Aborting."
log "ARM GCC toolchain not set. Aborting."
exit 1
fi
@ -165,12 +166,12 @@ do_install_bootloader() {
local gcc_version=$(${bootloader_toolchain}-gcc -dumpversion)
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
fi
[ ! -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.
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;
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
@ -226,7 +227,7 @@ while (( "$#" )); do
break
;;
-*)
echo "Error: unsupported option $1" >&2
log "Error: unsupported option $1"
exit 1
;;
*)

Loading…
Cancel
Save