diff options
author | Cai Zhiyong <caizhiyong@huawei.com> | 2013-09-11 17:20:09 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-11 18:56:57 -0400 |
commit | bab55417b10c95e6bff8cea315c315adfa009487 (patch) | |
tree | 56bfc578d47c7ea786bf6a35bf946f37e9b458b1 /block/partitions | |
parent | ed751e683c563be64322b9bfa0f0f7e5da9bd37c (diff) |
block: support embedded device command line partition
Read block device partition table from command line. The partition used
for fixed block device (eMMC) embedded device. It is no MBR, save
storage space. Bootloader can be easily accessed by absolute address of
data on the block device. Users can easily change the partition.
This code reference MTD partition, source "drivers/mtd/cmdlinepart.c"
About the partition verbose reference
"Documentation/block/cmdline-partition.txt"
[akpm@linux-foundation.org: fix printk text]
[yongjun_wei@trendmicro.com.cn: fix error return code in parse_parts()]
Signed-off-by: Cai Zhiyong <caizhiyong@huawei.com>
Cc: Karel Zak <kzak@redhat.com>
Cc: "Wanglin (Albert)" <albert.wanglin@huawei.com>
Cc: Marius Groeger <mag@sysgo.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Artem Bityutskiy <dedekind@infradead.org>
Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'block/partitions')
-rw-r--r-- | block/partitions/Kconfig | 7 | ||||
-rw-r--r-- | block/partitions/Makefile | 1 | ||||
-rw-r--r-- | block/partitions/check.c | 4 | ||||
-rw-r--r-- | block/partitions/cmdline.c | 99 | ||||
-rw-r--r-- | block/partitions/cmdline.h | 2 |
5 files changed, 113 insertions, 0 deletions
diff --git a/block/partitions/Kconfig b/block/partitions/Kconfig index 4cebb2f0d2f4..87a32086535d 100644 --- a/block/partitions/Kconfig +++ b/block/partitions/Kconfig | |||
@@ -260,3 +260,10 @@ config SYSV68_PARTITION | |||
260 | partition table format used by Motorola Delta machines (using | 260 | partition table format used by Motorola Delta machines (using |
261 | sysv68). | 261 | sysv68). |
262 | Otherwise, say N. | 262 | Otherwise, say N. |
263 | |||
264 | config CMDLINE_PARTITION | ||
265 | bool "Command line partition support" if PARTITION_ADVANCED | ||
266 | select CMDLINE_PARSER | ||
267 | help | ||
268 | Say Y here if you would read the partitions table from bootargs. | ||
269 | The format for the command line is just like mtdparts. | ||
diff --git a/block/partitions/Makefile b/block/partitions/Makefile index 2be4d7ba4e3a..37a95270503c 100644 --- a/block/partitions/Makefile +++ b/block/partitions/Makefile | |||
@@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o | |||
8 | obj-$(CONFIG_AMIGA_PARTITION) += amiga.o | 8 | obj-$(CONFIG_AMIGA_PARTITION) += amiga.o |
9 | obj-$(CONFIG_ATARI_PARTITION) += atari.o | 9 | obj-$(CONFIG_ATARI_PARTITION) += atari.o |
10 | obj-$(CONFIG_AIX_PARTITION) += aix.o | 10 | obj-$(CONFIG_AIX_PARTITION) += aix.o |
11 | obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o | ||
11 | obj-$(CONFIG_MAC_PARTITION) += mac.o | 12 | obj-$(CONFIG_MAC_PARTITION) += mac.o |
12 | obj-$(CONFIG_LDM_PARTITION) += ldm.o | 13 | obj-$(CONFIG_LDM_PARTITION) += ldm.o |
13 | obj-$(CONFIG_MSDOS_PARTITION) += msdos.o | 14 | obj-$(CONFIG_MSDOS_PARTITION) += msdos.o |
diff --git a/block/partitions/check.c b/block/partitions/check.c index 19ba207ea7d1..9ac1df74f699 100644 --- a/block/partitions/check.c +++ b/block/partitions/check.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "efi.h" | 34 | #include "efi.h" |
35 | #include "karma.h" | 35 | #include "karma.h" |
36 | #include "sysv68.h" | 36 | #include "sysv68.h" |
37 | #include "cmdline.h" | ||
37 | 38 | ||
38 | int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/ | 39 | int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/ |
39 | 40 | ||
@@ -65,6 +66,9 @@ static int (*check_part[])(struct parsed_partitions *) = { | |||
65 | adfspart_check_ADFS, | 66 | adfspart_check_ADFS, |
66 | #endif | 67 | #endif |
67 | 68 | ||
69 | #ifdef CONFIG_CMDLINE_PARTITION | ||
70 | cmdline_partition, | ||
71 | #endif | ||
68 | #ifdef CONFIG_EFI_PARTITION | 72 | #ifdef CONFIG_EFI_PARTITION |
69 | efi_partition, /* this must come before msdos */ | 73 | efi_partition, /* this must come before msdos */ |
70 | #endif | 74 | #endif |
diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c new file mode 100644 index 000000000000..56cf4ffad51e --- /dev/null +++ b/block/partitions/cmdline.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 HUAWEI | ||
3 | * Author: Cai Zhiyong <caizhiyong@huawei.com> | ||
4 | * | ||
5 | * Read block device partition table from command line. | ||
6 | * The partition used for fixed block device (eMMC) embedded device. | ||
7 | * It is no MBR, save storage space. Bootloader can be easily accessed | ||
8 | * by absolute address of data on the block device. | ||
9 | * Users can easily change the partition. | ||
10 | * | ||
11 | * The format for the command line is just like mtdparts. | ||
12 | * | ||
13 | * Verbose config please reference "Documentation/block/cmdline-partition.txt" | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/cmdline-parser.h> | ||
18 | |||
19 | #include "check.h" | ||
20 | #include "cmdline.h" | ||
21 | |||
22 | static char *cmdline; | ||
23 | static struct cmdline_parts *bdev_parts; | ||
24 | |||
25 | static int add_part(int slot, struct cmdline_subpart *subpart, void *param) | ||
26 | { | ||
27 | int label_min; | ||
28 | struct partition_meta_info *info; | ||
29 | char tmp[sizeof(info->volname) + 4]; | ||
30 | struct parsed_partitions *state = (struct parsed_partitions *)param; | ||
31 | |||
32 | if (slot >= state->limit) | ||
33 | return 1; | ||
34 | |||
35 | put_partition(state, slot, subpart->from >> 9, | ||
36 | subpart->size >> 9); | ||
37 | |||
38 | info = &state->parts[slot].info; | ||
39 | |||
40 | label_min = min_t(int, sizeof(info->volname) - 1, | ||
41 | sizeof(subpart->name)); | ||
42 | strncpy(info->volname, subpart->name, label_min); | ||
43 | info->volname[label_min] = '\0'; | ||
44 | |||
45 | snprintf(tmp, sizeof(tmp), "(%s)", info->volname); | ||
46 | strlcat(state->pp_buf, tmp, PAGE_SIZE); | ||
47 | |||
48 | state->parts[slot].has_info = true; | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | static int __init cmdline_parts_setup(char *s) | ||
54 | { | ||
55 | cmdline = s; | ||
56 | return 1; | ||
57 | } | ||
58 | __setup("blkdevparts=", cmdline_parts_setup); | ||
59 | |||
60 | /* | ||
61 | * Purpose: allocate cmdline partitions. | ||
62 | * Returns: | ||
63 | * -1 if unable to read the partition table | ||
64 | * 0 if this isn't our partition table | ||
65 | * 1 if successful | ||
66 | */ | ||
67 | int cmdline_partition(struct parsed_partitions *state) | ||
68 | { | ||
69 | sector_t disk_size; | ||
70 | char bdev[BDEVNAME_SIZE]; | ||
71 | struct cmdline_parts *parts; | ||
72 | |||
73 | if (cmdline) { | ||
74 | if (bdev_parts) | ||
75 | cmdline_parts_free(&bdev_parts); | ||
76 | |||
77 | if (cmdline_parts_parse(&bdev_parts, cmdline)) { | ||
78 | cmdline = NULL; | ||
79 | return -1; | ||
80 | } | ||
81 | cmdline = NULL; | ||
82 | } | ||
83 | |||
84 | if (!bdev_parts) | ||
85 | return 0; | ||
86 | |||
87 | bdevname(state->bdev, bdev); | ||
88 | parts = cmdline_parts_find(bdev_parts, bdev); | ||
89 | if (!parts) | ||
90 | return 0; | ||
91 | |||
92 | disk_size = get_capacity(state->bdev->bd_disk) << 9; | ||
93 | |||
94 | cmdline_parts_set(parts, disk_size, 1, add_part, (void *)state); | ||
95 | |||
96 | strlcat(state->pp_buf, "\n", PAGE_SIZE); | ||
97 | |||
98 | return 1; | ||
99 | } | ||
diff --git a/block/partitions/cmdline.h b/block/partitions/cmdline.h new file mode 100644 index 000000000000..26e0f8da1414 --- /dev/null +++ b/block/partitions/cmdline.h | |||
@@ -0,0 +1,2 @@ | |||
1 | |||
2 | int cmdline_partition(struct parsed_partitions *state); | ||