Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

APFS: a block device over part of an image, so the real volume can be read where it does not fit

vcvkk8f217624c763
diff --git a/tools/apfs/mksparse.py b/tools/apfs/mksparse.py
new file mode 100755
index 0000000..d465a32
--- /dev/null
+++ b/tools/apfs/mksparse.py
@@ -0,0 +1,164 @@
+#!/usr/bin/env python3
+# Make a sparse image of an APFS container: only the blocks a given walk actually reads,
+# plus a table saying where each of them went.
+#
+# Why: the phone has no driver for its own storage, so a volume there has to live in a RAM
+# disk, and the whole iOS root volume is 5368 MB against the 4288 MB the phone's firmware
+# leaves usable. Most of those blocks are never read by a given walk, though, so this
+# writes out the ones that are and the driver cannot tell the difference -- every block it
+# asks for is there.
+#
+# The blocks are found by walking with tools/apfs/apfs.py, which reads the image the same
+# way the kernel's C does (run-tests.sh step 5 checks that), and recording every block it
+# touches. A cache of a different size only changes how often a block is re-read, not
+# which blocks are needed, so the set is safe to hand to the kernel.
+#
+# Layout of what comes out (little-endian), as bsd/dev/redwood_sparse.c reads it:
+#
+# header, one block: "REDWOODSPARSE1\0\0", block size, block count of the container,
+# how many blocks are present, the offsets of the table and the data
+# table: one 32-bit entry per container block -- 0 absent, else the index
+# into the data area plus one
+# data: the blocks that are present, in the order the table numbers them
+#
+# usage: mksparse.py trace IMAGE [PATH ...] just say what it would take
+# mksparse.py build IMAGE OUT [PATH ...] write the sparse image
+# With no PATH the whole volume is walked.
+
+import os
+import struct
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import apfs
+
+MAGIC = b"REDWOODSPARSE1\0\0"
+HEADER_SIZE = 4096
+
+
+class Tracing(apfs.Blocks):
+ """A block reader that remembers every block it was asked for."""
+
+ def __init__(self, *a, **kw):
+ super().__init__(*a, **kw)
+ self.touched = set()
+
+ def get(self, addr, verify=True):
+ self.touched.add(addr)
+ return super().get(addr, verify)
+
+ def raw(self, addr, count=1):
+ for i in range(count):
+ self.touched.add(addr + i)
+ return super().raw(addr, count)
+
+
+def walk_and_trace(image, paths):
+ """
+ Walk and record. The recording reader has to be in place before the container is
+ opened, not swapped in after: opening it reads block zero, the checkpoint area, the
+ container's object map and the volume superblock, and without those in the image the
+ driver cannot even find a superblock to mount from.
+ """
+ plain = apfs.Blocks
+ apfs.Blocks = Tracing
+ try:
+ c = apfs.Container(image)
+ finally:
+ apfs.Blocks = plain
+ tr = c.blocks
+ tr.cache_limit = 60000
+ v = apfs.pick_volume(c, None)
+
+ starts = []
+ if paths:
+ for p in paths:
+ hit = v.lookup(p)
+ if hit is None:
+ print("mksparse.py: %s: not found" % p, file=sys.stderr)
+ return None, None, None
+ starts.append((hit[0], "/" + p.strip("/")))
+ else:
+ starts.append((apfs.ROOT_DIR_INO_NUM, ""))
+
+ n = 0
+ for oid, prefix in starts:
+ stack = [(oid, prefix)]
+ while stack:
+ d, px = stack.pop()
+ for name, fid, dt in v.dir_entries(d):
+ p = px + "/" + name
+ ino = v.inode(fid)
+ n += 1
+ if ino is None:
+ continue
+ if ino.is_reg or ino.is_link:
+ ino.contents() # what makes the data blocks be read
+ if dt == 4:
+ stack.append((fid, p))
+ if n % 20000 == 0:
+ sys.stderr.write("\r %d entries, %d blocks so far..."
+ % (n, len(tr.touched)))
+ sys.stderr.flush()
+ sys.stderr.write("\r")
+ return c, tr, n
+
+
+def main(argv):
+ if len(argv) < 3:
+ print(__doc__ or "", file=sys.stderr)
+ return 2
+ cmd = argv[1]
+ if cmd == "trace":
+ image, out, paths = argv[2], None, argv[3:]
+ elif cmd == "build":
+ if len(argv) < 4:
+ print("mksparse.py: build needs an output file", file=sys.stderr)
+ return 2
+ image, out, paths = argv[2], argv[3], argv[4:]
+ else:
+ print("mksparse.py: unknown command %r" % cmd, file=sys.stderr)
+ return 2
+
+ c, tr, entries = walk_and_trace(image, paths)
+ if c is None:
+ return 1
+ present = sorted(tr.touched)
+ bs = c.block_size
+ total = c.nx["block_count"]
+ size = HEADER_SIZE + total * 4 + len(present) * bs
+ print("walked %d entries over %s" % (entries, ", ".join(paths) if paths else "the whole volume"))
+ print("container %d blocks of %d (%.2f GB)" % (total, bs, total * bs / 1e9))
+ print("blocks needed %d (%.2f GB of data)" % (len(present), len(present) * bs / 1e9))
+ print("sparse image would be %d bytes (%.2f GB): %d header, %d table, %d data"
+ % (size, size / 1e9, HEADER_SIZE, total * 4, len(present) * bs))
+ if out is None:
+ return 0
+
+ index = {}
+ for i, a in enumerate(present):
+ index[a] = i + 1
+ with open(out, "wb") as g:
+ hdr = bytearray(HEADER_SIZE)
+ hdr[0:16] = MAGIC
+ struct.pack_into("<IQQQQ", hdr, 16, bs, total, len(present),
+ HEADER_SIZE, HEADER_SIZE + total * 4)
+ g.write(hdr)
+ table = bytearray(total * 4)
+ for a, i in index.items():
+ struct.pack_into("<I", table, a * 4, i)
+ g.write(table)
+ done = 0
+ for a in present:
+ g.write(c.blocks.raw(a))
+ done += 1
+ if done % 20000 == 0:
+ sys.stderr.write("\r wrote %d/%d blocks..." % (done, len(present)))
+ sys.stderr.flush()
+ sys.stderr.write("\r")
+ print("%s: %d bytes" % (out, os.path.getsize(out)))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/userland/build.sh b/userland/build.sh
index 7bac039..0949467 100755
--- a/userland/build.sh
+++ b/userland/build.sh
@@ -181,6 +181,9 @@ if [ -d $IOS/rootfs/usr/lib ]; then
[ -f obj/camera_avtest ] && cp obj/camera_avtest root/bin/
[ -f obj/record_test ] && cp obj/record_test root/bin/
for f in $EXTRA; do cp "$f" root/bin/; done
+ # /dev and /private/var exist so that this image can also be the root on its own:
+ # devfs is mounted on /dev, and init puts a ramfs on /private/var
+ mkdir -p root/dev root/private/var
mkdir -p root/lib
cp obj/libredwood.dylib obj/libredwood-sb.dylib root/lib/
[ -f obj/libredwood-media.dylib ] && cp obj/libredwood-media.dylib root/lib/ # (as with cpu_test)
diff --git a/xnu/files/bsd/dev/redwood_apfs_check.c b/xnu/files/bsd/dev/redwood_apfs_check.c
index d8cee18..5965a4b 100644
--- a/xnu/files/bsd/dev/redwood_apfs_check.c
+++ b/xnu/files/bsd/dev/redwood_apfs_check.c
@@ -18,7 +18,12 @@
* the whole of it, to see what the one lock round apfs_lib
* costs when there is more than one reader
* apfs_threads=N how many, for mode 5 (default 4)
- * apfs_dev=md1 the device to mount for modes 1 to 3 (default rvblk0)
+ * apfs_check=6 mount apfs_dev on apfs_mnt, walk it on this thread and go
+ * back to the loader. For a volume that is not the root and
+ * where there is no user space to make a mount point: the
+ * point is a directory of the root image itself.
+ * apfs_dev=md1 the device to mount for modes 1 to 3 and 6 (default rvblk0)
+ * apfs_mnt=/lib where to mount it for mode 6 (default /private/var/apfs-check)
* apfs_subtree=/usr walk only that part of the volume
*
* A line is the same one tools/apfs/apfs-tool's census and `verify.py clines` print:
@@ -64,6 +69,7 @@
extern void loader_return(void); /* osfmk/arm64/loader_return.c */
extern void apfs_stats_print(void); /* bsd/miscfs/apfs/apfs_vfsops.c */
+extern void redwood_sparse_report(void);
#define CHECK_MNT "/private/var/apfs-check"
#define CHECK_PARENT "/private/var"
@@ -528,8 +534,13 @@ apfs_check_thread(void *arg, __unused wait_result_t wr)
bzero(&cs, sizeof(cs));
cs.ctx = ctx;
cs.print_lines = (mode == 2);
+ /*
+ * NOCROSSMOUNT only where the volume is the root (modes 4 and 5). In mode 6 the
+ * path leads from the root image into the mount, so crossing has to be allowed; the
+ * walk is kept on the volume by the check against the mount it started on.
+ */
cs.lookup_flags = VNODE_LOOKUP_NOFOLLOW |
- ((mode >= 4) ? VNODE_LOOKUP_NOCROSSMOUNT : 0);
+ ((mode == 4 || mode == 5) ? VNODE_LOOKUP_NOCROSSMOUNT : 0);
if (PE_parse_boot_arg_str("apfs_dev", subtree, sizeof(subtree)) && subtree[0] != '\0') {
snprintf(devname, sizeof(devname), "/dev/%s", subtree);
}
@@ -542,13 +553,68 @@ apfs_check_thread(void *arg, __unused wait_result_t wr)
return;
}
+ if (mode == 6) {
+ char mnt[128] = CHECK_MNT;
+
+ if (PE_parse_boot_arg_str("apfs_mnt", subtree, sizeof(subtree)) &&
+ subtree[0] == '/') {
+ strlcpy(mnt, subtree, sizeof(mnt));
+ }
+ subtree[0] = '\0';
+ /*
+ * A node just made with devfs_make_node() is not in /dev the instant it is
+ * made -- this runs straight after the device registered itself, and the first
+ * lookup comes back ENOENT -- so wait for it rather than guess how long devfs
+ * takes to show it.
+ */
+ {
+ vnode_t t = NULLVP;
+ int tries;
+
+ for (tries = 0; tries < 100; tries++) {
+ if (vnode_lookup(devname, 0, &t, ctx) == 0) {
+ vnode_put(t);
+ break;
+ }
+ delay_for_interval(20, NSEC_PER_MSEC);
+ }
+ if (tries >= 100) {
+ printf("apfs-check: %s never showed up in /dev\n", devname);
+ } else if (tries > 0) {
+ printf("apfs-check: %s showed up in /dev after %d ms\n", devname,
+ tries * 20);
+ }
+ }
+ error = kernel_mount("apfs", NULLVP, NULLVP, mnt, devname, 0,
+ MNT_RDONLY | MNT_DONTBROWSE, KERNEL_MOUNT_NOAUTH, ctx);
+ if (error) {
+ printf("apfs-check: mounting %s on %s failed: %d\n", devname, mnt,
+ error);
+ kfree_data(cs.path, PATH_CAP);
+ kfree_data(cs.buf, READ_CHUNK);
+ return;
+ }
+ printf("apfs-check: %s mounted on %s\n", devname, mnt);
+ cs.rel = strlen(mnt);
+ strlcpy(cs.path, mnt, PATH_CAP);
+ cs.len = cs.rel;
+ if (PE_parse_boot_arg_str("apfs_subtree", subtree, sizeof(subtree)) &&
+ subtree[0] == '/') {
+ strlcat(cs.path, subtree, PATH_CAP);
+ cs.len = strlen(cs.path);
+ printf("apfs-check: walking %s\n", cs.path + cs.rel);
+ } else {
+ printf("apfs-check: walking the whole volume\n");
+ }
+ goto walk;
+ }
if (mode >= 5) {
kfree_data(cs.path, PATH_CAP);
kfree_data(cs.buf, READ_CHUNK);
apfs_check_concurrent();
return;
}
- if (mode >= 4) {
+ if (mode >= 4 && mode != 6) {
/*
* The volume is already the root: nothing to mount, and no mount point to
* make, so none of what follows about /private/var applies.
@@ -628,6 +694,7 @@ walk:
printf("apfs-check: line-hash sum %016llx\n", (unsigned long long)cs.sum);
printf("apfs-check: errors %u\n", cs.errors);
apfs_stats_print();
+ redwood_sparse_report();
printf("apfs-check: compare with tools/apfs/verify.py sum\n");
kfree_data(cs.path, PATH_CAP);
@@ -645,7 +712,8 @@ redwood_apfs_check_init(void)
}
if (mode >= 4) {
/*
- * The volume is the root, so everything the walk needs is already up -- and
+ * The volume is the root (or mode 6, which mounts it here), so everything the
+ * walk needs is already up -- and
* bsd_init is about to exec /sbin/launchd off it, which on anything but our
* own packfs image ends in a panic before a thread of our own would finish.
* So walk it here, on this thread, and go back to the loader with the answer
diff --git a/xnu/files/bsd/dev/redwood_sparse.c b/xnu/files/bsd/dev/redwood_sparse.c
new file mode 100644
index 0000000..7666aed
--- /dev/null
+++ b/xnu/files/bsd/dev/redwood_sparse.c
@@ -0,0 +1,281 @@
+/*
+ * A block device over an image that holds only some of its blocks (/dev/rsp0). Only with
+ * boot-arg apfs_sparse=<offset>.
+ *
+ * This exists so that the real iOS root volume can be read on the phone. The phone has
+ * no driver for its own storage, so a volume there has to live in a RAM disk, and that
+ * volume is 5368 MB against the 4288 MB its firmware leaves usable. But a given walk
+ * reads only some of those blocks, so tools/apfs/mksparse.py writes out the ones it reads
+ * together with a table saying where each went, and this serves them at their original
+ * addresses. The APFS driver above cannot tell the difference: every block it asks for is
+ * there, at the address it asks for.
+ *
+ * The image rides at the end of the resident RAM disk, after the packfs image that is the
+ * root -- packfs reads only as far as its own superblock says, so what follows is ignored
+ * by it -- and apfs_sparse is the byte offset where it starts.
+ *
+ * A block that is not in the image reads as zeros and is counted. Nothing should ask for
+ * one; the count is printed so that it does not go unnoticed if something does.
+ *
+ * Read only.
+ */
+
+#include <kern/clock.h>
+#include <libkern/libkern.h>
+#include <mach/mach_types.h>
+#include <mach/vm_param.h>
+#include <miscfs/devfs/devfs.h>
+#include <pexpert/pexpert.h>
+#include <sys/buf.h>
+#include <sys/conf.h>
+#include <sys/disk.h>
+#include <sys/errno.h>
+#include <sys/systm.h>
+#include <sys/redwood_sparse.h>
+
+extern dev_t mdevlookup(int devid);
+extern int mdevgetkernelrange(dev_t dev, vm_offset_t *base, uint64_t *size);
+
+#define SPARSE_MAGIC "REDWOODSPARSE1\0\0"
+#define SPARSE_SECTOR 512
+
+struct sparse_header {
+ char sh_magic[16];
+ uint32_t sh_block_size;
+ uint64_t sh_block_count; /* of the container this stands in for */
+ uint64_t sh_present; /* how many of them are here */
+ uint64_t sh_table_off; /* from the start of this header */
+ uint64_t sh_data_off;
+} __attribute__((packed));
+
+static const uint8_t *sparse_table; /* sh_block_count 32-bit entries */
+static const uint8_t *sparse_data;
+static uint32_t sparse_block_size;
+static uint64_t sparse_block_count;
+static uint64_t sparse_present;
+static bool sparse_ready;
+static int sparse_bmajor = -1, sparse_cmajor = -1;
+static uint64_t sparse_hits, sparse_misses;
+
+static int
+sparse_open(__unused dev_t dev, int flags, __unused int devtype, __unused proc_t p)
+{
+ if (!sparse_ready) {
+ return ENXIO;
+ }
+ return (flags & FWRITE) ? EROFS : 0;
+}
+
+static int
+sparse_close(__unused dev_t dev, __unused int flags, __unused int devtype,
+ __unused proc_t p)
+{
+ return 0;
+}
+
+/* Where block `blk` of the container is in the image, or NULL if it is not here. */
+static const uint8_t *
+sparse_block(uint64_t blk)
+{
+ uint32_t slot;
+
+ if (blk >= sparse_block_count) {
+ return NULL;
+ }
+ memcpy(&slot, sparse_table + blk * 4, sizeof(slot));
+ if (slot == 0) {
+ return NULL;
+ }
+ return sparse_data + (uint64_t)(slot - 1) * sparse_block_size;
+}
+
+static void
+sparse_strategy(buf_t bp)
+{
+ uint8_t *dst;
+ uint64_t off;
+ size_t left;
+
+ if (!sparse_ready) {
+ buf_seterror(bp, ENXIO);
+ buf_biodone(bp);
+ return;
+ }
+ if (!(buf_flags(bp) & B_READ)) {
+ buf_seterror(bp, EROFS);
+ buf_biodone(bp);
+ return;
+ }
+ off = (uint64_t)buf_blkno(bp) * SPARSE_SECTOR;
+ left = buf_count(bp);
+ dst = (uint8_t *)buf_dataptr(bp);
+
+ if (off >= sparse_block_count * sparse_block_size) {
+ buf_setresid(bp, buf_count(bp));
+ buf_seterror(bp, (off == sparse_block_count * sparse_block_size) ? 0 : EINVAL);
+ buf_biodone(bp);
+ return;
+ }
+ while (left > 0) {
+ uint64_t blk = off / sparse_block_size;
+ uint32_t skew = (uint32_t)(off % sparse_block_size);
+ size_t n = sparse_block_size - skew;
+ const uint8_t *src;
+
+ if (n > left) {
+ n = left;
+ }
+ src = sparse_block(blk);
+ if (src == NULL) {
+ /* nothing asked for this when the image was made */
+ bzero(dst, n);
+ sparse_misses++;
+ } else {
+ memcpy(dst, src + skew, n);
+ sparse_hits++;
+ }
+ dst += n;
+ off += n;
+ left -= n;
+ }
+ buf_setresid(bp, 0);
+ buf_biodone(bp);
+}
+
+static int
+sparse_ioctl(__unused dev_t dev, u_long cmd, caddr_t data, __unused int fflag,
+ __unused proc_t p)
+{
+ if (!sparse_ready) {
+ return ENXIO;
+ }
+ switch (cmd) {
+ case DKIOCGETBLOCKSIZE:
+ *(uint32_t *)data = SPARSE_SECTOR;
+ return 0;
+ case DKIOCSETBLOCKSIZE:
+ /* spec_open() sets 512 and back, and takes a refusal for a broken device */
+ return (*(uint32_t *)data == SPARSE_SECTOR) ? 0 : EINVAL;
+ case DKIOCGETBLOCKCOUNT:
+ *(uint64_t *)data = sparse_block_count *
+ (sparse_block_size / SPARSE_SECTOR);
+ return 0;
+ case DKIOCISWRITABLE:
+ *(uint32_t *)data = 0;
+ return 0;
+ default:
+ return ENOTTY;
+ }
+}
+
+static int
+sparse_size(__unused dev_t dev)
+{
+ return sparse_ready ? SPARSE_SECTOR : -1;
+}
+
+static const struct bdevsw sparse_bdevsw = {
+ .d_open = sparse_open,
+ .d_close = sparse_close,
+ .d_strategy = sparse_strategy,
+ .d_ioctl = sparse_ioctl,
+ .d_dump = eno_dump,
+ .d_psize = sparse_size,
+ .d_type = D_DISK,
+};
+
+static const struct cdevsw sparse_cdevsw = {
+ .d_open = sparse_open,
+ .d_close = sparse_close,
+ .d_read = eno_rdwrt,
+ .d_write = eno_rdwrt,
+ .d_ioctl = sparse_ioctl,
+ .d_stop = eno_stop,
+ .d_reset = eno_reset,
+ .d_ttys = NULL,
+ .d_select = eno_select,
+ .d_mmap = eno_mmap,
+ .d_strategy = eno_strat,
+ .d_reserved_1 = eno_getc,
+ .d_reserved_2 = eno_putc,
+ .d_type = D_DISK,
+};
+
+void
+redwood_sparse_report(void)
+{
+ if (!sparse_ready) {
+ return;
+ }
+ printf("sparse: %llu blocks served, %llu asked for that are not in the image\n",
+ (unsigned long long)sparse_hits, (unsigned long long)sparse_misses);
+}
+
+void
+redwood_sparse_init(void)
+{
+ uint64_t off = 0;
+ vm_offset_t base = 0;
+ uint64_t size = 0;
+ const struct sparse_header *hdr;
+ dev_t md;
+
+ if (!PE_parse_boot_argn("apfs_sparse", &off, sizeof(off)) || off == 0) {
+ return;
+ }
+ md = mdevlookup(0);
+ if (md == (dev_t)-1 || mdevgetkernelrange(md, &base, &size) != 0) {
+ printf("sparse: md0 is not a memory disk this can be read from\n");
+ return;
+ }
+ if (off + sizeof(*hdr) > size) {
+ printf("sparse: offset %llu is past the end of md0 (%llu bytes)\n",
+ (unsigned long long)off, (unsigned long long)size);
+ return;
+ }
+ hdr = (const struct sparse_header *)(base + off);
+ if (memcmp(hdr->sh_magic, SPARSE_MAGIC, sizeof(hdr->sh_magic)) != 0) {
+ printf("sparse: no sparse image at offset %llu in md0\n",
+ (unsigned long long)off);
+ return;
+ }
+ sparse_block_size = hdr->sh_block_size;
+ sparse_block_count = hdr->sh_block_count;
+ sparse_present = hdr->sh_present;
+ if (sparse_block_size < SPARSE_SECTOR || (sparse_block_size % SPARSE_SECTOR) != 0 ||
+ sparse_block_count == 0 || sparse_present == 0 ||
+ sparse_present > sparse_block_count) {
+ printf("sparse: the header makes no sense\n");
+ return;
+ }
+ if (off + hdr->sh_data_off + sparse_present * sparse_block_size > size ||
+ off + hdr->sh_table_off + sparse_block_count * 4 > size) {
+ printf("sparse: the image does not fit in md0 (%llu bytes)\n",
+ (unsigned long long)size);
+ return;
+ }
+ sparse_table = (const uint8_t *)(base + off + hdr->sh_table_off);
+ sparse_data = (const uint8_t *)(base + off + hdr->sh_data_off);
+
+ sparse_bmajor = bdevsw_add(-1, &sparse_bdevsw);
+ if (sparse_bmajor < 0) {
+ printf("sparse: bdevsw_add failed\n");
+ return;
+ }
+ sparse_cmajor = cdevsw_add_with_bdev(-1, &sparse_cdevsw, sparse_bmajor);
+ if (sparse_cmajor < 0) {
+ printf("sparse: cdevsw_add failed\n");
+ return;
+ }
+ if (devfs_make_node(makedev(sparse_bmajor, 0), DEVFS_BLOCK, UID_ROOT, GID_OPERATOR,
+ 0600, "rsp0") == NULL) {
+ printf("sparse: devfs_make_node failed\n");
+ return;
+ }
+ sparse_ready = true;
+ printf("sparse: /dev/rsp0 stands in for %llu blocks of %u, %llu of them here "
+ "(%llu MB), at offset %llu of md0\n", (unsigned long long)sparse_block_count,
+ sparse_block_size, (unsigned long long)sparse_present,
+ (unsigned long long)(sparse_present * sparse_block_size / (1024 * 1024)),
+ (unsigned long long)off);
+}
diff --git a/xnu/files/bsd/sys/redwood_sparse.h b/xnu/files/bsd/sys/redwood_sparse.h
new file mode 100644
index 0000000..cff008a
--- /dev/null
+++ b/xnu/files/bsd/sys/redwood_sparse.h
@@ -0,0 +1,12 @@
+/*
+ * A block device over an image holding only some of its blocks: how the real iOS root
+ * volume is read on the phone, which cannot hold all of it. Only with boot-arg
+ * apfs_sparse=<offset in md0>. See bsd/dev/redwood_sparse.c.
+ */
+#ifndef _SYS_REDWOOD_SPARSE_H_
+#define _SYS_REDWOOD_SPARSE_H_
+
+void redwood_sparse_init(void);
+void redwood_sparse_report(void);
+
+#endif /* _SYS_REDWOOD_SPARSE_H_ */
diff --git a/xnu/redwood.patch b/xnu/redwood.patch
index fbcca90..8c19945 100644
--- a/xnu/redwood.patch
+++ b/xnu/redwood.patch
@@ -46,10 +46,10 @@ index 222158a93918..68bb0f3e56bf 100755
######################################################################
# HISTORY
diff --git a/bsd/conf/files b/bsd/conf/files
-index 44274016a4cf..9902234f568c 100644
+index 44274016a4cf..489ab8da091f 100644
--- a/bsd/conf/files
+++ b/bsd/conf/files
-@@ -109,6 +109,33 @@ bsd/dev/munge.c optional config_requires_u32_munging
+@@ -109,6 +109,34 @@ bsd/dev/munge.c optional config_requires_u32_munging
bsd/dev/unix_startup.c standard
bsd/dev/monotonic.c optional monotonic
@@ -74,6 +74,7 @@ index 44274016a4cf..9902234f568c 100644
+bsd/dev/redwood_wifi.c standard
+bsd/dev/redwood_adsp.c standard
+bsd/dev/redwood_virtio_blk.c standard
++bsd/dev/redwood_sparse.c standard
+bsd/dev/redwood_apfs_check.c optional apfs
+bsd/dev/redwood_sound.c standard
+bsd/dev/redwood_qmi.c standard
@@ -83,7 +84,7 @@ index 44274016a4cf..9902234f568c 100644
bsd/dev/dev_perfmon.c optional config_perfmon
bsd/libkern/crc32.c standard
-@@ -155,6 +182,13 @@ bsd/miscfs/devfs/devfs_vfsops.c optional devfs
+@@ -155,6 +183,13 @@ bsd/miscfs/devfs/devfs_vfsops.c optional devfs
bsd/miscfs/mockfs/mockfs_fsnode.c optional mockfs
bsd/miscfs/mockfs/mockfs_vfsops.c optional mockfs
bsd/miscfs/mockfs/mockfs_vnops.c optional mockfs
@@ -97,7 +98,7 @@ index 44274016a4cf..9902234f568c 100644
bsd/miscfs/routefs/routefs_ops.c optional routefs
-@@ -361,6 +395,7 @@ bsd/security/audit/audit_syscalls.c standard
+@@ -361,6 +396,7 @@ bsd/security/audit/audit_syscalls.c standard
bsd/security/audit/audit_worker.c optional config_audit
bsd/pthread/pthread_shims.c standard
@@ -105,7 +106,7 @@ index 44274016a4cf..9902234f568c 100644
bsd/pthread/pthread_priority.c standard
bsd/pthread/pthread_workqueue.c standard
-@@ -383,6 +418,7 @@ bsd/kern/kern_debug.c standard
+@@ -383,6 +419,7 @@ bsd/kern/kern_debug.c standard
bsd/kern/kern_symfile.c standard
bsd/kern/kern_descrip.c standard
bsd/kern/kern_guarded.c standard
@@ -298,23 +299,24 @@ index 3e6bffa8c48e..43cffb98bdcc 100644
mdevremoveall(void)
{
diff --git a/bsd/kern/bsd_init.c b/bsd/kern/bsd_init.c
-index 4df41ba1f61b..0c71e8a534bb 100644
+index 4df41ba1f61b..16cf4fd8d8f1 100644
--- a/bsd/kern/bsd_init.c
+++ b/bsd/kern/bsd_init.c
-@@ -147,6 +147,12 @@
+@@ -147,6 +147,13 @@
#include <net/if_ether.h> /* for ether_family_init() */
#include <net/if_gif.h> /* for gif_init() */
#include <miscfs/devfs/devfsdefs.h> /* for devfs_kernel_mount() */
+#include <sys/redwood_input.h>
+#include <sys/redwood_audio.h>
+#include <sys/redwood_virtio_blk.h>
++#include <sys/redwood_sparse.h>
+#if APFS
+#include <sys/redwood_apfs_check.h>
+#endif
#include <vm/vm_kern.h> /* for kmem_suballoc() */
#include <sys/proc_uuid_policy.h> /* proc_uuid_policy_init() */
#include <netinet/flow_divert.h> /* flow_divert_init() */
-@@ -490,7 +496,7 @@ bsd_init(void)
+@@ -490,7 +497,7 @@ bsd_init(void)
platform_stall_panic_or_spin(PLATFORM_STALL_XNU_LOCATION_BSD_INIT);
#endif
@@ -323,13 +325,14 @@ index 4df41ba1f61b..0c71e8a534bb 100644
#if DEBUG_BSDINIT
#define bsd_init_kprintf(x, ...) kprintf("bsd_init: " x, ## __VA_ARGS__)
-@@ -976,6 +982,13 @@ bsd_init(void)
+@@ -976,6 +983,14 @@ bsd_init(void)
bsd_init_kprintf("calling devfs_kernel_mount\n");
devfs_kernel_mount(mounthere);
+ redwood_input_init(); /* /dev/redwood-touch */
+ redwood_audio_init(); /* /dev/redwood-audio */
+ redwood_virtio_blk_init(); /* /dev/rvblk0, a disk image of the host (QEMU) */
++ redwood_sparse_init(); /* /dev/rsp0, part of an image too big to hold */
+#if APFS
+ /* mounts and walks /dev/rvblk0 once userland has /private/var up */
+ redwood_apfs_check_init();