~aleteoryx/muditaos

333c8c0db3674afe2cf28e13035d20d98a4ed0b1 — Mateusz Grzegorzek 4 years ago 0802e8f
[BH-736] Add image generation

Add image generation
M cmake/modules/DiskImage.cmake => cmake/modules/DiskImage.cmake +8 -2
@@ 2,7 2,7 @@ function(add_image)
    cmake_parse_arguments(
        _ARG
        ""
        "PRODUCT;SYSROOT;ASSETS"
        "PRODUCT;SYSROOT;ASSETS;IMAGE_PARTITIONS"
        ""
        ${ARGN}
    )


@@ 16,6 16,11 @@ function(add_image)

    set(DISK_IMAGE_NAME ${_ARG_PRODUCT}.img)
    set(DISK_IMAGE_PATH ${CMAKE_BINARY_DIR}/${DISK_IMAGE_NAME})
    if(DEFINED _ARG_IMAGE_PARTITIONS)
        set(IMAGE_PARTITIONS ${_ARG_IMAGE_PARTITIONS})
    else()
        set(IMAGE_PARTITIONS ${CMAKE_SOURCE_DIR}/config/products/${_ARG_PRODUCT}/image_partitions.map)
    endif()

    if(HAS_BOOTFILE)
        set(BIN_FILE_TARGET ${_ARG_PRODUCT}-boot.bin)


@@ 31,7 36,7 @@ function(add_image)
    endif()

    set(COMMAND_DEPENDS "genlittlefs")
    list(APPEND COMMNDS_DEPENDS ${SCRIPT_PATH})
    list(APPEND COMMAND_DEPENDS ${SCRIPT_PATH})
    if(_ARG_ASSETS)
        list(APPEND COMMAND_DEPENDS ${_ARG_ASSETS})
    endif()


@@ 49,6 54,7 @@ function(add_image)
        COMMAND
            ${SCRIPT_PATH}
            ${DISK_IMAGE_NAME}
            ${IMAGE_PARTITIONS}
            ${CMAKE_BINARY_DIR}/${_ARG_SYSROOT}
            "${BIN_FILE_PATH}"
            "${UPDATER_FILE_PATH}"

M config/partition_emmc.sh => config/partition_emmc.sh +36 -11
@@ 20,18 20,42 @@ fi

source config/common.sh
is_root=`id -u`
if [ "$1" == "" ] || [ $is_root != 0 ]; then
	echo "Refuse to work with no device. Runme as root [uid=$is_root]"
	echo -e "$0 <dev> [-f]\n"
if [ $is_root != 0 ]; then
	echo "Runme as root [uid=$is_root]"
	exit 1
else
	dev=$1
fi

if [ "$2" == "-f" ]; then
	use_the_force=1
else
	use_the_force=0
usage() { echo "Usage: $0 -d /dev/sdX -p <PurePhone|BellHybrid> [-f]" 1>&2; exit 1; }

use_the_force=0
while getopts "d:p:f" o; do
    case $o in
        d)
            dev=${OPTARG}
            ;;
        p)
            product_name=${OPTARG}
            ;;
        f)
            use_the_force=1
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

if [ -z "${product_name}" ]; then
    usage
fi

echo "Using product: $product_name"

emmc_partition_table_dump_path=config/products/$product_name/emmc_partition_table.dump
if [ ! -f "$emmc_partition_table_dump_path" ]; then
	echo "ERROR! File \"config/products/$product_name/emmc_partition_table.dump\" not exist!"
	exit 1
fi

pcount=$(sfdisk --dump $dev | grep "start=" | wc -l)


@@ 68,7 92,7 @@ sleep 1
partprobe

echo "write partition table"
sfdisk --wipe always $dev < config/emmc_partition_table.dump
sfdisk --wipe always $dev < "$emmc_partition_table_dump_path"

if [ $? != 0 ]; then
	echo "partitioning device $dev failed"


@@ 76,11 100,12 @@ if [ $? != 0 ]; then
fi

part1=$(sfdisk $dev --dump | grep bootable | awk '{print $1}')
part2=$(sfdisk $dev --dump | tail -n 1 | awk '{print $1}')
part2=$(sfdisk $dev --dump | tail -n 2 | head -n -1 | awk '{print $1}')

echo "create FATs"
echo "FAT: $MUDITAOS_PARTITION_PRIMARY $part1"
mkfs.vfat -n $MUDITAOS_PARTITION_PRIMARY $part1

echo "FAT: $MUDITAOS_PARTITION_RECOVERY $part2"
mkfs.vfat -n $MUDITAOS_PARTITION_RECOVERY $part2


A config/products/BellHybrid/emmc_partition_table.dump => config/products/BellHybrid/emmc_partition_table.dump +8 -0
@@ 0,0 1,8 @@
label: dos
label-id: 0x09650eb4
device: /dev/sda
unit: sectors

/dev/sda1 : start=       2048, size=  524288, type=b, bootable
/dev/sda2 : start=     526336, size=  524288, type=9e
/dev/sda3 : start=    1050624, size= 6354944, type=9e

A config/products/BellHybrid/image_partitions.map => config/products/BellHybrid/image_partitions.map +2 -0
@@ 0,0 1,2 @@
DEVICE_BLK_COUNT=7403520
PART1_SIZE=524288

R config/emmc_partition_table.dump => config/products/PurePhone/emmc_partition_table.dump +2 -2
@@ 3,5 3,5 @@ label-id: 0x09650eb4
device: /dev/sda
unit: sectors

/dev/sda1 : start=        2048, size=    28522496, type=b, bootable
/dev/sda2 : start=    28524544, size=     2097152, type=b
/dev/sda1 : start= 2048,     size= 28522496, type=b, bootable
/dev/sda2 : start= 28524544, size= 2097152,  type=9e

A config/products/PurePhone/image_partitions.map => config/products/PurePhone/image_partitions.map +2 -0
@@ 0,0 1,2 @@
DEVICE_BLK_COUNT=30621696
PART1_SIZE=2097152

M test/CMakeLists.txt => test/CMakeLists.txt +1 -0
@@ 29,6 29,7 @@ add_image(
    PRODUCT Test
    SYSROOT test-sysroot
    ASSETS  test-assets
    IMAGE_PARTITIONS ${CMAKE_SOURCE_DIR}/config/products/PurePhone/image_partitions.map
)

macro(enable_test_filesystem)

M tools/generate_image.sh => tools/generate_image.sh +16 -10
@@ 4,24 4,28 @@

usage() {
cat << ==usage
Usage: $(basename $0) image_path build_dir [boot.bin_file] [updater.bin_file]
Usage: $(basename $0) image_path image_partitions build_dir [boot.bin_file] [updater.bin_file]
    image_path       - Destination image path name e.g., PurePhone.img
    image_partitions - Path to image_partitions.map product-specific file
    sysroot          - product's system root e.g., build-rt1051-RelWithDebInfo/sysroot
    boot.bin_file    - optional for linux image - name of the boot.bin file (for different targets)
    updater.bin_file - optional for linux image - name of the updater.bin file
==usage
}

if [[ ( $# -ne 2 ) && ( $# -ne 4 ) ]]; then
if [[ ( $# -ne 3 ) && ( $# -ne 5 ) ]]; then
	echo "Error! Invalid argument count"
	usage
	exit -1
fi

IMAGE_NAME=$(realpath $1)
SYSROOT=$(realpath $2)
BIN_FILE=$3
UPDATER_FILE=$4
PRODUCT_NAME=$(basename -s .img $1)
IMAGE_PARTITIONS=$(realpath $2)

SYSROOT=$(realpath $3)
BIN_FILE=$4
UPDATER_FILE=$5

if [ ! -d "$SYSROOT" ]; then
	echo "Error! ${SYSROOT} is not a directory"


@@ 57,12 61,11 @@ if [ -z ${GENLFS} ]; then
    exit -1
fi

#Number of sectors in the phone EMMC card
DEVICE_BLK_COUNT=30621696
source ${IMAGE_PARTITIONS}
DEVICE_BLK_SIZE=512

# Partition sizes in sector 512 units
PART1_START=2048
PART1_SIZE=2097152
PART2_START=$(($PART1_START + $PART1_SIZE))
PART2_SIZE=$PART1_SIZE
PART3_START=$(($PART2_START + $PART2_SIZE))


@@ 84,6 87,9 @@ unit: sectors
PART1="$IMAGE_NAME@@$(($PART1_START * $DEVICE_BLK_SIZE))"
mformat -i "$PART1" -F -T $PART1_SIZE -M $DEVICE_BLK_SIZE -v MUDITAOS

PART2="$IMAGE_NAME@@$(($PART2_START * $DEVICE_BLK_SIZE))"
mformat -i "$PART2" -F -T $PART2_SIZE -M $DEVICE_BLK_SIZE -v RECOVER

if [ ! -d "${SYSROOT}/sys" ]; then
	echo "Fatal! Image folder sys/ missing in build. Check build system."
	exit -1


@@ 126,8 132,8 @@ mcopy -s -i "$PART1" .boot.json.crc32 ::

#Littlefs generate image
echo $(pwd)
$GENLFS --image=$IMAGE_NAME --block_size=32768  --overwrite  --partition_num=3 -- user/*
$GENLFS --image=$IMAGE_NAME --block_size=4096  --overwrite  --partition_num=2
$GENLFS --image=$IMAGE_NAME --block_size=4096 --overwrite --partition_num=2
$GENLFS --image=$IMAGE_NAME --block_size=32768 --overwrite --partition_num=3 -- user/*

# back to previous dir
cd -