From: Erik M. <er...@us...> - 2002-02-13 00:20:00
|
Update of /cvsroot/blob/blob/include/blob In directory usw-pr-cvs1:/tmp/cvs-serv16728/include/blob Modified Files: partition.h Log Message: The new partition table code, initial part. Next on the list are functions to manipulate the table. Index: partition.h =================================================================== RCS file: /cvsroot/blob/blob/include/blob/partition.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- partition.h 26 Dec 2001 23:38:36 -0000 1.2 +++ partition.h 13 Feb 2002 00:19:57 -0000 1.3 @@ -1,7 +1,7 @@ /* * partition.h: flash paritioning * - * Copyright (C) 2001 Erik Mouw (J.A...@it...) + * Copyright (C) 2001 2002 Erik Mouw (J.A...@it...) * * $Id$ * @@ -29,30 +29,89 @@ #include <blob/types.h> -#define PART_PARTITION_NAMELEN (32) +/* A partition table can contain three types of entries: + * - The last entry + * - A valid entry + * - An invalid entry + * + * A last entry can be changed into a valid entry by changing the + * second last bit (with mask 0x00000002) from 1 to 0, or into an + * invalid entry by changing the last two bits (with mask 0x00000003) + * from 1 to 0. By doing it like this we can avoid erasing a flash + * block. + * + * Flash chips wear from erase operations (that's why flash lifetime + * is specified in erase cycles), so we try to limit the number of + * erase operations. Luckily the flash helps us a little bit with + * this, because it only allows you to change a '1' bit into a '0' + * during a write operation. This means that 0xffff can be changed + * into 0x1010, and 0x1010 into 0x0000, but 0x0000 can't be changed + * into anything else anymore because there are no '1' bits left. + * + * The magic values have been carefully choosen to allow changing a + * partition entry without having to erase the flash. For a "last" + * entry, it is best to keep all other fields except the magic + * unitialised: chances are high that the other fields are still at + * 0xffffffff so we can reuse them when we change the partition type. + */ + +#define BLOB_PART_LAST_MAGIC (0x42504533) /* BPE3, Blob Partition Entry 3 */ +#define BLOB_PART_VALID_MAGIC (0x42504531) /* BPE1, Blob Partition Entry 1 */ +#define BLOB_PART_INVALID_MAGIC (0x42504530) /* BPE0, Blob Partition Entry 0 */ +#define BLOB_PART_NAMELEN (32) + typedef struct { - u32 offset; /* offset wrt start of flash */ - u32 size; /* partition size */ + /* generic (i.e.: blob independent) data */ + u32 magic; /* magic value */ + u32 next; /* offset (in bytes) to next partition entry */ + u32 offset; /* offset (in bytes) wrt start of flash */ + u32 size; /* partition size (in bytes) */ + char name[BLOB_PART_NAMELEN]; + + /* blob specific items, can be changed for other bootloaders */ + u32 flags; /* blob specific flags */ u32 mem_base; /* load address in RAM */ u32 entry_point; /* entry point in RAM */ - u32 flags; - char name[PART_PARTITION_NAMELEN]; -} partition_t; +} blob_partition_t; -#define PART_VALID (1<<0) -#define PART_LOAD (1<<1) -#define PART_EXPAND (1<<2) +#define BLOB_PART_FLAG_PTABLE (1<<0) /* contains a partition table */ +#define BLOB_PART_FLAG_LOAD (1<<1) /* load partition into RAM */ +#define BLOB_PART_FLAG_EXEC (1<<2) /* partition/target is executable */ +#define BLOB_PART_FLAG_JFFS2 (1<<3) /* contains a JFFS2 */ +#define BLOB_PART_FLAG_CRAMFS (1<<4) /* contains a cramfs */ -#define PART_MAGIC (0x50727420) /* "Prt " */ -#define PART_MAX_PARTITIONS (16) /* 16 partitions ought to be enough */ +/* A partition table is marked with a special entry that marks the + * start of the table. + * + * There are two kinds of blob partition tables: the first one is the + * regular partition table that can be changed by the bootloader. The + * second one is a default partition table that can be put into the + * bootloader binary so it can avoid to waste a flash block for the + * partition table. The partition table parser first tries to find a + * regular partition table and will fall back on the default table if + * it can't find one. + * + * A partition table entry point has to specify the total size of the + * flash (in the size member), and the offset has to specify the + * absolute base address. + */ -typedef struct { - int magic; - int numpartitions; - partition_t partition[PART_MAX_PARTITIONS]; -} partition_table_t; +#define BLOB_FLASH_PART_TABLE_MAGIC (0x42465054) /* BFPT, Blob Flash + * Partition Table */ +#define BLOB_DEFAULT_PART_TABLE_MAGIC (0x42445054) /* BDPT, Blob Default + * Partition Table */ +#define BLOB_COPY_PART_TABLE_MAGIC (0x42435054) /* BCPT, Blob Copy + * Partition Table */ + + + + +/* flash functions */ + +extern const blob_partition_t *default_partition_table; +extern blob_partition_t *flash_partition_table; |