Partition: Add an own device id for partitions
Add an own device id for partitions. This is necessary to allow the partition layer to check if the given device is really a partition. Also, check for readonly flag in erase. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
59f72431f4
commit
65778b63d2
|
@ -41,10 +41,16 @@
|
|||
static int dev_del_partitions(struct device_d *physdev)
|
||||
{
|
||||
struct device_d *child, *tmp;
|
||||
struct partition *part;
|
||||
int ret;
|
||||
|
||||
device_for_each_child_safe(physdev, tmp, child) {
|
||||
struct partition *part = child->type_data;
|
||||
if (child->type != DEVICE_TYPE_PARTITION) {
|
||||
printf("not a partition: %s\n", child->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
part = child->type_data;
|
||||
|
||||
if (part->flags & PARTITION_FIXED) {
|
||||
debug("Skip fixed partition: %s\n", child->id);
|
||||
|
@ -191,6 +197,7 @@ static int do_addpart(cmd_tbl_t * cmdtp, int argc, char *argv[])
|
|||
part->num = num;
|
||||
part->device.map_base = dev->map_base + offset;
|
||||
part->device.type_data = part;
|
||||
part->device.type = DEVICE_TYPE_PARTITION;
|
||||
|
||||
if (mtd_part_do_parse_one(part, endp, &endp))
|
||||
goto free_out;
|
||||
|
|
|
@ -59,6 +59,7 @@ struct device_d *dev_add_partition(struct device_d *dev, unsigned long offset,
|
|||
part->device.map_base = dev->map_base + offset;
|
||||
part->device.size = size;
|
||||
part->device.type_data = part;
|
||||
part->device.type = DEVICE_TYPE_PARTITION;
|
||||
get_free_deviceid(part->device.id, name);
|
||||
|
||||
part->offset = offset;
|
||||
|
@ -71,6 +72,7 @@ struct device_d *dev_add_partition(struct device_d *dev, unsigned long offset,
|
|||
if (part->device.driver)
|
||||
return &part->device;
|
||||
|
||||
unregister_device(&part->device);
|
||||
free(part);
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,6 +89,9 @@ static int part_erase(struct device_d *dev, size_t count, unsigned long offset)
|
|||
{
|
||||
struct partition *part = dev->type_data;
|
||||
|
||||
if (part->flags & PARTITION_READONLY)
|
||||
return -EROFS;
|
||||
|
||||
return dev_erase(part->physdev, count, offset + part->offset);
|
||||
}
|
||||
|
||||
|
@ -246,6 +251,7 @@ struct driver_d part_driver = {
|
|||
.erase = part_erase,
|
||||
.protect= part_protect,
|
||||
.memmap = part_memmap,
|
||||
.type = DEVICE_TYPE_PARTITION,
|
||||
};
|
||||
|
||||
static int partition_init(void)
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
#define DEVICE_TYPE_MIIPHY 6
|
||||
#define DEVICE_TYPE_NAND 7
|
||||
#define DEVICE_TYPE_NAND_BB 8
|
||||
#define MAX_DEVICE_TYPE 8
|
||||
#define DEVICE_TYPE_PARTITION 9
|
||||
#define MAX_DEVICE_TYPE 9
|
||||
|
||||
#include <param.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue