diff mbox series

[v2,7/7] env: am57xx: Implement A/B boot process

Message ID 1544634754-3435-8-git-send-email-ruslan.trofymenko@linaro.org
State Accepted
Commit edd31084f2560008b7aed6c9654b014a90ebd33e
Headers show
Series android: Implement A/B boot process | expand

Commit Message

Ruslan Trofymenko Dec. 12, 2018, 5:12 p.m. UTC
Add support for A/B boot process on AM57xx based boards:

  1. Define 'slot_suffix' variable (using 'ab_select' command)
  2. Extend 'emmc_android_boot' boot command (add commands for A/B boot
     process)

'ab_select' command is used to decide which slot should be used for
booting up. A/B metadata resides in 'misc' partition.

To activate the A/B boot process, the following config options must be
set:

    CONFIG_ANDROID_AB=y
    CONFIG_CMD_AB_SELECT=y

For successful A/B boot, the corresponding A/B infrastructure must be
involved on Android side [1] (including mounting system as root), and
disk must be partitioned accordingly.

When A/B boot is enabled, there are some known limitations currently
exist (not related to A/B patches, need to be implemented later):

  1. The 'Verified Boot' sequence is not supported
  2. dev path to system partition (system_a or system_b) is passed via
     'bootargs' as 'root=' argument like 'root=/dev/mmcblk1p12', but
     further we'll need to rework it with respect to dm-verity
     requirements [2]

In case when A/B partitions are not present in system (and A/B boot is
enabled), boot up process will be terminated and next message will be
shown:

    "boot_a(b) partition not found"

[1] https://source.android.com/devices/tech/ota/ab
[2] https://source.android.com/devices/tech/ota/ab/ab_implement#kernel

Signed-off-by: Ruslan Trofymenko <ruslan.trofymenko@linaro.org>
Reviewed-by: Alistair Strachan <astrachan@google.com>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
---
Changes in v2:
  * Сhanges related to command renaming (android_ab_select -> ab_select)
  * Slotted sections (e.g. system_a and system_b) are added to the
    default sections if CONFIG_CMD_AB_SELECT flag is defined
  * Rebased on top of master
  * system partitions sizes increased to 1024 MiB (to be consistent with
    recent changes to boot.h file)

 include/environment/ti/boot.h | 58 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 6 deletions(-)

Comments

Simon Glass Jan. 5, 2019, 1:56 a.m. UTC | #1
On Wed, 12 Dec 2018 at 10:12, Ruslan Trofymenko
<ruslan.trofymenko@linaro.org> wrote:
>
> Add support for A/B boot process on AM57xx based boards:
>
>   1. Define 'slot_suffix' variable (using 'ab_select' command)
>   2. Extend 'emmc_android_boot' boot command (add commands for A/B boot
>      process)
>
> 'ab_select' command is used to decide which slot should be used for
> booting up. A/B metadata resides in 'misc' partition.
>
> To activate the A/B boot process, the following config options must be
> set:
>
>     CONFIG_ANDROID_AB=y
>     CONFIG_CMD_AB_SELECT=y
>
> For successful A/B boot, the corresponding A/B infrastructure must be
> involved on Android side [1] (including mounting system as root), and
> disk must be partitioned accordingly.
>
> When A/B boot is enabled, there are some known limitations currently
> exist (not related to A/B patches, need to be implemented later):
>
>   1. The 'Verified Boot' sequence is not supported
>   2. dev path to system partition (system_a or system_b) is passed via
>      'bootargs' as 'root=' argument like 'root=/dev/mmcblk1p12', but
>      further we'll need to rework it with respect to dm-verity
>      requirements [2]
>
> In case when A/B partitions are not present in system (and A/B boot is
> enabled), boot up process will be terminated and next message will be
> shown:
>
>     "boot_a(b) partition not found"
>
> [1] https://source.android.com/devices/tech/ota/ab
> [2] https://source.android.com/devices/tech/ota/ab/ab_implement#kernel
>
> Signed-off-by: Ruslan Trofymenko <ruslan.trofymenko@linaro.org>
> Reviewed-by: Alistair Strachan <astrachan@google.com>
> Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
> ---
> Changes in v2:
>   * Сhanges related to command renaming (android_ab_select -> ab_select)
>   * Slotted sections (e.g. system_a and system_b) are added to the
>     default sections if CONFIG_CMD_AB_SELECT flag is defined
>   * Rebased on top of master
>   * system partitions sizes increased to 1024 MiB (to be consistent with
>     recent changes to boot.h file)
>
>  include/environment/ti/boot.h | 58 ++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 52 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Igor Opaniuk Jan. 15, 2019, 11:42 a.m. UTC | #2
Reviewed-by: Igor Opaniuk <igor.opaniuk@linaro.org>

