-+ /* Setup the partition info. We duplicate the env_name for the partiton name */
-+ if (num_of_partitions == 0)
-+ avalanche_partition_info[num_of_partitions].name = strdup("linux");
-+ else if (num_of_partitions == 1)
-+ avalanche_partition_info[num_of_partitions].name = strdup("rootfs");
-+ else if (num_of_partitions == 2)
-+ avalanche_partition_info[num_of_partitions].name = strdup("adam2");
-+ else if (num_of_partitions == 3)
-+ avalanche_partition_info[num_of_partitions].name = strdup("config");
-+ else
-+ avalanche_partition_info[num_of_partitions].name = strdup(env_name);
-+ avalanche_partition_info[num_of_partitions].offset = offset;
-+ avalanche_partition_info[num_of_partitions].size = size;
-+ avalanche_partition_info[num_of_partitions].mask_flags = 0;
-+ num_of_partitions++;
-+ } while (num_of_partitions < MAX_NUM_PARTITIONS);
-+
-+ return num_of_partitions;
++
++ if (offset == 0) {
++ printk("Assuming adam2 size of 0x%x\n", size);
++ adam2_size = size; // boot loader
++ } else if (offset > 0x120000) {
++ if (config_offset > offset)
++ config_offset = offset; // reserved at the end of the flash chip
++ } else if (offset > 0x30000) {
++ printk("Assuming default rootfs offset of 0x%x\n", offset);
++ rootfs_start = offset; // probably root fs
++ }
++
++ p++;
++ } while (p < MAX_NUM_PARTITIONS);
++
++ p = 0;
++
++ ar7_partinfo[p].name = strdup("adam2");
++ ar7_partinfo[p].offset = 0;
++ ar7_partinfo[p].size = adam2_size;
++ ar7_partinfo[p++].mask_flags = 0;
++
++ ar7_partinfo[p].name = strdup("linux");
++ ar7_partinfo[p].offset = adam2_size;
++ ar7_partinfo[p].size = config_offset - adam2_size;
++ ar7_partinfo[p++].mask_flags = 0;
++
++ if (ar7_read32(&ar7_map, adam2_size) == 0xfeedfa42) {
++ rootfs_start = ar7_read32(&ar7_map, adam2_size + 4) + adam2_size + 28;
++ printk("Setting new rootfs offset to %08x\n", rootfs_start);
++ }
++
++ ar7_partinfo[p].name = strdup("rootfs");
++ ar7_partinfo[p].offset = rootfs_start;
++ ar7_partinfo[p].size = config_offset - rootfs_start;
++
++ ar7_partinfo[p++].mask_flags = 0;
++
++ ar7_partinfo[p].name = strdup("config");
++ ar7_partinfo[p].offset = config_offset;
++ ar7_partinfo[p].size = WINDOW_SIZE - config_offset;
++ ar7_partinfo[p++].mask_flags = 0;
++
++ if (ar7_read32(&ar7_map, rootfs_start) == SQUASHFS_MAGIC) {
++ int newsize, newoffset;
++ squashfs_super_block sb;
++
++ ar7_copy_from(&ar7_map, &sb, rootfs_start, sizeof(sb));
++ printk("Squashfs detected (size = 0x%08x)\n", sb.bytes_used);
++
++ newoffset = rootfs_start + sb.bytes_used;
++
++ if ((newoffset % ar7_mtd_info->erasesize) > 0)
++ newoffset += ar7_mtd_info->erasesize - (newoffset % ar7_mtd_info->erasesize);
++
++ ar7_partinfo[p - 2].size = newoffset - rootfs_start;
++
++ ar7_partinfo[p].name = strdup("OpenWrt");
++ ar7_partinfo[p].offset = newoffset;
++ ar7_partinfo[p].size = config_offset - newoffset;
++ ar7_partinfo[p++].mask_flags = 0;
++ } else {
++ printk("Unknown filesystem. Moving rootfs partition to next erase block");
++ if ((rootfs_start % ar7_mtd_info->erasesize) > 0)
++ rootfs_start += ar7_mtd_info->erasesize - (rootfs_start % ar7_mtd_info->erasesize);
++ }
++
++ return p;