tizen: enable support for formatting MBR partition layout during flashing
authorMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 26 Nov 2020 14:32:03 +0000 (15:32 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 12 Oct 2022 05:48:01 +0000 (14:48 +0900)
This is ensured by the following steps:
1. enable 'mbr' command and provide default partiton layout,
2. add support for formating block device from THOR downloaded script,
3. check MBR partition layout on boot and enter THOR mode if invalid
4. provide a script for formating MBR for THOR download

MBR partition layout is checked on boot if it mathes the one defined
during u-boot compilation. If not, set dfu_alt_info to the minimal safe
list and enter THOR download mode to flash the new, proper partition
layout and the complete Tizen image.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I490e5b3314513012259f3981feae047f95649c3b

include/samsung/tizen_amlogic.h
tizen/build-amlogic.sh

index 0aafba8..ea192bd 100644 (file)
        "ramdisk.img part -1 7;"                \
        "ramdisk-recovery.img part -1 8"
 
+/*
+ * '0-format.cmd' entity is common for all boards, but it has to be
+ * defined in the per-board DFU_ALT_BOOT_* to ensure that it is also
+ * available in the dfu_alt_fallback env
+ */
 #define DFU_ALT_BOOT_ODROID_N2 "u-boot-n2.bin raw 0x1 0x1000;" \
                                "u-boot-c4.bin skip 0 0;"       \
                                "u-boot-vim3l.bin skip 0 0;"    \
-                               "u-boot-vim3.bin skip 0 0"
+                               "u-boot-vim3.bin skip 0 0;"     \
+                               "0-format.cmd script 0 0"
 #define DFU_ALT_BOOT_VIM3      "u-boot-vim3.bin raw 0x1 0x1000;" \
                                "u-boot-c4.bin skip 0 0;"       \
                                "u-boot-vim3l.bin skip 0 0;"    \
-                               "u-boot-n2.bin skip 0 0"
+                               "u-boot-n2.bin skip 0 0;"       \
+                               "0-format.cmd script 0 0"
 #define DFU_ALT_BOOT_ODROID_C4 "u-boot-c4.bin raw 0x1 0x1000;" \
                                "u-boot-vim3.bin skip 0 0;"     \
                                "u-boot-vim3l.bin skip 0 0;"    \
-                               "u-boot-n2.bin skip 0 0"
+                               "u-boot-n2.bin skip 0 0;"       \
+                               "0-format.cmd script 0 0"
 #define DFU_ALT_BOOT_VIM3L     "u-boot-vim3l.bin raw 0x1 0x1000;" \
                                "u-boot-vim3.bin skip 0 0;"     \
                                "u-boot-c4.bin skip 0 0;"       \
-                               "u-boot-n2.bin skip 0 0"
+                               "u-boot-n2.bin skip 0 0;"       \
+                               "0-format.cmd script 0 0"
+
 #define CONFIG_SET_DFU_ALT_BUF_LEN     (SZ_1K)
 
+#define PARTS_DEFAULT \
+       "name=boot,start=4M,size=128M,bootable,id=0x0e;"        \
+       "name=rootfs,size=3072M,id=0x83;"                       \
+       "name=system-data,size=512M,id=0x83;"                   \
+       "name=[ext],size=-,id=0x05;"                            \
+       "name=user,size=-,id=0x83;"                             \
+       "name=modules,size=100M,id=0x83;"                       \
+       "name=ramdisk,size=8M,id=0x83;"                         \
+       "name=ramdisk-recovery,size=32M,id=0x83;"               \
+       "name=reserved0,size=8M,id=0x83;"                       \
+       "name=reserved1,size=64M,id=0x83;"                      \
+       "name=reserved2,size=128M,id=0x83;"                     \
+       ""
+
 /* DFU over USB/UDC */
 #if defined(CONFIG_CMD_DFU) || defined(CONFIG_CMD_THOR)
 #define CONFIG_SYS_DFU_DATA_BUF_SIZE   SZ_1M
 #define DEVICE_TREE_NAME       CONFIG_DEFAULT_DEVICE_TREE
 #endif
 
+#define MBR_CHECK      \
+       "env default mbr_parts; "                                       \
+       "if mbr verify ${dfu_interface} ${dfu_device}; "                \
+       "then true; else "                                              \
+       "echo \"MBR layout does not match flashed bootloader!\"; "      \
+       "echo \"Please flash complete Tizen image or Ctrl-C to continue.\"; " \
+       "env default dfu_alt_fallback; "                                \
+       "setenv dfu_alt_info \"${dfu_alt_fallback}\"; "                 \
+       "thor; "                                                        \
+       "fi"
+
 #define TIZEN_ENV_SETTING \
        "mmcbootpart=1\0"                       \
        "mmcrootpart=2\0"                       \
        "bootmode=ramdisk\0"                    \
        "bootdev=mmc\0"                         \
        "dfu_alt_info=" DFU_ALT_SYSTEM ";" DFU_ALT_BOOT "\0"\
+       "dfu_alt_fallback=" DFU_ALT_BOOT "\0"   \
        "fdt_high=0x20000000\0"                 \
        "initrd_high=0x3d800000\0"              \
        "opts=loglevel=4\0"                     \
        "dfu_interface=mmc\0"                   \
        "fdtfile=" DEVICE_TREE_NAME "\0"        \
        "board_name=" BOARD_NAME "\0"           \
-       "boot_prefixes=" TIZEN_BOOT_PREFIX "\0"
+       "boot_prefixes=" TIZEN_BOOT_PREFIX "\0" \
+       "mbr_parts=" PARTS_DEFAULT "\0"         \
+       "mbr_check=" MBR_CHECK "\0"
+
 
 #define CONFIG_TIZEN
 
index 5133e7e..bee5731 100755 (executable)
@@ -15,6 +15,7 @@ set_names()
        PARAMS=params-c4.bin
        OUTPUT_BIN=u-boot-c4.bin
        OUTPUT_TAR=odroidc4_bootloader.tar
+       OUTPUT2_TGZ=odroidc4_format_bootloader.tar.gz
        ;;
 
        n2)
