From: Erik M. <er...@us...> - 2001-12-19 22:53:48
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv15523/src/blob Modified Files: Makefile.am Added Files: partition.c bootldrpart.c Log Message: This is the initial flash partitioning support. It's not even near finished, but I already commit it as an RFC. Right now it is only able to parse bootldr partition tables, but I want a blob partition table format as well. Just look at the "mem_base" and "entry_point" and you'll understand why. --- NEW FILE: partition.c --- /* * partition.c: flash partitioning * * Copyright (C) 2001 Erik Mouw <J.A...@it...> * * $Id: partition.c,v 1.1 2001/12/19 22:53:45 erikm Exp $ * * 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 * */ #ident "$Id: partition.c,v 1.1 2001/12/19 22:53:45 erikm Exp $" #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif #include <blob/flash.h> #include <blob/partition.h> #include <blob/serial.h> #include <blob/error.h> static partition_table_t flash_partition_table; /* FIXME: this is for the time being */ extern int read_bootldr_partition_table(partition_table_t *ptable); static int read_partition_table(void) { int rv; int i; /* so far we only know about bootldr flash partitions */ rv = read_bootldr_partition_table(&flash_partition_table); if(rv < 0) { printerror(rv, "can't get partition table\n"); return rv; } SerialOutputString("Flash partition layout:\n"); for(i = 0; i < flash_partition_table.numpartitions; i++) { SerialOutputString(" 0x"); SerialOutputHex(flash_partition_table.partition[i].size); SerialOutputString(" @ 0x"); SerialOutputHex(flash_partition_table.partition[i].offset); if(flash_partition_table.partition[i].flags & PART_LOAD) { SerialOutputString(", load at 0x"); SerialOutputHex(flash_partition_table.partition[i].mem_base); SerialOutputString(", entry point at 0x"); SerialOutputHex(flash_partition_table.partition[i].entry_point); } SerialOutputByte('\n'); } return 0; } --- NEW FILE: bootldrpart.c --- /* * flashpart.c: bootldr compatible flash paritioning * * Copyright (C) 2001 Erik Mouw <J.A...@it...> * * $Id: bootldrpart.c,v 1.1 2001/12/19 22:53:45 erikm Exp $ * * 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 * */ /* * The bootldr partition information comes from the linux kernel * sources, file drivers/mtd/bootldr.c. */ #ident "$Id: bootldrpart.c,v 1.1 2001/12/19 22:53:45 erikm Exp $" #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif #include <blob/arch.h> #include <blob/types.h> #include <blob/partition.h> #include <blob/errno.h> #include <blob/util.h> #define FLASH_PARTITION_NAMELEN 32 enum LFR_FLAGS { LFR_SIZE_PREFIX = 1, /* prefix data with 4-byte size */ LFR_PATCH_BOOTLDR = 2, /* patch bootloader's 0th instruction */ LFR_KERNEL = 4, /* add BOOTIMG_MAGIC, imgsize and VKERNEL_BASE to head of programmed region (see bootldr.c) */ LFR_EXPAND = 8 /* expand partition size to fit rest of flash */ }; typedef struct { char name[FLASH_PARTITION_NAMELEN]; unsigned long base; unsigned long size; enum LFR_FLAGS flags; } FlashRegion; typedef struct { int magic; /* should be filled with 0x646c7470 (btlp) BOOTLDR_PARTITION_MAGIC */ int npartitions; FlashRegion partition[0]; } BootldrFlashPartitionTable; #define BOOTLDR_MAGIC 0x646c7462 /* btld: marks a valid bootldr image */ #define BOOTLDR_PARTITION_MAGIC 0x646c7470 /* btlp: marks a valid bootldr partition table in params sector */ #define BOOTLDR_MAGIC_OFFSET 0x20 /* offset 0x20 into the bootldr */ #define BOOTCAP_OFFSET 0X30 /* offset 0x30 into the bootldr */ #define BOOTCAP_WAKEUP (1<<0) #define BOOTCAP_PARTITIONS (1<<1) /* partition table stored in params sector */ #define BOOTCAP_PARAMS_AFTER_BOOTLDR (1<<2)/* params sector right after bootldr sector(s), else in last sector */ static BootldrFlashPartitionTable *find_bootldr_partition_table(void) { BootldrFlashPartitionTable *table; /* we currently assume that the partition table lives in the * PARAMETER flash block, so we only check if there really is * a partition table. later on we can really search for it. */ table = (BootldrFlashPartitionTable *)PARAM_FLASH_BASE; if(table->magic == BOOTLDR_PARTITION_MAGIC) return table; else return NULL; } #define MIN(a, b) ((a) < (b) ? (a) : (b)) /* returns number of partitions, or negative error number otherwise */ int read_bootldr_partition_table(partition_table_t *ptable) { BootldrFlashPartitionTable *bootldr; int i; /* get partition table */ bootldr = find_bootldr_partition_table(); /* is it real? */ if(bootldr == NULL) return -EMAGIC; ptable->numpartitions = bootldr->npartitions; for(i = 0; i < bootldr->npartitions; i++) { ptable->partition[i].flags = PART_VALID; ptable->partition[i].offset = bootldr->partition[i].base; ptable->partition[i].size = bootldr->partition[i].size; ptable->partition[i].mem_base = 0; ptable->partition[i].entry_point = 0; strlcpy(ptable->partition[i].name, bootldr->partition[i].name, MIN(PARTITION_NAMELEN, FLASH_PARTITION_NAMELEN)); /* the caller should figure out the real size */ if(bootldr->partition[i].flags & LFR_EXPAND) ptable->partition[i].flags |= PART_EXPAND; /* NOTE: this is a hack -- Erik */ if(strncmp(ptable->partition[i].name, "kernel", PARTITION_NAMELEN) == 0) { ptable->partition[i].mem_base = KERNEL_RAM_BASE; ptable->partition[i].entry_point = KERNEL_RAM_BASE; ptable->partition[i].flags |= PART_LOAD; } /* NOTE: and this is a hack as well -- Erik */ if(strncmp(ptable->partition[i].name, "ramdisk", PARTITION_NAMELEN) == 0) { ptable->partition[i].mem_base = RAMDISK_RAM_BASE; ptable->partition[i].flags |= PART_LOAD; } } return ptable->numpartitions; } Index: Makefile.am =================================================================== RCS file: /cvsroot/blob/blob/src/blob/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Makefile.am 2001/12/16 04:34:03 1.11 +++ Makefile.am 2001/12/19 22:53:45 1.12 @@ -120,6 +120,7 @@ flashasm.S \ stack.S \ testmem2.S \ + bootldrpart.c \ commands.c \ flash.c \ initcalls.c \ @@ -127,6 +128,7 @@ main.c \ memory.c \ param_block.c \ + partition.c \ reboot.c \ uucodec.c |