From: Donggeun Kim Date: Thu, 2 Dec 2010 13:10:29 +0000 (+0900) Subject: fat: update overflow check function X-Git-Tag: v0.2~200 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25b969cc6b2e1489452b4486a458c6ee5078492c;p=kernel%2Fu-boot.git fat: update overflow check function Signed-off-by: Donggeun Kim --- diff --git a/common/cmd_usbd.c b/common/cmd_usbd.c index dc51621..5543985 100644 --- a/common/cmd_usbd.c +++ b/common/cmd_usbd.c @@ -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--; diff --git a/fs/fat/fat.c b/fs/fat/fat.c index d9044b2..05e3281 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -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) diff --git a/include/configs/s5pc210_universal.h b/include/configs/s5pc210_universal.h index a5f9bff..83bc7c4 100644 --- a/include/configs/s5pc210_universal.h +++ b/include/configs/s5pc210_universal.h @@ -164,6 +164,8 @@ #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 diff --git a/include/usbd.h b/include/usbd.h index 685921a..0452c3c 100644 --- a/include/usbd.h +++ b/include/usbd.h @@ -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 */