My aim now is changing the table of partitions to let mtd command (mtd -r write firmware.bin linux) work correctly. I studied some of the WP54 OpenWrt source code (which is same as the official one, except for some few lines of myloader.c). This is what I found.
Referring to trunk/target/linux/adm5120-2.6/files/drivers/mtd/myloader.c, these appear to be the lines dealing with partitions.
static char *myloader_partitions_name[MYLO_MAX_PARTITIONS] =
{"lzma loader", "kernel", "rootfs", "reserved0", "reserved1", "reserved2", "reserved3", "reserved4"};
int parse_myloader_partitions(struct mtd_info *master,
struct mtd_partition **pparts,
unsigned long origin)
{
struct mylo_partition_table *tab;
struct mylo_partition *part;
struct mtd_partition *mtd_parts;
struct mtd_partition *mtd_part;
[...]
mtd_parts = kzalloc((num_parts*sizeof(*mtd_part) + num_parts*NAME_LEN_MAX),
GFP_KERNEL);
if (!mtd_parts) {
ret = -ENOMEM;
goto out_free_buf;
}
mtd_part = mtd_parts;
names = (char *)&mtd_parts[num_parts];
strncpy(names, NAME_MYLOADER, NAME_LEN_MAX-1);
mtd_part->name = names;
mtd_part->offset = 0;
mtd_part->size = blocklen;
mtd_part++;
names += NAME_LEN_MAX;
strncpy(names, NAME_PARTITION_TABLE, NAME_LEN_MAX-1);
mtd_part->name = names;
mtd_part->offset = blocklen;
mtd_part->size = blocklen;
mtd_part++;
names += NAME_LEN_MAX;
for (i = 0; i < MYLO_MAX_PARTITIONS; i++) {
part = &tab->partitions[i];
if (le16_to_cpu(part->type) == PARTITION_TYPE_FREE)
continue;
sprintf(names, myloader_partitions_name[i]);
mtd_part->name = names;
mtd_part->offset = le32_to_cpu(part->addr);
mtd_part->size = le32_to_cpu(part->size);
mtd_part++;
names += NAME_LEN_MAX;
}
mtd_part is a pointer to a mtd_partition class, which is defined in trunk/toolchain_build_mipsel/linux/include/linux/mtd/partitions.h
struct mtd_partition {
char *name; /* identifier string */
u_int32_t size; /* partition size */
u_int32_t offset; /* offset within the master MTD space */
u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/
struct mtd_info **mtdp; /* pointer to store the MTD object */
};
To let mtd command (mtd -r write firmware.bin linux) work correctly, I think I would merge "lzma loader" and "kernel" partitions into a "linux" one.
So:
static char *myloader_partitions_name[MYLO_MAX_PARTITIONS] =
{"linux", "rootfs", "reserved0", "reserved1", "reserved2", "reserved3", "reserved4", "reserved5"};
My only problem now is: how can I assign the right value of start point and size of the partitions?
I think the key is in those lines.
mtd_part->offset = le32_to_cpu(part->addr);
mtd_part->size = le32_to_cpu(part->size);
part is a pointer to a mylo_partition class, which is defined in trunk/target/linux/adm5120-2.6/files/include/asm-mips/mach-adm5120/myloader.h as following:
struct mylo_partition {
uint16_t flags; /* partition flags */
uint16_t type; /* type of the partition */
uint32_t addr; /* relative address of the partition from the
flash start */
uint32_t size; /* size of the partition in bytes */
uint32_t param; /* if this is the active partition, the
MyLoader load code to this address */
};
And an array of this struct is included into a mylo_partition_table
struct mylo_partition_table {
uint32_t magic; /* must be MYLO_MAGIC_PARTITIONS */
uint32_t res0; /* unknown/unused */
uint32_t res1; /* unknown/unused */
uint32_t res2; /* unknown/unused */
struct mylo_partition partitions[MYLO_MAX_PARTITIONS];
};
So my only question is how to correctly inizialize this structure with the right values of the partitions.
Since OpenWrt is an open source software, I hope someone to have the way, but above all the time to give me just a little hint to solve my problem.
Any help would be strongly appreciated.
Thank you in advance and sorry for the disturb.
(Last edited by ggp81 on 11 Jul 2007, 10:11)