summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/cmd_bootscan.c126
-rw-r--r--common/cmd_fat.c45
-rw-r--r--fs/fat/fat.c308
-rw-r--r--include/fat.h89
4 files changed, 538 insertions, 30 deletions
diff --git a/common/cmd_bootscan.c b/common/cmd_bootscan.c
index 68c65f8a66..1183fb1642 100644
--- a/common/cmd_bootscan.c
+++ b/common/cmd_bootscan.c
@@ -30,6 +30,8 @@
#define BOOTSCAN_DFLT_BOOTCMD CONFIG_BOOTCOMMAND
#define BOOTSCAN_ANDROID_BOOTCMD CONFIG_BOOTCOMMAND
#define BOOTSCAN_ANDROID_LABEL "Android"
+#define BOOTSCAN_ANDROID_SYSTEM "Android-Sys"
+#define BOOTSCAN_ANDROID_SYS_IMAGES "system_aa", ""
#define BOOTSCAN_ANDROID_BOOTSCR "boot.scr"
#define BOOTSCAN_BOOTBASEDIRS "/boot/", "/", ""
#define BOOTSCAN_BOOTIMAGES "zImage", "uImage", ""
@@ -60,6 +62,7 @@
#define BOOTSCAN_ROOT "bootscan_root"
#define BOOTSCAN_BANNER1 \
+"\n" \
" ___ _ _ _\n" \
" /___\\__| |_ __ ___ (_) __| |\n" \
" // // _` | '__/ _ \\| |/ _` |\n" \
@@ -72,6 +75,8 @@
" | || |_| || |_| | __) |\n" \
" |__ _|__ _| |/ __/\n" \
" |_| |_| |_|_____|\n"
+
+typedef enum { UNKNOWN, LINUX_ROOTFS, ANDROID_INSTALLER } rootfs_t;
/*
*
* bootimage is null string if no boot image found, or
@@ -81,8 +86,10 @@
* form. Example: mmcblk0p1 for mmc interface, 0 device, 1 partition.
* Another example would be sda1 for a usb or ide interface, first
* device and the first partition.
- * isrootfs specifies if this bootable is also contains the root filesystem
- * wrt linux. true implies yes it hosts a root file system.
+ * rootfs specifies if this bootable is also contains the root filesystem
+ * wrt linux. LINUX_ROOTFS implies it hosts a linux root file system.
+ * ANDROID_INSTALLER implies it hosts an Android installer image.
+ * In this case we also mark bootimage as BOOTSCAB_ANDROI_SYSTEM.
*/
struct bootscan_bootables {
char interface[5];
@@ -95,7 +102,7 @@ struct bootscan_bootables {
char bootini[64];
char fstype; /* 'e' => extXfs, 'f' => fat, '0' => invalid */
char chardev[16];
- int isrootfs;
+ rootfs_t rootfs;
};
/*
@@ -119,7 +126,7 @@ static void debug_print_bootlist(struct bootscan_bootables b[])
break;
printf("%d interface: %s device: %d partition: %d label: %s "
"uuid: %s bootimage: %s bootinitrd: %s bootini: %s "
- "fstype: %c chardev: %s isrootfs: %d\n",
+ "fstype: %c chardev: %s rootfs: %d\n",
i,
b[i].interface,
b[i].device,
@@ -131,7 +138,7 @@ static void debug_print_bootlist(struct bootscan_bootables b[])
b[i].bootini,
b[i].fstype,
b[i].chardev,
- b[i].isrootfs);
+ b[i].rootfs);
}
}
@@ -168,6 +175,7 @@ char savechar;
debug("line: %s\n", line);
/* and remove leading white spaces */
line = skip_spaces(line);
+ if (strlen(line) < 4) break;
/* Check if the character after "boot" is some white noice */
if ((line[4] < 33) || (line[4] > 126)) {
savechar = line[4];
@@ -336,7 +344,8 @@ static int is_android_partition(struct bootscan_bootables b)
debug("%s - b.fstype: %c b.bootimage: %s b.bootini: %s b.label: %s\n",
__func__, b.fstype, b.bootimage, b.bootini, b.label);
- if (strcmp(b.bootimage, BOOTSCAN_ANDROID_LABEL) == 0) {
+ if ( (strcmp(b.bootimage, BOOTSCAN_ANDROID_LABEL) == 0) ||
+ (strcmp(b.bootimage, BOOTSCAN_ANDROID_SYSTEM) == 0) ) {
debug("%s - its an Android partition\n", __func__);
return 1;
}
@@ -352,25 +361,30 @@ static int is_android_partition(struct bootscan_bootables b)
* In the new format, we just run the default bootcmd which we have as
* BOOTSCAN_ANDROID_BOOTCMD which is the default bootcmd of the system
* set as CONFIG_BOOTCOMMAND
+ * We do handle a new case when its an Android System installer.
+ * This is identified as .rootfs == ANDROID_INSTALLER
*/
static void run_android(struct bootscan_bootables b)
{
-#if 0
char command[128];
- sprintf(command, "fatload %s %d:%d %x %s",
- b.interface, b.device, b.partition,
- CONFIG_BOOTSCAN_SYS_LOAD_ADDR, b.bootini);
- debug("Issuing command: %s\n", command);
- if (run_command(command, 0) != 0) {
- /* Could not load boot.scr */
- printf("Error reading %s\n", b.bootini);
+ if (b.rootfs == ANDROID_INSTALLER) {
+ sprintf(command, "fatload %s %d:%d %x %s",
+ b.interface, b.device, b.partition,
+ CONFIG_BOOTSCAN_SYS_LOAD_ADDR, b.bootini);
+ debug("Issuing command: %s\n", command);
+ if (run_command(command, 0) != 0) {
+ /* Could not load boot.scr */
+ printf("Error reading %s\n", b.bootini);
+ return;
+ }
+ sprintf(command, "source %x", CONFIG_BOOTSCAN_SYS_LOAD_ADDR);
+ debug("Issuing command: %s\n", command);
+ run_command(command, 0);
+ /* This should not return */
return;
}
- sprintf(command, "source %x", CONFIG_BOOTSCAN_SYS_LOAD_ADDR);
- debug("Issuing command: %s\n", command);
- run_command(command, 0);
-#endif
+
run_command(BOOTSCAN_ANDROID_BOOTCMD, 0);
/* If we return here something wrong has happened and we
@@ -408,8 +422,14 @@ static int handle_choice(struct bootscan_bootables bootlist[], char *choice)
if (last_choice != NULL)
choice = last_choice;
else {
- /* Nothing here -> choose option 0 */
- choice = "0";
+ /* If nothing chosen and last choice is NULL */
+ /* But in the case there are no options we should */
+ /* choose '+' -> U-boot prompt */
+ if ( (bootlist[0].fstype == '\0') ||
+ (bootlist[0].fstype == '0') )
+ choice = "+";
+ else
+ choice = "0";
}
}
printf("\nYou chose:\n%s\n", choice);
@@ -730,13 +750,13 @@ static int bootscan_menu(struct bootscan_bootables bootlist[], int bootdelay)
for (j = 0; j < BOOTSCAN_MAX_BOOTABLES; j++) {
if (bootlist[j].fstype == '0')
break;
- if (bootlist[j].isrootfs == 0)
+ if (bootlist[j].rootfs == UNKNOWN)
continue;
/* We are here, we have a valid rootfs */
snprintf(menu_key[index], sizeof(menu_key[index]),
"%d", index);
generate_bid(bootlist[i], bid);
- if (bootlist[j].isrootfs) {
+ if (bootlist[j].rootfs != UNKNOWN) {
snprintf(menu_entry[index],
sizeof(menu_entry[index]),
"%d %-10.10s %-12.12s %-12.12s|"
@@ -846,20 +866,61 @@ static int check_for_file(struct bootscan_bootables bootlist[],
* So the new logic would be:
* 1. If fat partition and no kernel image assume its Android.
* returns 1 if Android is detected, 0 otherwise.
+ * Above does not work for an Android system image installer.
+ * They have a zImage, a boot.scr file and Android system installer files
+ * like system_aa etc.
+ * Hence newer logic:
+ * 1. Is a FAT partition
+ * 2. Has a Android system image like system_aa
+ * If 2. is true then its Android system installer. Special case.
+ * Here we also mark it as an installer image with rootfs
+ * set to ANDROIDSYSTEM.
+ * If 2 is not true but there exists a linux boot image (zImage) then
+ * its not an Android partition.
+ * If fall through here => Android partition.
+ *
*/
static int populate_android(struct bootscan_bootables bootlist[],
int *bootindex)
{
char *images[] = { BOOTSCAN_BOOTIMAGES };
- int findex = 0;
+ char *aimages[] = { BOOTSCAN_ANDROID_SYS_IMAGES };
+ char *inis[] = { BOOTSCAN_BOOTINIS };
+ int findex, bindex;
+ int isandroid = 0;
if (bootlist[*bootindex].fstype != 'f')
return 0;
/* It is a fat partition */
+ /* Lets check if there is an android system image */
+ findex = 0;
+ while (aimages[findex][0] != '\0') {
+ if (check_for_file(bootlist, bootindex, aimages[findex]) == 1) {
+ /* We hit on an Android system image install */
+ /* This should have a boot.ini or a boot.scr */
+ bindex = 0;
+ while (inis[bindex][0] != '\0') {
+ if (check_for_file(bootlist, bootindex,
+ inis[bindex]) == 1) {
+ /* We got the ini */
+ isandroid = 1;
+ bootlist[*bootindex].rootfs = ANDROID_INSTALLER;
+ strcpy(bootlist[*bootindex].bootini,
+ inis[bindex]);
+ break;
+ }
+ bindex++;
+ }
+ }
+ if (isandroid == 1)
+ break;
+ findex++;
+ }
/* Lets check if there is a linux image */
- while (images[findex][0] != '\0') {
+ findex = 0;
+ while ( (isandroid != 1) && (images[findex][0] != '\0') ) {
if (check_for_file(bootlist, bootindex, images[findex]) == 1) {
/* We hit on a linux image. Cant be Android! */
return 0;
@@ -867,11 +928,16 @@ static int populate_android(struct bootscan_bootables bootlist[],
findex++;
}
- /* We are here cause no linux images were found */
+ /* We are here cause no linux images were found or we found an */
+ /* Android system installer image */
/* Mark this as Android and return 1 */
/* Lets dummy mark the image file as Android */
- strcpy(bootlist[*bootindex].bootimage,
- BOOTSCAN_ANDROID_LABEL);
+ if (isandroid)
+ strcpy(bootlist[*bootindex].bootimage,
+ BOOTSCAN_ANDROID_SYSTEM);
+ else
+ strcpy(bootlist[*bootindex].bootimage,
+ BOOTSCAN_ANDROID_LABEL);
(*bootindex)++;
return 1;
@@ -897,7 +963,7 @@ static int populate_linux(struct bootscan_bootables bootlist[],
/* Lets check for a linux rootfs */
findex = 0;
- bootlist[*bootindex].isrootfs = 0;
+ bootlist[*bootindex].rootfs = UNKNOWN;
while (rootfs[findex][0] != '\0') {
/* rootfs[] already contains full path */
if (check_for_file(bootlist, bootindex,
@@ -906,7 +972,7 @@ static int populate_linux(struct bootscan_bootables bootlist[],
continue;
}
/* This contains the linux rootfs */
- bootlist[*bootindex].isrootfs = 1;
+ bootlist[*bootindex].rootfs = LINUX_ROOTFS;
break;
}
@@ -994,7 +1060,7 @@ static int populate_linux(struct bootscan_bootables bootlist[],
/*
* Handle the case when its only a rootfs. updated == 0.
*/
- if ((updated == 0) && (bootlist[*bootindex].isrootfs == 1)) {
+ if ((updated == 0) && (bootlist[*bootindex].rootfs == LINUX_ROOTFS)) {
(*bootindex)++;
if (*bootindex < BOOTSCAN_MAX_BOOTABLES) {
/* Prep next bootlist structure */
diff --git a/common/cmd_fat.c b/common/cmd_fat.c
index a12d8fa098..a32406c25a 100644
--- a/common/cmd_fat.c
+++ b/common/cmd_fat.c
@@ -131,3 +131,48 @@ U_BOOT_CMD(
" to 'dev' on 'interface'"
);
#endif
+
+int do_fat_format(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ int dev = 0;
+ int part = 1;
+ char *ep;
+ block_dev_desc_t *dev_desc = NULL;
+
+ if (argc < 2) {
+ printf ("usage : fatformat <interface> <dev[:part]>\n");
+ return(0);
+ }
+
+ dev = (int)simple_strtoul (argv[2], &ep, 16);
+ dev_desc = get_dev(argv[1], dev);
+
+ if (dev_desc == NULL) {
+ puts ("\n ** Invalid boot device **\n");
+ return 1;
+ }
+
+ if (*ep) {
+ if (*ep != ':') {
+ puts ("\n **Invald boot device,use 'dev[:part]'**\n");
+ return 1;
+ }
+ part = (int)simple_strtoul(++ep, NULL, 16);
+ if (part > 4 || part <1) {
+ puts ("** Partition Number should be 1 ~ 4 **\n");
+ }
+ }
+ printf("Start format MMC&d partition&d ...\n", dev, part);
+ if (fat_format_device(dev_desc, part) != 0) {
+ printf("Format failure!!!\n");
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ fatformat, 3, 0, do_fat_format,
+ "fatformat - disk format by FAT32\n",
+ "<interface(only support mmc)> <dev:partition num>\n"
+ " - format by FAT32 on 'interface'\n"
+);
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 492051b623..4501876789 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1261,3 +1261,311 @@ int fat_read_file(const char *filename, void *buf, int offset, int len)
void fat_close(void)
{
}
+
+/*
+ * Copy string, padding with spaces.
+ */
+static void
+setstr(u_int8_t *dest, const char *src, size_t len)
+{
+ while (len--)
+ *dest++ = *src ? *src++ : ' ';
+}
+
+static int write_pbr(block_dev_desc_t *dev_desc, disk_partition_t *info)
+{
+ struct bs *bs;
+ struct bsbpb *bsbpb;
+ struct bsxbpb *bsxbpb;
+ struct bsx *bsx;
+ __u8 *img;
+ int img_offset = 0;
+ int reserved_cnt= 0;
+ int i;
+ int fat_size = 0;
+
+ img = malloc(sizeof(__u8)*512);
+ if(img == NULL) {
+ printf("Can't make img buffer~~!!\n");
+ return -1;
+ }
+ memset(img, 0x0, sizeof(__u8)*512);
+
+
+ /* Erase Reserved Sector(PBR) */
+ for (i = 0;i < RESERVED_CNT; i++) {
+ if (dev_desc->block_write(dev_desc->dev, info->start + i,
+ 1, (ulong *)img) != 1) {
+ printf ("Can't erase reserved sector~~~!!!\n");
+ return -1;
+ }
+ }
+
+ /* Set bs */
+ bs = (struct bs *)img;
+ img_offset += sizeof(struct bs) - 1;
+
+ mk1(bs->jmp[0], 0xeb);
+ mk1(bs->jmp[1], 0x58);
+ mk1(bs->jmp[2], 0x90); /* Jump Boot Code */
+ setstr(bs->oem, "SAMSUNG", sizeof(bs->oem)); /* OEM Name */
+
+ uint spc;
+ /* Set bsbpb */
+ bsbpb = (struct bsbpb *)(img + img_offset);
+ img_offset += sizeof(struct bsbpb) - 2;
+
+ mk2(bsbpb->bps, 512); /* Byte Per Sector */
+
+ printf("size checking ...\n");
+ /* Sector Per Cluster */
+ if (info->size < 0x10000) { /* partition size >= 32Mb */
+ printf("Can't format less than 32Mb partition!!\n");
+ return -1;
+ }
+ if (info->size <= 0x20000) { /* under 64M -> 512 bytes */
+ printf("Under 64M\n");
+ mk1(bsbpb->spc, 1);
+ spc = 1;
+ }
+ else if (info->size <= 0x40000) { /* under 128M -> 1K */
+ printf("Under 128M\n");
+ mk1(bsbpb->spc, 2);
+ spc = 2;
+ }
+ else if (info->size <= 0x80000) { /* under 256M -> 2K */
+ printf("Under 256M\n");
+ mk1(bsbpb->spc, 4);
+ spc = 4;
+ }
+ else if (info->size <= 0xFA0000) { /* under 8G -> 4K */
+ printf("Under 8G\n");
+ mk1(bsbpb->spc, 8);
+ spc = 8;
+ }
+ else if (info->size <= 0x1F40000) { /* under 16G -> 8K */
+ printf("Under 16G\n");
+ mk1(bsbpb->spc, 16);
+ spc = 16;
+ }
+ else {
+ printf("16G~\n");
+ mk1(bsbpb->spc, 32);
+ spc = 32;
+ }
+
+ printf("write FAT info: %d\n",RESERVED_CNT);
+ mk2(bsbpb->res, RESERVED_CNT); /* Reserved Sector Count */
+ mk1(bsbpb->nft, 2); /* Number of FATs */
+ mk2(bsbpb->rde, 0); /* Root Directory Entry Count : It's no use in FAT32 */
+ mk2(bsbpb->sec, 0); /* Total Sector : It's no use in FAT32 */
+ mk1(bsbpb->mid, 0xF8); /* Media */
+ mk2(bsbpb->spf, 0); /* FAT Size 16 : It's no use in FAT32 */
+ mk2(bsbpb->spt, 0); /* Sector Per Track */
+ mk2(bsbpb->hds, 0); /* Number Of Heads */
+ mk4(bsbpb->hid, 0); /* Hidden Sector */
+ mk4(bsbpb->bsec, info->size); /* Total Sector For FAT32 */
+
+ /* Set bsxbpb */
+ bsxbpb = (struct bsxbpb *)(img + img_offset);
+ img_offset += sizeof(struct bsxbpb);
+
+ mk4(bsxbpb->bspf, (info->size / (spc * 128))); /* FAT Size 32 */
+ fat_size = info->size / (spc * 128);
+ printf("Fat size : 0x%x\n", info->size / (spc * 128));
+ mk2(bsxbpb->xflg, 0); /* Ext Flags */
+ mk2(bsxbpb->vers, 0); /* File System Version */
+ mk4(bsxbpb->rdcl, 2); /* Root Directory Cluster */
+ mk2(bsxbpb->infs, 1); /* File System Information */
+ mk2(bsxbpb->bkbs, 0); /* Boot Record Backup Sector */
+ /* Set bsx */
+ bsx = (struct bsx *)(img + img_offset);
+ mk1(bsx->drv, 0); /* Drive Number */
+ mk1(bsx->sig, 0x29); /* Boot Signature */
+ mk4(bsx->volid, 0x3333); /* Volume ID : 0x3333 means nothing */
+ setstr(bsx->label, "NO NAME ", sizeof(bsx->label)); /* Volume Label */
+ setstr(bsx->type, "FAT32", sizeof(bsx->type)); /* File System Type */
+
+ /* Set Magic Number */
+ mk2(img + BYTE_PER_SEC - 2, 0xaa55); /* Signature */
+
+/*
+ printf("Print Boot Recode\n");
+ for(i = 0;i<512;i++) {
+ if(img[i] == 0)
+ printf("00 ");
+ else
+ printf("%2x ", img[i]);
+ if (!((i+1) % 16))
+ printf("\n");
+ }
+*/
+
+ if (dev_desc->block_write(dev_desc->dev, info->start,
+ 1, (ulong *)img) != 1) {
+ printf ("Can't write PBR~~~!!!\n");
+ return -1;
+ }
+
+ return fat_size;
+}
+
+static int write_reserved(block_dev_desc_t *dev_desc, disk_partition_t *info)
+{
+ /* Set Reserved Region */
+ __u8 *img;
+ int i;
+ img = malloc(sizeof(__u8)*512);
+ if(img == NULL) {
+ printf("Can't make img buffer~~(reserved)!!\n");
+ return -1;
+ }
+
+ memset(img, 0x0, sizeof(__u8)*512);
+
+ mk4(img, 0x41615252); /* Lead Signature */
+ mk4(img + BYTE_PER_SEC - 28, 0x61417272); /* Struct Signature */
+ mk4(img + BYTE_PER_SEC - 24, 0xffffffff); /* Free Cluster Count */
+ mk4(img + BYTE_PER_SEC - 20, 0x3); /* Next Free Cluster */
+ mk2(img + BYTE_PER_SEC - 2, 0xaa55); /* Trail Signature */
+
+ /* Write Reserved region */
+ if (dev_desc->block_write(dev_desc->dev, info->start+1,
+ 1, (ulong *)img) != 1) {
+ printf ("Can't write reserved region~~~!!!\n");
+ return -1;
+ }
+
+ return 1;
+}
+
+static int write_fat(block_dev_desc_t *dev_desc, disk_partition_t *info, int
+fat_size)
+{
+ __u8 *dummy;
+ __u8 *img;
+ int i;
+
+ /* Create buffer for FAT */
+ img = malloc(sizeof(__u8)*512);
+ if(img == NULL) {
+ printf("Can't make img buffer~~!!\n");
+ return -1;
+ }
+ memset(img, 0x0, sizeof(__u8) * 512);
+
+ /* Create buffer for erase */
+ dummy = malloc(sizeof(__u8) * 8192);
+ if(dummy == NULL) {
+ printf("Can't make dummy buffer~~!!\n");
+ return -1;
+ }
+ memset(dummy, 0x0, sizeof(__u8) * 8192);
+
+ /* Erase FAT Region */
+ int erase_block_cnt = (fat_size * 2);
+ int temp = 0;
+ printf("Erase FAT region");
+ for (i = 0;i < erase_block_cnt + 10; i+=16) {
+ if (dev_desc->block_write(dev_desc->dev, info->start +
+ RESERVED_CNT + i, 16, (ulong *)dummy) != 16) {
+ printf ("Can't erase FAT region~~!!!\n");
+ }
+ if((i % 160) == 0)
+ printf(".");
+
+ }
+ printf("\n");
+
+ mk4(img, 0x0ffffff8);
+ mk4(img+4, 0x0fffffff);
+ mk4(img+8, 0x0fffffff); /* Root Directory */
+ /* Write FAT Region */
+ if (dev_desc->block_write(dev_desc->dev, info->start + RESERVED_CNT,
+ 1, (ulong *)img) != 1) {
+ printf ("Can't write FAT~~~!!!\n");
+ return -1;
+ }
+
+ return 1;
+}
+
+/*
+ * Make a volume label.
+ */
+
+static void
+mklabel(u_int8_t *dest, const char *src)
+{
+ int c, i;
+
+ for (i = 0; i < 11; i++) {
+ c = *src ? __toupper(*src++) : ' ';
+ *dest++ = !i && c == '\xe5' ? 5 : c;
+ }
+}
+
+
+/*
+ * * Format device
+ * */
+int
+fat_format_device(block_dev_desc_t *dev_desc, int part_no)
+{
+ unsigned char buffer[SECTOR_SIZE];
+ unsigned long part_offset;
+ int cur_part;
+ disk_partition_t info;
+
+ if (!dev_desc->block_read)
+ return -1;
+ cur_dev = dev_desc;
+ /* check if we have a MBR (on floppies we have only a PBR) */
+ if (dev_desc->block_read (dev_desc->dev, 0,
+ 1, (ulong *) buffer) != 1) {
+ printf ("** Can't read from device %d **\n", dev_desc->dev);
+ return -1;
+ }
+ if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
+ buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) {
+ printf("** MBR is broken **\n");
+ /* no signature found */
+ return -1;
+ }
+
+#if (defined(CONFIG_CMD_IDE) || \
+ defined(CONFIG_CMD_SCSI) || \
+ defined(CONFIG_CMD_USB) || \
+ defined(CONFIG_MMC) || \
+ defined(CONFIG_SYSTEMACE) )
+ /* First we assume, there is a MBR */
+ if (!get_partition_info (dev_desc, part_no, &info)) {
+ part_offset = info.start;
+ cur_part = part_no;
+ } else if (!strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3)) {
+ /* ok, we assume we are on a PBR only */
+ cur_part = 1;
+ part_offset = 0;
+ } else {
+ printf ("** Partition %d not valid on device %d **\n",
+ part_no, dev_desc->dev);
+ return -1;
+ }
+#endif
+
+ printf("Partition%d: Start Address(0x%x), Size(0x%x)\n",
+ part_no, info.start, info.size);
+
+ int fat_size;
+ fat_size = write_pbr(dev_desc, &info);
+ if(fat_size < 0)
+ return -1;
+ if(write_reserved(dev_desc, &info) < 0)
+ return -1;
+ if(write_fat(dev_desc, &info, fat_size) < 0)
+ return -1;
+ printf("Partition%d format complete.\n", part_no);
+
+ return 0;
+}
+
diff --git a/include/fat.h b/include/fat.h
index 2c951e7d79..a099f531ca 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -29,6 +29,13 @@
#define FAT16BUFSIZE (FATBUFSIZE/2)
#define FAT32BUFSIZE (FATBUFSIZE/4)
+#define SECTOR_SIZE 512
+#define BYTE_PER_SEC 512
+#define RESERVED_CNT 32
+#define DOS_PART_TBL_OFFSET 0x1be
+#define DOS_PART_MAGIC_OFFSET 0x1fe
+#define DOS_FS_TYPE_OFFSET 0x36
+#define DOS_FS32_TYPE_OFFSET 0x52
/* Filesystem identifiers */
#define FAT12_SIGN "FAT12 "
@@ -87,6 +94,88 @@
#define CHECK_CLUST(x, fatsize) ((x) <= 1 || \
(x) >= ((fatsize) != 32 ? 0xfff0 : 0xffffff0))
+#define mk1(p, x) \
+ (p) = (__u8)(x)
+
+#define mk2(p, x) \
+ (p)[0] = (__u8)(x), \
+ (p)[1] = (__u8)((x) >> 010)
+
+#define mk4(p, x) \
+ (p)[0] = (__u8)(x), \
+ (p)[1] = (__u8)((x) >> 010), \
+ (p)[2] = (__u8)((x) >> 020), \
+ (p)[3] = (__u8)((x) >> 030)
+
+struct bs {
+ __u8 jmp[3]; /* bootstrap entry point */
+ __u8 oem[9]; /* OEM name and version */
+};
+
+struct bsbpb {
+ __u8 bps[2]; /* bytes per sector */
+ __u8 spc; /* sectors per cluster */
+ __u8 res[2]; /* reserved sectors */
+ __u8 nft; /* number of FATs */
+ __u8 rde[2]; /* root directory entries */
+ __u8 sec[2]; /* total sectors */
+ __u8 mid; /* media descriptor */
+ __u8 spf[2]; /* sectors per FAT */
+ __u8 spt[2]; /* sectors per track */
+ __u8 hds[2]; /* drive heads */
+ __u8 hid[4]; /* hidden sectors */
+ __u8 bsec[6]; /* big total sectors */
+};
+
+/* For FAT32 */
+struct bsxbpb {
+ __u8 bspf[4]; /* big sectors per FAT */
+ __u8 xflg[2]; /* FAT control flags */
+ __u8 vers[2]; /* file system version */
+ __u8 rdcl[4]; /* root directory start cluster */
+ __u8 infs[2]; /* file system info sector */
+ __u8 bkbs[2]; /* backup boot sector */
+ __u8 rsvd[12]; /* reserved */
+};
+
+struct bsx {
+ __u8 drv; /* drive number */
+ __u8 rsvd; /* reserved */
+ __u8 sig; /* extended boot signature */
+ __u8 volid[4]; /* volume ID number */
+ __u8 label[11]; /* volume label */
+ __u8 type[8]; /* file system type */
+};
+
+struct de {
+ __u8 namext[11]; /* name and extension */
+ __u8 attr; /* attributes */
+ __u8 rsvd[10]; /* reserved */
+ __u8 time[2]; /* creation time */
+ __u8 date[2]; /* creation date */
+ __u8 clus[2]; /* starting cluster */
+ __u8 size[4]; /* size */
+};
+
+struct bpb {
+ __u32 bps; /* bytes per sector */
+ __u32 spc; /* sectors per cluster */
+ __u32 res; /* reserved sectors */
+ __u32 nft; /* number of FATs */
+ __u32 rde; /* root directory entries */
+ __u32 sec; /* total sectors */
+ __u32 mid; /* media descriptor */
+ __u32 spf; /* sectors per FAT */
+ __u32 spt; /* sectors per track */
+ __u32 hds; /* drive heads */
+ __u32 hid; /* hidden sectors */
+ __u32 bsec; /* big total sectors */
+ __u32 bspf; /* big sectors per FAT */
+ __u32 rdcl; /* root directory start cluster */
+ __u32 infs; /* file system info sector */
+ __u32 bkbs; /* backup boot sector */
+};
+
typedef struct boot_sector {
__u8 ignored[3]; /* Bootstrap code */
char system_id[8]; /* Name of fs */