Browse Source

MA-9375 [Android IMX] uboot: enable BCB and bootctrl

* Add API to read\write MISC partition.
* get the boot mode from BCB command when boot up.
* get the boot up tactics from bootctrl.

Change-Id: Icbba6340e10983dddc1b04804ecc012a3a3c57d0
Signed-off-by: zhang sanshan <sanshan.zhang@nxp.com>
imx_v2017.03_4.9.11_1.0.0_ga
zhang sanshan 4 years ago
committed by Zhang Bo
parent
commit
81c9431f56
27 changed files with 1154 additions and 838 deletions
  1. +0
    -52
      arch/arm/cpu/armv7/mx6/soc.c
  2. +0
    -56
      arch/arm/cpu/armv7/mx7/soc.c
  3. +1
    -31
      arch/arm/cpu/armv7/mx7ulp/soc.c
  4. +1
    -1
      board/freescale/common/Makefile
  5. +3
    -21
      board/freescale/common/recovery_keypad.c
  6. +13
    -0
      board/freescale/common/recovery_keypad.h
  7. +3
    -90
      board/freescale/mx6qsabreauto/mx6qsabreauto.c
  8. +2
    -87
      board/freescale/mx6sabresd/mx6sabresd.c
  9. +4
    -72
      board/freescale/mx6slevk/mx6slevk.c
  10. +4
    -78
      board/freescale/mx6sxsabreauto/mx6sxsabreauto.c
  11. +3
    -70
      board/freescale/mx6sxsabresd/mx6sxsabresd.c
  12. +4
    -79
      board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c
  13. +2
    -57
      board/freescale/mx7dsabresd/mx7dsabresd.c
  14. +4
    -4
      board/freescale/mx7ulp_evk/mx7ulp_evk.c
  15. +2
    -2
      cmd/read.c
  16. +1
    -1
      common/board_r.c
  17. +11
    -0
      common/image-android.c
  18. +2
    -0
      drivers/usb/gadget/Makefile
  19. +170
    -0
      drivers/usb/gadget/bcb.c
  20. +58
    -0
      drivers/usb/gadget/bcb.h
  21. +405
    -0
      drivers/usb/gadget/bootctrl.c
  22. +37
    -0
      drivers/usb/gadget/bootctrl.h
  23. +120
    -0
      drivers/usb/gadget/command.c
  24. +261
    -124
      drivers/usb/gadget/f_fastboot.c
  25. +4
    -0
      include/common.h
  26. +38
    -10
      include/fsl_fastboot.h
  27. +1
    -3
      include/recovery.h

+ 0
- 52
arch/arm/cpu/armv7/mx6/soc.c View File

