Jump to content


Photo

Patch For Linux To Use Partitions After Hda55/56 (f/g) - Native Instal


  • Please log in to reply
9 replies to this topic

#1 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 19 May 2008 - 01:30 AM

This came from Torne Wuff , torne-xboxlinuxdevellist@wolfpuppy.org.uk. He used his xbox on hda57 (partition 8) and swap on hda58 (partition 9) and that worked for him, enabling him to have
a linux filesystem natively formatted without giving up the F/G drives used by homebrew software.

Reference: http://article.gmane...xbox.devel/7572

CODE

Index: linux-2.4.32-xbox-r1/fs/partitions/xbox.c
===================================================================
--- linux-2.4.32-xbox-r1.orig/fs/partitions/xbox.c
+++ linux-2.4.32-xbox-r1/fs/partitions/xbox.c
@@ -26,7 +26,7 @@

/*
  * The offset for numbering xbox partitions:
- * We create hdX50->56
+ * We create hdX50->56 (or higher if a partition table is found in sector 0)
  */
#define XBOX_PARTITION_OFFSET    50

@@ -51,6 +51,26 @@

#define XBOX_SECTOR_MAGIC    (3L)

+#define XBOX_PARTITION_IN_USE    0x80000000
+
+typedef struct
+{
+    char name[16];
+    u32  flags;
+    u32  start;
+    u32  size;
+    u32  reserved;
+} xbox_partition_entry;
+
+
+typedef struct
+{
+    char                 magic[16];
+    char                 reserved[32];
+    xbox_partition_entry partitions[14];
+} xbox_partition_table;
+
+
static int
xbox_sig_string_match(    struct block_device *bdev,
            unsigned long at_sector,
@@ -101,6 +121,33 @@ xbox_drive_detect(struct block_device *b
        (xbox_sig_string_match(bdev,XBOX_SECTOR_STORE ,"FATX"))) {
        return 1; //success
    }
+
+    return 0; // no xbox drive
+}
+
+static inline int
+xbox_ptbl_detect(struct block_device *bdev)
+{
+    /**
+    * check for "BRFR" magic number, then for "****PARTINFO****" at
+    * start of zeroth sector. This intentionally doesn't check for
+    * FATX signatures at the expected system and store locations
+    * as it's possible for these partitions to have been moved.
+    */
+    if (xbox_sig_string_match(bdev,XBOX_SECTOR_MAGIC,"BRFR")) {
+        Sector sect;
+        int retv;
+        xbox_partition_table *table;
+
+        table = (xbox_partition_table*)read_dev_sector(bdev, XBOX_SECTOR_CONFIG, &sect);
+
+        if (!table) return 0;
+
+        if (strncmp(table->magic, "****PARTINFO****", 16) == 0) retv = 1; else retv = 0;
+
+        put_dev_sector(sect);
+        return retv;
+    }
    
    return 0; // no xbox drive
}
@@ -118,8 +165,32 @@ int xbox_partition(struct gendisk *hd, s
        return 0;
    }
    
-    if (xbox_drive_detect(bdev)) {
-        num_sectors = (blk_size[hd->major][first_part_minor-1] << 1);
+    num_sectors = (blk_size[hd->major][first_part_minor-1] << 1);
+
+    if (xbox_ptbl_detect(bdev)) {
+        Sector sect;
+        xbox_partition_table *table;
+
+        table = (xbox_partition_table*)read_dev_sector(bdev, XBOX_SECTOR_CONFIG, &sect);
+
+        if (!table) return 0;
+
+        int i;
+        for (i=0; i<14; i++) {
+            xbox_partition_entry *part = &table->partitions[i];
+            if (part->flags & XBOX_PARTITION_IN_USE) {
+                if (part->start >= num_sectors)
+                    printk("xbox_partition: partition %d starts off the end of the disk, at sector %d, skipping\n", i, part->start);
+                else if (part->start + part->size > num_sectors)
+                    printk("xbox_partition: partition %d extends past the end of the disk, to sector %d, skipping\n",
i, part->start + part->size - 1);
+                else
+                    add_gd_partition(hd,minor+i,part->start,part->size);
+            }
+        }
+
+        put_dev_sector(sect);
+        return 1;
+    } else if (xbox_drive_detect(bdev)) {
        add_gd_partition(hd,minor++,XBOX_SECTOR_STORE ,XBOX_SECTORS_STORE );
        add_gd_partition(hd,minor++,XBOX_SECTOR_SYSTEM,XBOX_SECTORS_SYSTEM);
        add_gd_partition(hd,minor++,XBOX_SECTOR_CACHE1,XBOX_SECTORS_CACHE1);
@@ -136,6 +207,7 @@ int xbox_partition(struct gendisk *hd, s
            /* Just a large F on this system - to end of drive*/
            else add_gd_partition(hd,minor++,XBOX_SECTOR_EXTEND_F, num_sectors-XBOX_SECTOR_EXTEND_F);
        }
+        return 0; // this will ensure other partition schemes are tried
    } else {
        //not an xbox drive
        return 0;
Index: linux-2.4.32-xbox-r1/fs/partitions/check.c
===================================================================
--- linux-2.4.32-xbox-r1.orig/fs/partitions/check.c
+++ linux-2.4.32-xbox-r1/fs/partitions/check.c
@@ -42,6 +42,14 @@ extern int *blk_size[];
int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/

static int (*check_part[])(struct gendisk *hd, struct block_device *bdev, unsigned long first_sect,
int first_minor) = {
+#ifdef CONFIG_XBOX_PARTITION
+/* do this first; if the drive is Xbox-formatted, add partitions 50+
+ * and then go ahead and look for other schemes - this way, an Xbox
+ * HD can have 2 partitioning systems: the implicit Xbox one (50+)
+ * and the explicit one (1+)
+ */
+    xbox_partition,
+#endif
#ifdef CONFIG_ACORN_PARTITION
    acorn_partition,
#endif
@@ -270,12 +278,6 @@ static void check_partition(struct gendi

    printk(" unknown partition table\n");
setup_devfs:
-/* if the drive is Xbox-formatted, add partitions 50+ to the existing
-   partitions - this way, an Xbox HD can have 2 partitioning systems
-   systems: the implicit Xbox one (50+) and the explicit one (1+) */
-#ifdef CONFIG_XBOX_PARTITION
-        xbox_partition(hd, bdev, first_sector, first_part_minor);
-#endif
    invalidate_bdev(bdev, 1);
    truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
    bdput(bdev);



#2 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 20 March 2010 - 03:21 PM

Comparing against ozpaulb's code, there are differences:

Paul's code
CODE

typedef struct tagPARTITION_TABLE {
char pt_magic[16];
unsigned char pt_reserved[32];
PARTITION_ENTRY pt_entries[MAX_PARTITIONS];
} PARTITION_TABLE;

#define LBA48_GET_INFO_MAGIC1_IDX 0
#define LBA48_GET_INFO_MAGIC1_VAL 0xcafebabe
#define LBA48_GET_INFO_MAGIC2_IDX 1
#define LBA48_GET_INFO_MAGIC2_VAL 0xbabeface
#define LBA48_GET_INFO_PATCHCODE_VERSION_IDX 2
#define LBA48_GET_INFO_LOWCODE_BASE_IDX  3
#define LBA48_GET_INFO_HIGHCODE_BASE_IDX 4
#define LBA48_GET_INFO_PATCHSEG_SIZE_IDX 5
#define LBA48_GET_INFO_PART_TABLE_OFS_IDX 6


CODE

if ((ioctl_cmd_out_buf[LBA48_GET_INFO_MAGIC1_IDX] != LBA48_GET_INFO_MAGIC1_VAL) ||
(ioctl_cmd_out_buf[LBA48_GET_INFO_MAGIC2_IDX] != LBA48_GET_INFO_MAGIC2_VAL)) {

return STATUS_UNSUCCESSFUL;
}

partition_table_addr = ioctl_cmd_out_buf[LBA48_GET_INFO_LOWCODE_BASE_IDX];
partition_table_addr += ioctl_cmd_out_buf[LBA48_GET_INFO_PART_TABLE_OFS_IDX];


Torne's patch
CODE

+typedef struct
+{
+    char                 magic[16];
+    char                 reserved[32];
+    xbox_partition_entry partitions[14];
+} xbox_partition_table;
+
+

if (strncmp(table->magic, "****PARTINFO****", 16) == 0) retv = 1; else retv = 0;


Seems that Torne's patch uses a different magic value.

In additional, xbpartitioner 1.0 uses additional logic for version 2 of the partition table scheme:
CODE

  if (*version == 2)
                        partition_table_addr += 0x200;


For Linux to understand xbpartitioner created partition table, more work is needed.

#3 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 22 March 2010 - 01:19 PM

Reference: IoSupport.cpp from XBMC:

CODE

662    unsigned int CIoSupport::ReadPartitionTable(PARTITION_TABLE *p_table)
663    {
664    #ifdef _XBOX
665      ANSI_STRING a_file;
666      OBJECT_ATTRIBUTES obj_attr;
667      IO_STATUS_BLOCK io_stat_block;
668      HANDLE handle;
669      unsigned int stat;
670      unsigned int ioctl_cmd_in_buf[100];
671      unsigned int ioctl_cmd_out_buf[100];
672      unsigned int partition_table_addr;
673    
674      memset(p_table, 0, sizeof(PARTITION_TABLE));
675    
676      RtlInitAnsiString(&a_file, "\\Device\\Harddisk0\\partition0");
677      obj_attr.RootDirectory = 0;
678      obj_attr.ObjectName = &a_file;
679      obj_attr.Attributes = OBJ_CASE_INSENSITIVE;
680    
681      stat = NtOpenFile(&handle, (GENERIC_READ | 0x00100000), &obj_attr, &io_stat_block, (FILE_SHARE_READ | FILE_SHARE_WRITE), 0x10);
682    
683      if (stat != STATUS_SUCCESS)
684      {
685        return stat;
686      }
687    
688      memset(ioctl_cmd_out_buf, 0, sizeof(ioctl_cmd_out_buf));
689      memset(ioctl_cmd_in_buf, 0, sizeof(ioctl_cmd_in_buf));
690      ioctl_cmd_in_buf[0] = IOCTL_SUBCMD_GET_INFO;
691    
692    
693      stat = NtDeviceIoControlFile(handle, 0, 0, 0, &io_stat_block,
694                                   IOCTL_CMD_LBA48_ACCESS,
695                                   ioctl_cmd_in_buf, sizeof(ioctl_cmd_in_buf),
696                                   ioctl_cmd_out_buf, sizeof(ioctl_cmd_out_buf));
697    
698      NtClose(handle);
699      if (stat != STATUS_SUCCESS)
700      {
701        return stat;
702      }
703    
704      if ((ioctl_cmd_out_buf[LBA48_GET_INFO_MAGIC1_IDX] != LBA48_GET_INFO_MAGIC1_VAL) ||
705          (ioctl_cmd_out_buf[LBA48_GET_INFO_MAGIC2_IDX] != LBA48_GET_INFO_MAGIC2_VAL))
706      {
707    
708        return STATUS_UNSUCCESSFUL;
709      }
710    
711      partition_table_addr = ioctl_cmd_out_buf[LBA48_GET_INFO_LOWCODE_BASE_IDX];
712      partition_table_addr += ioctl_cmd_out_buf[LBA48_GET_INFO_PART_TABLE_OFS_IDX];
713    
714      memcpy(p_table, (void *)partition_table_addr, sizeof(PARTITION_TABLE));
715    
716      return STATUS_SUCCESS;
717    #else
718      return (unsigned int) -1;
719    #endif
720    }


#4 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 03 April 2010 - 03:38 AM

I did a dd if=/dev/hda of=pt bs=512 count=3 to extract the first 3 sectors of my hdd formatted by xbpartitioner and a hexdump -C and this is what I got

CODE

00000000  2a 2a 2a 2a 50 41 52 54  49 4e 46 4f 2a 2a 2a 2a  |****PARTINFO****|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000030  58 42 4f 58 20 53 48 45  4c 4c 20 20 20 20 20 20  |XBOX SHELL      |
00000040  00 00 00 80 00 f4 55 00  b0 96 98 00 00 00 00 00  |......U.........|
00000050  58 42 4f 58 20 44 41 54  41 20 20 20 20 20 20 20  |XBOX DATA       |
00000060  00 00 00 80 00 54 46 00  00 a0 0f 00 00 00 00 00  |.....TF.........|
00000070  58 42 4f 58 20 47 41 4d  45 20 53 57 41 50 20 31  |XBOX GAME SWAP 1|
00000080  00 00 00 80 00 04 00 00  00 70 17 00 00 00 00 00  |.........p......|
00000090  58 42 4f 58 20 47 41 4d  45 20 53 57 41 50 20 32  |XBOX GAME SWAP 2|
000000a0  00 00 00 80 00 74 17 00  00 70 17 00 00 00 00 00  |.....t...p......|
000000b0  58 42 4f 58 20 47 41 4d  45 20 53 57 41 50 20 33  |XBOX GAME SWAP 3|
000000c0  00 00 00 80 00 e4 2e 00  00 70 17 00 00 00 00 00  |.........p......|
000000d0  58 42 4f 58 20 46 20 20  20 20 20 20 20 20 20 20  |XBOX F          |
000000e0  00 00 00 80 b0 8a ee 00  00 60 54 24 00 00 00 00  |.........`T$....|
000000f0  58 42 4f 58 20 47 20 20  20 20 20 20 20 20 20 20  |XBOX G          |
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000600


I see the PARTINFO magic value but not Paul's 0xcafebabe and 0xbabeface values. I cross referenced xbox linux and the partitions offsets match. Still can't figure out how Paul's code works... mad.gif

#5 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 03 April 2010 - 05:25 PM

Made some progress:
1. Found this through Google: http://forums.xbox-s...howtopic=710509
2. The magic values seem to be at different places. One on hdd , the others in memory.
3. Decided to hand patch Torne's code onto 2.4.32 kernel and uploaded the bzImage to xboxhdm2's sourceforge.

If you own a xbox with a hdd formatted by xbpartitioner and are also conversant with Linux, you can try the kernel and report back with your results. It doesn't yet handle large size FATX clusters so don't mount anything. Just check the hda partitions are created and match those with xbpartitioner.


#6 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 06 April 2010 - 01:15 PM

The patch appeared to work. I was able to mount F drive created by xbpartitioner in Xebian running the patched kernel. It was seen as /dev/hda55 in Linux/

Moreover, I patched the FATX kernel source to accept the 32k on-disk cluster size and it appeared to work too. I was able to copy a copy of XBMC from E drive to F drive without errors in Xebian and XBMC when executed from this copy appeared to work normally.

Changes was confined to fatx_parse_boot_block method in inode.c. To remove CLUSTER_SIZE and replace with b->cluster_size. There were errors reported "file cluster badly computed" during the copy but that did not seem to affect XBMC operations.

More testing is needed. Source , kernel bzImage and modules have been uploaded to xboxhdm2.1's sourceforge LBA48 folder.

Edited by ldotsfan, 06 April 2010 - 01:18 PM.


#7 scullc

scullc

    X-S Senior Member

  • Members
  • PipPip
  • 193 posts

Posted 06 April 2010 - 10:48 PM

Another great bit of work. Well done.
Your work continues to impress me beerchug.gif
I would love to help/test etc...unfortunately I am much too busy at the moment to offer any serious testing.
When I am available I will report back...but realistically it wont be til late July/early August.
Yup, tell me about it blink.gif lol

#8 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 07 April 2010 - 01:39 PM

QUOTE(ldotsfan @ Apr 6 2010, 08:15 PM) View Post

More testing is needed


Created a /dev/hda55 FATX with 16k cluster size and /dev/hda57 and reformatted to ext3. Yes hda56 is unused. sleep.gif

Copied some files from E drive to hda55 and randomly did a cmp to compare the files and they match. With 16k, no "file cluster badly computed" errors reported. A df on both partitions reported the right sizes.

Will reformat back to 32k for further tests.

Edited by ldotsfan, 07 April 2010 - 01:39 PM.


#9 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 12 April 2010 - 01:58 PM

Compiled cloop-1.0.2 and squashfs-2.2 modules. Preparation for Xebian based remake of xboxhdm. Reminder to use gcc3 instead of gcc4.

Will upload sources and binaries to sourceforge.

#10 ldotsfan

ldotsfan

    X-S Messiah

  • Dev/Contributor
  • PipPipPipPipPipPipPip
  • 3,100 posts
  • Xbox Version:v1.1
  • 360 version:unknown

Posted 12 April 2010 - 03:45 PM

QUOTE(ldotsfan @ Apr 6 2010, 08:15 PM) View Post

There were errors reported "file cluster badly computed" during the copy but that did not seem to affect XBMC operations.

The 2.6.22-xbox did things differently.

CODE

+       if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits - 9))) {
+               fatx_fs_panic(sb, "clusters badly computed (%d != %lu)",
+                       new_fclus, inode->i_blocks >> (sbi->cluster_bits - 9));
+               fatx_cache_inval_inode(inode);  


instead of 2.4.32-xbox:
CODE

if (file_cluster
            != inode->i_blocks / cluster_size / (sb->s_blocksize / 512)) {
                printk ("file_cluster badly computed!!! %d <> %ld\n",
                        file_cluster,
                        inode->i_blocks / cluster_size / (sb->s_blocksize / 512));
                fatx_cache_inval_inode(inode);
        }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users