@@ -25,6 +26,7 @@ set_names()
        PARAMS=params-n2.bin
        OUTPUT_BIN=u-boot-n2.bin
        OUTPUT_TAR=odroidn2_bootloader.tar
+       OUTPUT2_TGZ=odroidn2_format_bootloader.tar.gz
        ;;
 
        vim3)
@@ -35,6 +37,7 @@ set_names()
        PARAMS=params-vim3.bin
        OUTPUT_BIN=u-boot-vim3.bin
        OUTPUT_TAR=kvim3_bootloader.tar
+       OUTPUT2_TGZ=kvim3_format_bootloader.tar.gz
        ;;
 
        vim3l)
@@ -45,10 +48,12 @@ set_names()
        PARAMS=params-vim3l.bin
        OUTPUT_BIN=u-boot-vim3l.bin
        OUTPUT_TAR=kvim3l_bootloader.tar
+       OUTPUT2_TGZ=kvim3l_format_bootloader.tar.gz
        ;;
 
        all)
        OUTPUT_TAR=amlogic_bootloader.tar
+       OUTPUT2_TGZ=amlogic_format_bootloader.tar.gz
        ;;
 esac
 }
@@ -120,6 +125,32 @@ build_amlogic()
        cd ..
 }
 
+build_format()
+{
+       cd output
+
+       rm -f 0-format.cmd
+       for i in params*.bin
+       do
+               strings $i | grep 'board_name=' | sed -e 's/\([a-z_]*\)=\(.*\)/if test \$\{\1\} = "\2"; then/' >>0-format.cmd
+               strings $i | grep 'dfu_alt_info=' | sed -e 's/\([a-z_]*\)=\(.*\)/setenv \1 "\2";/' >>0-format.cmd
+               strings $i | grep 'mbr_parts=' | sed -e 's/\([a-z_]*\)=\(.*\)/setenv \1 "\2";/' >>0-format.cmd
+               echo 'mbr write ${dfu_interface} ${dfu_device} "${mbr_parts}";' >>0-format.cmd
+               echo 'fi;' >>0-format.cmd
+       done
+
+       # make empty FAT partiton
+       dd if=/dev/zero of=boot.img bs=1024 count=128k
+       mkfs.vfat -n BOOT boot.img
+       mmd -i boot.img odroid
+       mmd -i boot.img kvim
+       # WARNING: the order of files in the TAR is important!!!
+       # 0-format.cmd MUST be before any other MBR related entity
+       # boot.img must be before any file from FAT partiton
+       tar cvfz ${OUTPUT2_TGZ} u-boot-+([a-z0-9]).bin 0-format.cmd boot.img boot.scr.uimg params*.bin
+       cd ..
+}
+
 case $1 in
 c4|n2|vim3|vim3l)
        BOARDS=$1
@@ -155,3 +186,4 @@ then
        tar cvf ${OUTPUT_TAR} u-boot-+([a-z0-9]).bin boot.scr.uimg params*.bin
        cd ..
 fi
+build_format