@ -1055,55 +1055,3 @@ void finish_anatop_bypass(void)
}
#endif
#ifdef CONFIG_FSL_FASTBOOT
#ifdef CONFIG_ANDROID_RECOVERY
#define ANDROID_RECOVERY_BOOT (1 << 7)
/* check if the recovery bit is set by kernel, it can be set by kernel
* issue a command '# reboot recovery' */
int recovery_check_and_clean_flag(void)
{
int flag_set = 0;
u32 reg;
reg = readl(SNVS_BASE_ADDR + SNVS_LPGPR);
flag_set = !!(reg & ANDROID_RECOVERY_BOOT);
printf("check_and_clean: reg %x, flag_set %d\n", reg, flag_set);
/* clean it in case looping infinite here.... */
if (flag_set) {
reg &= ~ANDROID_RECOVERY_BOOT;
writel(reg, SNVS_BASE_ADDR + SNVS_LPGPR);
}
return flag_set;
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#define ANDROID_FASTBOOT_BOOT (1 << 8)
/* check if the recovery bit is set by kernel, it can be set by kernel
* issue a command '# reboot fastboot' */
int fastboot_check_and_clean_flag(void)
{
int flag_set = 0;
u32 reg;
reg = readl(SNVS_BASE_ADDR + SNVS_LPGPR);
flag_set = !!(reg & ANDROID_FASTBOOT_BOOT);
/* clean it in case looping infinite here.... */
if (flag_set) {
reg &= ~ANDROID_FASTBOOT_BOOT;
writel(reg, SNVS_BASE_ADDR + SNVS_LPGPR);
}
return flag_set;
}
void fastboot_enable_flag(void)
{
setbits_le32(SNVS_BASE_ADDR + SNVS_LPGPR,
ANDROID_FASTBOOT_BOOT);
}
#endif /*CONFIG_FSL_FASTBOOT*/

+ 0
- 56
arch/arm/cpu/armv7/mx7/soc.c View File

@ -507,59 +507,3 @@ void reset_cpu(ulong addr)
}
}
#ifdef CONFIG_FSL_FASTBOOT
#ifdef CONFIG_ANDROID_RECOVERY
#define ANDROID_RECOVERY_BOOT (1 << 7)
/*
* check if the recovery bit is set by kernel, it can be set by kernel
* issue a command '# reboot recovery'
*/
int recovery_check_and_clean_flag(void)
{
int flag_set = 0;
u32 reg;
reg = readl(SNVS_BASE_ADDR + SNVS_LPGPR);
flag_set = !!(reg & ANDROID_RECOVERY_BOOT);
printf("check_and_clean: reg %x, flag_set %d\n", reg, flag_set);
/* clean it in case looping infinite here.... */
if (flag_set) {
reg &= ~ANDROID_RECOVERY_BOOT;
writel(reg, SNVS_BASE_ADDR + SNVS_LPGPR);
}
return flag_set;
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#define ANDROID_FASTBOOT_BOOT (1 << 8)
/*
* check if the recovery bit is set by kernel, it can be set by kernel
* issue a command '# reboot fastboot'
*/
int fastboot_check_and_clean_flag(void)
{
int flag_set = 0;
u32 reg;
reg = readl(SNVS_BASE_ADDR + SNVS_LPGPR);
flag_set = !!(reg & ANDROID_FASTBOOT_BOOT);
/* clean it in case looping infinite here.... */
if (flag_set) {
reg &= ~ANDROID_FASTBOOT_BOOT;
writel(reg, SNVS_BASE_ADDR + SNVS_LPGPR);
}
return flag_set;
}
void fastboot_enable_flag(void)
{
setbits_le32(SNVS_BASE_ADDR + SNVS_LPGPR,
ANDROID_FASTBOOT_BOOT);
}
#endif /*CONFIG_FSL_FASTBOOT*/

+ 1
- 31
arch/arm/cpu/armv7/mx7ulp/soc.c View File

@ -375,35 +375,5 @@ void get_board_serial(struct tag_serialnr *serialnr)
serialnr->low = (fuse->cfg0 & 0xFFFF) + ((fuse->cfg1 & 0xFFFF) << 16);
serialnr->high = (fuse->cfg2 & 0xFFFF) + ((fuse->cfg3 & 0xFFFF) << 16);
}
#endif
#ifdef CONFIG_ANDROID_RECOVERY
/*
* check if the recovery filed is set by kernel, it can be set by kernel
* issue a command '# reboot recovery'
*/
int recovery_check_and_clean_flag(void)
{
/*
* TODO: will implement this part after porting BCB
*/
return 0;
}
#endif /*CONFIG_ANDROID_RECOVERY*/
/*
* check if the recovery field is set by kernel, it can be set by kernel
* issue a command '# reboot fastboot'
*/
int fastboot_check_and_clean_flag(void)
{
/*
* TODO: will implement this part after porting BCB
*/
return 0;
}
void fastboot_enable_flag(void)
{
/*
* TODO: will implement this part after porting BCB
*/
}
#endif /*CONFIG_SERIAL_TAG*/
#endif /*CONFIG_FSL_FASTBOOT*/

+ 1
- 1
board/freescale/common/Makefile View File

@ -66,7 +66,7 @@ obj-$(CONFIG_DM_PMIC_PFUZE100) += pfuze_dm.o
obj-$(CONFIG_MXC_EPDC) += epdc_setup.o
obj-y += mmc.o
ifdef CONFIG_FSL_FASTBOOT
obj-${CONFIG_ANDROID_RECOVERY} += recovery.o
obj-${CONFIG_ANDROID_RECOVERY} += recovery_keypad.o
endif
obj-$(CONFIG_LS102XA_STREAM_ID) += ls102xa_stream_id.o