On Wed, 12 Dec 2018 at 19:12, Ruslan Trofymenko
<ruslan.trofymenko@linaro.org> wrote:
>
> Add support for A/B boot process on AM57xx based boards:
>
>   1. Define 'slot_suffix' variable (using 'ab_select' command)
>   2. Extend 'emmc_android_boot' boot command (add commands for A/B boot
>      process)
>
> 'ab_select' command is used to decide which slot should be used for
> booting up. A/B metadata resides in 'misc' partition.
>
> To activate the A/B boot process, the following config options must be
> set:
>
>     CONFIG_ANDROID_AB=y
>     CONFIG_CMD_AB_SELECT=y
>
> For successful A/B boot, the corresponding A/B infrastructure must be
> involved on Android side [1] (including mounting system as root), and
> disk must be partitioned accordingly.
>
> When A/B boot is enabled, there are some known limitations currently
> exist (not related to A/B patches, need to be implemented later):
>
>   1. The 'Verified Boot' sequence is not supported
>   2. dev path to system partition (system_a or system_b) is passed via
>      'bootargs' as 'root=' argument like 'root=/dev/mmcblk1p12', but
>      further we'll need to rework it with respect to dm-verity
>      requirements [2]
>
> In case when A/B partitions are not present in system (and A/B boot is
> enabled), boot up process will be terminated and next message will be
> shown:
>
>     "boot_a(b) partition not found"
>
> [1] https://source.android.com/devices/tech/ota/ab
> [2] https://source.android.com/devices/tech/ota/ab/ab_implement#kernel
>
> Signed-off-by: Ruslan Trofymenko <ruslan.trofymenko@linaro.org>
> Reviewed-by: Alistair Strachan <astrachan@google.com>
> Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
> ---
> Changes in v2:
>   * Сhanges related to command renaming (android_ab_select -> ab_select)
>   * Slotted sections (e.g. system_a and system_b) are added to the
>     default sections if CONFIG_CMD_AB_SELECT flag is defined
>   * Rebased on top of master
>   * system partitions sizes increased to 1024 MiB (to be consistent with
>     recent changes to boot.h file)
>
>  include/environment/ti/boot.h | 58 ++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 52 insertions(+), 6 deletions(-)
>
> diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h
> index 5891009..e3ba689 100644
> --- a/include/environment/ti/boot.h
> +++ b/include/environment/ti/boot.h
> @@ -23,6 +23,18 @@
>  #define VBMETA_PART                    ""
>  #endif
>
> +#if defined(CONFIG_CMD_AB_SELECT)
> +#define COMMON_PARTS \
> +       "name=boot_a,size=10M,uuid=${uuid_gpt_boot_a};" \
> +       "name=boot_b,size=10M,uuid=${uuid_gpt_boot_b};" \
> +       "name=system_a,size=1024M,uuid=${uuid_gpt_system_a};" \
> +       "name=system_b,size=1024M,uuid=${uuid_gpt_system_b};"
> +#else
> +#define COMMON_PARTS \
> +       "name=boot,size=10M,uuid=${uuid_gpt_boot};" \
> +       "name=system,size=1024M,uuid=${uuid_gpt_system};"
> +#endif
> +
>  #ifndef PARTS_DEFAULT
>  /* Define the default GPT table for eMMC */
>  #define PARTS_DEFAULT \
> @@ -40,8 +52,7 @@
>         "name=efs,size=16M,uuid=${uuid_gpt_efs};" \
>         "name=crypto,size=16K,uuid=${uuid_gpt_crypto};" \
>         "name=recovery,size=40M,uuid=${uuid_gpt_recovery};" \
> -       "name=boot,size=10M,uuid=${uuid_gpt_boot};" \
> -       "name=system,size=768M,uuid=${uuid_gpt_system};" \
> +       COMMON_PARTS \
>         "name=vendor,size=256M,uuid=${uuid_gpt_vendor};" \
>         "name=cache,size=256M,uuid=${uuid_gpt_cache};" \
>         "name=ipu1,size=1M,uuid=${uuid_gpt_ipu1};" \
> @@ -63,6 +74,35 @@
>  #define AVB_VERIFY_CMD ""
>  #endif
>
> +#define CONTROL_PARTITION "misc"
> +
> +#if defined(CONFIG_CMD_AB_SELECT)
> +#define AB_SELECT \
> +       "if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \
> +       "then " \
> +               "echo " CONTROL_PARTITION \
> +                       " partition number:${control_part_number};" \
> +               "ab_select slot_name mmc ${mmcdev}:${control_part_number};" \
> +       "else " \
> +               "echo " CONTROL_PARTITION " partition not found;" \
> +               "exit;" \
> +       "fi;" \
> +       "setenv slot_suffix _${slot_name};" \
> +       "if part number mmc ${mmcdev} system${slot_suffix} " \
> +       "system_part_number; then " \
> +               "setenv bootargs_ab " \
> +                       "ro root=/dev/mmcblk${mmcdev}p${system_part_number} " \
> +                       "rootwait init=/init skip_initramfs " \
> +                       "androidboot.slot_suffix=${slot_suffix};" \
> +               "echo A/B cmdline addition: ${bootargs_ab};" \
> +               "setenv bootargs ${bootargs} ${bootargs_ab};" \
> +       "else " \
> +               "echo system${slot_suffix} partition not found;" \
> +       "fi;"
> +#else
> +#define AB_SELECT ""
> +#endif
> +
>  #define DEFAULT_COMMON_BOOT_TI_ARGS \
>         "console=" CONSOLEDEV ",115200n8\0" \
>         "fdtfile=undefined\0" \
> @@ -91,10 +131,16 @@
>                 "mmc dev $mmcdev; " \
>                 "mmc rescan; " \
>                 AVB_VERIFY_CHECK \
> -               "part start mmc ${mmcdev} boot boot_start; " \
> -               "part size mmc ${mmcdev} boot boot_size; " \
> -               "mmc read ${loadaddr} ${boot_start} ${boot_size}; " \
> -               "bootm ${loadaddr}#${fdtfile};\0 "
> +               AB_SELECT \
> +               "if part start mmc ${mmcdev} boot${slot_suffix} boot_start; " \
> +               "then " \
> +                       "part size mmc ${mmcdev} boot${slot_suffix} " \
> +                               "boot_size; " \
> +                       "mmc read ${loadaddr} ${boot_start} ${boot_size}; " \
> +                       "bootm ${loadaddr}#${fdtfile}; " \
> +               "else " \
> +                       "echo boot${slot_suffix} partition not found; " \
> +               "fi;\0"
>
>  #ifdef CONFIG_OMAP54XX
>
> --
> 2.7.4
>
diff mbox series

