summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/f_fastboot.c16
-rw-r--r--drivers/usb/gadget/fastboot_lock_unlock.c48
-rw-r--r--drivers/usb/gadget/fastboot_lock_unlock.h16
3 files changed, 43 insertions, 37 deletions
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 95b323b..335e949 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -1872,8 +1872,7 @@ use_given_ptn:
#endif /*CONFIG_SECURE_BOOT*/
#ifdef CONFIG_FASTBOOT_LOCK
- int lock_status = fastboot_get_lock_stat();
- if (lock_status == FASTBOOT_LOCK_ERROR) {
+ if (fastboot_get_lock_stat() == FASTBOOT_LOCK_ERROR) {
printf("In boota get fastboot lock status error. Set lock status\n");
fastboot_set_lock_stat(FASTBOOT_LOCK);
}
@@ -2402,8 +2401,7 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
else if (!strcmp_l1("secure", cmd)) {
strncat(response, FASTBOOT_VAR_SECURE, chars_left);
} else if (!strcmp_l1("unlocked",cmd)) {
- int status = fastboot_get_lock_stat();
- if (status == FASTBOOT_UNLOCK) {
+ if (fastboot_get_lock_stat() == FASTBOOT_UNLOCK) {
strncat(response, FASTBOOT_VAR_YES, chars_left);
} else {
strncat(response, FASTBOOT_VAR_NO, chars_left);
@@ -2591,7 +2589,7 @@ static void cb_continue(struct usb_ep *ep, struct usb_request *req)
#ifdef CONFIG_FASTBOOT_LOCK
int do_lock_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
- int status = fastboot_get_lock_stat();
+ FbLockState status = fastboot_get_lock_stat();
if (status != FASTBOOT_LOCK_ERROR) {
if (status == FASTBOOT_LOCK)
printf("fastboot lock status: locked.\n");
@@ -2616,8 +2614,7 @@ static int do_fastboot_unlock(void)
int status;
if (fastboot_lock_enable() == FASTBOOT_UL_ENABLE) {
printf("It is able to unlock device. %d\n",fastboot_lock_enable());
- status = fastboot_get_lock_stat();
- if (status == FASTBOOT_UNLOCK) {
+ if (fastboot_get_lock_stat() == FASTBOOT_UNLOCK) {
printf("The device is already unlocked\n");
return 1;
}
@@ -2640,8 +2637,7 @@ static int do_fastboot_unlock(void)
static int do_fastboot_lock(void)
{
int status;
- status = fastboot_get_lock_stat();
- if (status == FASTBOOT_LOCK) {
+ if (fastboot_get_lock_stat() == FASTBOOT_LOCK) {
printf("The device is already locked\n");
return 1;
}
@@ -2717,7 +2713,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
}
#ifdef CONFIG_FASTBOOT_LOCK
- int status;
+ FbLockState status;
status = fastboot_get_lock_stat();
if (status == FASTBOOT_LOCK) {
diff --git a/drivers/usb/gadget/fastboot_lock_unlock.c b/drivers/usb/gadget/fastboot_lock_unlock.c
index 4514bd0..63e0a8f 100644
--- a/drivers/usb/gadget/fastboot_lock_unlock.c
+++ b/drivers/usb/gadget/fastboot_lock_unlock.c
@@ -28,9 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <fsl_fastboot.h>
-#include "fastboot_lock_unlock.h"
-
#include <common.h>
#include <linux/types.h>
#include <part.h>
@@ -38,6 +35,10 @@
#include <stdio_dev.h>
#include <stdlib.h>
+#include <fsl_fastboot.h>
+#include "fastboot_lock_unlock.h"
+
+
#ifdef FASTBOOT_ENCRYPT_LOCK
#include <hash.h>
@@ -54,18 +55,21 @@
/*
* This will return FASTBOOT_LOCK, FASTBOOT_UNLOCK or FASTBOOT_ERROR
*/
-inline unsigned char decrypt_lock_store(unsigned char* bdata) {
- return *bdata;
+static inline FbLockState decrypt_lock_store(unsigned char* bdata) {
+ if (*bdata >= FASTBOOT_LOCK_NUM)
+ return FASTBOOT_LOCK_ERROR;
+ else
+ return *bdata;
}
-inline int encrypt_lock_store(unsigned char lock, unsigned char *bdata)
+static inline int encrypt_lock_store(FbLockState lock, unsigned char *bdata)
{
*bdata = lock;
return 0;
}
#else
-int sha1sum(unsigned char* data, int len, unsigned char* output) {
+static int sha1sum(unsigned char* data, int len, unsigned char* output) {
struct hash_algo *algo;
void *buf;
if (hash_lookup_algo("sha1", &algo)) {
@@ -80,13 +84,13 @@ int sha1sum(unsigned char* data, int len, unsigned char* output) {
}
-int generate_salt(unsigned char* salt) {
+static int generate_salt(unsigned char* salt) {
unsigned long time = get_timer(0);
return sha1sum((unsigned char *)&time, sizeof(unsigned long), salt);
}
-unsigned char decrypt_lock_store(unsigned char *bdata) {
+static FbLockState decrypt_lock_store(unsigned char *bdata) {
unsigned char plain_data[ENDATA_LEN];
int p = 0, ret;
@@ -127,10 +131,13 @@ unsigned char decrypt_lock_store(unsigned char *bdata) {
}
}
- return plain_data[ENDATA_LEN-1];
+ if (plain_data[ENDATA_LEN - 1] >= FASTBOOT_LOCK_NUM)
+ return FASTBOOT_LOCK_ERROR;
+ else
+ return plain_data[ENDATA_LEN-1];
}
-int encrypt_lock_store(unsigned char lock, unsigned char* bdata) {
+static int encrypt_lock_store(FbLockState lock, unsigned char* bdata) {
unsigned int p = 0;
int ret;
int salt_len = generate_salt(bdata);
@@ -188,18 +195,21 @@ char* get_mmc_part(int part) {
/*
* The enabling value is stored in the last byte of target partition.
*/
-inline unsigned char lock_enable_parse(unsigned char* bdata) {
+static inline FbLockEnableResult lock_enable_parse(unsigned char* bdata) {
DEBUG("lock_enable_parse: 0x%x\n", *(bdata + SECTOR_SIZE -1));
- return *(bdata + SECTOR_SIZE -1);
+ if (*(bdata + SECTOR_SIZE -1) >= FASTBOOT_UL_NUM)
+ return FASTBOOT_UL_ERROR;
+ else
+ return *(bdata + SECTOR_SIZE -1);
}
-static unsigned char g_lockstat = FASTBOOT_UNLOCK;
+static FbLockState g_lockstat = FASTBOOT_UNLOCK;
/*
* Set status of the lock&unlock to FSL_FASTBOOT_FB_PART
* Currently use the very first Byte of FSL_FASTBOOT_FB_PART
* to store the fastboot lock&unlock status
*/
-int fastboot_set_lock_stat(unsigned char lock) {
+int fastboot_set_lock_stat(FbLockState lock) {
block_dev_desc_t *fs_dev_desc;
disk_partition_t fs_partition;
unsigned char *bdata;
@@ -233,7 +243,7 @@ int fastboot_set_lock_stat(unsigned char lock) {
return 0;
}
-unsigned char fastboot_get_lock_stat(void)
+FbLockState fastboot_get_lock_stat(void)
{
block_dev_desc_t *fs_dev_desc;
@@ -270,12 +280,12 @@ unsigned char fastboot_get_lock_stat(void)
#ifdef CONFIG_BRILLO_SUPPORT
//Brillo has no presist data partition
-unsigned char fastboot_lock_enable(void)
+FbLockEnableResult fastboot_lock_enable(void)
{
return FASTBOOT_UL_ENABLE;
}
#else
-unsigned char fastboot_lock_enable() {
+FbLockEnableResult fastboot_lock_enable() {
block_dev_desc_t *fs_dev_desc;
disk_partition_t fs_partition;
unsigned char *bdata;
@@ -312,7 +322,7 @@ unsigned char fastboot_lock_enable() {
}
#endif
-int display_lock(int lock, int verify) {
+int display_lock(FbLockState lock, int verify) {
struct stdio_dev *disp;
disp = stdio_get_by_name("vga");
if (disp != NULL) {
diff --git a/drivers/usb/gadget/fastboot_lock_unlock.h b/drivers/usb/gadget/fastboot_lock_unlock.h
index 941e1be..e7ae544 100644
--- a/drivers/usb/gadget/fastboot_lock_unlock.h
+++ b/drivers/usb/gadget/fastboot_lock_unlock.h
@@ -41,28 +41,28 @@
#define DEBUG(format, ...)
#endif
-enum {
+typedef enum {
FASTBOOT_UNLOCK,
FASTBOOT_LOCK,
FASTBOOT_LOCK_ERROR,
FASTBOOT_LOCK_NUM
-};
+}FbLockState;
-enum {
+typedef enum {
FASTBOOT_UL_DISABLE,
FASTBOOT_UL_ENABLE,
FASTBOOT_UL_ERROR,
FASTBOOT_UL_NUM
-};
+}FbLockEnableResult;
-unsigned char fastboot_get_lock_stat(void);
+FbLockState fastboot_get_lock_stat(void);
-int fastboot_set_lock_stat(unsigned char lock);
+int fastboot_set_lock_stat(FbLockState lock);
int fastboot_wipe_data_partition(void);
-unsigned char fastboot_lock_enable(void);
+FbLockEnableResult fastboot_lock_enable(void);
-int display_lock(int lock, int verify);
+int display_lock(FbLockState lock, int verify);
#endif