board/freescale/common/recovery.c → board/freescale/common/recovery_keypad.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2010-2016 Freescale Semiconductor, Inc. All Rights Reserved.
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
@ -21,7 +22,7 @@ inline int test_key(int value, struct kpp_key_info *ki)
return (ki->val == value) && (ki->evt == KDepress);
}
int check_key_pressing(void)
int is_recovery_keypad_pressing(void)
{
struct kpp_key_info *key_info = NULL;
int state = 0, keys, i;
@ -52,27 +53,8 @@ int check_key_pressing(void)
}
#else
/* If not using mxc keypad, currently we will detect power key on board */
int check_key_pressing(void)
int is_recovery_keypad_pressing(void)
{
return 0;
}
#endif
void setup_recovery_env(void)
{
board_recovery_setup();
}
/* export to lib_arm/board.c */
void check_recovery_mode(void)
{
if (check_key_pressing()) {
puts("Fastboot: Recovery key pressing got!\n");
setup_recovery_env();
} else if (check_recovery_cmd_file()) {
puts("Fastboot: Recovery command file found!\n");
setup_recovery_env();
} else {
puts("Fastboot: Normal\n");
}
}

+ 13
- 0
board/freescale/common/recovery_keypad.h View File

@ -0,0 +1,13 @@
/*
* Copyright (C) 2016 Freescale Semiconductor, Inc. All Rights Reserved.
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __RECOVERY_KEYPAD_H_
#define __RECOVERY_KEYPAD_H_
int is_recovery_keypad_pressing(void);
#endif

+ 3
- 90
board/freescale/mx6qsabreauto/mx6qsabreauto.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2012-2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
*
* Author: Fabio Estevam <fabio.estevam@freescale.com>
*
@ -1136,51 +1137,6 @@ int checkboard(void)
}
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_SATA)
case SATA_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "sata");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota sata");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_SATA*/
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
case NAND_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "nand");
if (!getenv("fbparts"))
setenv("fbparts", ANDROID_FASTBOOT_NAND_PARTS);
if (!getenv("bootcmd"))
setenv("bootcmd",
"nand read ${loadaddr} ${boot_nand_offset} "
"${boot_nand_size};boota ${loadaddr}");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
#define GPIO_VOL_DN_KEY IMX_GPIO_NR(5, 14)
@ -1188,12 +1144,9 @@ iomux_v3_cfg_t const recovery_key_pads[] = {
(MX6_PAD_DISP0_DAT20__GPIO5_IO14 | MUX_PAD_CTRL(NO_PAD_CTRL)),
};
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int button_pressed = 0;
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
/* Check Recovery Combo Button press or not. */
imx_iomux_v3_setup_multiple_pads(recovery_key_pads,
@ -1207,49 +1160,9 @@ int check_recovery_cmd_file(void)
printf("Recovery key pressed\n");
}
return recovery_mode || button_pressed;
return button_pressed;
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_SATA)
case SATA_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota sata recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_SATA*/
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc0 recovery");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc1 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
case NAND_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"nand read ${loadaddr} ${recovery_nand_offset} "
"${recovery_nand_size};boota ${loadaddr}");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#endif /*CONFIG_FSL_FASTBOOT*/

+ 2
- 87
board/freescale/mx6sabresd/mx6sabresd.c View File

@ -1353,47 +1353,6 @@ int checkboard(void)
}
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_SATA)
case SATA_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "sata");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota sata");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_SATA*/
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
case MMC4_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc2");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc2");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
#define GPIO_VOL_DN_KEY IMX_GPIO_NR(1, 5)
@ -1401,12 +1360,9 @@ iomux_v3_cfg_t const recovery_key_pads[] = {
(MX6_PAD_GPIO_5__GPIO1_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
};
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int button_pressed = 0;
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
/* Check Recovery Combo Button press or not. */
imx_iomux_v3_setup_multiple_pads(recovery_key_pads,
@ -1420,48 +1376,7 @@ int check_recovery_cmd_file(void)
printf("Recovery key pressed\n");
}
return recovery_mode || button_pressed;
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_SATA)
case SATA_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota sata recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_SATA*/
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota mmc0 recovery");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota mmc1 recovery");
break;
case MMC4_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota mmc2 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
return button_pressed;
}
#endif /*CONFIG_ANDROID_RECOVERY*/


+ 4
- 72
board/freescale/mx6slevk/mx6slevk.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 - 2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
*
* Author: Fabio Estevam <fabio.estevam@freescale.com>
*
@ -37,6 +38,7 @@
#ifdef CONFIG_FSL_FASTBOOT
#include <fsl_fastboot.h>
#ifdef CONFIG_ANDROID_RECOVERY
#include "../common/recovery_keypad.h"
#include <recovery.h>
#endif
#endif /*CONFIG_FSL_FASTBOOT*/
@ -915,83 +917,13 @@ int setup_mxc_kpd(void)
#endif /*CONFIG_MXC_KPD*/
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc2");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc2");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
return recovery_check_and_clean_flag();
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
/*current uboot BSP only supports USDHC2*/
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota mmc0 recovery");
break;
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota mmc1 recovery");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"boota mmc2 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
return is_recovery_keypad_pressing();
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#endif /*CONFIG_FSL_FASTBOOT*/


+ 4
- 78
board/freescale/mx6sxsabreauto/mx6sxsabreauto.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
* Copyright 2017 nxp
*
* Author: Ye Li <ye.li@nxp.com>
*
@ -32,6 +33,7 @@
#include <fsl_fastboot.h>
#ifdef CONFIG_ANDROID_RECOVERY
#include <recovery.h>
#include "../common/recovery_keypad.h"
#endif
#endif /*CONFIG_FSL_FASTBOOT*/
@ -557,88 +559,12 @@ int checkboard(void)
}
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD4_BOOT:
case MMC4_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
case NAND_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "nand");
if (!getenv("fbparts"))
setenv("fbparts", ANDROID_FASTBOOT_NAND_PARTS);
if (!getenv("bootcmd"))
setenv("bootcmd",
"nand read ${loadaddr} ${boot_nand_offset} "
"${boot_nand_size};boota ${loadaddr}");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
return recovery_mode;
return is_recovery_keypad_pressing();
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc0 recovery");
break;
case SD4_BOOT:
case MMC4_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc1 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
case NAND_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"nand read ${loadaddr} ${recovery_nand_offset} "
"${recovery_nand_size};boota ${loadaddr}");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#endif /*CONFIG_FSL_FASTBOOT*/


+ 3
- 70
board/freescale/mx6sxsabresd/mx6sxsabresd.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
*
* Author: Fabio Estevam <fabio.estevam@freescale.com>
*
@ -977,38 +978,6 @@ int checkboard(void)
}
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
case SD4_BOOT:
case MMC4_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc2");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc2");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
#define GPIO_VOL_DN_KEY IMX_GPIO_NR(1, 19)
@ -1016,12 +985,9 @@ iomux_v3_cfg_t const recovery_key_pads[] = {
(MX6_PAD_CSI_DATA05__GPIO1_IO_19 | MUX_PAD_CTRL(BUTTON_PAD_CTRL)),
};
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int button_pressed = 0;
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
/* Check Recovery Combo Button press or not. */
imx_iomux_v3_setup_multiple_pads(recovery_key_pads,
@ -1035,42 +1001,9 @@ int check_recovery_cmd_file(void)
printf("Recovery key pressed\n");
}
return recovery_mode || button_pressed;
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc0 recovery");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc1 recovery");
break;
case SD4_BOOT:
case MMC4_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc2 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
return button_pressed;
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#endif /*CONFIG_FSL_FASTBOOT*/
#ifdef CONFIG_SPL_BUILD


+ 4
- 79
board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
@ -928,89 +929,13 @@ int checkboard(void)
}
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
case NAND_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "nand");
if (!getenv("fbparts"))
setenv("fbparts", ANDROID_FASTBOOT_NAND_PARTS);
if (!getenv("bootcmd"))
setenv("bootcmd",
"nand read ${loadaddr} ${boot_nand_offset} "
"${boot_nand_size};boota ${loadaddr}");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
return recovery_mode;
/* No key defined for this board */
return 0;
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc0 recovery");
break;
case SD2_BOOT:
case MMC2_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc1 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
case NAND_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery",
"nand read ${loadaddr} ${recovery_nand_offset} "
"${recovery_nand_size};boota ${loadaddr}");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#endif /*CONFIG_FSL_FASTBOOT*/


+ 2
- 57
board/freescale/mx7dsabresd/mx7dsabresd.c View File