Patch

diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h
index 5891009..e3ba689 100644
--- a/include/environment/ti/boot.h
+++ b/include/environment/ti/boot.h
@@ -23,6 +23,18 @@ 
 #define VBMETA_PART			""
 #endif
 
+#if defined(CONFIG_CMD_AB_SELECT)
+#define COMMON_PARTS \
+	"name=boot_a,size=10M,uuid=${uuid_gpt_boot_a};" \
+	"name=boot_b,size=10M,uuid=${uuid_gpt_boot_b};" \
+	"name=system_a,size=1024M,uuid=${uuid_gpt_system_a};" \
+	"name=system_b,size=1024M,uuid=${uuid_gpt_system_b};"
+#else
+#define COMMON_PARTS \
+	"name=boot,size=10M,uuid=${uuid_gpt_boot};" \
+	"name=system,size=1024M,uuid=${uuid_gpt_system};"
+#endif
+
 #ifndef PARTS_DEFAULT
 /* Define the default GPT table for eMMC */
 #define PARTS_DEFAULT \
@@ -40,8 +52,7 @@ 
 	"name=efs,size=16M,uuid=${uuid_gpt_efs};" \
 	"name=crypto,size=16K,uuid=${uuid_gpt_crypto};" \
 	"name=recovery,size=40M,uuid=${uuid_gpt_recovery};" \
