From 24722e68685f13323afd9f39f6d576015c9c5cd8 Mon Sep 17 00:00:00 2001 From: "ji.luo" Date: Wed, 18 Oct 2017 19:46:00 +0800 Subject: MA-10479 Remove CONFIG_FSL_BOOTCTL from u-boot This function is replaced by AVB, we don't need the CONFIG_FSL_BOOTCTL anymore. Change-Id: Ib418a4ec565e2a098f0a0ce574710317619bbebe Signed-off-by: ji.luo --- common/image-android.c | 10 - drivers/usb/gadget/Makefile | 2 - drivers/usb/gadget/bcb.c | 1 - drivers/usb/gadget/bootctrl.c | 406 ------------------------- drivers/usb/gadget/bootctrl.h | 37 --- drivers/usb/gadget/f_fastboot.c | 47 +-- include/configs/mx6ul_14x14_evkandroidthings.h | 1 - scripts/config_whitelist.txt | 1 - 8 files changed, 1 insertion(+), 504 deletions(-) delete mode 100644 drivers/usb/gadget/bootctrl.c delete mode 100644 drivers/usb/gadget/bootctrl.h diff --git a/common/image-android.c b/common/image-android.c index 1d09299cee..d8407d4ed5 100644 --- a/common/image-android.c +++ b/common/image-android.c @@ -20,12 +20,6 @@ static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; -#ifdef CONFIG_FSL_BOOTCTL -#include -#include -#include "../drivers/usb/gadget/bootctrl.h" -#endif - static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr) { /* @@ -128,10 +122,6 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, strcat(commandline, newbootargs); } -#ifdef CONFIG_FSL_BOOTCTL - sprintf(newbootargs, " androidboot.slot_suffix=%s", get_slot_suffix()); - strcat(commandline, newbootargs); -#endif #ifdef CONFIG_AVB_SUPPORT /* secondary cmdline added by avb */ char *bootargs_sec = getenv("bootargs_sec"); diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 2fb3580a71..c962140396 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -29,14 +29,12 @@ 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_FASTBOOT_LOCK) += fastboot_lock_unlock.o -obj-$(CONFIG_FSL_BOOTCTL) += bootctrl.o obj-$(CONFIG_BCB_SUPPORT) += command.o bcb.o endif else ifdef CONFIG_FSL_FASTBOOT obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o obj-$(CONFIG_FASTBOOT_LOCK) += fastboot_lock_unlock.o -obj-$(CONFIG_FSL_BOOTCTL) += bootctrl.o obj-$(CONFIG_BCB_SUPPORT) += command.o bcb.o endif endif diff --git a/drivers/usb/gadget/bcb.c b/drivers/usb/gadget/bcb.c index d5b434deca..4cc9e5d312 100644 --- a/drivers/usb/gadget/bcb.c +++ b/drivers/usb/gadget/bcb.c @@ -12,7 +12,6 @@ #include #include #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) diff --git a/drivers/usb/gadget/bootctrl.c b/drivers/usb/gadget/bootctrl.c deleted file mode 100644 index 2562e0b9a1..0000000000 --- a/drivers/usb/gadget/bootctrl.c +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright (C) 2015-2016 Freescale Semiconductor, Inc. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include "bootctrl.h" -#include -#include -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 get_slotvar(char *cmd, char *response, size_t chars_left) -{ - int ret; - struct boot_ctl t_bootctl; - memset(&t_bootctl, 0, sizeof(t_bootctl)); - - if (!strcmp_l1("has-slot:", cmd)) { - char *ptnname = NULL; - ptnname = strchr(cmd, ':') + 1; - if (!strcmp(ptnname, "system") || !strcmp(ptnname, "boot") - !strcmp(str, "oem") || !strcmp(str, "gapps") || - !strcmp(str, "vbmeta")) - strlcpy(response, "yes", chars_left); - else - strlcpy(response, "no", chars_left); - return 0; - } else if (!strcmp_l1("slot-suffixes", cmd)) { - strlcpy(response, "_a,_b", chars_left); - return 0; - } - - ret = read_bootctl(&t_bootctl); - if (ret) { - error("get_slotvar, read_bootctl failed\n"); - strcpy(response, "get_slotvar read_bootctl failed"); - return -1; - } - if (!strcmp_l1("current-slot", cmd)) { - unsigned int slot = slot_find(&t_bootctl); - if (slot < SLOT_NUM) - strlcpy(response, g_slot_suffix[slot], chars_left); - else { - strlcpy(response, "no valid slot", chars_left); - return -1; - } - } else if (!strcmp_l1("slot-successful:", cmd)) { - char *suffix = strchr(cmd, ':') + 1; - unsigned int slot = slotidx_from_suffix(suffix); - if (slot >= SLOT_NUM) { - strlcpy(response, "no such slot", chars_left); - return -1; - } else { - bool suc = t_bootctl.a_slot_meta[slot].bootsuc; - strlcpy(response, suc ? "yes" : "no", chars_left); - } - } else if (!strcmp_l1("slot-unbootable:", cmd)) { - char *suffix = strchr(cmd, ':') + 1; - unsigned int slot = slotidx_from_suffix(suffix); - if (slot >= SLOT_NUM) { - strlcpy(response, "no such slot", chars_left); - return -1; - } else { - unsigned int pri = t_bootctl.a_slot_meta[slot].priority; - strlcpy(response, pri ? "no" : "yes", chars_left); - } - } else if (!strcmp_l1("slot-retry-count:", cmd)) { - char *suffix = strchr(cmd, ':') + 1; - unsigned int slot = slotidx_from_suffix(suffix); - if (slot >= SLOT_NUM) { - strlcpy(response, "no such slot", chars_left); - return -1; - } else { - char str_num[7]; - sprintf(str_num, "%d", - t_bootctl.a_slot_meta[slot].tryremain); - strlcpy(response, str_num, chars_left); - } - } else { - strlcpy(response, "no such slot command", chars_left); - return -1; - } - - return 0; -} - - -void cb_set_active(struct usb_ep *ep, struct usb_request *req) -{ - int ret; - int i; - unsigned int slot = 0; - char *cmd = req->buf; - struct boot_ctl t_bootctl; - - memset(&t_bootctl, 0, sizeof(t_bootctl)); - - strsep(&cmd, ":"); - if (!cmd) { - error("missing slot suffix\n"); - fastboot_tx_write_str("FAILmissing slot suffix"); - return; - } - - slot = slotidx_from_suffix(cmd); - if (slot >= SLOT_NUM) { - fastboot_tx_write_str("FAILerr slot suffix"); - return; - } - - ret = read_bootctl(&t_bootctl); - if (ret) - fastboot_tx_write_str("FAILReadBootCtl failed"); - - t_bootctl.a_slot_meta[slot].bootsuc = 0; - t_bootctl.a_slot_meta[slot].priority = 15; - t_bootctl.a_slot_meta[slot].tryremain = 7; - - /* low other slot priority */ - for (i = 0; i < SLOT_NUM; i++) { - if (i == slot) - continue; - - if (t_bootctl.a_slot_meta[i].priority >= 15) - t_bootctl.a_slot_meta[i].priority = 14; - } - - ret = write_bootctl(&t_bootctl); - if (ret) - fastboot_tx_write_str("write_bootctl failed"); - else - fastboot_tx_write_str("OKAY"); - - return; -} - diff --git a/drivers/usb/gadget/bootctrl.h b/drivers/usb/gadget/bootctrl.h deleted file mode 100644 index a181cd73db..0000000000 --- a/drivers/usb/gadget/bootctrl.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2015-2016 Freescale Semiconductor, Inc. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#ifndef BOOTCTRL_H -#define BOOTCTRL_H - -#include -#include -#include -#include -#include "bcb.h" - -#define SLOT_NUM (unsigned int)2 -#define CRC_DATA_OFFSET \ - (uint32_t)(&(((struct boot_ctl *)0)->a_slot_meta[0])) - -struct slot_meta { - u8 bootsuc:1; - u8 tryremain:3; - u8 priority:4; -}; - -struct boot_ctl { - char magic[4]; /* "\0FSL" */ - u32 crc; - struct slot_meta a_slot_meta[SLOT_NUM]; - u8 recovery_tryremain; -}; -char *select_slot(void); -int invalid_curslot(void); -int get_slotvar(char *cmd, char *response, size_t chars_left); -void cb_set_active(struct usb_ep *ep, struct usb_request *req); -const char *get_slot_suffix(void); -#endif diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 39758945ad..c978132ba2 100755 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -46,9 +46,6 @@ #endif #endif -#ifdef CONFIG_FSL_BOOTCTL -#include "bootctrl.h" -#endif #ifdef CONFIG_BCB_SUPPORT #include "bcb.h" #endif @@ -1608,24 +1605,6 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc > 2) ptn = argv[2]; -#ifdef CONFIG_FSL_BOOTCTL - else { -slot_select: - ptn = select_slot(); - if (ptn == NULL) { - printf("no valid slot found, enter to recovery\n"); - ptn = "recovery"; - } -#ifdef CONFIG_SYSTEM_RAMDISK_SUPPORT - else { - fastboot_setup_system_boot_args(ptn); - } -#endif -use_given_ptn: - printf("use slot %s\n", ptn); - } -#endif - if (mmcc != -1) { #ifdef CONFIG_MMC struct fastboot_ptentry *pte; @@ -1781,23 +1760,7 @@ use_given_ptn: return 1; fail: -#if defined(CONFIG_FSL_BOOTCTL) - if (argc > 2) - return -1; - if (0 == strcmp(ptn, "recovery")) { - printf("boot recovery partition failed\n"); - return -1; - } - printf("invalid slot %s\n", ptn); - int ret = 0; - ret = invalid_curslot(); - if (ret == 0) { - goto slot_select; - } else { - ptn = "recovery"; - goto use_given_ptn; - } -#elif defined(CONFIG_FSL_FASTBOOT) +#if defined(CONFIG_FSL_FASTBOOT) return run_command("fastboot 0", 0); #else /*! CONFIG_FSL_FASTBOOT*/ return -1; @@ -2266,9 +2229,6 @@ static int get_single_var(char *cmd, char *response) if (get_slotvar_avb(&fsl_avb_ab_ops, cmd, response + strlen(response), chars_left + 1) < 0) return -1; -#elif defined(CONFIG_FSL_BOOTCTL) - if (get_slotvar(cmd, response + strlen(response), chars_left + 1) < 0) - return -1; #else strncat(response, FASTBOOT_VAR_NO, chars_left); #endif @@ -2845,11 +2805,6 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = { .cmd = "set_active", .cb = cb_set_active_avb, }, -#elif defined(CONFIG_FSL_BOOTCTL) - { - .cmd = "set_active", - .cb = cb_set_active, - }, #endif }; diff --git a/include/configs/mx6ul_14x14_evkandroidthings.h b/include/configs/mx6ul_14x14_evkandroidthings.h index e4cd20e98b..1aba102a8d 100644 --- a/include/configs/mx6ul_14x14_evkandroidthings.h +++ b/include/configs/mx6ul_14x14_evkandroidthings.h @@ -20,7 +20,6 @@ #define CONFIG_SHA256 #define FASTBOOT_ENCRYPT_LOCK -#define CONFIG_FSL_BOOTCTL #ifdef CONFIG_AVB_SUPPORT #ifdef CONFIG_SYS_MALLOC_LEN diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index ead41fa251..ab1df16a9d 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -1148,7 +1148,6 @@ CONFIG_FPGA_SPARTAN3 CONFIG_FPGA_STRATIX_V CONFIG_FPGA_ZYNQPL CONFIG_FSLDMAFEC -CONFIG_FSL_BOOTCTL CONFIG_FSL_CAAM_KB CONFIG_FSL_CADMUS CONFIG_FSL_CORENET -- cgit v1.2.3