Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153185941
D13648.id41013.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D13648.id41013.diff
View Options
Index: sys/conf/options
===================================================================
--- sys/conf/options
+++ sys/conf/options
@@ -140,6 +140,7 @@
GEOM_VIRSTOR opt_geom.h
GEOM_VOL opt_geom.h
GEOM_ZERO opt_geom.h
+GEOM_FLASHMAP_MKROOTFS opt_geom.h
IFLIB opt_iflib.h
KDTRACE_HOOKS opt_global.h
KDTRACE_FRAME opt_kdtrace.h
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.
@@ -28,6 +30,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include "opt_geom.h"
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -44,6 +48,12 @@
#define FLASHMAP_CLASS_NAME "Flashmap"
+#ifdef GEOM_FLASHMAP_MKROOTFS
+#define FLASHMAP_UBOOTHDRSIZE 64
+#define FLASHMAP_SECTORSIZE (64 * 1024)
+#define FLASHMAP_MARKER_STR "#!/bin/sh"
+#endif
+
struct g_flashmap_slice {
off_t sl_start;
off_t sl_end;
@@ -68,11 +78,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);
+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 +193,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 +212,48 @@
return (gp);
}
+#ifdef GEOM_FLASHMAP_MKROOTFS
+off_t
+chkuboothdr(struct g_consumer *cp, off_t offset)
+{
+ off_t val;
+ uint8_t *buf;
+ size_t sectorsize;
+
+ sectorsize = FLASHMAP_SECTORSIZE;
+ sectorsize = cp->provider->sectorsize;
+ buf = g_read_data(cp, offset, sectorsize, NULL);
+ if (buf[0] != 0x27 || buf[1] != 0x05 || buf[2] != 0x19 ||
+ buf[3] != 0x56) {
+ g_free(buf);
+ return 0;
+ }
+ val = buf[0xc] << 24 | buf[0xd] << 16 | buf[0xe] << 8 | buf[0xf];
+ val += FLASHMAP_UBOOTHDRSIZE;
+ val = (val - 1) / FLASHMAP_SECTORSIZE;
+ val = (val + 1) * FLASHMAP_SECTORSIZE;
+ g_free(buf);
+ buf = g_read_data(cp, offset + val, sectorsize, NULL);
+ if (strncmp(buf, FLASHMAP_MARKER_STR, strlen(FLASHMAP_MARKER_STR)) !=
+ 0) {
+ g_free(buf);
+ return 0;
+ }
+ g_free(buf);
+ return offset + val;
+}
+#endif
+
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 +265,36 @@
slice->sl_name = slices[i].label;
slice->sl_start = slices[i].base;
slice->sl_end = slices[i].base + slices[i].size - 1;
-
+#ifdef GEOM_FLASHMAP_MKROOTFS
+ 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);
+ }
+#else
STAILQ_INSERT_TAIL(head, slice, sl_link);
+#endif
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 20, 4:33 PM (7 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31851004
Default Alt Text
D13648.id41013.diff (4 KB)
Attached To
Mode
D13648: Add flashmap rootfs search function
Attached
Detach File
Event Timeline
Log In to Comment