--- /dev/null
+/*
+ * Copyright (c) 2016, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FASTBOOT_LOCK_UNLOCK_H
+#define FASTBOOT_LOCK_UNLOCK_H
+
+#define ALIGN_BYTES 64 /*armv7 cache line need 64 bytes aligned */
+
+//#define FASTBOOT_LOCK_DEBUG
+#ifdef CONFIG_FSL_CAAM_KB
+#define FASTBOOT_ENCRYPT_LOCK
+#endif
+
+#ifdef FASTBOOT_LOCK_DEBUG
+#define FB_DEBUG(format, ...) printf(format, ##__VA_ARGS__)
+#else
+#define FB_DEBUG(format, ...)
+#endif
+
+typedef enum {
+ FASTBOOT_UNLOCK,
+ FASTBOOT_LOCK,
+ FASTBOOT_LOCK_ERROR,
+ FASTBOOT_LOCK_NUM
+}FbLockState;
+
+typedef enum {
+ FASTBOOT_UL_DISABLE,
+ FASTBOOT_UL_ENABLE,
+ FASTBOOT_UL_ERROR,
+ FASTBOOT_UL_NUM
+}FbLockEnableResult;
+
+FbLockState fastboot_get_lock_stat(void);
+
+int fastboot_set_lock_stat(FbLockState lock);
+
+int fastboot_wipe_data_partition(void);
+void fastboot_wipe_all(void);
+
+FbLockEnableResult fastboot_lock_enable(void);
+void set_fastboot_lock_disable(void);
+
+int display_lock(FbLockState lock, int verify);
+
+bool valid_tos(void);
+#endif
#include <trusty/libtipc.h>
#endif
+#include "fb_fsl_common.h"
+
#if defined (CONFIG_ARCH_IMX8) || defined (CONFIG_ARCH_IMX8M)
#define DST_DECOMPRESS_LEN 1024*1024*32
#endif
lock_status, 2, 1, do_lock_status,
"lock_status",
"lock_status");
-}
#endif
#if defined(CONFIG_FLASH_MCUFIRMWARE_SUPPORT) && defined(CONFIG_ARCH_IMX8M)
#include <trusty/libtipc.h>
#endif
+#include "fb_fsl_common.h"
+
#define EP_BUFFER_SIZE 4096
/**
*/
static u32 fastboot_bytes_expected;
-#if defined(CONFIG_AVB_SUPPORT) && defined(CONFIG_MMC)
-static AvbABOps fsl_avb_ab_ops = {
- .read_ab_metadata = fsl_read_ab_metadata,
- .write_ab_metadata = fsl_write_ab_metadata,
- .ops = NULL
-};
-#ifdef CONFIG_AVB_ATX
-static AvbAtxOps fsl_avb_atx_ops = {
- .ops = NULL,
- .read_permanent_attributes = fsl_read_permanent_attributes,
- .read_permanent_attributes_hash = fsl_read_permanent_attributes_hash,
-#ifdef CONFIG_IMX_TRUSTY_OS
- .set_key_version = fsl_write_rollback_index_rpmb,
-#else
- .set_key_version = fsl_set_key_version,
-#endif
- .get_random = fsl_get_random
-};
-#endif
-static AvbOps fsl_avb_ops = {
- .ab_ops = &fsl_avb_ab_ops,
-#ifdef CONFIG_AVB_ATX
- .atx_ops = &fsl_avb_atx_ops,
-#endif
- .read_from_partition = fsl_read_from_partition_multi,
- .write_to_partition = fsl_write_to_partition,
-#ifdef CONFIG_AVB_ATX
- .validate_vbmeta_public_key = avb_atx_validate_vbmeta_public_key,
-#else
- .validate_vbmeta_public_key = fsl_validate_vbmeta_public_key_rpmb,
-#endif
- .read_rollback_index = fsl_read_rollback_index_rpmb,
- .write_rollback_index = fsl_write_rollback_index_rpmb,
- .read_is_device_unlocked = fsl_read_is_device_unlocked,
- .get_unique_guid_for_partition = fsl_get_unique_guid_for_partition,
- .get_size_of_partition = fsl_get_size_of_partition
-};
-#endif
+/* erase a partition on mmc */
+static void process_erase_mmc(const char *cmdbuf, char *response)
+{
+ int mmc_no = 0;
+ lbaint_t blks, blks_start, blks_size, grp_size;
+ struct mmc *mmc;
+ struct blk_desc *dev_desc;
+ struct fastboot_ptentry *ptn;
+ disk_partition_t info;
+
+ ptn = fastboot_flash_find_ptn(cmdbuf);
+ if ((ptn == NULL) || (ptn->flags & FASTBOOT_PTENTRY_FLAGS_UNERASEABLE)) {
+ sprintf(response, "FAILpartition does not exist or uneraseable");
+ fastboot_flash_dump_ptn();
+ return;
+ }
+ mmc_no = fastboot_devinfo.dev_id;
+ printf("erase target is MMC:%d\n", mmc_no);
+
+ mmc = find_mmc_device(mmc_no);
+ if ((mmc == NULL) || mmc_init(mmc)) {
+ printf("MMC card init failed!\n");
+ return;
+ }
+
+ dev_desc = blk_get_dev("mmc", mmc_no);
+ if (NULL == dev_desc) {
+ printf("Block device MMC %d not supported\n",
+ mmc_no);
+ sprintf(response, "FAILnot valid MMC card");
+ return;
+ }
+
+ if (part_get_info(dev_desc,
+ ptn->partition_index, &info)) {
+ printf("Bad partition index:%d for partition:%s\n",
+ ptn->partition_index, ptn->name);
+ sprintf(response, "FAILerasing of MMC card");
+ return;
+ }
+
+ /* Align blocks to erase group size to avoid erasing other partitions */
+ grp_size = mmc->erase_grp_size;
+ blks_start = (info.start + grp_size - 1) & ~(grp_size - 1);
+ if (info.size >= grp_size)
+ blks_size = (info.size - (blks_start - info.start)) &
+ (~(grp_size - 1));
+ else
+ blks_size = 0;
+
+ printf("Erasing blocks " LBAFU " to " LBAFU " due to alignment\n",
+ blks_start, blks_start + blks_size);
+
+ blks = blk_derase(dev_desc, blks_start, blks_size);
+ if (blks != blks_size) {
+ printf("failed erasing from device %d", dev_desc->devnum);
+ sprintf(response, "FAILerasing of MMC card");
+ return;
+ }
+
+ printf("........ erased " LBAFU " bytes from '%s'\n",
+ blks_size * info.blksz, cmdbuf);
+ sprintf(response, "OKAY");
+
+ return;
+}
/* Write the bcb with fastboot bootloader commands */
static void enable_fastboot_command(void)
cmd_parameter = cmd_string;
strsep(&cmd_parameter, ":");
+ /* separate cmdstring for "fastboot oem/flashing" with a blank */
+ if(cmd_parameter == NULL)
+ {
+ cmd_parameter = cmd_string;
+ strsep(&cmd_parameter, " ");
+ }
for (i = 0; i < ARRAY_SIZE(commands); i++) {
if (commands[i].command != NULL &&
extern void trusty_os_init(void);
#endif
+#include "fb_fsl_common.h"
+
+#if defined(CONFIG_AVB_SUPPORT) && defined(CONFIG_MMC)
+AvbABOps fsl_avb_ab_ops = {
+ .read_ab_metadata = fsl_read_ab_metadata,
+ .write_ab_metadata = fsl_write_ab_metadata,
+ .ops = NULL
+};
+#ifdef CONFIG_AVB_ATX
+AvbAtxOps fsl_avb_atx_ops = {
+ .ops = NULL,
+ .read_permanent_attributes = fsl_read_permanent_attributes,
+ .read_permanent_attributes_hash = fsl_read_permanent_attributes_hash,
+#ifdef CONFIG_IMX_TRUSTY_OS
+ .set_key_version = fsl_write_rollback_index_rpmb,
+#else
+ .set_key_version = fsl_set_key_version,
+#endif
+ .get_random = fsl_get_random
+};
+#endif
+AvbOps fsl_avb_ops = {
+ .ab_ops = &fsl_avb_ab_ops,
+#ifdef CONFIG_AVB_ATX
+ .atx_ops = &fsl_avb_atx_ops,
+#endif
+ .read_from_partition = fsl_read_from_partition_multi,
+ .write_to_partition = fsl_write_to_partition,
+#ifdef CONFIG_AVB_ATX
+ .validate_vbmeta_public_key = avb_atx_validate_vbmeta_public_key,
+#else
+ .validate_vbmeta_public_key = fsl_validate_vbmeta_public_key_rpmb,
+#endif
+ .read_rollback_index = fsl_read_rollback_index_rpmb,
+ .write_rollback_index = fsl_write_rollback_index_rpmb,
+ .read_is_device_unlocked = fsl_read_is_device_unlocked,
+ .get_unique_guid_for_partition = fsl_get_unique_guid_for_partition,
+ .get_size_of_partition = fsl_get_size_of_partition
+};
+#endif
+
+int get_block_size(void) {
+ int dev_no = 0;
+ struct blk_desc *dev_desc;
+
+ dev_no = fastboot_devinfo.dev_id;
+ dev_desc = blk_get_dev(fastboot_devinfo.type == DEV_SATA ? "sata" : "mmc", dev_no);
+ if (NULL == dev_desc) {
+ printf("** Block device %s %d not supported\n",
+ fastboot_devinfo.type == DEV_SATA ? "sata" : "mmc",
+ dev_no);
+ return 0;
+ }
+ return dev_desc->blksz;
+}
struct fastboot_device_info fastboot_devinfo = {0xff, 0xff};
--- /dev/null
+/*
+ * Copyright (c) 2016, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FB_FSL_COMMON_H
+#define FB_FSL_COMMON_H
+
+#ifdef CONFIG_AVB_SUPPORT
+#include <dt_table.h>
+#include <fsl_avb.h>
+#endif
+
+#if defined(CONFIG_AVB_SUPPORT) && defined(CONFIG_MMC)
+extern AvbABOps fsl_avb_ab_ops;
+#ifdef CONFIG_AVB_ATX
+extern AvbAtxOps fsl_avb_atx_ops;
+#endif
+extern AvbOps fsl_avb_ops;
+#endif
+
+int get_block_size(void);
+
+#endif // FB_FSL_COMMON_H
#include <asm/setup.h>
#include <environment.h>
+#include "fb_fsl_common.h"
+
static lbaint_t mmc_sparse_write(struct sparse_storage *info,
lbaint_t blk, lbaint_t blkcnt, const void *buffer)
{
#include "fastboot_lock_unlock.h"
#endif
+#include "fb_fsl_common.h"
+
#ifdef CONFIG_IMX_TRUSTY_OS
#include "u-boot/sha256.h"
#include <trusty/libtipc.h>
#define VARIANT_NAME "NXP i.MX"
#endif
-static int get_block_size(void) {
- int dev_no = 0;
- struct blk_desc *dev_desc;
-
- dev_no = fastboot_devinfo.dev_id;
- dev_desc = blk_get_dev(fastboot_devinfo.type == DEV_SATA ? "sata" : "mmc", dev_no);
- if (NULL == dev_desc) {
- printf("** Block device %s %d not supported\n",
- fastboot_devinfo.type == DEV_SATA ? "sata" : "mmc",
- dev_no);
- return 0;
- }
- return dev_desc->blksz;
-}
-
#ifdef CONFIG_IMX_TRUSTY_OS
static void uuid_hex2string(uint8_t *uuid, char* buf, uint32_t uuid_len, uint32_t uuid_strlen) {
uint32_t i;
#include <part.h>
#include <stdlib.h>
-#include <fsl_fastboot.h>
-#include "../../../drivers/usb/gadget/fastboot_lock_unlock.h"
+#include <fb_fsl.h>
+#include "../../../drivers/fastboot/fb_fsl/fastboot_lock_unlock.h"
#include <fsl_avb.h>
#include "fsl_avbkey.h"
#include <common.h>
#include <stdlib.h>
#include <linux/string.h>
-#include <fsl_fastboot.h>
+#include <fb_fsl.h>
#include <fsl_avb.h>
/* as libavb's bootctl doesn't have the get_var support