at91part.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. *
  3. * Copyright (C) 2007 OpenWrt.org
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * Atmel AT91 flash partition table. (Modified by Hamish Guthrie).
  20. * Based on ar7 map by Felix Fietkau.
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/slab.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/bootmem.h>
  28. #include <linux/squashfs_fs.h>
  29. static struct mtd_partition at91_parts[6];
  30. static int create_mtd_partitions(struct mtd_info *master,
  31. struct mtd_partition **pparts,
  32. unsigned long origin)
  33. {
  34. unsigned int offset, len;
  35. unsigned int pre_size = 0x42000, root_max = 0x362400;
  36. unsigned char buf[512];
  37. struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
  38. printk("Parsing AT91 partition map...\n");
  39. at91_parts[0].name = "loaders";
  40. at91_parts[0].offset = 0;
  41. at91_parts[0].size = 0x21000;
  42. at91_parts[0].mask_flags = MTD_WRITEABLE;
  43. at91_parts[1].name = "ubparams";
  44. at91_parts[1].offset = 0x21000;
  45. at91_parts[1].size = 0x8400;
  46. at91_parts[1].mask_flags = 0;
  47. at91_parts[2].name = "kernel";
  48. at91_parts[2].offset = pre_size;
  49. at91_parts[2].size = 0;
  50. at91_parts[2].mask_flags = 0;
  51. at91_parts[3].name = "rootfs";
  52. at91_parts[3].offset = 0;
  53. at91_parts[3].size = 0;
  54. at91_parts[3].mask_flags = 0;
  55. for(offset = pre_size; offset < root_max; offset += master->erasesize) {
  56. memset(&buf, 0xe5, sizeof(buf));
  57. if (master->read(master, offset, sizeof(buf), &len, buf) || len != sizeof(buf))
  58. break;
  59. if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
  60. printk(KERN_INFO "%s: Filesystem type: squashfs, size=0x%x\n",
  61. master->name, (u32) sb->bytes_used);
  62. at91_parts[3].size = sb->bytes_used;
  63. at91_parts[3].offset = offset;
  64. len = at91_parts[3].offset + at91_parts[3].size;
  65. len = ((len / (master->erasesize * 8)) + 1) * master->erasesize * 8;
  66. at91_parts[3].size = len - at91_parts[3].offset;
  67. at91_parts[2].size = offset - at91_parts[2].offset;
  68. break;
  69. }
  70. }
  71. if (at91_parts[3].size == 0) {
  72. printk(KERN_NOTICE "%s: Couldn't find root filesystem\n", master->name);
  73. return -1;
  74. }
  75. at91_parts[4].name = "rootfs_data";
  76. at91_parts[4].offset = root_max;
  77. at91_parts[4].size = master->size - root_max;
  78. at91_parts[4].mask_flags = 0;
  79. at91_parts[5].name = "complete";
  80. at91_parts[5].offset = 0;
  81. at91_parts[5].size = master->size;
  82. at91_parts[5].mask_flags = 0;
  83. *pparts = at91_parts;
  84. return 6;
  85. }
  86. static struct mtd_part_parser at91_parser = {
  87. .owner = THIS_MODULE,
  88. .parse_fn = create_mtd_partitions,
  89. .name = "at91part",
  90. };
  91. static int __init at91_parser_init(void)
  92. {
  93. register_mtd_parser(&at91_parser);
  94. return 0;
  95. }
  96. module_init(at91_parser_init);
  97. MODULE_LICENSE("GPL");
  98. MODULE_AUTHOR("Felix Fietkau, Eugene Konev, Hamish Guthrie");
  99. MODULE_DESCRIPTION("MTD partitioning for Atmel at91");