Commit 529e8a50 authored by carbon's avatar carbon

milkv-duo use genimage to create sd card img

parent db74adc7
......@@ -77,15 +77,16 @@ function prepare_env()
source build/${MV_BUILD_ENV} > /dev/null 2>&1
defconfig ${MV_BOARD_LINK} > /dev/null 2>&1
echo "OUTPUT_DIR: ${OUTPUT_DIR}" # @build/milkvsetup.sh
}
function milkv_duo_build()
{
# clean old img
install_dir="install/soc_${MV_BOARD_LINK}"
old_image_count=`ls ${install_dir}/*.img* | wc -l`
old_image_count=`ls ${OUTPUT_DIR}/*.img* | wc -l`
if [ ${old_image_count} -ge 0 ]; then
pushd ${install_dir}
pushd ${OUTPUT_DIR}
rm -rf *.img*
popd
fi
......@@ -102,18 +103,23 @@ function milkv_duo_build()
function milkv_duo_pack()
{
if [ "$(id -u)" -ne 0 ]; then
print_info "Creating sd card img requires root privileges"
sudo echo "Running with root privileges now"
fi
pack_sd_image
[ ! -d out ] && mkdir out
image_count=`ls ${install_dir}/*.img | wc -l`
image_count=`ls ${OUTPUT_DIR}/*.img | wc -l`
if [ ${image_count} -ge 0 ]; then
mv ${install_dir}/*.img out/
mv ${OUTPUT_DIR}/*.img out/
# rename milkv-duo.img file with time
pushd out
for img in *.img
do
if [ "${img}" == "${MILKV_BOARD}.img" ]; then
mv $img ${MILKV_BOARD}-`date +%Y%m%d-%H%M`.img
fi
done
popd
# show latest img
latest_img=`ls -t out/*.img | head -n1`
......
......@@ -310,6 +310,8 @@ BR2_PACKAGE_E2FSPROGS=y
# BR2_PACKAGE_E2FSPROGS_DEBUGFS is not set
# BR2_PACKAGE_E2FSPROGS_E2IMAGE is not set
BR2_PACKAGE_HOST_GENIMAGE=y
#
# e2scrub needs bash, coreutils, lvm2, and util-linux
#
......
#!/bin/bash
# sd image generator
# milkv sd image generator
# usage
if [ "$#" -ne "1" ]; then
echo "usage: sudo ${0} OUTPUT_DIR"
echo "usage: ${0} OUTPUT_DIR"
echo ""
echo " The script is used to create a sdcard image with two partitions, "
echo " one is fat32 with 128MB, the other is ext4 with 256MB."
echo " You can modify the capacities in this script as you wish!"
echo " You can modify the capacities in genimage cfg as you wish!"
echo " genimage cfg: milkv/genimage-milkv-duo.cfg"
echo ""
echo "Note: Please backup you sdcard files before using this image!"
exit
fi
vfat_cap=128M
vfat_label="boot"
ext4_cap=256M
ext4_label="rootfs"
echo "BR_DIR: $BR_DIR"
echo "BR_BOARD: $BR_BOARD"
# genimage command in buildroot host bin
BR_HOST_BIN="${BR_DIR}/output/${BR_BOARD}/host/bin"
if [ ! -d ${BR_HOST_BIN} ]; then
echo "host/bin not found, check buildroot output dir!"
exit 1
fi
export PATH=${BR_HOST_BIN}:${PATH}
output_dir=$1
echo ${output_dir}
pushd ${output_dir}
# gen a empty image
image=${MILKV_BOARD}-`date +%Y%m%d-%H%M`.img
echo ${image}
dd if=/dev/zero of=./${image} bs=1M count=512
################################
# Note: do not change this flow
################################
sudo fdisk ./${image} << EOF
n
p
1
+${vfat_cap}
n
p
2
+${ext4_cap}
w
EOF
# Note end
################################
dev_name=`sudo losetup -f`
echo ${dev_name}
echo ""
[ -d tmp ] && rm -rf tmp
sudo losetup ${dev_name} ./${image}
sudo partprobe ${dev_name}
sudo mkfs.vfat -F 32 -n ${vfat_label} ${dev_name}p1
sudo mkfs.ext4 -L ${ext4_label} ${dev_name}p2
# mount partitions
rm ./tmp1 ./tmp2 -rf
mkdir tmp1 tmp2
sudo mount -t vfat ${dev_name}p1 tmp1/
sudo mount -t ext4 ${dev_name}p2 tmp2/
# copy boot file and rootfs
sudo cp ${output_dir}/fip.bin ./tmp1/
sudo cp ${output_dir}/rawimages/boot.sd ./tmp1/
sudo cp -raf ${output_dir}/fs/* ./tmp2
sync
# umount
sudo umount tmp1 tmp2
sudo losetup -d ${dev_name}
rmdir tmp1 tmp2
echo "Gen image successful: ${image}"
echo ""
genimage --config ${TOP_DIR}/milkv/genimage-${MILKV_BOARD}.cfg --rootpath fs/ --inputpath ${PWD} --outputpath ${PWD}
if [ $? -eq 0 ]; then
echo "gnimage for ${MILKV_BOARD} success!"
else
echo "gnimage for ${MILKV_BOARD} failed!"
fi
popd
image boot.vfat {
vfat {
label = "boot"
files = {
"fip.bin",
"rawimages/boot.sd",
}
}
size = 128M
}
image rootfs.ext4 {
ext4 {
label = "rootfs"
}
size = 256M
}
image milkv-duo.img {
hdimage {
}
partition boot {
partition-type = 0xC
bootable = "true"
image = "boot.vfat"
}
partition rootfs {
partition-type = 0x83
image = "rootfs.ext4"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment