Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
079e6bd
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
chips
devices
hyperbus
lpddr
maps
nand
parsers
Kconfig
Makefile
afs.c
ar7part.c
bcm47xxpart.c
bcm63xxpart.c
cmdlinepart.c
ofpart_bcm4908.c
ofpart_bcm4908.h
ofpart_core.c
ofpart_linksys_ns.c
ofpart_linksys_ns.h
parser_imagetag.c
parser_trx.c
qcomsmempart.c
redboot.c
sharpslpart.c
spi-nor
tests
ubi
Kconfig
Makefile
ftl.c
inftlcore.c
inftlmount.c
mtd_blkdevs.c
mtdblock.c
mtdblock_ro.c
mtdchar.c
mtdconcat.c
mtdcore.c
mtdcore.h
mtdoops.c
mtdpart.c
mtdpstore.c
mtdsuper.c
mtdswap.c
nftlcore.c
nftlmount.c
rfd_ftl.c
sm_ftl.c
sm_ftl.h
ssfdc.c
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
vdpa
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
mtd
/
parsers
/
qcomsmempart.c
Blame
Blame
Latest commit
History
History
188 lines (162 loc) · 5.21 KB
Breadcrumbs
linux
/
drivers
/
mtd
/
parsers
/
qcomsmempart.c
Top
File metadata and controls
Code
Blame
188 lines (162 loc) · 5.21 KB
Raw
// SPDX-License-Identifier: GPL-2.0-only /* * Qualcomm SMEM NAND flash partition parser * * Copyright (C) 2020, Linaro Ltd. */ #include <linux/ctype.h> #include <linux/module.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #include <linux/slab.h> #include <linux/soc/qcom/smem.h> #define SMEM_AARM_PARTITION_TABLE 9 #define SMEM_APPS 0 #define SMEM_FLASH_PART_MAGIC1 0x55ee73aa #define SMEM_FLASH_PART_MAGIC2 0xe35ebddb #define SMEM_FLASH_PTABLE_V3 3 #define SMEM_FLASH_PTABLE_V4 4 #define SMEM_FLASH_PTABLE_MAX_PARTS_V3 16 #define SMEM_FLASH_PTABLE_MAX_PARTS_V4 48 #define SMEM_FLASH_PTABLE_HDR_LEN (4 * sizeof(u32)) #define SMEM_FLASH_PTABLE_NAME_SIZE 16 /** * struct smem_flash_pentry - SMEM Flash partition entry * @name: Name of the partition * @offset: Offset in blocks * @length: Length of the partition in blocks * @attr: Flags for this partition */ struct smem_flash_pentry { char name[SMEM_FLASH_PTABLE_NAME_SIZE]; __le32 offset; __le32 length; u8 attr; } __packed __aligned(4); /** * struct smem_flash_ptable - SMEM Flash partition table * @magic1: Partition table Magic 1 * @magic2: Partition table Magic 2 * @version: Partition table version * @numparts: Number of partitions in this ptable * @pentry: Flash partition entries belonging to this ptable */ struct smem_flash_ptable { __le32 magic1; __le32 magic2; __le32 version; __le32 numparts; struct smem_flash_pentry pentry[SMEM_FLASH_PTABLE_MAX_PARTS_V4]; } __packed __aligned(4); static int parse_qcomsmem_part(struct mtd_info *mtd, const struct mtd_partition **pparts, struct mtd_part_parser_data *data) { struct smem_flash_pentry *pentry; struct smem_flash_ptable *ptable; size_t len = SMEM_FLASH_PTABLE_HDR_LEN; struct mtd_partition *parts; int ret, i, numparts; char *name, *c; if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_4K_SECTORS) && mtd->type == MTD_NORFLASH) { pr_err("%s: SMEM partition parser is incompatible with 4K sectors\n", mtd->name); return -EINVAL; } pr_debug("Parsing partition table info from SMEM\n"); ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len); if (IS_ERR(ptable)) { if (PTR_ERR(ptable) != -EPROBE_DEFER) pr_err("Error reading partition table header\n"); return PTR_ERR(ptable); } /* Verify ptable magic */ if (le32_to_cpu(ptable->magic1) != SMEM_FLASH_PART_MAGIC1 || le32_to_cpu(ptable->magic2) != SMEM_FLASH_PART_MAGIC2) { pr_err("Partition table magic verification failed\n"); return -EINVAL; } /* Ensure that # of partitions is less than the max we have allocated */ numparts = le32_to_cpu(ptable->numparts); if (numparts > SMEM_FLASH_PTABLE_MAX_PARTS_V4) { pr_err("Partition numbers exceed the max limit\n"); return -EINVAL; } /* Find out length of partition data based on table version */ if (le32_to_cpu(ptable->version) <= SMEM_FLASH_PTABLE_V3) { len = SMEM_FLASH_PTABLE_HDR_LEN + SMEM_FLASH_PTABLE_MAX_PARTS_V3 * sizeof(struct smem_flash_pentry); } else if (le32_to_cpu(ptable->version) == SMEM_FLASH_PTABLE_V4) { len = SMEM_FLASH_PTABLE_HDR_LEN + SMEM_FLASH_PTABLE_MAX_PARTS_V4 * sizeof(struct smem_flash_pentry); } else { pr_err("Unknown ptable version (%d)", le32_to_cpu(ptable->version)); return -EINVAL; } /* * Now that the partition table header has been parsed, verified * and the length of the partition table calculated, read the * complete partition table */ ptable = qcom_smem_get(SMEM_APPS, SMEM_AARM_PARTITION_TABLE, &len); if (IS_ERR(ptable)) { pr_err("Error reading partition table\n"); return PTR_ERR(ptable); } parts = kcalloc(numparts, sizeof(*parts), GFP_KERNEL); if (!parts) return -ENOMEM; for (i = 0; i < numparts; i++) { pentry = &ptable->pentry[i]; if (pentry->name[0] == '\0') continue; name = kstrdup(pentry->name, GFP_KERNEL); if (!name) { ret = -ENOMEM; goto out_free_parts; } /* Convert name to lower case */ for (c = name; *c != '\0'; c++) *c = tolower(*c); parts[i].name = name; parts[i].offset = le32_to_cpu(pentry->offset) * mtd->erasesize; parts[i].mask_flags = pentry->attr; parts[i].size = le32_to_cpu(pentry->length) * mtd->erasesize; pr_debug("%d: %s offs=0x%08x size=0x%08x attr:0x%08x\n", i, pentry->name, le32_to_cpu(pentry->offset), le32_to_cpu(pentry->length), pentry->attr); } pr_debug("SMEM partition table found: ver: %d len: %d\n", le32_to_cpu(ptable->version), numparts); *pparts = parts; return numparts; out_free_parts: while (--i >= 0) kfree(parts[i].name); kfree(parts); *pparts = NULL; return ret; } static void parse_qcomsmem_cleanup(const struct mtd_partition *pparts, int nr_parts) { int i; for (i = 0; i < nr_parts; i++) kfree(pparts[i].name); } static const struct of_device_id qcomsmem_of_match_table[] = { { .compatible = "qcom,smem-part" }, {}, }; MODULE_DEVICE_TABLE(of, qcomsmem_of_match_table); static struct mtd_part_parser mtd_parser_qcomsmem = { .parse_fn = parse_qcomsmem_part, .cleanup = parse_qcomsmem_cleanup, .name = "qcomsmem", .of_match_table = qcomsmem_of_match_table, }; module_mtd_part_parser(mtd_parser_qcomsmem); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>"); MODULE_DESCRIPTION("Qualcomm SMEM NAND flash partition parser");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
You can’t perform that action at this time.