Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144582346
D13648.1775553366.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D13648.1775553366.diff
View Options
Index: sys/geom/geom_flashmap.c
===================================================================
--- sys/geom/geom_flashmap.c
+++ sys/geom/geom_flashmap.c
@@ -1,4 +1,6 @@
/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
* Copyright (c) 2012 Semihalf
* Copyright (c) 2009 Jakub Klama <jakub.klama@uj.edu.pl>
* All rights reserved.
@@ -44,6 +46,11 @@
#define FLASHMAP_CLASS_NAME "Flashmap"
+#define FLASHMAP_UBOOTHDRSIZE 64
+#define FLASHMAP_SECTORSIZE (64 * 1024)
+#define FLASHMAP_MARKER_STR "#!/bin/sh"
+#define FLASHMAP_MAX_HDRCHK 8
+
struct g_flashmap_slice {
off_t sl_start;
off_t sl_end;
@@ -68,11 +75,13 @@
static g_taste_t g_flashmap_taste;
static int g_flashmap_load(device_t dev, struct g_provider *pp,
- flash_slicer_t slicer, struct g_flashmap_head *head);
+ struct g_consumer *cp, flash_slicer_t slicer, struct g_flashmap_head *head);
static int g_flashmap_modify(struct g_geom *gp, const char *devname,
int secsize, struct g_flashmap_head *slices);
static void g_flashmap_print(struct g_flashmap_slice *slice);
+static off_t chkuboothdr(struct g_consumer *cp, off_t offset);
+
MALLOC_DECLARE(M_FLASHMAP);
MALLOC_DEFINE(M_FLASHMAP, "geom_flashmap", "GEOM flash memory slicer class");
@@ -181,7 +190,7 @@
if (slicer == NULL)
break;
- if (g_flashmap_load(dev, pp, slicer, &head) == 0)
+ if (g_flashmap_load(dev, pp, cp, slicer, &head) == 0)
break;
g_flashmap_modify(gp, cp->provider->name,
@@ -200,13 +209,67 @@
return (gp);
}
+static off_t
+chkuboothdr(struct g_consumer *cp, off_t offset)
+{
+ off_t val;
+ uint8_t *buf;
+ size_t sectorsize;
+ int i;
+ int uboothdr;
+
+ sectorsize = FLASHMAP_SECTORSIZE;
+ sectorsize = cp->provider->sectorsize;
+ buf = g_read_data(cp, offset, sectorsize, NULL);
+ /*
+ * check u-boot header magic number.
+ * A few u-boot have space before header.
+ */
+ uboothdr = -1;
+ for (i = 0; i < FLASHMAP_MAX_HDRCHK; ++i) {
+ if (buf[i*4] == 0x27 && buf[i*4+1] == 0x05 &&
+ buf[i*4+2] == 0x19 && buf[i*4+3] == 0x56) {
+ uboothdr = i;
+ break;
+ }
+ }
+ if (uboothdr == -1) {
+ g_free(buf);
+ return 0;
+ }
+ /* get image data size */
+ uboothdr *= 4;
+ val = buf[uboothdr+0xc] << 24 | buf[uboothdr+0xd] << 16 |
+ buf[uboothdr+0xe] << 8 | buf[uboothdr+0xf];
+ val += FLASHMAP_UBOOTHDRSIZE + uboothdr;
+ val = (val - 1) / FLASHMAP_SECTORSIZE;
+ val = (val + 1) * FLASHMAP_SECTORSIZE;
+ g_free(buf);
+ /* check 64K and 128K boundly */
+ for (i = 0; i < 2; ++i) {
+ buf = g_read_data(cp, offset + val, sectorsize, NULL);
+ if (strncmp(buf, FLASHMAP_MARKER_STR,
+ strlen(FLASHMAP_MARKER_STR)) == 0)
+ break;
+ g_free(buf);
+ val += FLASHMAP_SECTORSIZE;
+ }
+ if (i == 2)
+ return 0;
+ g_free(buf);
+ return offset + val;
+}
+
static int
-g_flashmap_load(device_t dev, struct g_provider *pp, flash_slicer_t slicer,
- struct g_flashmap_head *head)
+g_flashmap_load(device_t dev, struct g_provider *pp, struct g_consumer *cp,
+ flash_slicer_t slicer, struct g_flashmap_head *head)
{
struct flash_slice *slices;
struct g_flashmap_slice *slice;
int i, nslices = 0;
+ struct g_flashmap_slice *rootfs;
+ off_t rootfsbase;
+ char *rootfsname;
slices = malloc(sizeof(struct flash_slice) * FLASH_SLICES_MAX_NUM,
M_FLASHMAP, M_WAITOK | M_ZERO);
@@ -218,8 +281,32 @@
slice->sl_name = slices[i].label;
slice->sl_start = slices[i].base;
slice->sl_end = slices[i].base + slices[i].size - 1;
-
- STAILQ_INSERT_TAIL(head, slice, sl_link);
+ if(strcmp("firmware", slice->sl_name) == 0) {
+ rootfsbase = chkuboothdr(cp, slice->sl_start);
+ if (rootfsbase != 0) {
+ rootfs = malloc(sizeof(
+ struct g_flashmap_slice),
+ M_FLASHMAP, M_WAITOK);
+
+ slice->sl_end = rootfsbase - 1;
+ rootfsname = g_malloc(32,
+ M_WAITOK | M_ZERO);
+ strcpy(rootfsname, "rootfs");
+ rootfs->sl_name = rootfsname;
+ rootfs->sl_start = rootfsbase;
+ rootfs->sl_end = slices[i].base +
+ slices[i].size - 1;
+ STAILQ_INSERT_TAIL(head, slice,
+ sl_link);
+ STAILQ_INSERT_TAIL(head, rootfs,
+ sl_link);
+ } else {
+ STAILQ_INSERT_TAIL(head, slice,
+ sl_link);
+ }
+ } else {
+ STAILQ_INSERT_TAIL(head, slice, sl_link);
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 7, 9:16 AM (25 m, 44 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28291484
Default Alt Text
D13648.1775553366.diff (4 KB)
Attached To
Mode
D13648: Add flashmap rootfs search function
Attached
Detach File
Event Timeline
Log In to Comment