@ -689,31 +689,6 @@ int checkboard(void)
}
#ifdef CONFIG_FSL_FASTBOOT
void board_fastboot_setup(void)
{
switch (get_boot_device()) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc0");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc0");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("fastboot_dev"))
setenv("fastboot_dev", "mmc1");
if (!getenv("bootcmd"))
setenv("bootcmd", "boota mmc1");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("unsupported boot devices\n");
break;
}
}
#ifdef CONFIG_ANDROID_RECOVERY
/* Use S3 button for recovery key */
@ -722,12 +697,9 @@ iomux_v3_cfg_t const recovery_key_pads[] = {
(MX7D_PAD_SD2_WP__GPIO5_IO10 | MUX_PAD_CTRL(BUTTON_PAD_CTRL)),
};
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int button_pressed = 0;
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
/* Check Recovery Combo Button press or not. */
imx_iomux_v3_setup_multiple_pads(recovery_key_pads,
@ -741,35 +713,8 @@ int check_recovery_cmd_file(void)
printf("Recovery key pressed\n");
}
return recovery_mode || button_pressed;
return button_pressed;
}
void board_recovery_setup(void)
{
int bootdev = get_boot_device();
switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
case SD1_BOOT:
case MMC1_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc0 recovery");
break;
case SD3_BOOT:
case MMC3_BOOT:
if (!getenv("bootcmd_android_recovery"))
setenv("bootcmd_android_recovery", "boota mmc1 recovery");
break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
default:
printf("Unsupported bootup device for recovery: dev: %d\n",
bootdev);
return;
}
printf("setup env for recovery..\n");
setenv("bootcmd", "run bootcmd_android_recovery");
}
#endif /*CONFIG_ANDROID_RECOVERY*/
#endif /*CONFIG_FSL_FASTBOOT*/

+ 4
- 4
board/freescale/mx7ulp_evk/mx7ulp_evk.c View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
@ -233,11 +234,10 @@ void board_fastboot_setup(void)
}
#ifdef CONFIG_ANDROID_RECOVERY
int check_recovery_cmd_file(void)
int is_recovery_key_pressing(void)
{
int recovery_mode = 0;
recovery_mode = recovery_check_and_clean_flag();
return recovery_mode;
/* TODO: uboot can get the key event from M4 core*/
return 0;
}
void board_recovery_setup(void)


+ 2
- 2
cmd/read.c View File

@ -12,7 +12,7 @@
#include <command.h>
#include <part.h>
int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int do_raw_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *ep;
struct blk_desc *dev_desc = NULL;
@ -75,7 +75,7 @@ int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
U_BOOT_CMD(
read, 6, 0, do_read,
read, 6, 0, do_raw_read,
"Load binary data from a partition",
"<interface> <dev[:part]> addr blk# cnt"
);

+ 1
- 1
common/board_r.c View File

@ -731,7 +731,7 @@ static int initr_fastboot_setup(void)
static int initr_check_fastboot(void)
{
check_fastboot();
fastboot_run_bootmode();
return 0;
}
#endif


+ 11
- 0
common/image-android.c View File

@ -19,6 +19,12 @@
static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
#ifdef CONFIG_FSL_BOOTCTL
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include "../drivers/usb/gadget/bootctrl.h"
#endif
static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
{
/*
@ -125,6 +131,11 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
} else
printf("boot device type is incorrect.\n");
#ifdef CONFIG_FSL_BOOTCTL
char suffixStr[64];
sprintf(suffixStr, " androidboot.slot_suffix=%s", get_slot_suffix());
strcat(commandline, suffixStr);
#endif
setenv("bootargs", commandline);
if (os_data) {


+ 2
- 0
drivers/usb/gadget/Makefile View File

@ -28,6 +28,8 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o
obj-$(CONFIG_USB_FUNCTION_DFU) += f_dfu.o
obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o
obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o
obj-$(CONFIG_FSL_BOOTCTL) += bootctrl.o
obj-$(CONFIG_BCB_SUPPORT) += command.o bcb.o
endif
endif
ifdef CONFIG_USB_ETHER


+ 170
- 0
drivers/usb/gadget/bcb.c View File

@ -0,0 +1,170 @@
/*
* Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <fsl_fastboot.h>
#include <linux/stat.h>
#include <linux/types.h>
#include <common.h>
#include <g_dnl.h>
#include <mmc.h>
#include "bcb.h"
#include "bootctrl.h"
#define ALIGN_BYTES 64 /*armv7 cache line need 64 bytes aligned */
static ulong get_block_size(char *ifname, int dev)
{
struct blk_desc *dev_desc = NULL;
dev_desc = blk_get_dev(ifname, dev);
if (dev_desc == NULL) {
printf("Block device %s %d not supported\n", ifname, dev);
return 0;
}
return dev_desc->blksz;
}
static int do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *ep;
struct blk_desc *dev_desc = NULL;
int dev;
int part = 0;
disk_partition_t part_info;
ulong offset = 0u;
ulong limit = 0u;
void *addr;
uint blk;
uint cnt;
if (argc != 6) {
cmd_usage(cmdtp);
return 1;
}
dev = (int)simple_strtoul(argv[2], &ep, 16);
if (*ep) {
if (*ep != ':') {
printf("Invalid block device %s\n", argv[2]);
return 1;
}
part = (int)simple_strtoul(++ep, NULL, 16);
}
dev_desc = blk_get_dev(argv[1], dev);
if (dev_desc == NULL) {
printf("Block device %s %d not supported\n", argv[1], dev);
return 1;
}
addr = (void *)simple_strtoul(argv[3], NULL, 16);
blk = simple_strtoul(argv[4], NULL, 16);
cnt = simple_strtoul(argv[5], NULL, 16);
if (part != 0) {
if (part_get_info(dev_desc, part, &part_info)) {
printf("Cannot find partition %d\n", part);
return 1;
}
offset = part_info.start;
limit = part_info.size;
} else {
/* Largest address not available in block_dev_desc_t. */
limit = ~0;
}
if (cnt + blk > limit) {
printf("Write out of range\n");
return 1;
}
if (dev_desc->block_write(dev_desc, offset + blk, cnt, addr) != cnt) {
printf("Error writing blocks\n");
return 1;
}
return 0;
}
U_BOOT_CMD(
write, 6, 0, do_write,
"write binary data to a partition",
"<interface> <dev[:part]> addr blk# cnt"
);
int bcb_rw_block(bool bread, char **ppblock,
uint *pblksize, char *pblock_write, uint offset, uint size)
{
int ret;
char *argv[6];
char addr_str[20];
char cnt_str[8];
char devpart_str[8];
char block_begin_str[8];
ulong blk_size = 0;
uint blk_begin = 0;
uint blk_end = 0;
uint block_cnt = 0;
char *p_block = NULL;
unsigned int mmc_id;
if (bread && ((ppblock == NULL) || (pblksize == NULL)))
return -1;
if (!bread && (pblock_write == NULL))
return -1;
mmc_id = mmc_get_env_dev();
blk_size = get_block_size("mmc", mmc_id);
if (blk_size == 0) {
printf("bcb_rw_block, get_block_size return 0\n");
return -1;
}
blk_begin = offset/blk_size;
blk_end = (offset + size)/blk_size;
block_cnt = 1 + (blk_end - blk_begin);
sprintf(devpart_str, "0x%x:0x%x", mmc_id,
fastboot_flash_find_index(FASTBOOT_PARTITION_MISC));
sprintf(block_begin_str, "0x%x", blk_begin);
sprintf(cnt_str, "0x%x", block_cnt);
argv[0] = "rw"; /* not care */
argv[1] = "mmc";
argv[2] = devpart_str;
argv[3] = addr_str;
argv[4] = block_begin_str;
argv[5] = cnt_str;
if (bread) {
p_block = (char *)memalign(ALIGN_BYTES, blk_size * block_cnt);
if (NULL == p_block) {
printf("bcb_rw_block, memalign %d bytes failed\n",
(int)(blk_size * block_cnt));
return -1;
}
sprintf(addr_str, "0x%x", (unsigned int)p_block);
ret = do_raw_read(NULL, 0, 6, argv);
if (ret) {
free(p_block);
printf("do_raw_read failed, ret %d\n", ret);
return -1;
}
*ppblock = p_block;
*pblksize = (uint)blk_size;
} else {
sprintf(addr_str, "0x%x", (unsigned int)pblock_write);
ret = do_write(NULL, 0, 6, argv);
if (ret) {
printf("do_write failed, ret %d\n", ret);
return -1;
}
}
return 0;
}

+ 58
- 0
drivers/usb/gadget/bcb.h View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef BCB_H
#define BCB_H
#include <linux/types.h>
#include <linux/stat.h>
#define FASTBOOT_BCB_CMD "bootonce-bootloader"
#ifdef CONFIG_ANDROID_RECOVERY
#define RECOVERY_BCB_CMD "boot-recovery"
#endif
/* keep same as bootable/recovery/bootloader.h */
struct bootloader_message {
char command[32];
char status[32];
char recovery[768];
/* The 'recovery' field used to be 1024 bytes. It has only ever
been used to store the recovery command line, so 768 bytes
should be plenty. We carve off the last 256 bytes to store the
stage string (for multistage packages) and possible future
expansion. */
char stage[32];
/* The 'reserved' field used to be 224 bytes when it was initially
carved off from the 1024-byte recovery field. Bump it up to
1184-byte so that the entire bootloader_message struct rounds up
to 2048-byte.
*/
char reserved[1184];
};
struct bootloader_message_ab {
struct bootloader_message message;
char slot_suffix[32];
/* Round up the entire struct to 4096-byte. */
char reserved[2016];
};
/* start from bootloader_message_ab.slot_suffix[BOOTCTRL_IDX] */
#define BOOTCTRL_IDX 0
#define MISC_COMMAND_IDX 0
#define BOOTCTRL_OFFSET \
(u32)(&(((struct bootloader_message_ab *)0)->slot_suffix[BOOTCTRL_IDX]))
#define MISC_COMMAND \
(u32)(&(((struct bootloader_message *)0)->command[MISC_COMMAND_IDX]))
int bcb_rw_block(bool bread, char **ppblock,
uint *pblksize, char *pblock_write, uint offset, uint size);
int bcb_write_command(char *bcb_command);
int bcb_read_command(char *command);
#endif

