]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - disk/part_iso.c
Remove CONFIG_SYS_BOOTCOUNT_SINGLEWORD
[people/ms/u-boot.git] / disk / part_iso.c
index b83983badf5b27d6532d79a055706f47c528488f..ef582de7a116e8d376ef38d08edd322fa1b35aa3 100644 (file)
@@ -7,9 +7,10 @@
 
 #include <common.h>
 #include <command.h>
+#include <asm/unaligned.h>
 #include "part_iso.h"
 
-#ifdef HAVE_BLOCK_DEVICE
+#ifdef CONFIG_HAVE_BLOCK_DEVICE
 
 /* #define     ISO_PART_DEBUG */
 
 #undef CHECK_FOR_POWERPC_PLATTFORM
 #define CD_SECTSIZE 2048
 
-static unsigned char tmpbuf[CD_SECTSIZE];
+static unsigned char tmpbuf[CD_SECTSIZE] __aligned(ARCH_DMA_MINALIGN);
 
-/* Convert char[4] in little endian format to the host format integer
- */
-static inline unsigned long le32_to_int(unsigned char *le32)
+unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start,
+                        lbaint_t blkcnt, void *buffer)
 {
-    return ((le32[3] << 24) +
-           (le32[2] << 16) +
-           (le32[1] << 8) +
-            le32[0]
-          );
-}
-/* Convert char[2] in little endian format to the host format integer
- */
-static inline unsigned short le16_to_int(unsigned char *le16)
-{
-    return ((le16[1] << 8) +
-          le16[0]
-          );
-}
+       unsigned long ret;
 
+       if (block_dev->blksz == 512) {
+               /* Convert from 2048 to 512 sector size */
+               start *= 4;
+               blkcnt *= 4;
+       }
+
+       ret = blk_dread(block_dev, start, blkcnt, buffer);
+
+       if (block_dev->blksz == 512)
+               ret /= 4;
+
+       return ret;
+}
 
 /* only boot records will be listed as valid partitions */
 int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
@@ -58,12 +58,12 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
        iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
        iso_init_def_entry_t *pide;
 
-       if (dev_desc->blksz != CD_SECTSIZE)
+       if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512))
                return -1;
 
        /* the first sector (sector 0x10) must be a primary volume desc */
        blkaddr=PVD_OFFSET;
-       if (blk_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
+       if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
                return -1;
        if(ppr->desctype!=0x01) {
                if(verb)
@@ -77,15 +77,13 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
                                ppr->stand_ident, dev_desc->devnum, part_num);
                return (-1);
        }
-       lastsect= ((ppr->firstsek_LEpathtab1_LE & 0x000000ff)<<24) +
-                 ((ppr->firstsek_LEpathtab1_LE & 0x0000ff00)<< 8) +
-                 ((ppr->firstsek_LEpathtab1_LE & 0x00ff0000)>> 8) +
-                 ((ppr->firstsek_LEpathtab1_LE & 0xff000000)>>24) ;
-       info->blksz=ppr->secsize_BE; /* assuming same block size for all entries */
+       lastsect = le32_to_cpu(ppr->firstsek_LEpathtab1_LE);
+       /* assuming same block size for all entries */
+       info->blksz = be16_to_cpu(ppr->secsize_BE);
        PRINTF(" Lastsect:%08lx\n",lastsect);
        for(i=blkaddr;i<lastsect;i++) {
                PRINTF("Reading block %d\n", i);
-               if (blk_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
+               if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
                        return -1;
                if(ppr->desctype==0x00)
                        break; /* boot entry found */
@@ -103,9 +101,9 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
                                pbr->ident_str, dev_desc->devnum, part_num);
                return (-1);
        }
-       bootaddr=le32_to_int(pbr->pointer);
+       bootaddr = get_unaligned_le32(pbr->pointer);
        PRINTF(" Boot Entry at: %08lX\n",bootaddr);
-       if (blk_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
+       if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
                if(verb)
                        printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
                                bootaddr, dev_desc->devnum, part_num);
@@ -114,7 +112,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
        chksum=0;
        chksumbuf = (unsigned short *)tmpbuf;
        for(i=0;i<0x10;i++)
