diff options
Diffstat (limited to 'drivers')
-rwxr-xr-x | drivers/crypto/fsl_caam.c | 110 | ||||
-rw-r--r-- | drivers/usb/gadget/f_fastboot.c | 118 | ||||
-rw-r--r-- | drivers/usb/gadget/fastboot_lock_unlock.c | 19 | ||||
-rw-r--r-- | drivers/usb/gadget/fastboot_lock_unlock.h | 6 |
4 files changed, 108 insertions, 145 deletions
diff --git a/drivers/crypto/fsl_caam.c b/drivers/crypto/fsl_caam.c index fa041cf..4ba4718 100755 --- a/drivers/crypto/fsl_caam.c +++ b/drivers/crypto/fsl_caam.c @@ -38,6 +38,7 @@ /* Input job ring - single entry input ring */ uint32_t g_input_ring[JOB_RING_ENTRIES] = {0}; + /* Output job ring - single entry output ring (consists of two words) */ uint32_t g_output_ring[2*JOB_RING_ENTRIES] = {0, 0}; @@ -85,6 +86,7 @@ static uint8_t skeymod[] = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 }; + /*! * Secure memory run command. * @@ -102,69 +104,6 @@ uint32_t secmem_set_cmd_1(uint32_t sec_mem_cmd) return temp_reg; } -/*! - * CAAM page allocation. - * - * @param page Number of the page to allocate. - * @param partition Number of the partition to allocate. - */ -static uint32_t caam_page_alloc(uint8_t page_num, uint8_t partition_num) -{ - uint32_t temp_reg; - - /* - * De-Allocate partition_num if already allocated to ARM core - */ - if(__raw_readl(CAAM_SMPO_0) & PARTITION_OWNER(partition_num)) - { - temp_reg = secmem_set_cmd_1(PARTITION(partition_num) | CMD_PART_DEALLOC); - if(temp_reg & SMCSJR_AERR) - { - printf("Error: De-allocation status 0x%X\n",temp_reg); - return ERROR_IN_PAGE_ALLOC; - } - } - - /* set the access rights to allow full access */ - __raw_writel(0xF, CAAM_SMAG1JR0(partition_num)); - __raw_writel(0xF, CAAM_SMAG2JR0(partition_num)); - __raw_writel(0xFF, CAAM_SMAPJR0(partition_num)); - - /* Now need to allocate partition_num of secure RAM. */ - /* De-Allocate page_num by starting with a page inquiry command */ - temp_reg = secmem_set_cmd_1(PAGE(page_num) | CMD_INQUIRY); - /* if the page is owned, de-allocate it */ - if((temp_reg & SMCSJR_PO) == PAGE_OWNED) - { - temp_reg = secmem_set_cmd_1(PAGE(page_num) | CMD_PAGE_DEALLOC); - if(temp_reg & SMCSJR_AERR) - { - printf("Error: Allocation status 0x%X\n",temp_reg); - return ERROR_IN_PAGE_ALLOC; - } - } - - /* Allocate page_num to partition_num */ - temp_reg = secmem_set_cmd_1(PAGE(page_num) | PARTITION(partition_num) - | CMD_PAGE_ALLOC); - if(temp_reg & SMCSJR_AERR) - { - printf("Error: Allocation status 0x%X\n",temp_reg); - return ERROR_IN_PAGE_ALLOC; - } - /* page inquiry command to ensure that the page was allocated */ - temp_reg = secmem_set_cmd_1(PAGE(page_num) | CMD_INQUIRY); - /* if the page is not owned => problem */ - if((temp_reg & SMCSJR_PO) != PAGE_OWNED) - { - printf("Error: Allocation of page %d in partition %d failed 0x%X\n" - ,temp_reg, page_num, partition_num); - - return ERROR_IN_PAGE_ALLOC; - } - - return SUCCESS; -} /*! * Use CAAM to decapsulate a blob to secure memory. @@ -180,7 +119,6 @@ uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size) uint32_t ret = SUCCESS; /* Buffer that holds blob */ - uint8_t *blob = (uint8_t *)blob_addr; /**** Prepare partition and page, and start the job to create the blob ***/ #if 0 @@ -204,8 +142,8 @@ uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size) decap_dsc[6] = (uint32_t)(uint8_t*)plain_text; decap_dsc[7] = (uint32_t)0x860D0000; -// uncomment when using descriptor from "fsl_caam_internal.h" -// does not use key modifier. +/* uncomment when using descriptor from "fsl_caam_internal.h" + does not use key modifier. */ #if 0 /* Fill in input blob addr in decap_dsc */ decap_dsc[5] = (uint32_t)blob; @@ -217,10 +155,14 @@ uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size) /* Add job to input ring */ g_input_ring[0] = (uint32_t)decap_dsc; - flush_dcache_range((uint32_t)blob_addr & 0xffffffe0, ((uint32_t)blob_addr & 0xffffffe0) + 2*size); - flush_dcache_range((uint32_t)plain_text& 0xffffffe0, ((uint32_t)plain_text& 0xffffffe0) + 2*size); - flush_dcache_range((uint32_t)decap_dsc & 0xffffffe0, ((uint32_t)decap_dsc & 0xffffffe0) + 128); - flush_dcache_range((uint32_t)g_input_ring & 0xffffffe0, ((uint32_t)g_input_ring & 0xffffffe0) + 128); + flush_dcache_range((uint32_t)blob_addr & 0xffffffe0, + ((uint32_t)blob_addr & 0xffffffe0) + 2*size); + flush_dcache_range((uint32_t)plain_text & 0xffffffe0, + ((uint32_t)plain_text & 0xffffffe0) + 2*size); + flush_dcache_range((uint32_t)decap_dsc & 0xffffffe0, + ((uint32_t)decap_dsc & 0xffffffe0) + 128); + flush_dcache_range((uint32_t)g_input_ring & 0xffffffe0, + ((uint32_t)g_input_ring & 0xffffffe0) + 128); /* Increment jobs added */ __raw_writel(1, CAAM_IRJAR0); @@ -228,7 +170,8 @@ uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size) while(__raw_readl(CAAM_ORSFR0) != 1); // TODO: check if Secure memory is cacheable. - invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, ((uint32_t)g_output_ring & 0xffffffe0) + 128); + invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, + ((uint32_t)g_output_ring & 0xffffffe0) + 128); /* check that descriptor address is the one expected in the output ring */ if(g_output_ring[0] == (uint32_t)decap_dsc) { @@ -244,7 +187,8 @@ uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size) printf("Error: blob decap job output ring descriptor address does" \ " not match\n"); } - flush_dcache_range((uint32_t)plain_text& 0xffffffe0, ((uint32_t)plain_text& 0xffffffe0) + 2*size); + flush_dcache_range((uint32_t)plain_text & 0xffffffe0, + ((uint32_t)plain_text & 0xffffffe0) + 2*size); /* Remove job from Job Ring Output Queue */ @@ -264,7 +208,6 @@ uint32_t caam_decap_blob(uint32_t plain_text, uint32_t blob_addr, uint32_t size) uint32_t caam_gen_blob(uint32_t plain_data_addr, uint32_t blob_addr, uint32_t size) { uint32_t ret = SUCCESS; - uint32_t addr; /* Buffer to hold the resulting blob */ uint8_t *blob = (uint8_t *)blob_addr; @@ -311,9 +254,12 @@ uint32_t caam_gen_blob(uint32_t plain_data_addr, uint32_t blob_addr, uint32_t si /* Add job to input ring */ g_input_ring[0] = (uint32_t)encap_dsc; - flush_dcache_range((uint32_t)plain_data_addr& 0xffffffe0, ((uint32_t)plain_data_addr& 0xffffffe0) + size); - flush_dcache_range((uint32_t)encap_dsc & 0xffffffe0, ((uint32_t)encap_dsc & 0xffffffe0) + 128); - flush_dcache_range((uint32_t)blob & 0xffffffe0, ((uint32_t)g_input_ring & 0xffffffe0) + 2 * size); + flush_dcache_range((uint32_t)plain_data_addr & 0xffffffe0, + ((uint32_t)plain_data_addr & 0xffffffe0) + size); + flush_dcache_range((uint32_t)encap_dsc & 0xffffffe0, + ((uint32_t)encap_dsc & 0xffffffe0) + 128); + flush_dcache_range((uint32_t)blob & 0xffffffe0, + ((uint32_t)g_input_ring & 0xffffffe0) + 2 * size); /* Increment jobs added */ __raw_writel(1, CAAM_IRJAR0); @@ -321,8 +267,10 @@ uint32_t caam_gen_blob(uint32_t plain_data_addr, uint32_t blob_addr, uint32_t si while(__raw_readl(CAAM_ORSFR0) != 1); // flush cache - invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, ((uint32_t)g_output_ring & 0xffffffe0) + 128); - invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, ((uint32_t)g_output_ring & 0xffffffe0) + 128); + invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, + ((uint32_t)g_output_ring & 0xffffffe0) + 128); + invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, + ((uint32_t)g_output_ring & 0xffffffe0) + 128); /* check that descriptor address is the one expected in the output ring */ if(g_output_ring[0] == (uint32_t)encap_dsc) { @@ -414,7 +362,8 @@ void caam_open(void) /* Add job to input ring */ g_input_ring[0] = (uint32_t)rng_inst_dsc; - flush_dcache_range((uint32_t)g_input_ring & 0xffffffe0, ((uint32_t)g_input_ring & 0xffffffe0) + 128); + flush_dcache_range((uint32_t)g_input_ring & 0xffffffe0, + ((uint32_t)g_input_ring & 0xffffffe0) + 128); /* Increment jobs added */ __raw_writel(1, CAAM_IRJAR0); @@ -422,7 +371,8 @@ void caam_open(void) while(__raw_readl(CAAM_ORSFR0) != 1); - invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, ((uint32_t)g_output_ring & 0xffffffe0) + 128); + invalidate_dcache_range((uint32_t)g_output_ring & 0xffffffe0, + ((uint32_t)g_output_ring & 0xffffffe0) + 128); /* check that descriptor address is the one expected in the out ring */ if(g_output_ring[0] == (uint32_t)rng_inst_dsc) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 4ff0284..b22ec76 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -15,6 +15,7 @@ #include <config.h> #include <common.h> #include <errno.h> +#include <stdlib.h> #include <malloc.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> @@ -1071,8 +1072,8 @@ static void parameters_setup(void) CONFIG_USB_FASTBOOT_BUF_SIZE; } -static struct fastboot_ptentry ptable[MAX_PTN]; -static unsigned int pcount; +static struct fastboot_ptentry g_ptable[MAX_PTN]; +static unsigned int g_pcount; struct fastboot_device_info fastboot_devinfo; /* @@ -1453,7 +1454,7 @@ static int _fastboot_parts_load_from_env(void) while (s < e) { if (_fastboot_parts_add_env_entry(s, &s)) { printf("Error:Fastboot: Abort adding partitions\n"); - pcount = 0; + g_pcount = 0; return 1; } /* Skip a bunch of delimiters */ @@ -1478,7 +1479,7 @@ static int _fastboot_parts_load_from_env(void) static void _fastboot_load_partitions(void) { - pcount = 0; + g_pcount = 0; #if defined(CONFIG_FASTBOOT_STORAGE_NAND) _fastboot_parts_load_from_env(); #elif defined(CONFIG_FASTBOOT_STORAGE_SATA) \ @@ -1491,19 +1492,21 @@ static void _fastboot_load_partitions(void) * Android style flash utilties */ void fastboot_flash_add_ptn(struct fastboot_ptentry *ptn) { - if (pcount < MAX_PTN) { - memcpy(ptable + pcount, ptn, sizeof(struct fastboot_ptentry)); - pcount++; + if (g_pcount < MAX_PTN) { + memcpy(g_ptable + g_pcount, ptn, + sizeof(struct fastboot_ptentry)); + g_pcount++; } } void fastboot_flash_dump_ptn(void) { unsigned int n; - for (n = 0; n < pcount; n++) { - struct fastboot_ptentry *ptn = ptable + n; - printf("ptn %d name='%s' start=%d len=%d\n", - n, ptn->name, ptn->start, ptn->length); + for (n = 0; n < g_pcount; n++) { + struct fastboot_ptentry *ptn = g_ptable + n; + printf("idx %d, ptn %d name='%s' start=%d len=%d\n", + n, ptn->partition_index, ptn->name, + ptn->start, ptn->length); } } @@ -1512,11 +1515,11 @@ struct fastboot_ptentry *fastboot_flash_find_ptn(const char *name) { unsigned int n; - for (n = 0; n < pcount; n++) { + for (n = 0; n < g_pcount; n++) { /* Make sure a substring is not accepted */ - if (strlen(name) == strlen(ptable[n].name)) { - if (0 == strcmp(ptable[n].name, name)) - return ptable + n; + if (strlen(name) == strlen(g_ptable[n].name)) { + if (0 == strcmp(g_ptable[n].name, name)) + return g_ptable + n; } } @@ -1527,15 +1530,15 @@ struct fastboot_ptentry *fastboot_flash_find_ptn(const char *name) struct fastboot_ptentry *fastboot_flash_get_ptn(unsigned int n) { - if (n < pcount) - return ptable + n; + if (n < g_pcount) + return g_ptable + n; else return 0; } unsigned int fastboot_flash_get_ptn_count(void) { - return pcount; + return g_pcount; } /* @@ -1610,7 +1613,7 @@ bootimg_print_image_hdr(struct andr_img_hdr *hdr) printf(" page_size: 0x%x\n", hdr->page_size); printf(" name: %s\n", hdr->name); - printf(" cmdline: %s%x\n", hdr->cmdline); + printf(" cmdline: %s\n", hdr->cmdline); for (i = 0; i < 8; i++) printf(" id[%d]: 0x%x\n", i, hdr->id[i]); @@ -2176,7 +2179,8 @@ static int strcmp_l1(const char *s1, const char *s2) return strncmp(s1, s2, strlen(s1)); } -static int get_block_size() { +static int get_block_size(void) +{ int mmc_no = 0; block_dev_desc_t *dev_desc; mmc_no = fastboot_devinfo.dev_id; @@ -2215,7 +2219,8 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req) } #endif char *str; - if (str = strstr(cmd, "partition-size:")) { + str = strstr(cmd, "partition-size:"); + if (str) { str+=strlen("partition-size:"); struct fastboot_ptentry* fb_part; fb_part = fastboot_flash_find_ptn(str); @@ -2226,7 +2231,8 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req) sprintf(var, "OKAY0x%016x", fb_part->length * get_block_size()); strcpy(response, var); } - } else if (str = strstr(cmd, "partition-type:")) { + } else if (strstr(cmd, "partition-type:")) { + str = strstr(cmd, "partition-type:"); str+=strlen("partition-type:"); struct fastboot_ptentry* fb_part; fb_part = fastboot_flash_find_ptn(str); @@ -2487,38 +2493,8 @@ U_BOOT_CMD( "lock_status", "lock_status"); -static void cb_flashing(struct usb_ep *ep, struct usb_request *req) +static int do_fastboot_unlock(void) { - char *cmd = req->buf; - char response[RESPONSE_LEN]; - unsigned char len = strlen(cmd); - int status; - if (!strncmp(cmd + len - 15, "unlock_critical", 15)) { - strcpy(response, "OKAY"); - } else if (!strncmp(cmd + len - 13, "lock_critical", 13)) { - strcpy(response, "OKAY"); - } else if (!strncmp(cmd + len - 6, "unlock", 6)) { - printf("flashing unlock.\n"); - status = do_fastboot_unlock(); - if (status >= 0) - strcpy(response, "OKAY"); - else - strcpy(response, "FAIL unlock device failed."); - } else if (!strncmp(cmd + len - 4, "lock", 4)) { - printf("flashing lock.\n"); - status = do_fastboot_lock(); - if (status >= 0) - strcpy(response, "OKAY"); - else - strcpy(response, "FAIL lock device failed."); - } else { - printf("Unknown flashing command:%s\n", cmd); - strcpy(response, "FAIL command not defined"); - } - fastboot_tx_write_str(response); -} - -int do_fastboot_unlock() { int status; if (fastboot_lock_enable() == FASTBOOT_UL_ENABLE) { printf("It is able to unlock device. %d\n",fastboot_lock_enable()); @@ -2543,7 +2519,8 @@ int do_fastboot_unlock() { return status; } -int do_fastboot_lock() { +static int do_fastboot_lock(void) +{ int status; status = fastboot_get_lock_stat(); if (status == FASTBOOT_LOCK) { @@ -2559,9 +2536,38 @@ int do_fastboot_lock() { printf("Wipe /data completed.\n"); return status; - } +static void cb_flashing(struct usb_ep *ep, struct usb_request *req) +{ + char *cmd = req->buf; + char response[RESPONSE_LEN]; + unsigned char len = strlen(cmd); + int status; + if (!strncmp(cmd + len - 15, "unlock_critical", 15)) { + strcpy(response, "OKAY"); + } else if (!strncmp(cmd + len - 13, "lock_critical", 13)) { + strcpy(response, "OKAY"); + } else if (!strncmp(cmd + len - 6, "unlock", 6)) { + printf("flashing unlock.\n"); + status = do_fastboot_unlock(); + if (status >= 0) + strcpy(response, "OKAY"); + else + strcpy(response, "FAIL unlock device failed."); + } else if (!strncmp(cmd + len - 4, "lock", 4)) { + printf("flashing lock.\n"); + status = do_fastboot_lock(); + if (status >= 0) + strcpy(response, "OKAY"); + else + strcpy(response, "FAIL lock device failed."); + } else { + printf("Unknown flashing command:%s\n", cmd); + strcpy(response, "FAIL command not defined"); + } + fastboot_tx_write_str(response); +} #endif @@ -2611,6 +2617,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) } #endif +/* static void cb_oem(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; @@ -2632,6 +2639,7 @@ static void cb_oem(struct usb_ep *ep, struct usb_request *req) fastboot_tx_write_str("FAILunknown oem command"); } } +*/ #ifdef CONFIG_FASTBOOT_FLASH static void cb_erase(struct usb_ep *ep, struct usb_request *req) diff --git a/drivers/usb/gadget/fastboot_lock_unlock.c b/drivers/usb/gadget/fastboot_lock_unlock.c index 25f4660..7afc33d 100644 --- a/drivers/usb/gadget/fastboot_lock_unlock.c +++ b/drivers/usb/gadget/fastboot_lock_unlock.c @@ -36,6 +36,7 @@ #include <part.h> #include <ext_common.h> #include <stdio_dev.h> +#include <stdlib.h> #ifdef FASTBOOT_ENCRYPT_LOCK @@ -69,7 +70,7 @@ int sha1sum(unsigned char* data, int len, unsigned char* output) { printf("error in lookup sha1 algo!\n"); return -1; } - buf = map_sysmem(data, len); + buf = map_sysmem((ulong)data, len); algo->hash_func_ws(buf, len, output, algo->chunk_size); unmap_sysmem(buf); @@ -79,7 +80,7 @@ int sha1sum(unsigned char* data, int len, unsigned char* output) { int generate_salt(unsigned char* salt) { unsigned long time = get_timer(0); - return sha1sum(&time, sizeof(unsigned long), salt); + return sha1sum((unsigned char *)&time, sizeof(unsigned long), salt); } @@ -88,7 +89,8 @@ unsigned char decrypt_lock_store(unsigned char *bdata) { int p = 0, ret; caam_open(); - ret = caam_decap_blob((uint32_t)plain_data, bdata + ENDATA_LEN, ENDATA_LEN); + ret = caam_decap_blob((uint32_t)plain_data, + (uint32_t)bdata + ENDATA_LEN, ENDATA_LEN); if (ret != 0) { printf("Error during blob decap operation: 0x%x\n",ret); return FASTBOOT_LOCK_ERROR; @@ -131,7 +133,7 @@ int encrypt_lock_store(unsigned char lock, unsigned char* bdata) { int ret; int salt_len = generate_salt(bdata); if (salt_len < 0) - return; + return -1; //salt_len cannot be longer than endata block size. if (salt_len >= ENDATA_LEN) @@ -227,7 +229,8 @@ int fastboot_set_lock_stat(unsigned char lock) { return 0; } -unsigned char fastboot_get_lock_stat() { +unsigned char fastboot_get_lock_stat(void) +{ block_dev_desc_t *fs_dev_desc; disk_partition_t fs_partition; @@ -263,7 +266,8 @@ unsigned char fastboot_get_lock_stat() { #ifdef CONFIG_BRILLO_SUPPORT //Brillo has no presist data partition -unsigned char fastboot_lock_enable() { +unsigned char fastboot_lock_enable(void) +{ return FASTBOOT_UL_ENABLE; } #else @@ -337,7 +341,8 @@ int display_lock(int lock, int verify) { } -int fastboot_wipe_data_partition() { +int fastboot_wipe_data_partition(void) +{ block_dev_desc_t *fs_dev_desc; disk_partition_t fs_partition; int status; diff --git a/drivers/usb/gadget/fastboot_lock_unlock.h b/drivers/usb/gadget/fastboot_lock_unlock.h index 007da57..ee2d7a5 100644 --- a/drivers/usb/gadget/fastboot_lock_unlock.h +++ b/drivers/usb/gadget/fastboot_lock_unlock.h @@ -56,13 +56,13 @@ enum { FASTBOOT_UL_NUM }; -unsigned char fastboot_get_lock_stat(); +unsigned char fastboot_get_lock_stat(void); int fastboot_set_lock_stat(unsigned char lock); -int fastboot_wipe_data_partition(); +int fastboot_wipe_data_partition(void); -unsigned char fastboot_lock_enable(); +unsigned char fastboot_lock_enable(void); int display_lock(int lock, int verify); #endif |