fat: update overflow check function
authorDonggeun Kim <dg77.kim@samsung.com>
Thu, 2 Dec 2010 13:10:29 +0000 (22:10 +0900)
committerDonggeun Kim <dg77.kim@samsung.com>
Thu, 2 Dec 2010 13:10:29 +0000 (22:10 +0900)
Signed-off-by: Donggeun Kim <dg77.kim@samsung.com>
common/cmd_usbd.c
fs/fat/fat.c
include/configs/s5pc210_universal.h
include/usbd.h

index dc51621..5543985 100644 (file)
@@ -828,6 +828,8 @@ static int process_data(struct usbd_ops *usbd)
        int ubi_mode = 0;
        int img_type;
 
+       block_dev_desc_t *block_dev;
+
        sprintf(ramaddr, "0x%x", (uint) down_ram_addr);
 
        /* Parse command */
@@ -997,16 +999,16 @@ static int process_data(struct usbd_ops *usbd)
        case COMMAND_WRITE_IMG_2:
                printf("COMMAND_WRITE_KERNEL\n");
                /* TODO: Not support yet, just return */
-               *((ulong *) usbd->tx_data) = STATUS_DONE;
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
-               return 1;
+               img_type = IMG_KERNEL_V2;
+               part_id = 2;
+               break;
 
        case COMMAND_WRITE_IMG_3:
                printf("COMMAND_WRITE_MODEM\n");
                /* TODO: Not support yet, just return */
-               *((ulong *) usbd->tx_data) = STATUS_DONE;
-               usbd->send_data(usbd->tx_data, usbd->tx_len);
-               return 1;
+               img_type = IMG_MODEM_V2;
+               part_id = 2;
+               break;
 
        case COMMAND_WRITE_IMG_4:
                printf("COMMAND_WRITE_BOOT_PART\n");
@@ -1324,6 +1326,56 @@ out:
 #endif
                break;
 
+       case IMG_KERNEL_V2:
+               if (!block_dev)
+                       block_dev = mmc_get_dev(0);
+
+               if (!block_dev) {
+                       printf("no mmc block dev\n");
+                       ret = 0;
+                       break;
+               }
+
+               ret = fat_register_device(block_dev, part_id);
+               if (ret < 0) {
+                       printf("error : fat_register_divce\n");
+                       ret = 0;
+                       break;
+               }
+
+               ret = file_fat_write("uImage", down_ram_addr, len);
+               if (ret < 0) {
+                       printf("error : writing uImage\n");
+                       ret = 0;
+                       break;
+               }
+               break;
+
+       case IMG_MODEM_V2:
+               if (!block_dev)
+                       block_dev = mmc_get_dev(0);
+
+               if (!block_dev) {
+                       printf("no mmc block dev\n");
+                       ret = 0;
+                       break;
+               }
+
+               ret = fat_register_device(block_dev, part_id);
+               if (ret < 0) {
+                       printf("error : fat_register_divce\n");
+                       ret = 0;
+                       break;
+               }
+
+               ret = file_fat_write("modem.bin", down_ram_addr, len);
+               if (ret < 0) {
+                       printf("error : writing modem.bin\n");
+                       ret = 0;
+                       break;
+               }
+               break;
+
        default:
                /* Retry? */
                write_part--;
index d9044b2..05e3281 100644 (file)
@@ -57,6 +57,7 @@ static void uppercase (char *str, int len)
 static block_dev_desc_t *cur_dev = NULL;
 
 static unsigned long part_offset = 0;
+static unsigned long next_part_offset = 0;
 
 static int cur_part = 1;
 
@@ -133,6 +134,9 @@ int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
        if (!get_partition_info(dev_desc, part_no, &info)) {
                part_offset = info.start;
                cur_part = part_no;
+
+               if (!get_partition_info(dev_desc, part_no + 1, &info))
+                       next_part_offset = info.start;
        } else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
                   (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
                /* ok, we assume we are on a PBR only */
@@ -1502,7 +1506,7 @@ set_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
  */
 static int find_empty_cluster(fsdata *mydata)
 {
-       __u32 fat_val, entry = 2;
+       __u32 fat_val, entry = 3;
 
        while (1) {
                fat_val = get_fatent(mydata, entry);
@@ -1595,7 +1599,10 @@ set_contents (fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
                gotsize += actsize;
 
                /* Mark end of file in FAT */
-               newclust = 0xfffffff;
+               if (mydata->fatsize == 16)
+                       newclust = 0xffff;
+               else if (mydata->fatsize == 32)
+                       newclust = 0xfffffff;
                set_fatent_value(mydata, endclust, newclust);
 
                return gotsize;
@@ -1680,6 +1687,10 @@ static int do_fat_write (const char *filename, void *buffer,
                return 0;
        }
 
+       if (total_sector == 0) {
+               total_sector = next_part_offset - part_offset;
+       }
+
        root_cluster = bs.root_cluster;
 
        if (mydata->fatsize == 32)
index a5f9bff..83bc7c4 100644 (file)
 #define CONFIG_UBIFS_MK
 #define CONFIG_UBINIZE
 
+#define CONFIG_FAT_WRITE
+
 /* To use the TFTPBOOT over USB, Please enable the CONFIG_CMD_NET */
 #undef CONFIG_CMD_NET
 
index 685921a..0452c3c 100644 (file)
@@ -39,6 +39,8 @@ enum {
        IMG_V2,
        IMG_MBR,
        IMG_BOOTLOADER, /* bootloader on mmc raw sector */
+       IMG_KERNEL_V2,
+       IMG_MODEM_V2,
 };
 
 /* Download command definition */