-               chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8);
+               chksum += le16_to_cpu(chksumbuf[i]);
        if(chksum!=0) {
                if(verb)
                        printf("** Checksum Error in booting catalog validation entry on %d:%d **\n",
@@ -136,33 +134,10 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
        }
 #endif
        /* the validation entry seems to be ok, now search the "partition" */
-       entry_num=0;
+       entry_num=1;
        offset=0x20;
        strcpy((char *)info->type, "U-Boot");
-       switch(dev_desc->if_type) {
-               case IF_TYPE_IDE:
-               case IF_TYPE_SATA:
-               case IF_TYPE_ATAPI:
-                       sprintf ((char *)info->name, "hd%c%d",
-                               'a' + dev_desc->devnum, part_num);
-                       break;
-               case IF_TYPE_SCSI:
-                       sprintf ((char *)info->name, "sd%c%d",
-                               'a' + dev_desc->devnum, part_num);
-                       break;
-               case IF_TYPE_USB:
-                       sprintf ((char *)info->name, "usbd%c%d",
-                               'a' + dev_desc->devnum, part_num);
-                       break;
-               case IF_TYPE_DOC:
-                       sprintf ((char *)info->name, "docd%c%d",
-                               'a' + dev_desc->devnum, part_num);
-                       break;
-               default:
-                       sprintf ((char *)info->name, "xx%c%d",
-                               'a' + dev_desc->devnum, part_num);
-                       break;
-       }
+       part_set_generic_name(dev_desc, part_num, (char *)info->name);
        /* the bootcatalog (including validation Entry) is limited to 2048Bytes
         * (63 boot entries + validation entry) */
         while(offset<2048) {
@@ -203,7 +178,7 @@ found:
        }
        switch(pide->boot_media) {
                case 0x00: /* no emulation */
-                       info->size=le16_to_int(pide->sec_cnt)>>2;
+                       info->size = get_unaligned_le16(pide->sec_cnt)>>2;
                        break;
                case 0x01:      info->size=2400>>2; break; /* 1.2MByte Floppy */
                case 0x02:      info->size=2880>>2; break; /* 1.44MByte Floppy */
@@ -211,16 +186,23 @@ found:
                case 0x04:      info->size=2880>>2; break; /* dummy (HD Emulation) */
                default:        info->size=0; break;
        }
-       newblkaddr=le32_to_int(pide->rel_block_addr);
+       newblkaddr = get_unaligned_le32(pide->rel_block_addr);
        info->start=newblkaddr;
-       PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size);
+
+       if (dev_desc->blksz == 512) {
+               info->size *= 4;
+               info->start *= 4;
+               info->blksz = 512;
+       }
+
+       PRINTF(" part %d found @ %lx size %lx\n",part_num,info->start,info->size);
        return 0;
 }
 
 static int part_get_info_iso(struct blk_desc *dev_desc, int part_num,
                                  disk_partition_t *info)
 {
-       return part_get_info_iso_verb(dev_desc, part_num, info, 1);
+       return part_get_info_iso_verb(dev_desc, part_num, info, 0);
 }
 
 static void part_print_iso(struct blk_desc *dev_desc)
@@ -228,13 +210,13 @@ static void part_print_iso(struct blk_desc *dev_desc)
        disk_partition_t info;
        int i;
 
-       if (part_get_info_iso_verb(dev_desc, 0, &info, 0) == -1) {
+       if (part_get_info_iso_verb(dev_desc, 1, &info, 0) == -1) {
                printf("** No boot partition found on device %d **\n",
                       dev_desc->devnum);
                return;
        }
        printf("Part   Start     Sect x Size Type\n");
-       i=0;
+       i=1;
        do {
                printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n",
                       i, info.start, info.size, info.blksz, info.type);
@@ -246,12 +228,13 @@ static int part_test_iso(struct blk_desc *dev_desc)
 {
        disk_partition_t info;
 
-       return part_get_info_iso_verb(dev_desc, 0, &info, 0);
+       return part_get_info_iso_verb(dev_desc, 1, &info, 0);
 }
 
 U_BOOT_PART_TYPE(iso) = {
        .name           = "ISO",
        .part_type      = PART_TYPE_ISO,
+       .max_entries    = ISO_ENTRY_NUMBERS,
        .get_info       = part_get_info_iso,
        .print          = part_print_iso,
        .test           = part_test_iso,