]> git.sur5r.net Git - u-boot/blobdiff - disk/part_amiga.c
spi_flash: add a bunch of winbond flashes to id-table
[u-boot] / disk / part_amiga.c
index aafbcd84cc43ac065272e0b0047bae035b9b97a6..86d008d476e39fe3320f3c04da18ddb70c3fd2f5 100644 (file)
@@ -1,33 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2001
- * Hans-Joerg Frieden, Hyperion Entertainment 
+ * 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 <cmd_disk.h>
 #include "part_amiga.h"
 
-#if ((CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI)) && defined(CONFIG_AMIGA_PARTITION)
+#ifdef CONFIG_HAVE_BLOCK_DEVICE
 
 #undef AMIGA_DEBUG
 
@@ -72,7 +54,7 @@ static void bstr_print(char *string)
     int len = *string++;
     char buffer[256];
     int i;
-    
+
     i = 0;
     while (len)
     {
@@ -97,7 +79,7 @@ int sum_block(struct block_header *header)
 
     for (i = 0; i < header->summed_longs; i++)
        sum += *block++;
-    
+
     return (sum != 0);
 }
 
@@ -126,12 +108,12 @@ static void print_disk_type(u32 disk_type)
 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 , 
+    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);
@@ -143,22 +125,21 @@ static void print_part_info(struct partition_block *p)
  * 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)
+struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc)
 {
     int i;
     int limit;
     char *s;
 
-    s = getenv("amiga_scanlimit");
+    s = env_get("amiga_scanlimit");
     if (s)
-       limit = atoi(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);
+       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;
@@ -178,21 +159,21 @@ struct rigid_disk_block *get_rdisk(block_dev_desc_t *dev_desc)
     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)
+struct bootcode_block *get_bootcode(struct blk_desc *dev_desc)
 {
     int i;
     int limit;
     char *s;
 
-    s = getenv("amiga_scanlimit");
+    s = env_get("amiga_scanlimit");
     if (s)
-       limit = atoi(s);
+       limit = simple_strtoul(s, NULL, 10);
     else
        limit = AMIGA_BLOCK_LIMIT;
 
@@ -200,7 +181,7 @@ struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc)
 
     for (i = 0; i < limit; i++)
     {
-       ulong res = dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)block_buffer);
+       ulong res = blk_dread(dev_desc, i, 1, (ulong *)block_buffer);
        if (res == 1)
        {
            struct bootcode_block *boot = (struct bootcode_block *)block_buffer;
@@ -221,40 +202,41 @@ struct bootcode_block *get_bootcode(block_dev_desc_t *dev_desc)
     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)
+static int part_test_amiga(struct blk_desc *dev_desc)
 {
     struct rigid_disk_block *rdb;
     struct bootcode_block *bootcode;
 
-    PRINTF("test_part_amiga: Testing for an Amiga RDB partition\n");
-    
+    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("test_part_amiga: bootable Amiga disk\n");
+           PRINTF("part_test_amiga: bootable Amiga disk\n");
        else
-           PRINTF("test_part_amiga: non-bootable Amiga disk\n");
+           PRINTF("part_test_amiga: non-bootable Amiga disk\n");
 
        return 0;
     }
-    else 
+    else
     {
-       PRINTF("test_part_amiga: no RDB found\n");
+       PRINTF("part_test_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)
+static struct partition_block *find_partition(struct blk_desc *dev_desc,
+                                             int partnum)
 {
     struct rigid_disk_block *rdb;
     struct partition_block *p;
@@ -262,12 +244,12 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
 
     PRINTF("Trying to find partition block %d\n", partnum);
     rdb = get_rdisk(dev_desc);
-    if (!rdb) 
+    if (!rdb)
     {
        PRINTF("find_partition: no rdb found\n");
        return NULL;
     }
-    
+
     PRINTF("find_partition: Scanning partition list\n");
 
     block = rdb->partition_list;
@@ -275,8 +257,7 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
 
     while (block != 0xFFFFFFFF)
     {
-       ulong res = dev_desc->block_read(dev_desc->dev, block, 1,
-                                        (ulong *)block_buffer);
+       ulong res = blk_dread(dev_desc, block, 1, (ulong *)block_buffer);
        if (res == 1)
        {
            p = (struct partition_block *)block_buffer;
@@ -286,7 +267,7 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
                if (sum_block((struct block_header *)p) == 0)
                {
                    if (partnum == 0) break;
-                   else 
+                   else
                    {
                        partnum--;
                        block = p->next;
@@ -296,7 +277,7 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
        } else block = 0xFFFFFFFF;
     }
 
-    if (block == 0xFFFFFFFF) 
+    if (block == 0xFFFFFFFF)
     {
        PRINTF("PART block not found\n");
        return NULL;
@@ -305,10 +286,11 @@ static struct partition_block *find_partition(block_dev_desc_t *dev_desc, int pa
     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)
+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;
@@ -320,8 +302,8 @@ int get_partition_info_amiga (block_dev_desc_t *dev_desc, int part, disk_partiti
     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);
-    
+    bcpl_strcpy((char *)info->name, p->drive_name);
+
 
     disk_type = g->dos_type;
 
@@ -331,12 +313,12 @@ int get_partition_info_amiga (block_dev_desc_t *dev_desc, int part, disk_partiti
     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)
-{    
+static void part_print_amiga(struct blk_desc *dev_desc)
+{
     struct rigid_disk_block *rdb;
     struct bootcode_block *boot;
     struct partition_block *p;
@@ -344,16 +326,16 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
     int i = 1;
 
     rdb = get_rdisk(dev_desc);
-    if (!rdb) 
+    if (!rdb)
     {
-       PRINTF("print_part_amiga: no rdb found\n");
+       PRINTF("part_print_amiga: no rdb found\n");
        return;
     }
-    
-    PRINTF("print_part_amiga: Scanning partition list\n");
+
+    PRINTF("part_print_amiga: Scanning partition list\n");
 
     block = rdb->partition_list;
-    PRINTF("print_part_amiga: partition list at 0x%x\n", block);
+    PRINTF("part_print_amiga: partition list at 0x%x\n", block);
 
     printf("Summary:  DiskBlockSize: %d\n"
           "          Cylinders    : %d\n"
@@ -370,9 +352,8 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
        ulong res;
 
        PRINTF("Trying to load block #0x%X\n", block);
-       
-       res = dev_desc->block_read(dev_desc->dev, block, 1,
-                                  (ulong *)block_buffer);
+
+       res = blk_dread(dev_desc, block, 1, (ulong *)block_buffer);
        if (res == 1)
        {
            p = (struct partition_block *)block_buffer;
@@ -396,4 +377,13 @@ void print_part_amiga (block_dev_desc_t *dev_desc)
     }
 }
 
+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