Changes in 4.9.249 spi: bcm2835aux: Fix use-after-free on unbind spi: bcm2835aux: Restore err assignment in bcm2835aux_spi_probe iwlwifi: pcie: limit memory read spin time arm64: dts: rockchip: Assign a fixed index to mmc devices on rk3399 boards. ARC: stack unwinding: don't assume non-current task is sleeping platform/x86: acer-wmi: add automatic keyboard background light toggle key as KEY_LIGHTS_TOGGLE Input: cm109 - do not stomp on control URB Input: i8042 - add Acer laptops to the i8042 reset list pinctrl: amd: remove debounce filter setting in IRQ type setting scsi: be2iscsi: Revert "Fix a theoretical leak in beiscsi_create_eqs()" spi: Prevent adding devices below an unregistering controller net/mlx4_en: Avoid scheduling restart task if it is already running tcp: fix cwnd-limited bug for TSO deferral where we send nothing net: stmmac: delete the eee_ctrl_timer after napi disabled net: stmmac: dwmac-meson8b: fix mask definition of the m250_sel mux net: bridge: vlan: fix error return code in __vlan_add() mac80211: mesh: fix mesh_pathtbl_init() error path USB: dummy-hcd: Fix uninitialized array use in init() USB: add RESET_RESUME quirk for Snapscan 1212 ALSA: usb-audio: Fix potential out-of-bounds shift ALSA: usb-audio: Fix control 'access overflow' errors from chmap xhci: Give USB2 ports time to enter U3 in bus suspend USB: sisusbvga: Make console support depend on BROKEN ALSA: pcm: oss: Fix potential out-of-bounds shift serial: 8250_omap: Avoid FIFO corruption caused by MDR1 access pinctrl: merrifield: Set default bias in case no particular value given pinctrl: baytrail: Avoid clearing debounce value when turning it off scsi: bnx2i: Requires MMU can: softing: softing_netdev_open(): fix error handling RDMA/cm: Fix an attempt to use non-valid pointer when cleaning timewait kernel/cpu: add arch override for clear_tasks_mm_cpumask() mm handling drm/tegra: sor: Disable clocks on error in tegra_sor_init() scsi: mpt3sas: Increase IOCInit request timeout to 30s dm table: Remove BUG_ON(in_interrupt()) soc/tegra: fuse: Fix index bug in get_process_id USB: serial: option: add interface-number sanity check to flag handling USB: gadget: f_acm: add support for SuperSpeed Plus USB: gadget: f_midi: setup SuperSpeed Plus descriptors USB: gadget: f_rndis: fix bitrate for SuperSpeed and above usb: gadget: f_fs: Re-use SS descriptors for SuperSpeedPlus usb: chipidea: ci_hdrc_imx: Pass DISABLE_DEVICE_STREAMING flag to imx6ul ARM: dts: exynos: fix roles of USB 3.0 ports on Odroid XU ARM: dts: exynos: fix USB 3.0 VBUS control and over-current pins on Exynos5410 ARM: dts: exynos: fix USB 3.0 pins supply being turned off on Odroid XU HID: i2c-hid: add Vero K147 to descriptor override serial_core: Check for port state when tty is in error state media: msi2500: assign SPI bus number dynamically md: fix a warning caused by a race between concurrent md_ioctl()s Bluetooth: Fix slab-out-of-bounds read in hci_le_direct_adv_report_evt() drm/gma500: fix double free of gma_connector RDMA/rxe: Compute PSN windows correctly ARM: p2v: fix handling of LPAE translation in BE mode crypto: talitos - Fix return type of current_desc_hdr() spi: img-spfi: fix reference leak in img_spfi_resume ASoC: pcm: DRAIN support reactivation arm64: dts: exynos: Correct psci compatible used on Exynos7 Bluetooth: Fix null pointer dereference in hci_event_packet() spi: spi-ti-qspi: fix reference leak in ti_qspi_setup spi: tegra20-slink: fix reference leak in slink ops of tegra20 spi: tegra20-sflash: fix reference leak in tegra_sflash_resume spi: tegra114: fix reference leak in tegra spi ops RDMa/mthca: Work around -Wenum-conversion warning MIPS: BCM47XX: fix kconfig dependency bug for BCM47XX_BCMA staging: greybus: codecs: Fix reference counter leak in error handling media: solo6x10: fix missing snd_card_free in error handling case drm/omap: dmm_tiler: fix return error code in omap_dmm_probe() Input: ads7846 - fix integer overflow on Rt calculation Input: ads7846 - fix unaligned access on 7845 powerpc/feature: Fix CPU_FTRS_ALWAYS by removing CPU_FTRS_GENERIC_32 crypto: omap-aes - Fix PM disable depth imbalance in omap_aes_probe soc: ti: knav_qmss: fix reference leak in knav_queue_probe soc: ti: Fix reference imbalance in knav_dma_probe drivers: soc: ti: knav_qmss_queue: Fix error return code in knav_queue_probe RDMA/cxgb4: Validate the number of CQEs memstick: fix a double-free bug in memstick_check ARM: dts: at91: sama5d4_xplained: add pincontrol for USB Host ARM: dts: at91: sama5d3_xplained: add pincontrol for USB Host orinoco: Move context allocation after processing the skb cw1200: fix missing destroy_workqueue() on error in cw1200_init_common media: siano: fix memory leak of debugfs members in smsdvb_hotplug mips: cdmm: fix use-after-free in mips_cdmm_bus_discover HSI: omap_ssi: Don't jump to free ID in ssi_add_controller() ARM: dts: at91: at91sam9rl: fix ADC triggers NFSv4.2: condition READDIR's mask for security label based on LSM state SUNRPC: xprt_load_transport() needs to support the netid "rdma6" lockd: don't use interval-based rebinding over TCP NFS: switch nfsiod to be an UNBOUND workqueue. vfio-pci: Use io_remap_pfn_range() for PCI IO memory media: saa7146: fix array overflow in vidioc_s_audio() clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() pinctrl: falcon: add missing put_device() call in pinctrl_falcon_probe() memstick: r592: Fix error return in r592_probe() ASoC: jz4740-i2s: add missed checks for clk_get() dm ioctl: fix error return code in target_message clocksource/drivers/arm_arch_timer: Correct fault programming of CNTKCTL_EL1.EVNTI cpufreq: highbank: Add missing MODULE_DEVICE_TABLE cpufreq: st: Add missing MODULE_DEVICE_TABLE cpufreq: loongson1: Add missing MODULE_ALIAS cpufreq: scpi: Add missing MODULE_ALIAS scsi: pm80xx: Fix error return in pm8001_pci_probe() seq_buf: Avoid type mismatch for seq_buf_init scsi: fnic: Fix error return code in fnic_probe() powerpc/pseries/hibernation: drop pseries_suspend_begin() from suspend ops usb: ehci-omap: Fix PM disable depth umbalance in ehci_hcd_omap_probe usb: oxu210hp-hcd: Fix memory leak in oxu_create speakup: fix uninitialized flush_lock nfsd: Fix message level for normal termination nfs_common: need lock during iterate through the list x86/kprobes: Restore BTF if the single-stepping is cancelled clk: tegra: Fix duplicated SE clock entry extcon: max77693: Fix modalias string ASoC: wm_adsp: remove "ctl" from list on error in wm_adsp_create_control() irqchip/alpine-msi: Fix freeing of interrupts on allocation error path um: chan_xterm: Fix fd leak nfc: s3fwrn5: Release the nfc firmware powerpc/ps3: use dma_mapping_error() checkpatch: fix unescaped left brace net: bcmgenet: Fix a resource leak in an error handling path in the probe functin net: allwinner: Fix some resources leak in the error handling path of the probe and in the remove function net: korina: fix return value watchdog: qcom: Avoid context switch in restart handler clk: ti: Fix memleak in ti_fapll_synth_setup perf record: Fix memory leak when using '--user-regs=?' to list registers qlcnic: Fix error code in probe clk: s2mps11: Fix a resource leak in error handling paths in the probe function cfg80211: initialize rekey_data Input: cros_ec_keyb - send 'scancodes' in addition to key events Input: goodix - add upside-down quirk for Teclast X98 Pro tablet media: gspca: Fix memory leak in probe media: sunxi-cir: ensure IR is handled when it is continuous media: netup_unidvb: Don't leak SPI master in probe error path Input: cyapa_gen6 - fix out-of-bounds stack access Revert "ACPI / resources: Use AE_CTRL_TERMINATE to terminate resources walks" ACPI: PNP: compare the string length in the matching_id() ALSA: pcm: oss: Fix a few more UBSAN fixes ALSA: usb-audio: Disable sample read check if firmware doesn't give back s390/dasd: prevent inconsistent LCU device data s390/dasd: fix list corruption of pavgroup group list s390/dasd: fix list corruption of lcu list staging: comedi: mf6x4: Fix AI end-of-conversion detection powerpc/perf: Exclude kernel samples while counting events in user space. USB: serial: mos7720: fix parallel-port state restore USB: serial: keyspan_pda: fix dropped unthrottle interrupts USB: serial: keyspan_pda: fix write deadlock USB: serial: keyspan_pda: fix stalled writes USB: serial: keyspan_pda: fix write-wakeup use-after-free USB: serial: keyspan_pda: fix tx-unthrottle use-after-free USB: serial: keyspan_pda: fix write unthrottling btrfs: quota: Set rescan progress to (u64)-1 if we hit last leaf btrfs: scrub: Don't use inode page cache in scrub_handle_errored_block() Btrfs: fix selftests failure due to uninitialized i_mode in test inodes btrfs: fix return value mixup in btrfs_get_extent ext4: fix a memory leak of ext4_free_data KVM: arm64: Introduce handling of AArch32 TTBCR2 traps powerpc/xmon: Change printk() to pr_cont() ceph: fix race in concurrent __ceph_remove_cap invocations jffs2: Fix GC exit abnormally jfs: Fix array index bounds check in dbAdjTree drm/dp_aux_dev: check aux_dev before use in drm_dp_aux_dev_get_by_minor() spi: spi-sh: Fix use-after-free on unbind spi: davinci: Fix use-after-free on unbind spi: pic32: Don't leak DMA channels in probe error path spi: rb4xx: Don't leak SPI master in probe error path spi: sc18is602: Don't leak SPI master in probe error path spi: st-ssc4: Fix unbalanced pm_runtime_disable() in probe error path soc: qcom: smp2p: Safely acquire spinlock without IRQs mtd: parser: cmdline: Fix parsing of part-names with colons iio: buffer: Fix demux update iio: adc: rockchip_saradc: fix missing clk_disable_unprepare() on error in rockchip_saradc_resume iio:pressure:mpl3115: Force alignment of buffer clk: mvebu: a3700: fix the XTAL MODE pin to MPP1_9 xen-blkback: set ring->xenblkd to NULL after kthread_stop() PCI: Fix pci_slot_release() NULL pointer dereference Linux 4.9.249 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I4829a32e2ea6e76eefea716f35f42ee02b75c265
440 lines
11 KiB
C
440 lines
11 KiB
C
/*
|
|
* Read flash partition table from command line
|
|
*
|
|
* Copyright © 2002 SYSGO Real-Time Solutions GmbH
|
|
* Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
|
|
*
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
* The format for the command line is as follows:
|
|
*
|
|
* mtdparts=<mtddef>[;<mtddef]
|
|
* <mtddef> := <mtd-id>:<partdef>[,<partdef>]
|
|
* <partdef> := <size>[@<offset>][<name>][ro][lk]
|
|
* <mtd-id> := unique name used in mapping driver/device (mtd->name)
|
|
* <size> := standard linux memsize OR "-" to denote all remaining space
|
|
* size is automatically truncated at end of device
|
|
* if specified or truncated size is 0 the part is skipped
|
|
* <offset> := standard linux memsize
|
|
* if omitted the part will immediately follow the previous part
|
|
* or 0 if the first part
|
|
* <name> := '(' NAME ')'
|
|
* NAME will appear in /proc/mtd
|
|
*
|
|
* <size> and <offset> can be specified such that the parts are out of order
|
|
* in physical memory and may even overlap.
|
|
*
|
|
* The parts are assigned MTD numbers in the order they are specified in the
|
|
* command line regardless of their order in physical memory.
|
|
*
|
|
* Examples:
|
|
*
|
|
* 1 NOR Flash, with 1 single writable partition:
|
|
* edb7312-nor:-
|
|
*
|
|
* 1 NOR Flash with 2 partitions, 1 NAND with one
|
|
* edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "mtd: " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include <linux/mtd/partitions.h>
|
|
#include <linux/module.h>
|
|
#include <linux/err.h>
|
|
|
|
/* debug macro */
|
|
#if 0
|
|
#define dbg(x) do { printk("DEBUG-CMDLINE-PART: "); printk x; } while(0)
|
|
#else
|
|
#define dbg(x)
|
|
#endif
|
|
|
|
|
|
/* special size referring to all the remaining space in a partition */
|
|
#define SIZE_REMAINING ULLONG_MAX
|
|
#define OFFSET_CONTINUOUS ULLONG_MAX
|
|
|
|
struct cmdline_mtd_partition {
|
|
struct cmdline_mtd_partition *next;
|
|
char *mtd_id;
|
|
int num_parts;
|
|
struct mtd_partition *parts;
|
|
};
|
|
|
|
/* mtdpart_setup() parses into here */
|
|
static struct cmdline_mtd_partition *partitions;
|
|
|
|
/* the command line passed to mtdpart_setup() */
|
|
static char *mtdparts;
|
|
static char *cmdline;
|
|
static int cmdline_parsed;
|
|
|
|
/*
|
|
* Parse one partition definition for an MTD. Since there can be many
|
|
* comma separated partition definitions, this function calls itself
|
|
* recursively until no more partition definitions are found. Nice side
|
|
* effect: the memory to keep the mtd_partition structs and the names
|
|
* is allocated upon the last definition being found. At that point the
|
|
* syntax has been verified ok.
|
|
*/
|
|
static struct mtd_partition * newpart(char *s,
|
|
char **retptr,
|
|
int *num_parts,
|
|
int this_part,
|
|
unsigned char **extra_mem_ptr,
|
|
int extra_mem_size)
|
|
{
|
|
struct mtd_partition *parts;
|
|
unsigned long long size, offset = OFFSET_CONTINUOUS;
|
|
char *name;
|
|
int name_len;
|
|
unsigned char *extra_mem;
|
|
char delim;
|
|
unsigned int mask_flags;
|
|
|
|
/* fetch the partition size */
|
|
if (*s == '-') {
|
|
/* assign all remaining space to this partition */
|
|
size = SIZE_REMAINING;
|
|
s++;
|
|
} else {
|
|
size = memparse(s, &s);
|
|
if (!size) {
|
|
pr_err("partition has size 0\n");
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
}
|
|
|
|
/* fetch partition name and flags */
|
|
mask_flags = 0; /* this is going to be a regular partition */
|
|
delim = 0;
|
|
|
|
/* check for offset */
|
|
if (*s == '@') {
|
|
s++;
|
|
offset = memparse(s, &s);
|
|
}
|
|
|
|
/* now look for name */
|
|
if (*s == '(')
|
|
delim = ')';
|
|
|
|
if (delim) {
|
|
char *p;
|
|
|
|
name = ++s;
|
|
p = strchr(name, delim);
|
|
if (!p) {
|
|
pr_err("no closing %c found in partition name\n", delim);
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
name_len = p - name;
|
|
s = p + 1;
|
|
} else {
|
|
name = NULL;
|
|
name_len = 13; /* Partition_000 */
|
|
}
|
|
|
|
/* record name length for memory allocation later */
|
|
extra_mem_size += name_len + 1;
|
|
|
|
/* test for options */
|
|
if (strncmp(s, "ro", 2) == 0) {
|
|
mask_flags |= MTD_WRITEABLE;
|
|
s += 2;
|
|
}
|
|
|
|
/* if lk is found do NOT unlock the MTD partition*/
|
|
if (strncmp(s, "lk", 2) == 0) {
|
|
mask_flags |= MTD_POWERUP_LOCK;
|
|
s += 2;
|
|
}
|
|
|
|
/* test if more partitions are following */
|
|
if (*s == ',') {
|
|
if (size == SIZE_REMAINING) {
|
|
pr_err("no partitions allowed after a fill-up partition\n");
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
/* more partitions follow, parse them */
|
|
parts = newpart(s + 1, &s, num_parts, this_part + 1,
|
|
&extra_mem, extra_mem_size);
|
|
if (IS_ERR(parts))
|
|
return parts;
|
|
} else {
|
|
/* this is the last partition: allocate space for all */
|
|
int alloc_size;
|
|
|
|
*num_parts = this_part + 1;
|
|
alloc_size = *num_parts * sizeof(struct mtd_partition) +
|
|
extra_mem_size;
|
|
|
|
parts = kzalloc(alloc_size, GFP_KERNEL);
|
|
if (!parts)
|
|
return ERR_PTR(-ENOMEM);
|
|
extra_mem = (unsigned char *)(parts + *num_parts);
|
|
}
|
|
|
|
/* enter this partition (offset will be calculated later if it is zero at this point) */
|
|
parts[this_part].size = size;
|
|
parts[this_part].offset = offset;
|
|
parts[this_part].mask_flags = mask_flags;
|
|
if (name)
|
|
strlcpy(extra_mem, name, name_len + 1);
|
|
else
|
|
sprintf(extra_mem, "Partition_%03d", this_part);
|
|
parts[this_part].name = extra_mem;
|
|
extra_mem += name_len + 1;
|
|
|
|
dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
|
|
this_part, parts[this_part].name, parts[this_part].offset,
|
|
parts[this_part].size, parts[this_part].mask_flags));
|
|
|
|
/* return (updated) pointer to extra_mem memory */
|
|
if (extra_mem_ptr)
|
|
*extra_mem_ptr = extra_mem;
|
|
|
|
/* return (updated) pointer command line string */
|
|
*retptr = s;
|
|
|
|
/* return partition table */
|
|
return parts;
|
|
}
|
|
|
|
/*
|
|
* Parse the command line.
|
|
*/
|
|
static int mtdpart_setup_real(char *s)
|
|
{
|
|
cmdline_parsed = 1;
|
|
|
|
for( ; s != NULL; )
|
|
{
|
|
struct cmdline_mtd_partition *this_mtd;
|
|
struct mtd_partition *parts;
|
|
int mtd_id_len, num_parts;
|
|
char *p, *mtd_id, *semicol, *open_parenth;
|
|
|
|
/*
|
|
* Replace the first ';' by a NULL char so strrchr can work
|
|
* properly.
|
|
*/
|
|
semicol = strchr(s, ';');
|
|
if (semicol)
|
|
*semicol = '\0';
|
|
|
|
/*
|
|
* make sure that part-names with ":" will not be handled as
|
|
* part of the mtd-id with an ":"
|
|
*/
|
|
open_parenth = strchr(s, '(');
|
|
if (open_parenth)
|
|
*open_parenth = '\0';
|
|
|
|
mtd_id = s;
|
|
|
|
/*
|
|
* fetch <mtd-id>. We use strrchr to ignore all ':' that could
|
|
* be present in the MTD name, only the last one is interpreted
|
|
* as an <mtd-id>/<part-definition> separator.
|
|
*/
|
|
p = strrchr(s, ':');
|
|
|
|
/* Restore the '(' now. */
|
|
if (open_parenth)
|
|
*open_parenth = '(';
|
|
|
|
/* Restore the ';' now. */
|
|
if (semicol)
|
|
*semicol = ';';
|
|
|
|
if (!p) {
|
|
pr_err("no mtd-id\n");
|
|
return -EINVAL;
|
|
}
|
|
mtd_id_len = p - mtd_id;
|
|
|
|
dbg(("parsing <%s>\n", p+1));
|
|
|
|
/*
|
|
* parse one mtd. have it reserve memory for the
|
|
* struct cmdline_mtd_partition and the mtd-id string.
|
|
*/
|
|
parts = newpart(p + 1, /* cmdline */
|
|
&s, /* out: updated cmdline ptr */
|
|
&num_parts, /* out: number of parts */
|
|
0, /* first partition */
|
|
(unsigned char**)&this_mtd, /* out: extra mem */
|
|
mtd_id_len + 1 + sizeof(*this_mtd) +
|
|
sizeof(void*)-1 /*alignment*/);
|
|
if (IS_ERR(parts)) {
|
|
/*
|
|
* An error occurred. We're either:
|
|
* a) out of memory, or
|
|
* b) in the middle of the partition spec
|
|
* Either way, this mtd is hosed and we're
|
|
* unlikely to succeed in parsing any more
|
|
*/
|
|
return PTR_ERR(parts);
|
|
}
|
|
|
|
/* align this_mtd */
|
|
this_mtd = (struct cmdline_mtd_partition *)
|
|
ALIGN((unsigned long)this_mtd, sizeof(void *));
|
|
/* enter results */
|
|
this_mtd->parts = parts;
|
|
this_mtd->num_parts = num_parts;
|
|
this_mtd->mtd_id = (char*)(this_mtd + 1);
|
|
strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1);
|
|
|
|
/* link into chain */
|
|
this_mtd->next = partitions;
|
|
partitions = this_mtd;
|
|
|
|
dbg(("mtdid=<%s> num_parts=<%d>\n",
|
|
this_mtd->mtd_id, this_mtd->num_parts));
|
|
|
|
|
|
/* EOS - we're done */
|
|
if (*s == 0)
|
|
break;
|
|
|
|
/* does another spec follow? */
|
|
if (*s != ';') {
|
|
pr_err("bad character after partition (%c)\n", *s);
|
|
return -EINVAL;
|
|
}
|
|
s++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Main function to be called from the MTD mapping driver/device to
|
|
* obtain the partitioning information. At this point the command line
|
|
* arguments will actually be parsed and turned to struct mtd_partition
|
|
* information. It returns partitions for the requested mtd device, or
|
|
* the first one in the chain if a NULL mtd_id is passed in.
|
|
*/
|
|
static int parse_cmdline_partitions(struct mtd_info *master,
|
|
const struct mtd_partition **pparts,
|
|
struct mtd_part_parser_data *data)
|
|
{
|
|
unsigned long long offset;
|
|
int i, err;
|
|
struct cmdline_mtd_partition *part;
|
|
const char *mtd_id = master->name;
|
|
|
|
/* parse command line */
|
|
if (!cmdline_parsed) {
|
|
err = mtdpart_setup_real(cmdline);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Search for the partition definition matching master->name.
|
|
* If master->name is not set, stop at first partition definition.
|
|
*/
|
|
for (part = partitions; part; part = part->next) {
|
|
if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
|
|
break;
|
|
}
|
|
|
|
if (!part)
|
|
return 0;
|
|
|
|
for (i = 0, offset = 0; i < part->num_parts; i++) {
|
|
if (part->parts[i].offset == OFFSET_CONTINUOUS)
|
|
part->parts[i].offset = offset;
|
|
else
|
|
offset = part->parts[i].offset;
|
|
|
|
if (part->parts[i].size == SIZE_REMAINING)
|
|
part->parts[i].size = master->size - offset;
|
|
|
|
if (offset + part->parts[i].size > master->size) {
|
|
pr_warn("%s: partitioning exceeds flash size, truncating\n",
|
|
part->mtd_id);
|
|
part->parts[i].size = master->size - offset;
|
|
}
|
|
offset += part->parts[i].size;
|
|
|
|
if (part->parts[i].size == 0) {
|
|
pr_warn("%s: skipping zero sized partition\n",
|
|
part->mtd_id);
|
|
part->num_parts--;
|
|
memmove(&part->parts[i], &part->parts[i + 1],
|
|
sizeof(*part->parts) * (part->num_parts - i));
|
|
i--;
|
|
}
|
|
}
|
|
|
|
*pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts,
|
|
GFP_KERNEL);
|
|
if (!*pparts)
|
|
return -ENOMEM;
|
|
|
|
return part->num_parts;
|
|
}
|
|
|
|
|
|
/*
|
|
* This is the handler for our kernel parameter, called from
|
|
* main.c::checksetup(). Note that we can not yet kmalloc() anything,
|
|
* so we only save the commandline for later processing.
|
|
*
|
|
* This function needs to be visible for bootloaders.
|
|
*/
|
|
static int __init mtdpart_setup(char *s)
|
|
{
|
|
cmdline = s;
|
|
return 1;
|
|
}
|
|
|
|
__setup("mtdparts=", mtdpart_setup);
|
|
|
|
static struct mtd_part_parser cmdline_parser = {
|
|
.parse_fn = parse_cmdline_partitions,
|
|
.name = "cmdlinepart",
|
|
};
|
|
|
|
static int __init cmdline_parser_init(void)
|
|
{
|
|
if (mtdparts)
|
|
mtdpart_setup(mtdparts);
|
|
register_mtd_parser(&cmdline_parser);
|
|
return 0;
|
|
}
|
|
|
|
static void __exit cmdline_parser_exit(void)
|
|
{
|
|
deregister_mtd_parser(&cmdline_parser);
|
|
}
|
|
|
|
module_init(cmdline_parser_init);
|
|
module_exit(cmdline_parser_exit);
|
|
|
|
MODULE_PARM_DESC(mtdparts, "Partitioning specification");
|
|
module_param(mtdparts, charp, 0);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
|
|
MODULE_DESCRIPTION("Command line configuration of MTD partitions");
|