-	"name=boot,size=10M,uuid=${uuid_gpt_boot};" \
-	"name=system,size=768M,uuid=${uuid_gpt_system};" \
+	COMMON_PARTS \
 	"name=vendor,size=256M,uuid=${uuid_gpt_vendor};" \
 	"name=cache,size=256M,uuid=${uuid_gpt_cache};" \
 	"name=ipu1,size=1M,uuid=${uuid_gpt_ipu1};" \
@@ -63,6 +74,35 @@ 
 #define AVB_VERIFY_CMD ""
 #endif
 
+#define CONTROL_PARTITION "misc"
+
+#if defined(CONFIG_CMD_AB_SELECT)
+#define AB_SELECT \
+	"if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \
+	"then " \
+		"echo " CONTROL_PARTITION \
+			" partition number:${control_part_number};" \
+		"ab_select slot_name mmc ${mmcdev}:${control_part_number};" \
+	"else " \
+		"echo " CONTROL_PARTITION " partition not found;" \
+		"exit;" \
+	"fi;" \
+	"setenv slot_suffix _${slot_name};" \
+	"if part number mmc ${mmcdev} system${slot_suffix} " \
+	"system_part_number; then " \
+		"setenv bootargs_ab " \
+			"ro root=/dev/mmcblk${mmcdev}p${system_part_number} " \
+			"rootwait init=/init skip_initramfs " \
+			"androidboot.slot_suffix=${slot_suffix};" \
+		"echo A/B cmdline addition: ${bootargs_ab};" \
+		"setenv bootargs ${bootargs} ${bootargs_ab};" \
+	"else " \
+		"echo system${slot_suffix} partition not found;" \
+	"fi;"
+#else
+#define AB_SELECT ""
+#endif
+
 #define DEFAULT_COMMON_BOOT_TI_ARGS \
 	"console=" CONSOLEDEV ",115200n8\0" \
 	"fdtfile=undefined\0" \
@@ -91,10 +131,16 @@ 
 		"mmc dev $mmcdev; " \
 		"mmc rescan; " \
 		AVB_VERIFY_CHECK \
-		"part start mmc ${mmcdev} boot boot_start; " \
-		"part size mmc ${mmcdev} boot boot_size; " \
-		"mmc read ${loadaddr} ${boot_start} ${boot_size}; " \
-		"bootm ${loadaddr}#${fdtfile};\0 "
+		AB_SELECT \
+		"if part start mmc ${mmcdev} boot${slot_suffix} boot_start; " \
+		"then " \
+			"part size mmc ${mmcdev} boot${slot_suffix} " \
+				"boot_size; " \
+			"mmc read ${loadaddr} ${boot_start} ${boot_size}; " \
+			"bootm ${loadaddr}#${fdtfile}; " \
+		"else " \
+			"echo boot${slot_suffix} partition not found; " \
+		"fi;\0"
 
 #ifdef CONFIG_OMAP54XX