+ 405
- 0
drivers/usb/gadget/bootctrl.c View File

@ -0,0 +1,405 @@
/*
* Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <g_dnl.h>
#include <fsl_fastboot.h>
#include "bootctrl.h"
#include <linux/types.h>
#include <linux/stat.h>
static unsigned int g_slot_selected;
static const char *g_slot_suffix[SLOT_NUM] = {"_a", "_b"};
static int init_slotmeta(struct boot_ctl *ptbootctl);
static int strcmp_l1(const char *s1, const char *s2)
{
if (!s1 || !s2)
return -1;
return strncmp(s1, s2, strlen(s1));
}
static void dump_slotmeta(struct boot_ctl *ptbootctl)
{
int i;
if (ptbootctl == NULL)
return;
printf("RecoveryTryRemain %d, crc %u\n",
ptbootctl->recovery_tryremain, ptbootctl->crc);
for (i = 0; i < SLOT_NUM; i++) {
printf("slot %d: pri %d, try %d, suc %d\n", i,
ptbootctl->a_slot_meta[i].priority,
ptbootctl->a_slot_meta[i].tryremain,
ptbootctl->a_slot_meta[i].bootsuc);
}
return;
}
const char *get_slot_suffix(void)
{
return g_slot_suffix[g_slot_selected];
}
static unsigned int slot_find(struct boot_ctl *ptbootctl)
{
unsigned int max_pri = 0;
unsigned int slot = -1;
int i;
for (i = 0; i < SLOT_NUM; i++) {
struct slot_meta *pslot_meta = &(ptbootctl->a_slot_meta[i]);
if ((pslot_meta->priority > max_pri) &&
((pslot_meta->bootsuc > 0) ||
(pslot_meta->tryremain > 0))) {
max_pri = pslot_meta->priority;
slot = i;
printf("select_slot slot %d\n", slot);
}
}
return slot;
}
static int read_bootctl(struct boot_ctl *ptbootctl)
{
int ret = 0;
unsigned int crc = 0;
char *p_block = NULL;
uint offset_in_block = 0;
uint blk_size = 0;
char *pmagic = NULL;
if (ptbootctl == NULL)
return -1;
ret = bcb_rw_block(true, &p_block, &blk_size, NULL,
BOOTCTRL_OFFSET, sizeof(struct boot_ctl));
if (ret) {
printf("read_bootctl, bcb_rw_block read failed\n");
return -1;
}
offset_in_block = BOOTCTRL_OFFSET%blk_size;
memcpy(ptbootctl, p_block + offset_in_block, sizeof(struct boot_ctl));
pmagic = ptbootctl->magic;
if (!((pmagic[0] == '\0') && (pmagic[1] == 'F') &&
(pmagic[2] == 'S') && (pmagic[3] == 'L'))) {
printf("magic error, 0x%x 0x%x 0x%x 0x%x\n",
pmagic[0], pmagic[1], pmagic[2], pmagic[3]);
ret = init_slotmeta(ptbootctl);
if (ret) {
printf("init_slotmeta failed, ret %d\n", ret);
free(p_block);
return -1;
}
}
/* check crc */
crc = crc32(0, (unsigned char *)ptbootctl + CRC_DATA_OFFSET,
sizeof(struct boot_ctl) - CRC_DATA_OFFSET);
if (crc != ptbootctl->crc) {
printf("crc check failed, caculated %d, read %d\n",
crc, ptbootctl->crc);
free(p_block);
return -1;
}
free(p_block);
return 0;
}
static int write_bootctl(struct boot_ctl *ptbootctl)
{
int ret = 0;
char *p_block = NULL;
uint offset_in_block = 0;
uint blk_size = 0;
if (ptbootctl == NULL)
return -1;
ptbootctl->crc = crc32(0, (unsigned char *)ptbootctl + CRC_DATA_OFFSET,
sizeof(struct boot_ctl) - CRC_DATA_OFFSET);
ret = bcb_rw_block(true, &p_block, &blk_size, NULL,
BOOTCTRL_OFFSET, sizeof(struct boot_ctl));
if (ret) {
printf("write_bootctl, bcb_rw_block read failed\n");
return -1;
}
offset_in_block = BOOTCTRL_OFFSET%blk_size;
memcpy(p_block + offset_in_block, ptbootctl, sizeof(struct boot_ctl));
ret = bcb_rw_block(false, NULL, NULL, p_block,
BOOTCTRL_OFFSET, sizeof(struct boot_ctl));
if (ret) {
free(p_block);
printf("write_bootctl, bcb_rw_block write failed\n");
return -1;
}
free(p_block);
return 0;
}
static int init_slotmeta(struct boot_ctl *ptbootctl)
{
int ret = 0;
if (ptbootctl == NULL)
return -1;
memset(ptbootctl, 0, sizeof(struct boot_ctl));
ptbootctl->recovery_tryremain = 7;
ptbootctl->a_slot_meta[0].priority = 8;
ptbootctl->a_slot_meta[0].tryremain = 7;
ptbootctl->a_slot_meta[0].bootsuc = 0;
ptbootctl->a_slot_meta[1].priority = 6;
ptbootctl->a_slot_meta[1].tryremain = 7;
ptbootctl->a_slot_meta[1].bootsuc = 0;
ptbootctl->magic[0] = '\0';
ptbootctl->magic[1] = 'F';
ptbootctl->magic[2] = 'S';
ptbootctl->magic[3] = 'L';
ptbootctl->crc = crc32(0, (uint8_t *)ptbootctl + CRC_DATA_OFFSET,
sizeof(struct boot_ctl) - CRC_DATA_OFFSET);
ret = write_bootctl(ptbootctl);
return ret;
}
char *select_slot(void)
{
int i = 0;
int ret = 0;
unsigned int slot;
struct boot_ctl t_bootctl;
bool b_need_write = false;
ret = read_bootctl(&t_bootctl);
if (ret) {
printf("read_bootctl failed, ret %d\n", ret);
return NULL;
}
dump_slotmeta(&t_bootctl);
slot = slot_find(&t_bootctl);
if (slot >= SLOT_NUM) {
printf("!!! select_slot, no valid slot\n");
return NULL;
}
/* invalid slot, set priority to 0 */
for (i = 0; i < SLOT_NUM; i++) {
struct slot_meta *pslot_meta = &(t_bootctl.a_slot_meta[i]);
if ((pslot_meta->bootsuc == 0) &&
(pslot_meta->tryremain == 0) &&
(pslot_meta->priority > 0)) {
pslot_meta->priority = 0;
b_need_write = true;
}
}
if (t_bootctl.recovery_tryremain != 7) {
b_need_write = true;
t_bootctl.recovery_tryremain = 7;
}
if ((t_bootctl.a_slot_meta[slot].bootsuc == 0) &&
(t_bootctl.a_slot_meta[slot].tryremain > 0)) {
b_need_write = true;
t_bootctl.a_slot_meta[slot].tryremain--;
}
if (b_need_write) {
ret = write_bootctl(&t_bootctl);
if (ret)
printf("!!! write_bootctl failed, ret %d\n", ret);
}
g_slot_selected = slot;
if (slot == 0)
return FASTBOOT_PARTITION_BOOT_A;
else
return FASTBOOT_PARTITION_BOOT_B;
}
int invalid_curslot(void)
{
int ret = 0;
struct boot_ctl t_bootctl;
unsigned int slot = g_slot_selected;
printf("invalid_curslot %d\n", slot);
if (slot >= SLOT_NUM)
return -1;
ret = read_bootctl(&t_bootctl);
if (ret) {
printf("invalid_slot failed, ret %d\n", ret);
return -1;
}
t_bootctl.a_slot_meta[slot].priority = 0;
ret = write_bootctl(&t_bootctl);
if (ret) {
printf("!!! write_bootctl failed, ret %d\n", ret);
return -1;
}
return 0;
}
static unsigned int slotidx_from_suffix(char *suffix)
{
unsigned int slot = -1;
if (!strcmp(suffix, "_a") ||
!strcmp(suffix, "a"))
slot = 0;
else if (!strcmp(suffix, "_b") ||
!strcmp(suffix, "b"))
slot = 1;
return slot;
}
int