123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- #include <common.h>
- #include <command.h>
- #include <ide.h>
- #include "part_amiga.h"
- #ifdef HAVE_BLOCK_DEVICE
- #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};
- static void bcpl_strcpy(char *to, char *from)
- {
- int len = *from++;
- while (len)
- {
- *to++ = *from++;
- len--;
- }
- *to = 0;
- }
- 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);
- }
- 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);
- }
- 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);
- }
- 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);
- }
- struct rigid_disk_block *get_rdisk(struct blk_desc *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 = blk_dread(dev_desc, 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;
- }
- struct bootcode_block *get_bootcode(struct blk_desc *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 = blk_dread(dev_desc, 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;
- }
- static int part_test_amiga(struct blk_desc *dev_desc)
- {
- struct rigid_disk_block *rdb;
- struct bootcode_block *bootcode;
- PRINTF("part_test_amiga: Testing for an Amiga RDB partition\n");
- rdb = get_rdisk(dev_desc);
- if (rdb)
- {
- bootcode = get_bootcode(dev_desc);
- if (bootcode)
- PRINTF("part_test_amiga: bootable Amiga disk\n");
- else
- PRINTF("part_test_amiga: non-bootable Amiga disk\n");
- return 0;
- }
- else
- {
- PRINTF("part_test_amiga: no RDB found\n");
- return -1;
- }
- }
- static struct partition_block *find_partition(struct blk_desc *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 = blk_dread(dev_desc, 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;
- }
- static int part_get_info_amiga(struct blk_desc *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((char *)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;
- }
- static void part_print_amiga(struct blk_desc *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("part_print_amiga: no rdb found\n");
- return;
- }
- PRINTF("part_print_amiga: Scanning partition list\n");
- block = rdb->partition_list;
- PRINTF("part_print_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 = blk_dread(dev_desc, 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");
- }
- }
- U_BOOT_PART_TYPE(amiga) = {
- .name = "AMIGA",
- .part_type = PART_TYPE_AMIGA,
- .max_entries = AMIGA_ENTRY_NUMBERS,
- .get_info = part_get_info_amiga,
- .print = part_print_amiga,
- .test = part_test_amiga,
- };
- #endif
|