diff options
author | H. Nikolaus Schaller <hns@goldelico.com> | 2012-03-26 20:55:28 +0200 |
---|---|---|
committer | H. Nikolaus Schaller <hns@goldelico.com> | 2012-03-26 20:55:28 +0200 |
commit | 92988a21ad4c4c9504295ccb580c9f806134471b (patch) | |
tree | 5effc9f14170112450de05c67dafbe8d5034d595 /disk | |
parent | ca2b506783b676c95762c54ea24dcfdaae1947c9 (diff) | |
download | bootable_bootloader_goldelico_gta04-92988a21ad4c4c9504295ccb580c9f806134471b.zip bootable_bootloader_goldelico_gta04-92988a21ad4c4c9504295ccb580c9f806134471b.tar.gz bootable_bootloader_goldelico_gta04-92988a21ad4c4c9504295ccb580c9f806134471b.tar.bz2 |
added boot script files to repository
Diffstat (limited to 'disk')
-rw-r--r-- | disk/Makefile | 53 | ||||
-rw-r--r-- | disk/part.c | 438 | ||||
-rw-r--r-- | disk/part_amiga.c | 403 | ||||
-rw-r--r-- | disk/part_amiga.h | 157 | ||||
-rw-r--r-- | disk/part_dos.c | 262 | ||||
-rw-r--r-- | disk/part_dos.h | 56 | ||||
-rw-r--r-- | disk/part_efi.c | 428 | ||||
-rw-r--r-- | disk/part_efi.h | 138 | ||||
-rw-r--r-- | disk/part_iso.c | 268 | ||||
-rw-r--r-- | disk/part_iso.h | 160 | ||||
-rw-r--r-- | disk/part_mac.c | 256 | ||||
-rw-r--r-- | disk/part_mac.h | 99 |
12 files changed, 0 insertions, 2718 deletions
diff --git a/disk/Makefile b/disk/Makefile deleted file mode 100644 index 17266a2..0000000 --- a/disk/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# (C) Copyright 2000-2006 -# Wolfgang Denk, DENX Software Engineering, wd@denx.de. -# -# See file CREDITS for list of people who contributed to this -# project. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of -# the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307 USA -# - -include $(TOPDIR)/config.mk - -#CFLAGS += -DET_DEBUG -DDEBUG - -LIB = $(obj)libdisk.o - -COBJS-y += part.o -COBJS-$(CONFIG_MAC_PARTITION) += part_mac.o -COBJS-$(CONFIG_DOS_PARTITION) += part_dos.o -COBJS-$(CONFIG_ISO_PARTITION) += part_iso.o -COBJS-$(CONFIG_AMIGA_PARTITION) += part_amiga.o -COBJS-$(CONFIG_EFI_PARTITION) += part_efi.o - -COBJS := $(COBJS-y) -SRCS := $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(COBJS)) - -all: $(LIB) - -$(LIB): $(obj).depend $(OBJS) - $(call cmd_link_o_target, $(OBJS)) - -######################################################################### - -# defines $(obj).depend target -include $(SRCTREE)/rules.mk - -sinclude $(obj).depend - -######################################################################### diff --git a/disk/part.c b/disk/part.c deleted file mode 100644 index 13723f2..0000000 --- a/disk/part.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - * (C) Copyright 2001 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include <common.h> -#include <command.h> -#include <ide.h> -#include <part.h> - -#undef PART_DEBUG - -#ifdef PART_DEBUG -#define PRINTF(fmt,args...) printf (fmt ,##args) -#else -#define PRINTF(fmt,args...) -#endif - -#if (defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) ) - -struct block_drvr { - char *name; - block_dev_desc_t* (*get_dev)(int dev); -}; - -static const struct block_drvr block_drvr[] = { -#if defined(CONFIG_CMD_IDE) - { .name = "ide", .get_dev = ide_get_dev, }, -#endif -#if defined(CONFIG_CMD_SATA) - {.name = "sata", .get_dev = sata_get_dev, }, -#endif -#if defined(CONFIG_CMD_SCSI) - { .name = "scsi", .get_dev = scsi_get_dev, }, -#endif -#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) - { .name = "usb", .get_dev = usb_stor_get_dev, }, -#endif -#if defined(CONFIG_MMC) - { .name = "mmc", .get_dev = mmc_get_dev, }, -#endif -#if defined(CONFIG_SYSTEMACE) - { .name = "ace", .get_dev = systemace_get_dev, }, -#endif -#if defined(CONFIG_CMD_MG_DISK) - { .name = "mgd", .get_dev = mg_disk_get_dev, }, -#endif - { }, -}; - -DECLARE_GLOBAL_DATA_PTR; - -block_dev_desc_t *get_dev(char* ifname, int dev) -{ - const struct block_drvr *drvr = block_drvr; - block_dev_desc_t* (*reloc_get_dev)(int dev); - char *name; - - name = drvr->name; -#ifdef CONFIG_NEEDS_MANUAL_RELOC - name += gd->reloc_off; -#endif - while (name) { - name = drvr->name; - reloc_get_dev = drvr->get_dev; -#ifdef CONFIG_NEEDS_MANUAL_RELOC - name += gd->reloc_off; - reloc_get_dev += gd->reloc_off; -#endif - if (strncmp(ifname, name, strlen(name)) == 0) - return reloc_get_dev(dev); - drvr++; - } - return NULL; -} -#else -block_dev_desc_t *get_dev(char* ifname, int dev) -{ - return NULL; -} -#endif - -#if (defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) ) - -/* ------------------------------------------------------------------------- */ -/* - * reports device info to the user - */ - -#ifdef CONFIG_LBA48 -typedef uint64_t lba512_t; -#else -typedef lbaint_t lba512_t; -#endif - -/* - * Overflowless variant of (block_count * mul_by / div_by) - * when div_by > mul_by - */ -static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by) -{ - lba512_t bc_quot, bc_rem; - - /* x * m / d == x / d * m + (x % d) * m / d */ - bc_quot = block_count / div_by; - bc_rem = block_count - div_by * bc_quot; - return bc_quot * mul_by + (bc_rem * mul_by) / div_by; -} - -void dev_print (block_dev_desc_t *dev_desc) -{ - lba512_t lba512; /* number of blocks if 512bytes block size */ - - if (dev_desc->type == DEV_TYPE_UNKNOWN) { - puts ("not available\n"); - return; - } - - switch (dev_desc->if_type) { - case IF_TYPE_SCSI: - printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", - dev_desc->target,dev_desc->lun, - dev_desc->vendor, - dev_desc->product, - dev_desc->revision); - break; - case IF_TYPE_ATAPI: - case IF_TYPE_IDE: - case IF_TYPE_SATA: - printf ("Model: %s Firm: %s Ser#: %s\n", - dev_desc->vendor, - dev_desc->revision, - dev_desc->product); - break; - case IF_TYPE_SD: - case IF_TYPE_MMC: - case IF_TYPE_USB: - printf ("Vendor: %s Rev: %s Prod: %s\n", - dev_desc->vendor, - dev_desc->revision, - dev_desc->product); - break; - case IF_TYPE_DOC: - puts("device type DOC\n"); - return; - case IF_TYPE_UNKNOWN: - puts("device type unknown\n"); - return; - default: - printf("Unhandled device type: %i\n", dev_desc->if_type); - return; - } - puts (" Type: "); - if (dev_desc->removable) - puts ("Removable "); - switch (dev_desc->type & 0x1F) { - case DEV_TYPE_HARDDISK: - puts ("Hard Disk"); - break; - case DEV_TYPE_CDROM: - puts ("CD ROM"); - break; - case DEV_TYPE_OPDISK: - puts ("Optical Device"); - break; - case DEV_TYPE_TAPE: - puts ("Tape"); - break; - default: - printf ("# %02X #", dev_desc->type & 0x1F); - break; - } - puts ("\n"); - if ((dev_desc->lba * dev_desc->blksz)>0L) { - ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; - lbaint_t lba; - - lba = dev_desc->lba; - - lba512 = (lba * (dev_desc->blksz/512)); - /* round to 1 digit */ - mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */ - - mb_quot = mb / 10; - mb_rem = mb - (10 * mb_quot); - - gb = mb / 1024; - gb_quot = gb / 10; - gb_rem = gb - (10 * gb_quot); -#ifdef CONFIG_LBA48 - if (dev_desc->lba48) - printf (" Supports 48-bit addressing\n"); -#endif -#if defined(CONFIG_SYS_64BIT_LBA) - printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n", - mb_quot, mb_rem, - gb_quot, gb_rem, - lba, - dev_desc->blksz); -#else - printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%ld x %ld)\n", - mb_quot, mb_rem, - gb_quot, gb_rem, - (ulong)lba, - dev_desc->blksz); -#endif - } else { - puts (" Capacity: not available\n"); - } -} -#endif - -#if (defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) ) - -#if defined(CONFIG_MAC_PARTITION) || \ - defined(CONFIG_DOS_PARTITION) || \ - defined(CONFIG_ISO_PARTITION) || \ - defined(CONFIG_AMIGA_PARTITION) || \ - defined(CONFIG_EFI_PARTITION) - -void init_part (block_dev_desc_t * dev_desc) -{ -#ifdef CONFIG_ISO_PARTITION - if (test_part_iso(dev_desc) == 0) { - dev_desc->part_type = PART_TYPE_ISO; - return; - } -#endif - -#ifdef CONFIG_MAC_PARTITION - if (test_part_mac(dev_desc) == 0) { - dev_desc->part_type = PART_TYPE_MAC; - return; - } -#endif - -/* must be placed before DOS partition detection */ -#ifdef CONFIG_EFI_PARTITION - if (test_part_efi(dev_desc) == 0) { - dev_desc->part_type = PART_TYPE_EFI; - return; - } -#endif - -#ifdef CONFIG_DOS_PARTITION - if (test_part_dos(dev_desc) == 0) { - dev_desc->part_type = PART_TYPE_DOS; - return; - } -#endif - -#ifdef CONFIG_AMIGA_PARTITION - if (test_part_amiga(dev_desc) == 0) { - dev_desc->part_type = PART_TYPE_AMIGA; - return; - } -#endif -} - - -int get_partition_info (block_dev_desc_t *dev_desc, int part - , disk_partition_t *info) -{ - switch (dev_desc->part_type) { -#ifdef CONFIG_MAC_PARTITION - case PART_TYPE_MAC: - if (get_partition_info_mac(dev_desc,part,info) == 0) { - PRINTF ("## Valid MAC partition found ##\n"); - return (0); - } - break; -#endif - -#ifdef CONFIG_DOS_PARTITION - case PART_TYPE_DOS: - if (get_partition_info_dos(dev_desc,part,info) == 0) { - PRINTF ("## Valid DOS partition found ##\n"); - return (0); - } - break; -#endif - -#ifdef CONFIG_ISO_PARTITION - case PART_TYPE_ISO: - if (get_partition_info_iso(dev_desc,part,info) == 0) { - PRINTF ("## Valid ISO boot partition found ##\n"); - return (0); - } - break; -#endif - -#ifdef CONFIG_AMIGA_PARTITION - case PART_TYPE_AMIGA: - if (get_partition_info_amiga(dev_desc, part, info) == 0) - { - PRINTF ("## Valid Amiga partition found ##\n"); - return (0); - } - break; -#endif - -#ifdef CONFIG_EFI_PARTITION - case PART_TYPE_EFI: - if (get_partition_info_efi(dev_desc,part,info) == 0) { - PRINTF ("## Valid EFI partition found ##\n"); - return (0); - } - break; -#endif - default: - break; - } - return (-1); -} - -static void print_part_header (const char *type, block_dev_desc_t * dev_desc) -{ - puts ("\nPartition Map for "); - switch (dev_desc->if_type) { - case IF_TYPE_IDE: - puts ("IDE"); - break; - case IF_TYPE_SATA: - puts ("SATA"); - break; - case IF_TYPE_SCSI: - puts ("SCSI"); - break; - case IF_TYPE_ATAPI: - puts ("ATAPI"); - break; - case IF_TYPE_USB: - puts ("USB"); - break; - case IF_TYPE_DOC: - puts ("DOC"); - break; - case IF_TYPE_MMC: - puts ("MMC"); - break; - default: - puts ("UNKNOWN"); - break; - } - printf (" device %d -- Partition Type: %s\n\n", - dev_desc->dev, type); -} - -void print_part (block_dev_desc_t * dev_desc) -{ - - switch (dev_desc->part_type) { -#ifdef CONFIG_MAC_PARTITION - case PART_TYPE_MAC: - PRINTF ("## Testing for valid MAC partition ##\n"); - print_part_header ("MAC", dev_desc); - print_part_mac (dev_desc); - return; -#endif -#ifdef CONFIG_DOS_PARTITION - case PART_TYPE_DOS: - PRINTF ("## Testing for valid DOS partition ##\n"); - print_part_header ("DOS", dev_desc); - print_part_dos (dev_desc); - return; -#endif - -#ifdef CONFIG_ISO_PARTITION - case PART_TYPE_ISO: - PRINTF ("## Testing for valid ISO Boot partition ##\n"); - print_part_header ("ISO", dev_desc); - print_part_iso (dev_desc); - return; -#endif - -#ifdef CONFIG_AMIGA_PARTITION - case PART_TYPE_AMIGA: - PRINTF ("## Testing for a valid Amiga partition ##\n"); - print_part_header ("AMIGA", dev_desc); - print_part_amiga (dev_desc); - return; -#endif - -#ifdef CONFIG_EFI_PARTITION - case PART_TYPE_EFI: - PRINTF ("## Testing for valid EFI partition ##\n"); - print_part_header ("EFI", dev_desc); - print_part_efi (dev_desc); - return; -#endif - } - puts ("## Unknown partition table\n"); -} - - -#else /* neither MAC nor DOS nor ISO nor AMIGA nor EFI partition configured */ -# error neither CONFIG_MAC_PARTITION nor CONFIG_DOS_PARTITION -# error nor CONFIG_ISO_PARTITION nor CONFIG_AMIGA_PARTITION -# error nor CONFIG_EFI_PARTITION configured! -#endif - -#endif diff --git a/disk/part_amiga.c b/disk/part_amiga.c deleted file mode 100644 index 50efe39..0000000 --- a/disk/part_amiga.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * (C) Copyright 2001 - * Hans-Joerg Frieden, Hyperion Entertainment - * Hans-JoergF@hyperion-entertainment.com - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ -#include <common.h> -#include <command.h> -#include <ide.h> -#include "part_amiga.h" - -#if defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) - -#undef AMIGA_DEBUG - -#ifdef AMIGA_DEBUG -#define PRINTF(fmt, args...) printf(fmt ,##args) -#else -#define PRINTF(fmt, args...) -#endif - -struct block_header -{ - u32 id; - u32 summed_longs; - s32 chk_sum; -}; - -static unsigned char block_buffer[DEFAULT_SECTOR_SIZE]; -static struct rigid_disk_block rdb = {0}; -static struct bootcode_block bootcode = {0}; - -/* - * Copy a bcpl to a c string - */ -static void bcpl_strcpy(char *to, char *from) -{ - int len = *from++; - - while (len) - { - *to++ = *from++; - len--; - } - *to = 0; -} - -/* - * Print a BCPL String. BCPL strings start with a byte with the length - * of the string, and don't contain a terminating nul character - */ -static void bstr_print(char *string) -{ - int len = *string++; - char buffer[256]; - int i; - - i = 0; - while (len) - { - buffer[i++] = *string++; - len--; - } - - buffer[i] = 0; - printf("%-10s", buffer); -} - -/* - * Sum a block. The checksum of a block must end up at zero - * to be valid. The chk_sum field is selected so that adding - * it yields zero. - */ -int sum_block(struct block_header *header) -{ - s32 *block = (s32 *)header; - u32 i; - s32 sum = 0; - - for (i = 0; i < header->summed_longs; i++) - sum += *block++; - - return (sum != 0); -} - -/* - * Print an AmigaOS disk type. Disk types are a four-byte identifier - * describing the file system. They are usually written as a three-letter - * word followed by a backslash and a version number. For example, - * DOS\0 would be the original file system. SFS\0 would be SmartFileSystem. - * DOS\1 is FFS. - */ -static void print_disk_type(u32 disk_type) -{ - char buffer[6]; - buffer[0] = (disk_type & 0xFF000000)>>24; - buffer[1] = (disk_type & 0x00FF0000)>>16; - buffer[2] = (disk_type & 0x0000FF00)>>8; - buffer[3] = '\\'; - buffer[4] = (disk_type & 0x000000FF) + '0'; - buffer[5] = 0; - printf("%s", buffer); -} - -/* - * Print the info contained within the given partition block - */ -static void print_part_info(struct partition_block *p) -{ - struct amiga_part_geometry *g; - - g = (struct amiga_part_geometry *)&(p->environment); - - bstr_print(p->drive_name); - printf("%6d\t%6d\t", - g->low_cyl * g->block_per_track * g->surfaces , - (g->high_cyl - g->low_cyl + 1) * g->block_per_track * g->surfaces - 1); - print_disk_type(g->dos_type); - printf("\t%5d\n", g->boot_priority); -} - -/* - * Search for the Rigid Disk Block. The rigid disk block is required - * to be within the first 16 blocks of a drive, needs to have - * the ID AMIGA_ID_RDISK ('RDSK') and needs to have a valid - * sum-to-zero checksum - */ -struct rigid_disk_block *get_rdisk(block_dev_desc_t *dev_desc) -{ - int i; - int limit; - char *s; - - s = getenv("amiga_scanlimit"); - if (s) - limit = simple_strtoul(s, NULL, 10); - else - limit = AMIGA_BLOCK_LIMIT; - - for (i=0; i<limit; i++) - { - ulong res = dev_desc->block_read(dev_desc->dev, i, 1, - (ulong *)block_buffer); - if (res == 1) - { - struct rigid_disk_block *trdb = (struct rigid_disk_block *)block_buffer; - if (trdb->id == AMIGA_ID_RDISK) - { - PRINTF("Rigid disk block suspect at %d, checking checksum\n",i); - if (sum_block((struct block_header *)block_buffer) == 0) - { - PRINTF("FOUND\n"); - memcpy(&rdb, trdb, sizeof(struct rigid_disk_block)); - return (struct rigid_disk_block *)&rdb; - } - } - } - } - PRINTF("Done scanning, no RDB found\n"); - return NULL; -} - -/* - * Search for boot code - * Again, the first boot block must be located somewhere in the first 16 blocks, or rooted in the - * Ridgid disk block - */ - -struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc) -{ - int i; - int limit; - char *s; - - s = getenv("amiga_scanlimit"); - if (s) - limit = simple_strtoul(s, NULL, 10); - else - limit = AMIGA_BLOCK_LIMIT; - - PRINTF("Scanning for BOOT from 0 to %d\n", limit); - - for (i = 0; i < limit; i++) - { - ulong res = dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)block_buffer); - if (res == 1) - { - struct bootcode_block *boot = (struct bootcode_block *)block_buffer; - if (boot->id == AMIGA_ID_BOOT) - { - PRINTF("BOOT block at %d, checking checksum\n", i); - if (sum_block((struct block_header *)block_buffer) == 0) - { - PRINTF("Found valid bootcode block\n"); - memcpy(&bootcode, boot, sizeof(struct bootcode_block)); - return &bootcode; - } - } - } - } - - PRINTF("No boot code found on disk\n"); - return 0; -} - -/* - * Test if the given partition has an Amiga partition table/Rigid - * Disk block - */ -int test_part_amiga(block_dev_desc_t *dev_desc) -{ - struct rigid_disk_block *rdb; - struct bootcode_block *bootcode; - - PRINTF("test_part_amiga: Testing for an Amiga RDB partition\n"); - - rdb = get_rdisk(dev_desc); - if (rdb) - { - bootcode = get_bootcode(dev_desc); - if (bootcode) - PRINTF("test_part_amiga: bootable Amiga disk\n"); - else - PRINTF("test_part_amiga: non-bootable Amiga disk\n"); - - return 0; - } - else - { - PRINTF("test_part_amiga: no RDB found\n"); - return -1; - } - -} - -/* - * Find partition number partnum on the given drive. - */ -static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int partnum) -{ - struct rigid_disk_block *rdb; - struct partition_block *p; - u32 block; - - PRINTF("Trying to find partition block %d\n", partnum); - rdb = get_rdisk(dev_desc); - if (!rdb) - { - PRINTF("find_partition: no rdb found\n"); - return NULL; - } - - PRINTF("find_partition: Scanning partition list\n"); - - block = rdb->partition_list; - PRINTF("find_partition: partition list at 0x%x\n", block); - - while (block != 0xFFFFFFFF) - { - ulong res = dev_desc->block_read(dev_desc->dev, block, 1, - (ulong *)block_buffer); - if (res == 1) - { - p = (struct partition_block *)block_buffer; - if (p->id == AMIGA_ID_PART) - { - PRINTF("PART block suspect at 0x%x, checking checksum\n",block); - if (sum_block((struct block_header *)p) == 0) - { - if (partnum == 0) break; - else - { - partnum--; - block = p->next; - } - } - } else block = 0xFFFFFFFF; - } else block = 0xFFFFFFFF; - } - - if (block == 0xFFFFFFFF) - { - PRINTF("PART block not found\n"); - return NULL; - } - - return (struct partition_block *)block_buffer; -} - -/* - * Get info about a partition - */ -int get_partition_info_amiga (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) -{ - struct partition_block *p = find_partition(dev_desc, part-1); - struct amiga_part_geometry *g; - u32 disk_type; - - if (!p) return -1; - - g = (struct amiga_part_geometry *)&(p->environment); - info->start = g->low_cyl * g->block_per_track * g->surfaces; - info->size = (g->high_cyl - g->low_cyl + 1) * g->block_per_track * g->surfaces - 1; - info->blksz = rdb.block_bytes; - bcpl_strcpy(info->name, p->drive_name); - - - disk_type = g->dos_type; - - info->type[0] = (disk_type & 0xFF000000)>>24; - info->type[1] = (disk_type & 0x00FF0000)>>16; - info->type[2] = (disk_type & 0x0000FF00)>>8; - info->type[3] = '\\'; - info->type[4] = (disk_type & 0x000000FF) + '0'; - info->type[5] = 0; - - return 0; -} - -void print_part_amiga (block_dev_desc_t *dev_desc) -{ - struct rigid_disk_block *rdb; - struct bootcode_block *boot; - struct partition_block *p; - u32 block; - int i = 1; - - rdb = get_rdisk(dev_desc); - if (!rdb) - { - PRINTF("print_part_amiga: no rdb found\n"); - return; - } - - PRINTF("print_part_amiga: Scanning partition list\n"); - - block = rdb->partition_list; - PRINTF("print_part_amiga: partition list at 0x%x\n", block); - - printf("Summary: DiskBlockSize: %d\n" - " Cylinders : %d\n" - " Sectors/Track: %d\n" - " Heads : %d\n\n", - rdb->block_bytes, rdb->cylinders, rdb->sectors, - rdb->heads); - - printf(" First Num. \n" - "Nr. Part. Name Block Block Type Boot Priority\n"); - - while (block != 0xFFFFFFFF) - { - ulong res; - - PRINTF("Trying to load block #0x%X\n", block); - - res = dev_desc->block_read(dev_desc->dev, block, 1, - (ulong *)block_buffer); - if (res == 1) - { - p = (struct partition_block *)block_buffer; - if (p->id == AMIGA_ID_PART) - { - PRINTF("PART block suspect at 0x%x, checking checksum\n",block); - if (sum_block((struct block_header *)p) == 0) - { - printf("%-4d ", i); i++; - print_part_info(p); - block = p->next; - } - } else block = 0xFFFFFFFF; - } else block = 0xFFFFFFFF; - } - - boot = get_bootcode(dev_desc); - if (boot) - { - printf("Disk is bootable\n"); - } -} - -#endif diff --git a/disk/part_amiga.h b/disk/part_amiga.h deleted file mode 100644 index 20a8fdf..0000000 --- a/disk/part_amiga.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * (C) Copyright 2000 - * Hans-Joerg Frieden, Hyperion Entertainment - * Hans-JoergF@hyperion-entertainment.com - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#ifndef _DISK_PART_AMIGA_H -#define _DISK_PART_AMIGA_H -#include <common.h> - -#ifdef CONFIG_ISO_PARTITION -/* Make the buffers bigger if ISO partition support is enabled -- CD-ROMS - have 2048 byte blocks */ -#define DEFAULT_SECTOR_SIZE 2048 -#else -#define DEFAULT_SECTOR_SIZE 512 -#endif - - -#define AMIGA_BLOCK_LIMIT 16 - -/* - * Amiga disks have a very open structure. The head for the partition table information - * is stored somewhere within the first 16 blocks on disk, and is called the - * "RigidDiskBlock". - */ - -struct rigid_disk_block -{ - u32 id; - u32 summed_longs; - s32 chk_sum; - u32 host_id; - u32 block_bytes; - u32 flags; - u32 bad_block_list; - u32 partition_list; - u32 file_sys_header_list; - u32 drive_init; - u32 bootcode_block; - u32 reserved_1[5]; - - /* Physical drive geometry */ - u32 cylinders; - u32 sectors; - u32 heads; - u32 interleave; - u32 park; - u32 reserved_2[3]; - u32 write_pre_comp; - u32 reduced_write; - u32 step_rate; - u32 reserved_3[5]; - - /* logical drive geometry */ - u32 rdb_blocks_lo; - u32 rdb_blocks_hi; - u32 lo_cylinder; - u32 hi_cylinder; - u32 cyl_blocks; - u32 auto_park_seconds; - u32 high_rdsk_block; - u32 reserved_4; - - char disk_vendor[8]; - char disk_product[16]; - char disk_revision[4]; - char controller_vendor[8]; - char controller_product[16]; - char controller_revision[4]; - - u32 reserved_5[10]; -}; - -/* - * Each partition on this drive is defined by such a block - */ - -struct partition_block -{ - u32 id; - u32 summed_longs; - s32 chk_sum; - u32 host_id; - u32 next; - u32 flags; - u32 reserved_1[2]; - u32 dev_flags; - char drive_name[32]; - u32 reserved_2[15]; - u32 environment[17]; - u32 reserved_3[15]; -}; - -struct bootcode_block -{ - u32 id; - u32 summed_longs; - s32 chk_sum; - u32 host_id; - u32 next; - u32 load_data[123]; -}; - - -#define AMIGA_ID_RDISK 0x5244534B -#define AMIGA_ID_PART 0x50415254 -#define AMIGA_ID_BOOT 0x424f4f54 - -/* - * The environment array in the partition block - * describes the partition - */ - -struct amiga_part_geometry -{ - u32 table_size; - u32 size_blocks; - u32 unused1; - u32 surfaces; - u32 sector_per_block; - u32 block_per_track; - u32 reserved; - u32 prealloc; - u32 interleave; - u32 low_cyl; - u32 high_cyl; - u32 num_buffers; - u32 buf_mem_type; - u32 max_transfer; - u32 mask; - s32 boot_priority; - u32 dos_type; - u32 baud; - u32 control; - u32 boot_blocks; -}; - -#endif /* _DISK_PART_AMIGA_H_ */ diff --git a/disk/part_dos.c b/disk/part_dos.c deleted file mode 100644 index 2de1bb8..0000000 --- a/disk/part_dos.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * (C) Copyright 2001 - * Raymond Lo, lo@routefree.com - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * Support for harddisk partitions. - * - * To be compatible with LinuxPPC and Apple we use the standard Apple - * SCSI disk partitioning scheme. For more information see: - * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92 - */ - -#include <common.h> -#include <command.h> -#include <ide.h> -#include "part_dos.h" - -#if defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) - -/* Convert char[4] in little endian format to the host format integer - */ -static inline int le32_to_int(unsigned char *le32) -{ - return ((le32[3] << 24) + - (le32[2] << 16) + - (le32[1] << 8) + - le32[0] - ); -} - -static inline int is_extended(int part_type) -{ - return (part_type == 0x5 || - part_type == 0xf || - part_type == 0x85); -} - -static void print_one_part (dos_partition_t *p, int ext_part_sector, int part_num) -{ - int lba_start = ext_part_sector + le32_to_int (p->start4); - int lba_size = le32_to_int (p->size4); - - printf ("%5d\t\t%10d\t%10d\t%2x%s\n", - part_num, lba_start, lba_size, p->sys_ind, - (is_extended (p->sys_ind) ? " Extd" : "")); -} - -static int test_block_type(unsigned char *buffer) -{ - if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) || - (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) { - return (-1); - } /* no DOS Signature at all */ - if (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0 || - strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],"FAT32",5)==0) { - return DOS_PBR; /* is PBR */ - } - return DOS_MBR; /* Is MBR */ -} - - -int test_part_dos (block_dev_desc_t *dev_desc) -{ - unsigned char buffer[DEFAULT_SECTOR_SIZE]; - - if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1) || - (buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) || - (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) { - return (-1); - } - return (0); -} - -/* Print a partition that is relative to its Extended partition table - */ -static void print_partition_extended (block_dev_desc_t *dev_desc, int ext_part_sector, int relative, - int part_num) -{ - unsigned char buffer[DEFAULT_SECTOR_SIZE]; - dos_partition_t *pt; - int i; - - if (dev_desc->block_read(dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) { - printf ("** Can't read partition table on %d:%d **\n", - dev_desc->dev, ext_part_sector); - return; - } - i=test_block_type(buffer); - if(i==-1) { - printf ("bad MBR sector signature 0x%02x%02x\n", - buffer[DOS_PART_MAGIC_OFFSET], - buffer[DOS_PART_MAGIC_OFFSET + 1]); - return; - } - if(i==DOS_PBR) { - printf (" 1\t\t 0\t%10ld\t%2x\n", - dev_desc->lba, buffer[DOS_PBR_MEDIA_TYPE_OFFSET]); - return; - } - /* Print all primary/logical partitions */ - pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); - for (i = 0; i < 4; i++, pt++) { - /* - * fdisk does not show the extended partitions that - * are not in the MBR - */ - - if ((pt->sys_ind != 0) && - (ext_part_sector == 0 || !is_extended (pt->sys_ind)) ) { - print_one_part (pt, ext_part_sector, part_num); - } - - /* Reverse engr the fdisk part# assignment rule! */ - if ((ext_part_sector == 0) || - (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) ) { - part_num++; - } - } - - /* Follows the extended partitions */ - pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); - for (i = 0; i < 4; i++, pt++) { - if (is_extended (pt->sys_ind)) { - int lba_start = le32_to_int (pt->start4) + relative; - - print_partition_extended (dev_desc, lba_start, - ext_part_sector == 0 ? lba_start - : relative, - part_num); - } - } - - return; -} - - -/* Print a partition that is relative to its Extended partition table - */ -static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part_sector, - int relative, int part_num, - int which_part, disk_partition_t *info) -{ - unsigned char buffer[DEFAULT_SECTOR_SIZE]; - dos_partition_t *pt; - int i; - - if (dev_desc->block_read (dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) { - printf ("** Can't read partition table on %d:%d **\n", - dev_desc->dev, ext_part_sector); - return -1; - } - if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 || - buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) { - printf ("bad MBR sector signature 0x%02x%02x\n", - buffer[DOS_PART_MAGIC_OFFSET], - buffer[DOS_PART_MAGIC_OFFSET + 1]); - return -1; - } - - /* Print all primary/logical partitions */ - pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); - for (i = 0; i < 4; i++, pt++) { - /* - * fdisk does not show the extended partitions that - * are not in the MBR - */ - if (((pt->boot_ind & ~0x80) == 0) && - (pt->sys_ind != 0) && - (part_num == which_part) && - (is_extended(pt->sys_ind) == 0)) { - info->blksz = 512; - info->start = ext_part_sector + le32_to_int (pt->start4); - info->size = le32_to_int (pt->size4); - 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->dev, part_num); - break; - case IF_TYPE_SCSI: - sprintf ((char *)info->name, "sd%c%d", - 'a' + dev_desc->dev, part_num); - break; - case IF_TYPE_USB: - sprintf ((char *)info->name, "usbd%c%d", - 'a' + dev_desc->dev, part_num); - break; - case IF_TYPE_DOC: - sprintf ((char *)info->name, "docd%c%d", - 'a' + dev_desc->dev, part_num); - break; - default: - sprintf ((char *)info->name, "xx%c%d", - 'a' + dev_desc->dev, part_num); - break; - } - /* sprintf(info->type, "%d, pt->sys_ind); */ - sprintf ((char *)info->type, "U-Boot"); - return 0; - } - - /* Reverse engr the fdisk part# assignment rule! */ - if ((ext_part_sector == 0) || - (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) ) { - part_num++; - } - } - - /* Follows the extended partitions */ - pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); - for (i = 0; i < 4; i++, pt++) { - if (is_extended (pt->sys_ind)) { - int lba_start = le32_to_int (pt->start4) + relative; - - return get_partition_info_extended (dev_desc, lba_start, - ext_part_sector == 0 ? lba_start : relative, - part_num, which_part, info); - } - } - return -1; -} - -void print_part_dos (block_dev_desc_t *dev_desc) -{ - printf ("Partition Start Sector Num Sectors Type\n"); - print_partition_extended (dev_desc, 0, 0, 1); -} - -int get_partition_info_dos (block_dev_desc_t *dev_desc, int part, disk_partition_t * info) -{ - return get_partition_info_extended (dev_desc, 0, 0, 1, part, info); -} - - -#endif diff --git a/disk/part_dos.h b/disk/part_dos.h deleted file mode 100644 index 195a32c..0000000 --- a/disk/part_dos.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * (C) Copyright 2000 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#ifndef _DISK_PART_DOS_H -#define _DISK_PART_DOS_H - - -#ifdef CONFIG_ISO_PARTITION -/* Make the buffers bigger if ISO partition support is enabled -- CD-ROMS - have 2048 byte blocks */ -#define DEFAULT_SECTOR_SIZE 2048 -#else -#define DEFAULT_SECTOR_SIZE 512 -#endif -#define DOS_PART_TBL_OFFSET 0x1be -#define DOS_PART_MAGIC_OFFSET 0x1fe -#define DOS_PBR_FSTYPE_OFFSET 0x36 -#define DOS_PBR32_FSTYPE_OFFSET 0x52 -#define DOS_PBR_MEDIA_TYPE_OFFSET 0x15 -#define DOS_MBR 0 -#define DOS_PBR 1 - -typedef struct dos_partition { - unsigned char boot_ind; /* 0x80 - active */ - unsigned char head; /* starting head */ - unsigned char sector; /* starting sector */ - unsigned char cyl; /* starting cylinder */ - unsigned char sys_ind; /* What partition type */ - unsigned char end_head; /* end head */ - unsigned char end_sector; /* end sector */ - unsigned char end_cyl; /* end cylinder */ - unsigned char start4[4]; /* starting sector counting from 0 */ - unsigned char size4[4]; /* nr of sectors in partition */ -} dos_partition_t; - -#endif /* _DISK_PART_DOS_H */ diff --git a/disk/part_efi.c b/disk/part_efi.c deleted file mode 100644 index 1b04c27..0000000 --- a/disk/part_efi.c +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Copyright (C) 2008 RuggedCom, Inc. - * Richard Retanubun <RichardRetanubun@RuggedCom.com> - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * Problems with CONFIG_SYS_64BIT_LBA: - * - * struct disk_partition.start in include/part.h is sized as ulong. - * When CONFIG_SYS_64BIT_LBA is activated, lbaint_t changes from ulong to uint64_t. - * For now, it is cast back to ulong at assignment. - * - * This limits the maximum size of addressable storage to < 2 Terra Bytes - */ -#include <common.h> -#include <command.h> -#include <ide.h> -#include <malloc.h> -#include "part_efi.h" - -#if defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) - -/* 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]); -} - -/* Convert char[4] in little endian format to the host format integer - */ -static inline unsigned long le32_to_int(unsigned char *le32) -{ - return ((le32[3] << 24) + (le32[2] << 16) + (le32[1] << 8) + le32[0]); -} - -/* Convert char[8] in little endian format to the host format integer - */ -static inline unsigned long long le64_to_int(unsigned char *le64) -{ - return (((unsigned long long)le64[7] << 56) + - ((unsigned long long)le64[6] << 48) + - ((unsigned long long)le64[5] << 40) + - ((unsigned long long)le64[4] << 32) + - ((unsigned long long)le64[3] << 24) + - ((unsigned long long)le64[2] << 16) + - ((unsigned long long)le64[1] << 8) + - (unsigned long long)le64[0]); -} - -/** - * efi_crc32() - EFI version of crc32 function - * @buf: buffer to calculate crc32 of - * @len - length of buf - * - * Description: Returns EFI-style CRC32 value for @buf - */ -static inline unsigned long efi_crc32(const void *buf, unsigned long len) -{ - return crc32(0, buf, len); -} - -/* - * Private function prototypes - */ - -static int pmbr_part_valid(struct partition *part); -static int is_pmbr_valid(legacy_mbr * mbr); - -static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba, - gpt_header * pgpt_head, gpt_entry ** pgpt_pte); - -static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc, - gpt_header * pgpt_head); - -static int is_pte_valid(gpt_entry * pte); - -/* - * Public Functions (include/part.h) - */ - -void print_part_efi(block_dev_desc_t * dev_desc) -{ - gpt_header gpt_head; - gpt_entry **pgpt_pte = NULL; - int i = 0; - - if (!dev_desc) { - printf("%s: Invalid Argument(s)\n", __FUNCTION__); - return; - } - /* This function validates AND fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - &(gpt_head), pgpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __FUNCTION__); - return; - } - - debug("%s: gpt-entry at 0x%08X\n", __FUNCTION__, (unsigned int)*pgpt_pte); - - printf("Part Start LBA End LBA\n"); - for (i = 0; i < le32_to_int(gpt_head.num_partition_entries); i++) { - - if (is_pte_valid(&(*pgpt_pte)[i])) { - printf("%s%d 0x%llX 0x%llX\n", GPT_ENTRY_NAME, - (i + 1), - le64_to_int((*pgpt_pte)[i].starting_lba), - le64_to_int((*pgpt_pte)[i].ending_lba)); - } else { - break; /* Stop at the first non valid PTE */ - } - } - - /* Remember to free pte */ - if (*pgpt_pte != NULL) { - debug("%s: Freeing pgpt_pte\n", __FUNCTION__); - free(*pgpt_pte); - } - return; -} - -int get_partition_info_efi(block_dev_desc_t * dev_desc, int part, - disk_partition_t * info) -{ - gpt_header gpt_head; - gpt_entry **pgpt_pte = NULL; - - /* "part" argument must be at least 1 */ - if (!dev_desc || !info || part < 1) { - printf("%s: Invalid Argument(s)\n", __FUNCTION__); - return -1; - } - - /* This function validates AND fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, - &(gpt_head), pgpt_pte) != 1) { - printf("%s: *** ERROR: Invalid GPT ***\n", __FUNCTION__); - return -1; - } - - /* The ulong casting limits the maximum disk size to 2 TB */ - info->start = (ulong) le64_to_int((*pgpt_pte)[part - 1].starting_lba); - /* The ending LBA is inclusive, to calculate size, add 1 to it */ - info->size = ((ulong)le64_to_int((*pgpt_pte)[part - 1].ending_lba) + 1) - - info->start; - info->blksz = GPT_BLOCK_SIZE; - - sprintf((char *)info->name, "%s%d", GPT_ENTRY_NAME, part); - sprintf((char *)info->type, "U-Boot"); - - debug("%s: start 0x%lX, size 0x%lX, name %s", __FUNCTION__, - info->start, info->size, info->name); - - /* Remember to free pte */ - if (*pgpt_pte != NULL) { - debug("%s: Freeing pgpt_pte\n", __FUNCTION__); - free(*pgpt_pte); - } - return 0; -} - -int test_part_efi(block_dev_desc_t * dev_desc) -{ - legacy_mbr legacymbr; - - /* Read legacy MBR from block 0 and validate it */ - if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) & legacymbr) != 1) - || (is_pmbr_valid(&legacymbr) != 1)) { - return -1; - } - return 0; -} - -/* - * Private functions - */ -/* - * pmbr_part_valid(): Check for EFI partition signature - * - * Returns: 1 if EFI GPT partition type is found. - */ -static int pmbr_part_valid(struct partition *part) -{ - if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT && - le32_to_int(part->start_sect) == 1UL) { - return 1; - } - - return 0; -} - -/* - * is_pmbr_valid(): test Protective MBR for validity - * - * Returns: 1 if PMBR is valid, 0 otherwise. - * Validity depends on two things: - * 1) MSDOS signature is in the last two bytes of the MBR - * 2) One partition of type 0xEE is found, checked by pmbr_part_valid() - */ -static int is_pmbr_valid(legacy_mbr * mbr) -{ - int i = 0; - - if (!mbr || le16_to_int(mbr->signature) != MSDOS_MBR_SIGNATURE) { - return 0; - } - - for (i = 0; i < 4; i++) { - if (pmbr_part_valid(&mbr->partition_record[i])) { - return 1; - } - } - return 0; -} - -/** - * is_gpt_valid() - tests one GPT header and PTEs for validity - * - * lba is the logical block address of the GPT header to test - * gpt is a GPT header ptr, filled on return. - * ptes is a PTEs ptr, filled on return. - * - * Description: returns 1 if valid, 0 on error. - * If valid, returns pointers to PTEs. - */ -static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba, - gpt_header * pgpt_head, gpt_entry ** pgpt_pte) -{ - unsigned char crc32_backup[4] = { 0 }; - unsigned long calc_crc32; - unsigned long long lastlba; - - if (!dev_desc || !pgpt_head) { - printf("%s: Invalid Argument(s)\n", __FUNCTION__); - return 0; - } - - /* Read GPT Header from device */ - if (dev_desc->block_read(dev_desc->dev, lba, 1, pgpt_head) != 1) { - printf("*** ERROR: Can't read GPT header ***\n"); - return 0; - } - - /* Check the GPT header signature */ - if (le64_to_int(pgpt_head->signature) != GPT_HEADER_SIGNATURE) { - printf("GUID Partition Table Header signature is wrong:" - "0x%llX != 0x%llX\n", - (unsigned long long)le64_to_int(pgpt_head->signature), - (unsigned long long)GPT_HEADER_SIGNATURE); - return 0; - } - - /* Check the GUID Partition Table CRC */ - memcpy(crc32_backup, pgpt_head->header_crc32, sizeof(crc32_backup)); - memset(pgpt_head->header_crc32, 0, sizeof(pgpt_head->header_crc32)); - - calc_crc32 = efi_crc32((const unsigned char *)pgpt_head, - le32_to_int(pgpt_head->header_size)); - - memcpy(pgpt_head->header_crc32, crc32_backup, sizeof(crc32_backup)); - - if (calc_crc32 != le32_to_int(crc32_backup)) { - printf("GUID Partition Table Header CRC is wrong:" - "0x%08lX != 0x%08lX\n", - le32_to_int(crc32_backup), calc_crc32); - return 0; - } - - /* Check that the my_lba entry points to the LBA that contains the GPT */ - if (le64_to_int(pgpt_head->my_lba) != lba) { - printf("GPT: my_lba incorrect: %llX != %llX\n", - (unsigned long long)le64_to_int(pgpt_head->my_lba), - (unsigned long long)lba); - return 0; - } - - /* Check the first_usable_lba and last_usable_lba are within the disk. */ - lastlba = (unsigned long long)dev_desc->lba; - if (le64_to_int(pgpt_head->first_usable_lba) > lastlba) { - printf("GPT: first_usable_lba incorrect: %llX > %llX\n", - le64_to_int(pgpt_head->first_usable_lba), lastlba); - return 0; - } - if (le64_to_int(pgpt_head->last_usable_lba) > lastlba) { - printf("GPT: last_usable_lba incorrect: %llX > %llX\n", - le64_to_int(pgpt_head->last_usable_lba), lastlba); - return 0; - } - - debug("GPT: first_usable_lba: %llX last_usable_lba %llX last lba %llX\n", - le64_to_int(pgpt_head->first_usable_lba), - le64_to_int(pgpt_head->last_usable_lba), lastlba); - - /* Read and allocate Partition Table Entries */ - *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head); - if (*pgpt_pte == NULL) { - printf("GPT: Failed to allocate memory for PTE\n"); - return 0; - } - - /* Check the GUID Partition Table Entry Array CRC */ - calc_crc32 = efi_crc32((const unsigned char *)*pgpt_pte, - le32_to_int(pgpt_head->num_partition_entries) * - le32_to_int(pgpt_head->sizeof_partition_entry)); - - if (calc_crc32 != le32_to_int(pgpt_head->partition_entry_array_crc32)) { - printf("GUID Partition Table Entry Array CRC is wrong:" - "0x%08lX != 0x%08lX\n", - le32_to_int(pgpt_head->partition_entry_array_crc32), - calc_crc32); - - if (*pgpt_pte != NULL) { - free(*pgpt_pte); - } - return 0; - } - - /* We're done, all's well */ - return 1; -} - -/** - * alloc_read_gpt_entries(): reads partition entries from disk - * @dev_desc - * @gpt - GPT header - * - * Description: Returns ptes on success, NULL on error. - * Allocates space for PTEs based on information found in @gpt. - * Notes: remember to free pte when you're done! - */ -static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc, - gpt_header * pgpt_head) -{ - size_t count = 0; - gpt_entry *pte = NULL; - - if (!dev_desc || !pgpt_head) { - printf("%s: Invalid Argument(s)\n", __FUNCTION__); - return NULL; - } - - count = le32_to_int(pgpt_head->num_partition_entries) * - le32_to_int(pgpt_head->sizeof_partition_entry); - - debug("%s: count = %lu * %lu = %u\n", __FUNCTION__, - le32_to_int(pgpt_head->num_partition_entries), - le32_to_int(pgpt_head->sizeof_partition_entry), count); - - /* Allocate memory for PTE, remember to FREE */ - if (count != 0) { - pte = malloc(count); - } - - if (count == 0 || pte == NULL) { - printf("%s: ERROR: Can't allocate 0x%X bytes for GPT Entries\n", - __FUNCTION__, count); - return NULL; - } - - /* Read GPT Entries from device */ - if (dev_desc->block_read (dev_desc->dev, - (unsigned long)le64_to_int(pgpt_head->partition_entry_lba), - (lbaint_t) (count / GPT_BLOCK_SIZE), pte) - != (count / GPT_BLOCK_SIZE)) { - - printf("*** ERROR: Can't read GPT Entries ***\n"); - free(pte); - return NULL; - } - return pte; -} - -/** - * is_pte_valid(): validates a single Partition Table Entry - * @gpt_entry - Pointer to a single Partition Table Entry - * - * Description: returns 1 if valid, 0 on error. - */ -static int is_pte_valid(gpt_entry * pte) -{ - efi_guid_t unused_guid; - - if (!pte) { - printf("%s: Invalid Argument(s)\n", __FUNCTION__); - return 0; - } - - /* Only one validation for now: - * The GUID Partition Type != Unused Entry (ALL-ZERO) - */ - memset(unused_guid.b, 0, sizeof(unused_guid.b)); - - if (memcmp(pte->partition_type_guid.b, unused_guid.b, - sizeof(unused_guid.b)) == 0) { - - debug("%s: Found an unused PTE GUID at 0x%08X\n", __FUNCTION__, - (unsigned int)pte); - - return 0; - } else { - return 1; - } -} -#endif diff --git a/disk/part_efi.h b/disk/part_efi.h deleted file mode 100644 index 6bbb06b..0000000 --- a/disk/part_efi.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2008 RuggedCom, Inc. - * Richard Retanubun <RichardRetanubun@RuggedCom.com> - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * See also linux/fs/partitions/efi.h - * - * EFI GUID Partition Table - * Per Intel EFI Specification v1.02 - * http://developer.intel.com/technology/efi/efi.htm -*/ - -#ifndef _DISK_PART_EFI_H -#define _DISK_PART_EFI_H - -#define MSDOS_MBR_SIGNATURE 0xAA55 -#define EFI_PMBR_OSTYPE_EFI 0xEF -#define EFI_PMBR_OSTYPE_EFI_GPT 0xEE - -#define GPT_BLOCK_SIZE 512 -#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL -#define GPT_HEADER_REVISION_V1 0x00010000 -#define GPT_PRIMARY_PARTITION_TABLE_LBA 1ULL -#define GPT_ENTRY_NAME "gpt" - -#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \ - ((efi_guid_t) \ - {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \ - (b) & 0xff, ((b) >> 8) & 0xff, \ - (c) & 0xff, ((c) >> 8) & 0xff, \ - (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}) - -#define PARTITION_SYSTEM_GUID \ - EFI_GUID( 0xC12A7328, 0xF81F, 0x11d2, \ - 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B) -#define LEGACY_MBR_PARTITION_GUID \ - EFI_GUID( 0x024DEE41, 0x33E7, 0x11d3, \ - 0x9D, 0x69, 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F) -#define PARTITION_MSFT_RESERVED_GUID \ - EFI_GUID( 0xE3C9E316, 0x0B5C, 0x4DB8, \ - 0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE) -#define PARTITION_BASIC_DATA_GUID \ - EFI_GUID( 0xEBD0A0A2, 0xB9E5, 0x4433, \ - 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7) -#define PARTITION_LINUX_RAID_GUID \ - EFI_GUID( 0xa19d880f, 0x05fc, 0x4d3b, \ - 0xa0, 0x06, 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e) -#define PARTITION_LINUX_SWAP_GUID \ - EFI_GUID( 0x0657fd6d, 0xa4ab, 0x43c4, \ - 0x84, 0xe5, 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f) -#define PARTITION_LINUX_LVM_GUID \ - EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \ - 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28) - -/* linux/include/efi.h */ -typedef unsigned short efi_char16_t; - -typedef struct { - unsigned char b[16]; -} efi_guid_t; - -/* based on linux/include/genhd.h */ -struct partition { - unsigned char boot_ind; /* 0x80 - active */ - unsigned char head; /* starting head */ - unsigned char sector; /* starting sector */ - unsigned char cyl; /* starting cylinder */ - unsigned char sys_ind; /* What partition type */ - unsigned char end_head; /* end head */ - unsigned char end_sector; /* end sector */ - unsigned char end_cyl; /* end cylinder */ - unsigned char start_sect[4]; /* starting sector counting from 0 */ - unsigned char nr_sects[4]; /* nr of sectors in partition */ -} __attribute__ ((packed)); - -/* based on linux/fs/partitions/efi.h */ -typedef struct _gpt_header { - unsigned char signature[8]; - unsigned char revision[4]; - unsigned char header_size[4]; - unsigned char header_crc32[4]; - unsigned char reserved1[4]; - unsigned char my_lba[8]; - unsigned char alternate_lba[8]; - unsigned char first_usable_lba[8]; - unsigned char last_usable_lba[8]; - efi_guid_t disk_guid; - unsigned char partition_entry_lba[8]; - unsigned char num_partition_entries[4]; - unsigned char sizeof_partition_entry[4]; - unsigned char partition_entry_array_crc32[4]; - unsigned char reserved2[GPT_BLOCK_SIZE - 92]; -} __attribute__ ((packed)) gpt_header; - -typedef struct _gpt_entry_attributes { - unsigned long long required_to_function:1; - unsigned long long reserved:47; - unsigned long long type_guid_specific:16; -} __attribute__ ((packed)) gpt_entry_attributes; - -typedef struct _gpt_entry { - efi_guid_t partition_type_guid; - efi_guid_t unique_partition_guid; - unsigned char starting_lba[8]; - unsigned char ending_lba[8]; - gpt_entry_attributes attributes; - efi_char16_t partition_name[72 / sizeof(efi_char16_t)]; -} -__attribute__ ((packed)) gpt_entry; - -typedef struct _legacy_mbr { - unsigned char boot_code[440]; - unsigned char unique_mbr_signature[4]; - unsigned char unknown[2]; - struct partition partition_record[4]; - unsigned char signature[2]; -} __attribute__ ((packed)) legacy_mbr; - -#endif /* _DISK_PART_EFI_H */ diff --git a/disk/part_iso.c b/disk/part_iso.c deleted file mode 100644 index 990da95..0000000 --- a/disk/part_iso.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * (C) Copyright 2001 - * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include <common.h> -#include <command.h> -#include "part_iso.h" - -#if defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) - -/* #define ISO_PART_DEBUG */ - -#ifdef ISO_PART_DEBUG -#define PRINTF(fmt,args...) printf (fmt ,##args) -#else -#define PRINTF(fmt,args...) -#endif - -/* enable this if CDs are written with the PowerPC Platform ID */ -#undef CHECK_FOR_POWERPC_PLATTFORM -#define CD_SECTSIZE 2048 - -static unsigned char tmpbuf[CD_SECTSIZE]; - -/* Convert char[4] in little endian format to the host format integer - */ -static inline unsigned long le32_to_int(unsigned char *le32) -{ - 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] - ); -} - - -/* only boot records will be listed as valid partitions */ -int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info, int verb) -{ - int i,offset,entry_num; - unsigned short *chksumbuf; - unsigned short chksum; - unsigned long newblkaddr,blkaddr,lastsect,bootaddr; - iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf; /* boot record */ - iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf; /* primary desc */ - iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf; - iso_init_def_entry_t *pide; - - /* the first sector (sector 0x10) must be a primary volume desc */ - blkaddr=PVD_OFFSET; - if (dev_desc->block_read (dev_desc->dev, PVD_OFFSET, 1, (ulong *) tmpbuf) != 1) - return (-1); - if(ppr->desctype!=0x01) { - if(verb) - printf ("** First descriptor is NOT a primary desc on %d:%d **\n", - dev_desc->dev, part_num); - return (-1); - } - if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) { - if(verb) - printf ("** Wrong ISO Ident: %s on %d:%d **\n", - ppr->stand_ident,dev_desc->dev, 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 */ - PRINTF(" Lastsect:%08lx\n",lastsect); - for(i=blkaddr;i<lastsect;i++) { - PRINTF("Reading block %d\n", i); - if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *) tmpbuf) != 1) - return (-1); - if(ppr->desctype==0x00) - break; /* boot entry found */ - if(ppr->desctype==0xff) { - if(verb) - printf ("** No valid boot catalog found on %d:%d **\n", - dev_desc->dev, part_num); - return (-1); - } - } - /* boot entry found */ - if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) { - if(verb) - printf ("** Wrong El Torito ident: %s on %d:%d **\n", - pbr->ident_str,dev_desc->dev, part_num); - return (-1); - } - bootaddr=le32_to_int(pbr->pointer); - PRINTF(" Boot Entry at: %08lX\n",bootaddr); - if (dev_desc->block_read (dev_desc->dev, bootaddr, 1, (ulong *) tmpbuf) != 1) { - if(verb) - printf ("** Can't read Boot Entry at %lX on %d:%d **\n", - bootaddr,dev_desc->dev, part_num); - return (-1); - } - chksum=0; - chksumbuf = (unsigned short *)tmpbuf; - for(i=0;i<0x10;i++) - chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8); - if(chksum!=0) { - if(verb) - printf ("** Checksum Error in booting catalog validation entry on %d:%d **\n", - dev_desc->dev, part_num); - return (-1); - } - if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) { - if(verb) - printf ("** Key 0x55 0xAA error on %d:%d **\n", - dev_desc->dev, part_num); - return(-1); - } -#ifdef CHECK_FOR_POWERPC_PLATTFORM - if(pve->platform!=0x01) { - if(verb) - printf ("** No PowerPC platform CD on %d:%d **\n", - dev_desc->dev, part_num); - return(-1); - } -#endif - /* the validation entry seems to be ok, now search the "partition" */ - entry_num=0; - offset=0x20; - sprintf ((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->dev, part_num); - break; - case IF_TYPE_SCSI: - sprintf ((char *)info->name, "sd%c%d", - 'a' + dev_desc->dev, part_num); - break; - case IF_TYPE_USB: - sprintf ((char *)info->name, "usbd%c%d", - 'a' + dev_desc->dev, part_num); - break; - case IF_TYPE_DOC: - sprintf ((char *)info->name, "docd%c%d", - 'a' + dev_desc->dev, part_num); - break; - default: - sprintf ((char *)info->name, "xx%c%d", - 'a' + dev_desc->dev, part_num); - break; - } - /* the bootcatalog (including validation Entry) is limited to 2048Bytes - * (63 boot entries + validation entry) */ - while(offset<2048) { - pide=(iso_init_def_entry_t *)&tmpbuf[offset]; - if ((pide->boot_ind==0x88) || - (pide->boot_ind==0x00)) { /* Header Id for default Sections Entries */ - if(entry_num==part_num) { /* part found */ - goto found; - } - entry_num++; /* count partitions Entries (boot and non bootables */ - offset+=0x20; - continue; - } - if ((pide->boot_ind==0x90) || /* Section Header Entry */ - (pide->boot_ind==0x91) || /* Section Header Entry (last) */ - (pide->boot_ind==0x44)) { /* Extension Indicator */ - offset+=0x20; /* skip unused entries */ - } - else { - if(verb) - printf ("** Partition %d not found on device %d **\n", - part_num,dev_desc->dev); - return(-1); - } - } - /* if we reach this point entire sector has been - * searched w/o succsess */ - if(verb) - printf ("** Partition %d not found on device %d **\n", - part_num,dev_desc->dev); - return(-1); -found: - if(pide->boot_ind!=0x88) { - if(verb) - printf ("** Partition %d is not bootable on device %d **\n", - part_num,dev_desc->dev); - return (-1); - } - switch(pide->boot_media) { - case 0x00: /* no emulation */ - info->size=le16_to_int(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 */ - case 0x03: info->size=5760>>2; break; /* 2.88MByte Floppy */ - case 0x04: info->size=2880>>2; break; /* dummy (HD Emulation) */ - default: info->size=0; break; - } - newblkaddr=le32_to_int(pide->rel_block_addr); - info->start=newblkaddr; - PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size); - return 0; -} - -int get_partition_info_iso(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info) -{ - return(get_partition_info_iso_verb(dev_desc, part_num, info, 1)); -} - - -void print_part_iso(block_dev_desc_t * dev_desc) -{ - disk_partition_t info; - int i; - if(get_partition_info_iso_verb(dev_desc,0,&info,0)==-1) { - printf("** No boot partition found on device %d **\n",dev_desc->dev); - return; - } - printf("Part Start Sect x Size Type\n"); - i=0; - do { - printf (" %2d %8ld %8ld %6ld %.32s\n", - i, info.start, info.size, info.blksz, info.type); - i++; - } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1); -} - -int test_part_iso (block_dev_desc_t *dev_desc) -{ - disk_partition_t info; - - return(get_partition_info_iso_verb(dev_desc,0,&info,0)); -} - -#endif diff --git a/disk/part_iso.h b/disk/part_iso.h deleted file mode 100644 index c139d4b..0000000 --- a/disk/part_iso.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * (C) Copyright 2001 - * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ -#ifndef _PART_CD_H -#define _PART_CD_H - -#define BRVD 0x11 -#define PVD_OFFSET 0x10 - - -typedef struct iso_boot_rec { - unsigned char desctype; /* type of Volume descriptor: 0 = boot record, 1 = primary, 2 = Supplement, 3 = volume part 0xff trminator */ - unsigned char stand_ident[5]; /* "CD001" */ - unsigned char vers; /* Version */ - char ident_str[0x20]; /* Ident String "EL TORITO SPECIFICATION" */ - unsigned char unused[0x20]; /* unused */ - unsigned char pointer[4]; /* absolute pointer to Boot Catalog */ -} iso_boot_rec_t; - - -typedef struct iso_pri_rec { - unsigned char desctype; /* type of Volume descriptor: 0 = boot record, 1 = primary, 2 = Supplement, 3 = volume part 0xff trminator */ - unsigned char stand_ident[5]; /* "CD001" */ - unsigned char vers; /* Version */ - unsigned char unused; - char sysid[32]; /* system Identifier */ - char volid[32]; /* volume Identifier */ - unsigned char zeros1[8]; /* unused */ - unsigned long volsiz_LE; /* volume size Little Endian */ - unsigned long volsiz_BE; /* volume size Big Endian */ - unsigned char zeros2[32]; /* unused */ - unsigned short setsize_LE; /* volume set size LE */ - unsigned short setsize_BE; /* volume set size BE */ - unsigned short seqnum_LE; /* volume sequence number LE */ - unsigned short seqnum_BE; /* volume sequence number BE */ - unsigned short secsize_LE; /* sector size LE */ - unsigned short secsize_BE; /* sector size BE */ - unsigned long pathtablen_LE;/* Path Table size LE */ - unsigned long pathtablen_BE;/* Path Table size BE */ - unsigned long firstsek_LEpathtab1_LE; /* location of first occurrence of little endian type path table */ - unsigned long firstsek_LEpathtab2_LE; /* location of optional occurrence of little endian type path table */ - unsigned long firstsek_BEpathtab1_BE; /* location of first occurrence of big endian type path table */ - unsigned long firstsek_BEpathtab2_BE; /* location of optional occurrence of big endian type path table */ - unsigned char rootdir[34]; /* directory record for root dir */ - char volsetid[128];/* Volume set identifier */ - char pubid[128]; /* Publisher identifier */ - char dataprepid[128]; /* data preparer identifier */ - char appid[128]; /* application identifier */ - char copyr[37]; /* copyright string */ - char abstractfileid[37]; /* abstract file identifier */ - char bibliofileid[37]; /* bibliographic file identifier */ - unsigned char creationdate[17]; /* creation date */ - unsigned char modify[17]; /* modification date */ - unsigned char expire[17]; /* expiring date */ - unsigned char effective[17];/* effective date */ - unsigned char filestruc_ver; /* file structur version */ -} iso_pri_rec_t; - -typedef struct iso_sup_rec { - unsigned char desctype; /* type of Volume descriptor: 0 = boot record, 1 = primary, 2 = Supplement, 3 = volume part 0xff trminator */ - unsigned char stand_ident[5]; /* "CD001" */ - unsigned char vers; /* Version */ - unsigned char volumeflags; /* if bit 0 = 0 => all escape sequences are according ISO 2375 */ - char sysid[32]; /* system Identifier */ - char volid[32]; /* volume Identifier */ - unsigned char zeros1[8]; /* unused */ - unsigned long volsiz_LE; /* volume size Little Endian */ - unsigned long volsiz_BE; /* volume size Big Endian */ - unsigned char escapeseq[32];/* Escape sequences */ - unsigned short setsize_LE; /* volume set size LE */ - unsigned short setsize_BE; /* volume set size BE */ - unsigned short seqnum_LE; /* volume sequence number LE */ - unsigned short seqnum_BE; /* volume sequence number BE */ - unsigned short secsize_LE; /* sector size LE */ - unsigned short secsize_BE; /* sector size BE */ - unsigned long pathtablen_LE;/* Path Table size LE */ - unsigned long pathtablen_BE;/* Path Table size BE */ - unsigned long firstsek_LEpathtab1_LE; /* location of first occurrence of little endian type path table */ - unsigned long firstsek_LEpathtab2_LE; /* location of optional occurrence of little endian type path table */ - unsigned long firstsek_BEpathtab1_BE; /* location of first occurrence of big endian type path table */ - unsigned long firstsek_BEpathtab2_BE; /* location of optional occurrence of big endian type path table */ - unsigned char rootdir[34]; /* directory record for root dir */ - char volsetid[128];/* Volume set identifier */ - char pubid[128]; /* Publisher identifier */ - char dataprepid[128]; /* data preparer identifier */ - char appid[128]; /* application identifier */ - char copyr[37]; /* copyright string */ - char abstractfileid[37]; /* abstract file identifier */ - char bibliofileid[37]; /* bibliographic file identifier */ - unsigned char creationdate[17]; /* creation date */ - unsigned char modify[17]; /* modification date */ - unsigned char expire[17]; /* expiring date */ - unsigned char effective[17];/* effective date */ - unsigned char filestruc_ver; /* file structur version */ -}iso_sup_rec_t; - -typedef struct iso_part_rec { - unsigned char desctype; /* type of Volume descriptor: 0 = boot record, 1 = primary, 2 = Supplement, 3 = volume part 0xff trminator */ - unsigned char stand_ident[5]; /* "CD001" */ - unsigned char vers; /* Version */ - unsigned char unused; - char sysid[32]; /* system Identifier */ - char volid[32]; /* volume partition Identifier */ - unsigned long partloc_LE; /* volume partition location LE */ - unsigned long partloc_BE; /* volume partition location BE */ - unsigned long partsiz_LE; /* volume partition size LE */ - unsigned long partsiz_BE; /* volume partition size BE */ -}iso_part_rec_t; - - -typedef struct iso_val_entry { - unsigned char header_id; /* Header ID must be 0x01 */ - unsigned char platform; /* Platform: 0=x86, 1=PowerPC, 2=MAC */ - unsigned char res[2]; /* reserved */ - char manu_str[0x18]; /* Ident String of manufacturer/developer */ - unsigned char chk_sum[2]; /* Check sum (all words must be zero) */ - unsigned char key[2]; /* key[0]=55, key[1]=0xAA */ -} iso_val_entry_t; - -typedef struct iso_header_entry { - unsigned char header_id; /* Header ID must be 0x90 or 0x91 */ - unsigned char platform; /* Platform: 0=x86, 1=PowerPC, 2=MAC */ - unsigned char numentry[2]; /* number of entries */ - char id_str[0x1C]; /* Ident String of sectionr */ -} iso_header_entry_t; - - -typedef struct iso_init_def_entry { - unsigned char boot_ind; /* Boot indicator 0x88=bootable 0=not bootable */ - unsigned char boot_media; /* boot Media Type: 0=no Emulation, 1=1.2MB floppy, 2=1.44MB floppy, 3=2.88MB floppy 4=hd (0x80) */ - unsigned char ld_seg[2]; /* Load segment (flat model=addr/10) */ - unsigned char systype; /* System Type copy of byte5 of part table */ - unsigned char res; /* reserved */ - unsigned char sec_cnt[2]; /* sector count in VIRTUAL Blocks (0x200) */ - unsigned char rel_block_addr[4]; /* relative Block address */ -} iso_init_def_entry_t; - - -void print_partition_cd(int dev); - -#endif /* _PART_CD_H */ diff --git a/disk/part_mac.c b/disk/part_mac.c deleted file mode 100644 index bebe415..0000000 --- a/disk/part_mac.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * (C) Copyright 2000 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * Support for harddisk partitions. - * - * To be compatible with LinuxPPC and Apple we use the standard Apple - * SCSI disk partitioning scheme. For more information see: - * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92 - */ - -#include <common.h> -#include <command.h> -#include <ide.h> -#include "part_mac.h" - -#if defined(CONFIG_CMD_IDE) || \ - defined(CONFIG_CMD_MG_DISK) || \ - defined(CONFIG_CMD_SCSI) || \ - defined(CONFIG_CMD_SATA) || \ - defined(CONFIG_CMD_USB) || \ - defined(CONFIG_MMC) || \ - defined(CONFIG_SYSTEMACE) - -/* stdlib.h causes some compatibility problems; should fixe these! -- wd */ -#ifndef __ldiv_t_defined -typedef struct { - long int quot; /* Quotient */ - long int rem; /* Remainder */ -} ldiv_t; -extern ldiv_t ldiv (long int __numer, long int __denom); -# define __ldiv_t_defined 1 -#endif - - -static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p); -static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p); - -/* - * Test for a valid MAC partition - */ -int test_part_mac (block_dev_desc_t *dev_desc) -{ - mac_driver_desc_t ddesc; - mac_partition_t mpart; - ulong i, n; - - if (part_mac_read_ddb (dev_desc, &ddesc)) { - /* error reading Driver Desriptor Block, or no valid Signature */ - return (-1); - } - - n = 1; /* assuming at least one partition */ - for (i=1; i<=n; ++i) { - if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)&mpart) != 1) || - (mpart.signature != MAC_PARTITION_MAGIC) ) { - return (-1); - } - /* update partition count */ - n = mpart.map_count; - } - return (0); -} - - -void print_part_mac (block_dev_desc_t *dev_desc) -{ - ulong i, n; - mac_driver_desc_t ddesc; - mac_partition_t mpart; - ldiv_t mb, gb; - - if (part_mac_read_ddb (dev_desc, &ddesc)) { - /* error reading Driver Desriptor Block, or no valid Signature */ - return; - } - - n = ddesc.blk_count; - - mb = ldiv(n, ((1024 * 1024) / ddesc.blk_size)); /* MB */ - /* round to 1 digit */ - mb.rem *= 10 * ddesc.blk_size; - mb.rem += 512 * 1024; - mb.rem /= 1024 * 1024; - - gb = ldiv(10 * mb.quot + mb.rem, 10240); - gb.rem += 512; - gb.rem /= 1024; - - - printf ("Block Size=%d, Number of Blocks=%d, " - "Total Capacity: %ld.%ld MB = %ld.%ld GB\n" - "DeviceType=0x%x, DeviceId=0x%x\n\n" - " #: type name" - " length base (size)\n", - ddesc.blk_size, - ddesc.blk_count, - mb.quot, mb.rem, gb.quot, gb.rem, - ddesc.dev_type, ddesc.dev_id - ); - - n = 1; /* assuming at least one partition */ - for (i=1; i<=n; ++i) { - ulong bytes; - char c; - - printf ("%4ld: ", i); - if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *)&mpart) != 1) { - printf ("** Can't read Partition Map on %d:%ld **\n", - dev_desc->dev, i); - return; - } - - if (mpart.signature != MAC_PARTITION_MAGIC) { - printf ("** Bad Signature on %d:%ld - " - "expected 0x%04x, got 0x%04x\n", - dev_desc->dev, i, MAC_PARTITION_MAGIC, mpart.signature); - return; - } - - /* update partition count */ - n = mpart.map_count; - - c = 'k'; - bytes = mpart.block_count; - bytes /= (1024 / ddesc.blk_size); /* kB; assumes blk_size == 512 */ - if (bytes >= 1024) { - bytes >>= 10; - c = 'M'; - } - if (bytes >= 1024) { - bytes >>= 10; - c = 'G'; - } - - printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)\n", - mpart.type, - mpart.name, - mpart.block_count, - mpart.start_block, - bytes, c - ); - } - - return; -} - - -/* - * Read Device Descriptor Block - */ -static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p) -{ - if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)ddb_p) != 1) { - printf ("** Can't read Driver Desriptor Block **\n"); - return (-1); - } - - if (ddb_p->signature != MAC_DRIVER_MAGIC) { -#if 0 - printf ("** Bad Signature: expected 0x%04x, got 0x%04x\n", - MAC_DRIVER_MAGIC, ddb_p->signature); -#endif - return (-1); - } - return (0); -} - -/* - * Read Partition Descriptor Block - */ -static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p) -{ - int n = 1; - - for (;;) { - /* - * We must always read the descritpor block for - * partition 1 first since this is the only way to - * know how many partitions we have. - */ - if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) { - printf ("** Can't read Partition Map on %d:%d **\n", - dev_desc->dev, n); - return (-1); - } - - if (pdb_p->signature != MAC_PARTITION_MAGIC) { - printf ("** Bad Signature on %d:%d: " - "expected 0x%04x, got 0x%04x\n", - dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature); - return (-1); - } - - if (n == part) - return (0); - - if ((part < 1) || (part > pdb_p->map_count)) { - printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n", - dev_desc->dev, part, - dev_desc->dev, - dev_desc->dev, pdb_p->map_count); - return (-1); - } - - /* update partition count */ - n = part; - } - - /* NOTREACHED */ -} - -int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info) -{ - mac_driver_desc_t ddesc; - mac_partition_t mpart; - - if (part_mac_read_ddb (dev_desc, &ddesc)) { - return (-1); - } - - info->blksz = ddesc.blk_size; - - if (part_mac_read_pdb (dev_desc, part, &mpart)) { - return (-1); - } - - info->start = mpart.start_block; - info->size = mpart.block_count; - memcpy (info->type, mpart.type, sizeof(info->type)); - memcpy (info->name, mpart.name, sizeof(info->name)); - - return (0); -} - -#endif diff --git a/disk/part_mac.h b/disk/part_mac.h deleted file mode 100644 index a7ad697..0000000 --- a/disk/part_mac.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * (C) Copyright 2000 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * See also Linux sources, fs/partitions/mac.h - * - * This file describes structures and values related to the standard - * Apple SCSI disk partitioning scheme. For more information see: - * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92 - */ - -#ifndef _DISK_PART_MAC_H -#define _DISK_PART_MAC_H - -#define MAC_DRIVER_MAGIC 0x4552 - -/* - * Driver Descriptor Structure, in block 0. - * This block is (and shall remain) 512 bytes long. - * Note that there is an alignment problem for the driver descriptor map! - */ -typedef struct mac_driver_desc { - __u16 signature; /* expected to be MAC_DRIVER_MAGIC */ - __u16 blk_size; /* block size of device */ - __u32 blk_count; /* number of blocks on device */ - __u16 dev_type; /* device type */ - __u16 dev_id; /* device id */ - __u32 data; /* reserved */ - __u16 drvr_cnt; /* number of driver descriptor entries */ - __u16 drvr_map[247]; /* driver descriptor map */ -} mac_driver_desc_t; - -/* - * Device Driver Entry - * (Cannot be included in mac_driver_desc because of alignment problems) - */ -typedef struct mac_driver_entry { - __u32 block; /* block number of starting block */ - __u16 size; /* size of driver, in 512 byte blocks */ - __u16 type; /* OS Type */ -} mac_driver_entry_t; - - -#define MAC_PARTITION_MAGIC 0x504d - -/* type field value for A/UX or other Unix partitions */ -#define APPLE_AUX_TYPE "Apple_UNIX_SVR2" - -/* - * Each Partition Map entry (in blocks 1 ... N) has this format: - */ -typedef struct mac_partition { - __u16 signature; /* expected to be MAC_PARTITION_MAGIC */ - __u16 sig_pad; /* reserved */ - __u32 map_count; /* # blocks in partition map */ - __u32 start_block; /* abs. starting block # of partition */ - __u32 block_count; /* number of blocks in partition */ - uchar name[32]; /* partition name */ - uchar type[32]; /* string type description */ - __u32 data_start; /* rel block # of first data block */ - __u32 data_count; /* number of data blocks */ - __u32 status; /* partition status bits */ - __u32 boot_start; /* first block of boot code */ - __u32 boot_size; /* size of boot code, in bytes */ - __u32 boot_load; /* boot code load address */ - __u32 boot_load2; /* reserved */ - __u32 boot_entry; /* boot code entry point */ - __u32 boot_entry2; /* reserved */ - __u32 boot_cksum; /* boot code checksum */ - uchar processor[16]; /* Type of Processor */ - __u16 part_pad[188]; /* reserved */ -#ifdef CONFIG_ISO_PARTITION - uchar iso_dummy[2048];/* Reservere enough room for an ISO partition block to fit */ -#endif -} mac_partition_t; - -#define MAC_STATUS_BOOTABLE 8 /* partition is bootable */ - -#endif /* _DISK_PART_MAC_H */ |