Commit 3afcb91c authored by Macpaul Lin's avatar Macpaul Lin Committed by Greg Kroah-Hartman

staging/gdm72xx: usb_boot: replace firmware upgrade API in em_download

Replace firmware upgrade API in em_download_image().
Signed-off-by: default avatarMacpaul Lin <macpaul@gmail.com>
Cc: Paul Stewart <pstew@chromium.org>
Cc: Ben Chan <benchan@chromium.org>
Cc: Sage Ahn <syahn@gctsemi.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d084610b
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
#define MAX_IMG_CNT 16 #define MAX_IMG_CNT 16
#define FW_DIR "gdm72xx/" #define FW_DIR "gdm72xx/"
#define FW_UIMG "gdmuimg.bin" #define FW_UIMG "gdmuimg.bin"
#define KERN_PATH "/lib/firmware/gdm72xx/zImage" #define FW_KERN "zImage"
#define FS_PATH "/lib/firmware/gdm72xx/ramdisk.jffs2" #define FW_FS "ramdisk.jffs2"
struct dn_header { struct dn_header {
u32 magic_num; u32 magic_num;
...@@ -276,38 +276,27 @@ static int em_wait_ack(struct usb_device *usbdev, int send_zlp) ...@@ -276,38 +276,27 @@ static int em_wait_ack(struct usb_device *usbdev, int send_zlp)
return ret; return ret;
} }
static int em_download_image(struct usb_device *usbdev, char *path, static int em_download_image(struct usb_device *usbdev, const char *img_name,
char *type_string) char *type_string)
{ {
struct file *filp;
struct inode *inode;
static mm_segment_t fs;
char *buf = NULL; char *buf = NULL;
loff_t pos = 0; loff_t pos = 0;
int ret = 0; int ret = 0;
int len, readn = 0; int len;
int img_len;
const struct firmware *firm;
#if defined(GDM7205_PADDING) #if defined(GDM7205_PADDING)
const int pad_size = GDM7205_PADDING; const int pad_size = GDM7205_PADDING;
#else #else
const int pad_size = 0; const int pad_size = 0;
#endif #endif
fs = get_fs(); ret = request_firmware(&firm, img_name, &usbdev->dev);
set_fs(get_ds()); if (ret < 0) {
printk(KERN_ERR
filp = filp_open(path, O_RDONLY | O_LARGEFILE, 0); "requesting firmware %s failed with error %d\n",
if (IS_ERR(filp)) { img_name, ret);
printk(KERN_ERR "Can't find %s.\n", path); return ret;
set_fs(fs);
ret = -ENOENT;
goto restore_fs;
}
inode = filp->f_dentry->d_inode;
if (!S_ISREG(inode->i_mode)) {
printk(KERN_ERR "Invalid file type: %s\n", path);
ret = -EINVAL;
goto out;
} }
buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL); buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL);
...@@ -321,18 +310,28 @@ static int em_download_image(struct usb_device *usbdev, char *path, ...@@ -321,18 +310,28 @@ static int em_download_image(struct usb_device *usbdev, char *path,
if (ret < 0) if (ret < 0)
goto out; goto out;
while ((len = filp->f_op->read(filp, buf+pad_size, DOWNLOAD_CHUCK, img_len = firm->size;
&pos))) {
if (len < 0) { if (img_len <= 0) {
ret = -1; ret = -1;
goto out; goto out;
} }
readn += len;
while (img_len > 0) {
if (img_len > DOWNLOAD_CHUCK)
len = DOWNLOAD_CHUCK;
else
len = img_len; /* the last chunk of data */
memcpy(buf+pad_size, firm->data + pos, len);
ret = gdm_wibro_send(usbdev, buf, len+pad_size); ret = gdm_wibro_send(usbdev, buf, len+pad_size);
if (ret < 0) if (ret < 0)
goto out; goto out;
img_len -= DOWNLOAD_CHUCK;
pos += DOWNLOAD_CHUCK;
ret = em_wait_ack(usbdev, ((len+pad_size) % 512 == 0)); ret = em_wait_ack(usbdev, ((len+pad_size) % 512 == 0));
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -343,11 +342,7 @@ static int em_download_image(struct usb_device *usbdev, char *path, ...@@ -343,11 +342,7 @@ static int em_download_image(struct usb_device *usbdev, char *path,
goto out; goto out;
out: out:
filp_close(filp, NULL); release_firmware(firm);
restore_fs:
set_fs(fs);
kfree(buf); kfree(buf);
return ret; return ret;
...@@ -365,18 +360,20 @@ static int em_fw_reset(struct usb_device *usbdev) ...@@ -365,18 +360,20 @@ static int em_fw_reset(struct usb_device *usbdev)
int usb_emergency(struct usb_device *usbdev) int usb_emergency(struct usb_device *usbdev)
{ {
int ret; int ret;
const char *kern_name = FW_DIR FW_KERN;
const char *fs_name = FW_DIR FW_FS;
ret = em_download_image(usbdev, KERN_PATH, KERNEL_TYPE_STRING); ret = em_download_image(usbdev, kern_name, KERNEL_TYPE_STRING);
if (ret < 0) if (ret < 0)
goto out; return ret;
printk(KERN_INFO "GCT Emergency: Kernel download success.\n"); printk(KERN_INFO "GCT Emergency: Kernel download success.\n");
ret = em_download_image(usbdev, FS_PATH, FS_TYPE_STRING); ret = em_download_image(usbdev, fs_name, FS_TYPE_STRING);
if (ret < 0) if (ret < 0)
goto out; return ret;
printk(KERN_INFO "GCT Emergency: Filesystem download success.\n"); printk(KERN_INFO "GCT Emergency: Filesystem download success.\n");
ret = em_fw_reset(usbdev); ret = em_fw_reset(usbdev);
out:
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment