From: David Blythe <blythe@routefree.com>
To: Steven Hein <ssh@sgi.com>
Cc: linuxppc-embedded@lists.linuxppc.org
Subject: Re: mkcramfs changes to switch endianness
Date: Wed, 02 May 2001 16:56:03 -0700 [thread overview]
Message-ID: <3AF09E93.80A5B92B@routefree.com> (raw)
In-Reply-To: 3AF07046.3827B997@sgi.com
[-- Attachment #1: Type: text/plain, Size: 591 bytes --]
Steven Hein wrote:
>
> I'm getting ready to try using cramfs in the 2.4.4 kernel.
> Anybody done the work to make 'mkcramfs' create a big-endian
> image on a little-endian PC? Before I reinvent the wheel,
> I'd like to find out if anybody as done it (and would like
> to share :)
I have the changes for the pre-midori mkcramfs. works fine but it
is very ugly because of the use of bit fields. Have been running it for
a few months and it does work fine :) We are in the process of
integrating the latest changes from transmeta, but here is the patch for
the old version.
>
> Steve
>
[-- Attachment #2: mkcramfs.patch --]
[-- Type: text/plain, Size: 2693 bytes --]
diff -u -r1.1 -r1.2
--- scripts/cramfs/mkcramfs.c 2000/07/28 19:02:52 1.1
+++ scripts/cramfs/mkcramfs.c 2001/03/09 19:55:28 1.2
@@ -25,7 +25,7 @@
static void usage(void)
{
- fprintf(stderr, "Usage: '%s dirname outfile'\n"
+ fprintf(stderr, "Usage: '%s [-e] dirname outfile'\n"
" where <dirname> is the root of the\n"
" filesystem to be compressed.\n", progname);
exit(1);
@@ -46,6 +46,7 @@
static unsigned int blksize = PAGE_CACHE_SIZE;
static int warn_dev, warn_gid, warn_namelen, warn_size, warn_uid;
+static int swap_endian;
#ifndef MIN
# define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
@@ -273,6 +274,39 @@
memset(area, 0x00, size);
}
+static void fix_inode(struct cramfs_inode *inode)
+{
+#define wswap(x) (((x)>>24) | (((x)>>8)&0xff00) | (((x)&0xff00)<<8) | (((x)&0xff)<<24))
+ /* attempt #2 */
+ inode->mode = (inode->mode >> 8) | ((inode->mode&0xff)<<8);
+ inode->uid = (inode->uid >> 8) | ((inode->uid&0xff)<<8);
+ inode->size = (inode->size >> 16) | (inode->size&0xff00) |
+ ((inode->size&0xff)<<16);
+ ((u32*)inode)[2] = wswap(inode->offset | (inode->namelen<<26));
+}
+
+static void fix_offset(struct cramfs_inode *inode, u32 offset)
+{
+ u32 tmp = wswap(((u32*)inode)[2]);
+ ((u32*)inode)[2] = wswap((offset >> 2) | (tmp&0xfc000000));
+}
+
+static void fix_block_pointer(u32 *p)
+{
+ *p = wswap(*p);
+}
+
+static void fix_super(struct cramfs_super *super)
+{
+ u32 *p = (u32*)super;
+ p[0] = wswap(p[0]); /* magic */
+ p[1] = wswap(p[1]); /* size */
+ p[2] = wswap(p[2]); /* flags */
+ p[3] = wswap(p[3]); /* future */
+ fix_inode(&super->root);
+#undef wswap
+}
+
/* Returns sizeof(struct cramfs_super), which includes the root inode. */
static unsigned int write_superblock(struct entry *root, char *base)
{
@@ -293,6 +327,7 @@
super->root.gid = root->gid;
super->root.size = root->size;
super->root.offset = offset >> 2;
+ if (swap_endian) fix_super(super);
return offset;
}
@@ -305,7 +340,10 @@
fprintf(stderr, "filesystem too big. Exiting.\n");
exit(1);
}
- inode->offset = (offset >> 2);
+ if (swap_endian)
+ fix_offset(inode, offset);
+ else
+ inode->offset = (offset >> 2);
}
@@ -360,6 +398,7 @@
stack_entries++;
}
entry = entry->next;
+ if (swap_endian) fix_inode(inode);
}
/*
@@ -452,6 +491,7 @@
}
*(u32 *) (base + offset) = curr;
+ if (swap_endian) fix_block_pointer((u32*)(base + offset));
offset += 4;
} while (size);
@@ -529,6 +569,18 @@
if (argc)
progname = argv[0];
+ while(argc > 1 && argv[1][0] == '-') {
+ switch(argv[1][1]) {
+ case 'e':
+ swap_endian = 1;
+ break;
+ default:
+ usage();
+ break;
+ }
+ argv++; argc--;
+ }
+
if (argc != 3)
usage();
next prev parent reply other threads:[~2001-05-02 23:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-02 20:38 mkcramfs changes to switch endianness Steven Hein
2001-05-02 20:39 ` Matthew Locke
2001-05-02 23:56 ` David Blythe [this message]
2001-05-03 2:24 ` Steve Hein
2001-05-03 18:32 ` David Blythe
2001-05-03 18:48 ` Matthew Locke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3AF09E93.80A5B92B@routefree.com \
--to=blythe@routefree.com \
--cc=linuxppc-embedded@lists.linuxppc.org \
--cc=ssh@sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).