Просмотр исходного кода

bootscan: tail the storage scan in a live window

Capture the bootscan kernel thread's COM1 output in a bootcon ring exposed through SYS_BOOTLOG, and add an ngui window that follows it. The WM starts the window before the terminal so the terminal stays focused, and the log keeps its scrollback after the scan finishes.
Johannes Zellner 2 дней назад
Родитель
Сommit
35c014d819
17 измененных файлов с 610 добавлено и 51 удалено
  1. 33 12
      AGENTS.md
  2. 6 1
      Makefile
  3. 6 6
      docs/boot.html
  4. 1 1
      docs/development.html
  5. 1 1
      docs/index.html
  6. 1 1
      docs/memory.html
  7. 11 6
      docs/userland.html
  8. 17 0
      include/syscall.h
  9. 83 0
      kernel/bootcon.c
  10. 20 0
      kernel/bootcon.h
  11. 12 7
      kernel/kernel.c
  12. 4 1
      kernel/serial.c
  13. 13 4
      kernel/sys_wm.c
  14. 33 0
      kernel/syscall.c
  15. 289 0
      user/apps/bootscan/ucmd_bootscan.c
  16. 68 11
      user/apps/wm/ucmd_wm.c
  17. 12 0
      user/ucmd_lib.h

+ 33 - 12
AGENTS.md

@@ -245,8 +245,10 @@ and `make net-dev`/`kernel-net-dev` reload over the network.  `bootlog save
    `SYS_NET_INFO` does not trigger the NIC probe (it reports "no NIC" until
    `kernel_main` probed), so the first frame never waits for a PHY reset.
    COM1 prints `wm: first window frame (term) at N ms` (uptime) when the
-   first app window presents: the end point of a boot-time measurement
-   (~0.35-0.4 s after the kernel starts on QEMU's USB image).
+   first terminal presents (the bootscan window is not counted): the end
+   point of a boot-time measurement
+   (~0.5-0.6 s after the kernel starts on QEMU's USB image; the bootscan
+   window is created first).
 4. `mbr.S` — MBR (USB/HDD boot); loads the active partition's boot sector
    (partition 1 at LBA 63).
 5. **UEFI (`boot/efi/`)** — an x86-64 PE32+ `BOOTX64.EFI` loads from the ESP. It
@@ -450,8 +452,10 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   canvas at `WM_CONTENT_VA_BASE`, routes input, owns the cursor, kexec
   detection and the boot-console handoff.  Every window is a canvas client;
   there is no in-kernel WM or terminal fallback.  The WM paints the desktop,
-  spawns the first terminal after `wm_server_boot_ready()` (set after the
-  storage mount), and composites the canvases into the shadow.  A normal
+  spawns the `/ramfs/bin/bootscan` live-log window first and only then the
+  first terminal after `wm_server_boot_ready()`, so the terminal is the
+  newest window and keeps the keyboard focus on startup, and composites the
+  canvases into the shadow.  A normal
   window has no visible frame: its `WM_TITLE_H` title bar starts at the
   window origin and a resize band (`WM_RESIZE_IN` 1 px inside,
   `WM_RESIZE_OUT` 3 px outside every outer edge) is the edge/corner resize
@@ -1469,6 +1473,21 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `bin/gallery` launcher, which prefers `/share/GALLERY` (development upload
   via `make gallery-dev`), then the pack copy, then the `GALLERY` disk
   fallback on `root.img`/FAT mounts.
+- **Boot scan window**: `ucmd_bootscan.c` is the `bootscan` window, a live
+  tail of the `bootscan` kernel thread's own COM1 output.  `boot_storage_main()`
+  calls `bootcon_scan_begin()`/`bootcon_scan_end()`; while active,
+  `serial_putc()` passes every COM1 character through `bootcon_scan_char()`,
+  which keeps only the owning thread's output (CRs dropped) in a 16 KB
+  frame-allocated ring.  The ring survives the thread, so a later manual
+  `bootscan` launch still shows the completed scan.  `SYS_BOOTLOG` (122, STAT
+  fills `struct sys_bootlog` with total/start/capacity/active, READ copies
+  one 1 KB chunk from an absolute offset) is the ring-3 view.  The WM spawns
+  the window before the terminal, waits (2 s bound) for it to appear and
+  places it flush right under the top bar, so the terminal is created last
+  and owns the focus.  The app follows the tail while the scan runs, keeps
+  the scrollback afterwards (wheel/PgUp/PgDn/Up/Down/Home/End, scrolling up
+  pauses the follow), colours `vfs:`/`blk:`/`[boot]` lines, and closes with
+  Esc or the title-bar X.
 - **Process monitor**: `ucmd_process.c` — the graphical task manager (`process`
   or the top bar's `Tasks` button), the ngui counterpart of `top`.  It
   samples once per second and keeps 60 s
@@ -2107,7 +2126,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
 
 `cd [path]`, `ls [path]`, `cat <path>`, `save <path> <text>`, `rm <path>`,
 `mkdir <path>`, `rmdir <path>`, `hello`, `reboot`, `poweroff`,
-`display`, `cpuinfo`, `mouseinfo`, `gfxbench`, `lsusb`, `touchpad [rightclick off|tap|corner|both] [tapclick on|off] [scroll on|off|natural|traditional]`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `disks` (the ngui storage manager), `meminfo`, `top`, `process` (the ngui task manager), `sched`, `format [-y] <device> [size]` (binary units, e.g. `format ide0 100mb` or `1gb`; no size formats the whole disk; `-y` skips the prompt), `install [-y] <target> [source|self]` (clone the live image, or write the running image; auto-detects the source, preferring `usb0`; `auto` targets the only non-USB NebOS disk),
+`display`, `cpuinfo`, `mouseinfo`, `gfxbench`, `lsusb`, `touchpad [rightclick off|tap|corner|both] [tapclick on|off] [scroll on|off|natural|traditional]`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `disks` (the ngui storage manager), `meminfo`, `top`, `process` (the ngui task manager), `bootscan` (the live boot storage-scan window), `sched`, `format [-y] <device> [size]` (binary units, e.g. `format ide0 100mb` or `1gb`; no size formats the whole disk; `-y` skips the prompt), `install [-y] <target> [source|self]` (clone the live image, or write the running image; auto-detects the source, preferring `usb0`; `auto` targets the only non-USB NebOS disk),
 `ps`, `renice <pid> <weight>`, `kill <pid>`, `idle [auto|hlt|c1e|c3|c6]`, `power`, `powerinfo`, `cpufreq [auto|min|max|off|<pstate>]`, `spin [ms]`, `backlight [0-100|up|down]` (also `probe`), `keytest` (raw scancode tap), `help`, `clear`, `serial test`, `kexec`, `dbg`, `view <file>` (image viewer; PNG, baseline/progressive JPEG, animated GIF, BMP, TGA, PNM, ICO, PAM), `browser [url|file]` (disk app launcher), and `chat [config-path]` (Cloudron Chat client).
 
 Network: `netinfo`, `netrecv`, `netsend`, `netip [a.b.c.d]`, `dhcp` (re-run the
@@ -2692,12 +2711,12 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
    with `--gc-sections`; the current full pack with the UI fonts, both
    WiFi firmwares (7265D 1,036,312 bytes, ~442 KiB gzip; 6000 454,608 bytes,
    ~204 KiB gzip), the RTL8821A firmware and tables (31,898 + 11,668
-   bytes) and `install/kernel.bin` is ~1.88 MiB gzip (~120 KB under the
-   cap), inflating to ~3.6 MB, which adds about
-   half a second to the boot; the floppy lite pack is ~580 KiB gzip and
+   bytes) and `install/kernel.bin` is ~1.98 MiB gzip (~20 KB under the
+   cap), inflating to ~4.1 MB, which adds about
+   half a second to the boot; the floppy lite pack is ~638 KiB gzip and
    deliberately omits the firmware, `install/kernel.bin` and the browser
    (`BROWSER` on `root.img` is the floppy copy).  `libdeflate-gzip -12` is still preferred.  Over
-   115200 serial a raw `cmds-dev` pack (3.5 MiB) now takes about four
+   115200 serial a raw `cmds-dev` pack (4.1 MiB) now takes about four
    minutes; use `net-cmds`.
 9. SMP is **ACPI/MADT only**: no Intel MP-table fallback, so a Pentium II SMP
     board that exposes only MP tables stays UP (deliberate; there is no test
@@ -2767,8 +2786,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     ~0x8ef20 before (with the 6200/6300 DVM layer, the RTL8821AU driver, the
     8×16 boot-console font, the IOAPIC/AMD-thermal additions and the safe
     AMD MTRR path, the 32x32 cursor save buffer and the mount-policy table)
-    ~0x8bf20 now that the frame bitmap moved out of BSS, ~16 KB below the
-    `0x90000` wall, and the remaining limit
+    ~0x8bf20 once the frame bitmap moved out of BSS; with the ioremap
+    window, the EHCI handoff fix and the boot-scan log ring it is ~0x8df80,
+    ~8 KB below the `0x90000` wall, and the
+    remaining limit
     is kernel code/buffers only.
 
 22. Browser limits: JavaScript runs inline and external classic scripts on
@@ -3183,4 +3204,4 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     drivers and only Cirrus and the software cursor are tested in QEMU.
     The cursor shape follows the WM poll, so it can lag the pointer by
     one WM loop.  The 4 KB save buffer and the cursor code (~8 KB in all) are included in
-    `_end` ~0x8bf20, ~16 KB below the `0x90000` wall.
+    `_end` ~0x8df80, ~8 KB below the `0x90000` wall.

+ 6 - 1
Makefile

@@ -379,7 +379,7 @@ $(UL)/wifi/wpa.o: XFLAGS = $(SECTION_CFLAGS)
 # single-file command needs nothing else; one that links libraries gets an
 # explicit .elf rule below.
 UCMDS = cpuinfo ls cat save rm mkdir rmdir \
-        meminfo mouseinfo storage top process \
+        meminfo mouseinfo storage top process bootscan \
         clock colors edit wm term spin \
         netinfo netip netdns host dhcp \
         netsend netrecv ping pong netlog \
@@ -436,6 +436,11 @@ $(call app,files).elf: $(call app,files).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
 $(call app,process).elf: $(call app,process).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
 	$(ULINK)
 
+# Boot scan window: live tail of the bootscan kernel thread's serial output.
+$(call app,bootscan).elf: $(call app,bootscan).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
+	$(ULINK)
+$(call app,bootscan).o: OPT = -Os
+
 $(call app,mines).elf: $(call app,mines).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
 	$(ULINK)
 

+ 6 - 6
docs/boot.html

@@ -411,9 +411,9 @@
 			<li>Start APs through INIT-SIPI-SIPI (they idle until scheduling is enabled).</li>
 			<li>Initialise PS/2 (the I2C touchpad probe only on Airmont) and the VGA shadow buffer.</li>
 			<li>Inflate the command pack into <code>/ramfs</code> (table-driven whole-buffer inflate); start the WM and the first frame.</li>
-			<li>Publish <code>vfs_scan_busy</code> and call <code>wm_server_boot_ready()</code>; idle (1 s cap) until the first terminal has presented a frame.</li>
+			<li>Publish <code>vfs_scan_busy</code> and call <code>wm_server_boot_ready()</code>; the WM spawns the <code>bootscan</code> log window first and the first terminal after it, then idle (1 s cap) until the terminal presents.</li>
 			<li>Bring up USB (controllers, HID, USB NICs/WiFi/disks) non-preemptibly, as before the WM existed; probe the NIC, restore retained network config, start the kworker.</li>
-			<li>Start the <code>bootscan</code> kernel thread (storage probe + FAT mounts, then the <code>/data</code> WiFi autoconnect once the boot DHCP is done); run DHCP if needed.</li>
+			<li>Start the <code>bootscan</code> kernel thread (storage probe + FAT mounts, then the <code>/data</code> WiFi autoconnect once the boot DHCP is done); its COM1 output is captured into the <code>SYS_BOOTLOG</code> ring, which the <code>bootscan</code> window tails live. Run DHCP if needed.</li>
 			<li>Enable scheduling on the APs and enter the kernel idle loop.</li>
 		</ol>
 		<p>
@@ -426,8 +426,8 @@
 			and the scan thread sleeps through its long probe timeouts.  The
 			end point of a boot measurement is the one-shot COM1 line
 			<code>wm: first window frame (term) at N ms</code> (uptime), written
-			by <span class="file">sys_wm.c</span> when the first application
-			window presents.
+			by <span class="file">sys_wm.c</span> when the first terminal
+			window presents (the bootscan window is skipped).
 		</p>
 		<p>
 			The boot trace lines written along the way (<code>boot_trace</code>,
@@ -444,7 +444,7 @@
 		<h2>Failure modes to know</h2>
 		<ul>
 			<li><strong>No VBE mode.</strong> The legacy stage cannot produce a framebuffer; the kernel may start headless or the boot stops in the stage.</li>
-			<li><strong>Pack larger than the cap.</strong> The legacy BIOS path caps the compressed pack at 2 MB <code>PACK_MAX</code> (<code>CMDS_GZ_MAX</code> in the Makefile); UEFI and kexec can carry larger packs up to the 8 MB ramfs cap. The WiFi firmware and the bundled install kernel make the full pack about 1.3 MB, and inflating it adds roughly half a second to the boot.</li>
+			<li><strong>Pack larger than the cap.</strong> The legacy BIOS path caps the compressed pack at 2 MB <code>PACK_MAX</code> (<code>CMDS_GZ_MAX</code> in the Makefile); UEFI and kexec can carry larger packs up to the 8 MB ramfs cap. The WiFi firmware, the bundled install kernel and the UI assets make the full pack about 1.98 MB, close to the cap, and inflating it adds roughly half a second to the boot.</li>
 			<li><strong>PIT not ticking.</strong> <code>kernel_main</code> prints <code>*** PIT NOT TICKING ***</code> and halts; no process scheduling is possible.</li>
 			<li><strong>UEFI Secure Boot.</strong> The unsigned <code>BOOTX64.EFI</code> is rejected before any NebOS code runs.</li>
 			<li><strong>Stale boot info.</strong> The checksum makes an invalid <code>0x500</code> block read as absent rather than as a bogus pack or RSDP.</li>
@@ -465,7 +465,7 @@
 			<li><code>kernel/kexec.c</code>, <code>kernel/kexec_tramp.S</code> — serial reload</li>
 			<li><code>kernel/netkexec.c</code> — network reload</li>
 			<li><code>kernel/kernel.c</code> — init order</li>
-			<li><code>kernel/bootcon.c</code>, <code>common/font_8x16.c</code> — direct-to-LFB boot console</li>
+			<li><code>kernel/bootcon.c</code>, <code>common/font_8x16.c</code> — direct-to-LFB boot console and the <code>bootscan</code> thread's serial ring (<code>SYS_BOOTLOG</code>)</li>
 			<li><code>kernel/install.c</code>, <code>kernel/install.h</code> — clone, self-update and net-install writer</li>
 			<li><code>include/rootfs.h</code> — installed image geometry</li>
 			<li><code>kernel/kernel.ld</code> — image limits</li>

+ 1 - 1
docs/development.html

@@ -357,7 +357,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 		<h2>Debugging</h2>
 		<ul>
 			<li><strong>Serial log.</strong> <code>make monitor</code> shows the boot trace and printf-style driver output. The <code>NebOS v… booted</code> line is written before the framebuffer is ready.</li>
-			<li><strong>Boot time.</strong> Timestamp COM1 on the host (QEMU <code>-serial stdio</code>): the kernel starts at <code>NebOS v… booted</code>, the desktop at <code>wm: first frame</code>, and the terminal is on screen at <code>wm: first window frame (term) at N ms</code> (kernel uptime).  On QEMU the USB image reaches it about 0.4 s after the kernel starts; USB, the NIC and the disks are probed after that (<code>[boot] usb/net/storage</code> lines).</li>
+			<li><strong>Boot time.</strong> Timestamp COM1 on the host (QEMU <code>-serial stdio</code>): the kernel starts at <code>NebOS v… booted</code>, the desktop at <code>wm: first frame</code>, and the terminal is on screen at <code>wm: first window frame (term) at N ms</code> (kernel uptime; the <code>bootscan</code> window presents just before it and is not counted).  On QEMU the USB image reaches it about 0.5 s after the kernel starts; USB, the NIC and the disks are probed after that (<code>[boot] usb/net/storage</code> lines).</li>
 			<li><strong>No serial port.</strong> The boot console is the early log. After the desktop, <code>bootlog</code> prints the captured text and <code>bootlog save /usb0p3/BOOTLOG.TXT</code> writes it to the live stick's FAT ESP (mount that partition on the host to read it). Once DHCP works, <code>make netmon</code> mirrors serial and terminal output to UDP 19290, so it becomes the serial console.</li>
 			<li><strong>Network console.</strong> <code>make netmon</code> listens to UDP 19290 for serial and terminal output; <code>netconsole host &lt;ip&gt;</code> narrows the target.</li>
 			<li><strong>dbg.</strong> The ring-0 serial monitor accepts <code>r addr len</code>, <code>w addr b0 …</code>, <code>i port</code>, <code>o port val</code>, <code>h</code> and <code>q</code>.</li>

+ 1 - 1
docs/index.html

@@ -78,7 +78,7 @@
 
 				<rect class="svg-box accent" x="100" y="8" width="720" height="72" rx="9"/>
 				<text class="svg-text" x="124" y="35">Ring 3 · commands &amp; GUI apps</text>
-				<text class="svg-sub" x="124" y="55">ls · cat · edit · view · files · process · browser · chat · gallery · solitaire</text>
+				<text class="svg-sub" x="124" y="55">ls · cat · edit · view · files · process · bootscan · browser · chat · gallery · solitaire</text>
 				<text class="svg-tiny" x="796" y="35" text-anchor="end">0x40000000</text>
 
 				<path class="svg-line" d="M460 80v22"/>

+ 1 - 1
docs/memory.html

@@ -319,7 +319,7 @@
 	<section id="pack">
 		<h2>Rootfs pack lifetime</h2>
 		<ol>
-			<li>The compressed pack is at most 2 MB (<code>PACK_MAX</code>), so the legacy copy ends below <code>0xB00000</code>; inflated it is about 2 MB with the WiFi firmware (the 8 MB <code>RAMFS_MAX_DECOMPRESSED</code> cap applies).</li>
+			<li>The compressed pack is at most 2 MB (<code>PACK_MAX</code>), so the legacy copy ends below <code>0xB00000</code>; inflated it is about 4.1 MB with the WiFi firmware (the 8 MB <code>RAMFS_MAX_DECOMPRESSED</code> cap applies).</li>
 			<li>The boot path places the gzip pack in RAM: the legacy stage copies it directly to <code>0x900000</code> with a protected-mode <code>rep movsb</code>, UEFI into a loader-data buffer below 1 GB, kexec in its staging buffer.</li>
 			<li><code>mm_init</code> reserves <code>[pack_addr, pack_addr + pack_size)</code> so the frame allocator cannot reuse it.</li>
 			<li><code>ramfs_init</code> takes a private page-allocated copy, validates the <code>NBROOT1</code> header and inflates the pack into it.</li>

+ 11 - 6
docs/userland.html

@@ -231,6 +231,7 @@
 					<tr><td>NIC menu</td><td>111–112</td><td><code>SYS_NET_DEVLIST</code> (present drivers with kind/active/link) and <code>SYS_NET_SELECT</code> (make a named netdev active)</td></tr>
 					<tr><td>Hardware settings</td><td>113–114</td><td><code>SYS_BACKLIGHT(op, value)</code> get/set/step the panel PWM, <code>SYS_CPUFREQ(mode)</code> get/set the P-state mode (control panel sliders/tiles)</td></tr>
 					<tr><td>Popover layout</td><td>115–116</td><td><code>SYS_WIN_RESIZE_SELF(w, h)</code> resizes the caller's canvas, <code>SYS_SCREEN_INFO(out)</code> returns the framebuffer dimensions (the control panel collapses/grows)</td></tr>
+					<tr><td>Boot log</td><td>122</td><td><code>SYS_BOOTLOG(STAT|READ, ...)</code> returns the ring counters or one 1 KB chunk of the <code>bootscan</code> thread's captured COM1 output (the <code>bootscan</code> window)</td></tr>
 					<tr><td>Storage</td><td>119–120</td><td><code>SYS_BLK_READ(index, lba, buf)</code> reads one raw sector, <code>SYS_MOUNT_CTL(op, ...)</code> sets/gets a mount policy (name, read-only, no automount); used by <code>disks</code></td></tr>
 					<tr><td>Mouse cursor</td><td>117–118, 121</td><td><code>SYS_WIN_SET_CURSOR(shape)</code> sets the caller's content cursor, <code>SYS_WM_SET_CURSOR(shape | -1)</code> is the WM's override for its chrome, and <code>SYS_WM_MOUSE_CAPTURE(on)</code> takes/releases the pointer while the WM drags or resizes a window (shapes in <span class="file">cursor_abi.h</span>)</td></tr>
 				</tbody>
@@ -251,14 +252,16 @@
 			The windowed shell is <span class="file">ucmd_term.c</span>; the
 			kernel-side <span class="file">terminal.c</span> holds the privileged
 			command registry used through <code>SYS_SPAWN_KCMD</code>. There is
-			no kernel terminal fallback; the WM spawns the first terminal once
-			storage is ready. Each terminal has a current working directory and
-			a PATH (default <code>/ramfs/bin</code>). Pressing Tab completes
-			builtin and PATH names; <code>help</code> lists both.
+			no kernel terminal fallback; the WM spawns the <code>bootscan</code>
+			log window first and the first terminal after it (the newest
+			window, so it keeps the keyboard focus). Each terminal has a
+			current working directory and a PATH (default
+			<code>/ramfs/bin</code>). Pressing Tab completes builtin and PATH
+			names; <code>help</code> lists both.
 		</p>
 		<ul>
 			<li><strong>Dispatch order.</strong> Builtins → PATH file → kernel command. A PATH hit loads the ELF through the VFS and spawns it as ring 3.</li>
-			<li><strong>Builtins.</strong> <code>cd</code>, <code>path</code>, <code>help</code>, <code>clear</code>; the ring-3 shell also handles <code>ps</code> and <code>kill</code> inline. <code>bootlog</code> is a kernel command.</li>
+			<li><strong>Builtins.</strong> <code>cd</code>, <code>path</code>, <code>help</code>, <code>clear</code>; the ring-3 shell also handles <code>ps</code> and <code>kill</code> inline. <code>bootlog</code> is a kernel command that dumps the early boot console; <code>bootscan</code> is the ring-3 live scan window.</li>
 			<li><strong>Arguments.</strong> The raw remainder of the line is passed verbatim; commands parse their own flags.</li>
 			<li><strong>Working directory.</strong> The prompt shows <code>[dir] &gt;</code>; <code>cd</code> changes only the current terminal's cwd, and spawned commands inherit it.</li>
 			<li><strong>Windows.</strong> A window receives keys through its window key queue (<code>SYS_WIN_KEY_WAIT</code>) or the generic <code>SYS_KEY_POLL</code>; closing the window kills its owner process.</li>
@@ -330,7 +333,7 @@
 			</div>
 			<div class="card">
 				<h3>GUI</h3>
-				<p><code>wm</code> <code>term</code> <code>files</code> <code>disks</code> <code>view</code> <code>mines</code> <code>solitaire</code> <code>process</code> <code>gallery</code> <code>browser</code> <code>chat</code> <code>clock</code> <code>colors</code> <code>settime</code></p>
+				<p><code>wm</code> <code>term</code> <code>bootscan</code> <code>files</code> <code>disks</code> <code>view</code> <code>mines</code> <code>solitaire</code> <code>process</code> <code>gallery</code> <code>browser</code> <code>chat</code> <code>clock</code> <code>colors</code> <code>settime</code></p>
 			</div>
 		</div>
 		<p>
@@ -347,6 +350,7 @@
 		<h2>GUI applications</h2>
 		<ul>
 			<li><strong>files</strong> — browser for the VFS; opens text in <code>edit</code>, images in <code>view</code>, HTML in <code>browser</code>. First user of ngui.</li>
+			<li><strong>bootscan</strong> — live tail of the boot storage-scan kernel thread's output (the WM opens it before the terminal, flush right under the top bar). The kernel captures the thread's COM1 trail (mounts, probes, boot traces) into a ring exposed by <code>SYS_BOOTLOG</code>; the window follows the tail while the scan runs, keeps the scrollback afterwards, pauses the follow when scrolled up, and closes with Esc. Also startable from the shell.</li>
 			<li><strong>process</strong> — graphical task manager (top-bar <em>Tasks</em> button or <code>process</code>), the ngui counterpart of <code>top</code>. It samples once per second into 60 s histories of CPU busy (<code>SYS_SCHEDINFO</code> idle ticks summed over all CPUs), physical memory in use (<code>SYS_MEMINFO</code>) and NIC throughput (<code>SYS_NET_INFO.rx_bytes</code>/<code>tx_bytes</code> from the netdev frame counters), then draws the three graphs with ngui rectangles and lines. The table lists PID, state, CPU%, memory, total CPU time and name; clicking a header sorts by PID, state, CPU, memory, time or name, and PgUp/PgDn or the wheel scrolls. Selecting a row shows its details; <em>End task</em> asks for a second click and then calls <code>SYS_KILL</code>, while kernel threads (<code>kernel_thread</code> in the process snapshot) and the monitor itself are protected. Esc closes it.</li>
 			<li><strong>disks</strong> — storage manager (top-bar <em>Disks</em> button, or the <em>Disks</em> button in <code>files</code>): devices, MBR partitions and mounts; per-volume mount name, read-only and automount saved to <code>/data/MOUNTS.CFG</code>; Format and Install NebOS dialogs that run <code>format -y</code>/<code>install -y</code> on a private tty and show the log. See <a href="filesystems.html#disks">Filesystems → Storage manager</a>.</li>
 			<li><strong>gallery</strong> — live widget and primitive showcase; the real app ships in the pack.</li>
@@ -450,6 +454,7 @@
 			<li><code>user/apps/wifi/ucmd_wifi.c</code>, <code>user/lib/wifi/wpa.c</code>, <code>user/lib/tls/wpa_crypto.c</code> — <code>wifi</code> command and the WPA2-PSK supplicant</li>
 			<li><code>user/apps/disks/ucmd_disks.c</code> — storage manager</li>
 			<li><code>user/apps/process/ucmd_process.c</code> — graphical task manager and its history graphs</li>
+			<li><code>user/apps/bootscan/ucmd_bootscan.c</code> — live boot-scan log window (<code>SYS_BOOTLOG</code>, <code>kernel/bootcon.c</code>)</li>
 			<li><code>user/apps/netmenu/ucmd_netmenu.c</code>, <code>include/wifi_cfg.h</code>, <code>user/lib/wifi/wifi_store.c/h</code> — top-bar control panel, staged WiFi connect record and saved-network list</li>
 		</ul>
 	</section>

+ 17 - 0
include/syscall.h

@@ -132,6 +132,23 @@
  * live in RAM; the boot scan loads SYS_MOUNT_CFG_PATH from /data. */
 #define SYS_BLK_READ      119 /* (index, lba, void *buf512) -> 0/<0 */
 #define SYS_MOUNT_CTL     120 /* (op, a2, a3) */
+
+/* Boot storage-scan log (the `bootscan` kernel thread's serial output,
+ * captured while it runs).  STAT fills struct sys_bootlog, READ copies from
+ * absolute byte offset a2 into the caller's SYS_BOOTLOG_CHUNK buffer at a3
+ * and returns the number of bytes (0 at the end, <0 on a bad range).  The
+ * producer is a ring: `start` is the oldest byte still available. */
+#define SYS_BOOTLOG       122
+#define SYS_BOOTLOG_STAT  0
+#define SYS_BOOTLOG_READ  1
+#define SYS_BOOTLOG_CHUNK 1024
+
+struct sys_bootlog {
+	unsigned int total;      /* bytes ever written */
+	unsigned int start;      /* absolute offset of the oldest available byte */
+	unsigned int capacity;   /* ring size in bytes (0: no log) */
+	unsigned int active;     /* the scan thread is still producing */
+};
 #define SYS_MOUNT_POLICY_SET 0 /* (const struct sys_mount_policy *) -> 0/<0 */
 #define SYS_MOUNT_POLICY_GET 1 /* (index, struct sys_mount_policy *out) -> 1/0 */
 #define SYS_BACKLIGHT     113 /* (int op, int value) -> percent / -1.

+ 83 - 0
kernel/bootcon.c

@@ -14,6 +14,7 @@
 #include "bootinfo.h"
 #include "font_8x16.h"
 #include "mm.h"
+#include "process.h"
 #include "serial.h"
 #include "vga.h"
 
@@ -41,6 +42,14 @@ static unsigned int log_cap;
 static unsigned int log_len;
 static int log_truncated;
 
+/* Serial output of the bootscan kernel thread (bootcon_scan_begin). */
+static char *scan_buf;
+static unsigned int scan_cap;
+static unsigned int scan_total;
+static unsigned int scan_start;
+static unsigned int scan_pid;
+static int scan_active;
+
 static void fb_px(unsigned int x, unsigned int y, unsigned int r,
 		  unsigned int g, unsigned int b)
 {
@@ -258,6 +267,80 @@ int bootcon_log_truncated(void)
 	return log_truncated;
 }
 
+/* ---- bootscan thread serial capture ---------------------------------- */
+
+void bootcon_scan_begin(void)
+{
+	unsigned int mem;
+
+	if (!scan_buf) {
+		mem = mm_alloc_pages(BOOTCON_SCAN_PAGES);
+		if (!mem) {
+			scan_cap = 0;
+			scan_active = 0;
+			return;
+		}
+		scan_buf = (char *)mem;
+		scan_cap = BOOTCON_SCAN_PAGES * PAGE_SIZE;
+	}
+	scan_pid = current_proc() ? current_proc()->pid : 0;
+	scan_total = 0;
+	scan_start = 0;
+	scan_active = 1;
+}
+
+void bootcon_scan_end(void)
+{
+	scan_active = 0;
+}
+
+void bootcon_scan_char(char c)
+{
+	if (!scan_active || !scan_cap)
+		return;
+	if (!current_proc() || current_proc()->pid != scan_pid)
+		return;
+	if (c == '\r')
+		return;                 /* serial_puts emits CR before every LF */
+	if (scan_total - scan_start >= scan_cap)
+		scan_start = scan_total - scan_cap + 1;
+	scan_buf[scan_total % scan_cap] = c;
+	scan_total++;
+}
+
+unsigned int bootcon_scan_total(void)
+{
+	return scan_total;
+}
+
+unsigned int bootcon_scan_start(void)
+{
+	return scan_start;
+}
+
+unsigned int bootcon_scan_capacity(void)
+{
+	return scan_cap;
+}
+
+int bootcon_scan_running(void)
+{
+	return scan_active;
+}
+
+unsigned int bootcon_scan_read(unsigned int off, char *dst, unsigned int max)
+{
+	unsigned int n = 0;
+
+	if (!scan_buf || !scan_cap)
+		return 0;
+	if (off < scan_start)
+		off = scan_start;
+	while (off < scan_total && n < max)
+		dst[n++] = scan_buf[off++ % scan_cap];
+	return n;
+}
+
 void bootcon_dec(unsigned int v)
 {
 	char buf[12];

+ 20 - 0
kernel/bootcon.h

@@ -13,6 +13,9 @@
 #define BOOTCON_H
 
 #define BOOTCON_LOG_PAGES 8
+/* Ring for the storage scan thread's own serial output (see bootcon.c).  It
+ * is allocated on demand from the frame allocator, not BSS. */
+#define BOOTCON_SCAN_PAGES 4
 
 void bootcon_init(void);
 int  bootcon_ok(void);
@@ -35,4 +38,21 @@ void bootcon_log_init(void);
 const char *bootcon_log(unsigned int *len);
 int bootcon_log_truncated(void);
 
+/* Capture the bootscan kernel thread's serial output.  begin() is called by
+ * the thread itself (it allocates the ring and records the thread pid), end()
+ * stops the capture when the thread returns.  serial_putc() feeds every COM1
+ * character through bootcon_scan_char(), which keeps only the owning
+ * thread's output.  The ring survives end() so the `bootscan` window can
+ * still tail the completed log. */
+void bootcon_scan_begin(void);
+void bootcon_scan_end(void);
+void bootcon_scan_char(char c);
+unsigned int bootcon_scan_total(void);
+unsigned int bootcon_scan_start(void);
+unsigned int bootcon_scan_capacity(void);
+int bootcon_scan_running(void);
+/* Copy up to max bytes from absolute offset off; off is clamped to the
+ * oldest byte still in the ring.  Returns the byte count. */
+unsigned int bootcon_scan_read(unsigned int off, char *dst, unsigned int max);
+
 #endif

+ 12 - 7
kernel/kernel.c

@@ -402,11 +402,14 @@ static void boot_wifi_autoconnect(void)
  * (floppy motor, ATA/AHCI timeouts) go through vfs_scan_relax() and the WM
  * and the first terminal run meanwhile.  Disk file operations wait for
  * vfs_scan_busy; /ramfs and /share do not.  The WiFi autoconnect needs
- * /data, so it runs here after the mount. */
+ * /data, so it runs here after the mount.  Every COM1 character this thread
+ * writes is also captured into the bootcon scan ring, which the ring-3
+ * `bootscan` window tails live (it is spawned before the first terminal). */
 static volatile int boot_dhcp_done;
 
 static void boot_storage_main(void)
 {
+	bootcon_scan_begin();
 	vfs_mount_all();
 	sys_mount_load_config();
 	boot_trace("storage");
@@ -416,6 +419,7 @@ static void boot_storage_main(void)
 		process_sleep_ms(20);
 	boot_wifi_autoconnect();
 	boot_trace("wifi auto");
+	bootcon_scan_end();
 }
 
 void kernel_main(void);
@@ -589,8 +593,9 @@ void kernel_main(void)
 	/* Publish the storage scan before anything can run a command: disk
 	 * paths wait for vfs_scan_busy (owned by the idle context until the
 	 * bootscan thread's vfs_mount_all() takes it over), /ramfs and /share
-	 * do not.  Then let the WM spawn the first terminal at once; neither
-	 * it nor the WM needs the NIC probe or the disks below. */
+	 * do not.  Then let the WM spawn the bootscan window and the first
+	 * terminal at once; neither it nor the WM needs the NIC probe or the
+	 * disks below. */
 	vfs_scan_owner_pid = 0;
 	vfs_scan_busy = 1;
 #ifndef NOWM
@@ -601,10 +606,10 @@ void kernel_main(void)
 #endif
 
 #ifndef NOWM
-	/* Let the WM put the first terminal on screen before the USB bring-up
-	 * below: kernel_main is the idle context, so halting here hands the
-	 * CPU to the WM and the new terminal.  Bounded, in case no terminal
-	 * ever presents (missing /ramfs/bin/term). */
+	/* Let the WM put the bootscan log window and the first terminal on
+	 * screen before the USB bring-up below: kernel_main is the idle
+	 * context, so halting here hands the CPU to the WM and those windows.
+	 * Bounded, in case no terminal ever presents. */
 	{
 		unsigned int t0 = get_ticks_ms();
 

+ 4 - 1
kernel/serial.c

@@ -1,4 +1,5 @@
 #include "serial.h"
+#include "bootcon.h"
 #include "serial_ring_buf.h"
 #include "netlog.h"
 #include "pci.h"
@@ -28,8 +29,10 @@ void serial_putc(unsigned int port, char c)
 	 * the mirror is enabled and the NIC is up).  This must happen even when
 	 * COM1 itself is unusable -- boards without a serial port are exactly
 	 * the ones that use netlog. */
-	if (port == SERIAL_COM1)
+	if (port == SERIAL_COM1) {
+		bootcon_scan_char(c);
 		netlog_char(c);
+	}
 
 	/* A machine without a serial port can leave LSR.THRE clear forever
 	 * (the port is decoded but the UART is absent or clocked off).  Never

+ 13 - 4
kernel/sys_wm.c

@@ -166,16 +166,25 @@ int sys_win_create(const struct win_create *in, struct win_info *out)
 	return r;
 }
 
-/* One serial line when the first application window (normally the boot
- * terminal) presents a frame: the end point of the boot-time measurement
- * ("[boot] ..." lines are relative to the PIT start, this is uptime). */
+/* One serial line when the first terminal presents a frame: the end point of
+ * the boot-time measurement ("[boot] ..." lines are relative to the PIT
+ * start, this is uptime).  The bootscan log window presents before it and is
+ * deliberately not counted here. */
 volatile int wm_first_window_presented;
 
+static int is_term_proc(void)
+{
+	const char *n = current_proc() ? current_proc()->name : "";
+
+	return n[0] == 't' && n[1] == 'e' && n[2] == 'r' && n[3] == 'm' &&
+	       n[4] == '\0';
+}
+
 static void boot_first_present(void)
 {
 	static int done;
 
-	if (done)
+	if (done || !is_term_proc())
 		return;
 	done = 1;
 	wm_first_window_presented = 1;

+ 33 - 0
kernel/syscall.c

@@ -2,6 +2,7 @@
 
 #include "syscall.h"
 #include "backlight.h"
+#include "bootcon.h"
 #include "io.h"
 #include "paging.h"
 #include "power.h"
@@ -481,6 +482,38 @@ static int syscall_dispatch_locked(int num, int a1, int a2, int a3)
 		return process_is_alive((unsigned int)a1);
 	case SYS_KILL:
 		return process_kill((unsigned int)a1);
+	case SYS_BOOTLOG:
+		if (a1 == SYS_BOOTLOG_STAT) {
+			struct sys_bootlog *out = (struct sys_bootlog *)a2;
+
+			if (!paging_user_range_ok(current_proc()->cr3,
+						  (unsigned int)out,
+						  sizeof(*out), 1))
+				return -1;
+			out->total = bootcon_scan_total();
+			out->start = bootcon_scan_start();
+			out->capacity = bootcon_scan_capacity();
+			out->active = (unsigned int)bootcon_scan_running();
+			return 0;
+		}
+		if (a1 == SYS_BOOTLOG_READ) {
+			unsigned int off = (unsigned int)a2;
+			unsigned int total = bootcon_scan_total();
+			unsigned int n;
+
+			if (off < bootcon_scan_start())
+				return -1;      /* ring wrapped; re-read the info */
+			if (off >= total)
+				return 0;
+			n = total - off;
+			if (n > SYS_BOOTLOG_CHUNK)
+				n = SYS_BOOTLOG_CHUNK;
+			if (!paging_user_range_ok(current_proc()->cr3,
+						  (unsigned int)a3, n, 1))
+				return -1;
+			return (int)bootcon_scan_read(off, (char *)a3, n);
+		}
+		return -1;
 	case SYS_CHDIR: {
 		char arg[VFS_PATH_MAX], abs[VFS_PATH_MAX];
 		unsigned int size;

+ 289 - 0
user/apps/bootscan/ucmd_bootscan.c

@@ -0,0 +1,289 @@
+/* bootscan: live tail of the boot storage-scan kernel thread's output.
+ *
+ * The kernel captures every COM1 character boot_storage_main() writes (the
+ * vfs/blk mount trail, the driver probes and the final boot traces) into a
+ * ring exposed by SYS_BOOTLOG.  The WM spawns this window before the first
+ * terminal, so the terminal is created last and keeps the keyboard focus.
+ *
+ * The view follows the tail while the scan runs and keeps the scrollback
+ * afterwards.  Wheel, PgUp/PgDn, Up/Down, Home and End scroll; scrolling up
+ * stops the follow until the bottom is reached again.  Esc closes it.
+ */
+
+#include "ucmd_lib.h"
+#include "ngui.h"
+
+#define TEXT_MAX (32 * 1024)
+#define POLL_MS  100
+#define LINE_PX  12
+#define PAD      8
+#define FOOT_H   20
+
+static struct ngui ui;
+static struct ngui_scroll sc;
+static char text[TEXT_MAX];
+static unsigned int text_len;
+static unsigned int seen;
+static int follow = 1;
+static int pending_tail;
+static int have_info;
+static int scan_active;
+static unsigned int scan_cap;
+static int quit;
+
+static void append_text(const char *p, unsigned int n)
+{
+	unsigned int i;
+
+	for (i = 0; i < n && text_len + 1 < TEXT_MAX; i++)
+		text[text_len++] = p[i];
+}
+
+/* Fetch every byte that appeared since the last poll.  Returns 1 when the
+ * view changed. */
+static int pull(void)
+{
+	struct sys_bootlog info;
+	int changed = 0;
+	int passes = 0;
+
+	if (u_bootlog_stat(&info) != 0)
+		return 0;
+	if (!have_info || info.active != (unsigned int)scan_active ||
+	    info.capacity != scan_cap) {
+		have_info = 1;
+		scan_active = (int)info.active;
+		scan_cap = info.capacity;
+		changed = 1;
+	}
+	if (!info.capacity)
+		return changed;
+	if (seen < info.start || seen > info.total)
+		seen = info.start;
+	while (seen < info.total && passes++ < 64) {
+		char chunk[SYS_BOOTLOG_CHUNK];
+		int n = u_bootlog_read(seen, chunk);
+
+		if (n < 0) {
+			/* The ring wrapped between the two calls. */
+			if (u_bootlog_stat(&info) != 0)
+				break;
+			if (seen < info.start || seen > info.total)
+				seen = info.start;
+			if (seen >= info.total)
+				break;
+			continue;
+		}
+		if (n == 0)
+			break;
+		append_text(chunk, (unsigned int)n);
+		seen += (unsigned int)n;
+		changed = 1;
+		if ((unsigned int)n < SYS_BOOTLOG_CHUNK)
+			break;
+	}
+	return changed;
+}
+
+static unsigned int count_lines(void)
+{
+	unsigned int i, n = 0;
+
+	if (!text_len)
+		return 0;
+	for (i = 0; i < text_len; i++)
+		if (text[i] == '\n')
+			n++;
+	if (text[text_len - 1] != '\n')
+		n++;
+	return n;
+}
+
+static unsigned short line_color(const char *s, unsigned int n)
+{
+	if (n >= 4 && s[0] == 'v' && s[1] == 'f' && s[2] == 's' &&
+	    s[3] == ':')
+		return ui.theme.accent;
+	if (n >= 4 && s[0] == 'b' && s[1] == 'l' && s[2] == 'k' &&
+	    s[3] == ':')
+		return ui.theme.text_dim;
+	if (n >= 6 && s[0] == '[' && s[1] == 'b' && s[2] == 'o' &&
+	    s[3] == 'o' && s[4] == 't' && s[5] == ']')
+		return ui.theme.text_dim;
+	return ui.theme.text;
+}
+
+static void draw_footer(struct ngui_rect r)
+{
+	const char *status;
+	const char *hint = "PgUp/PgDn scroll  |  Esc close";
+	unsigned short color;
+	int hint_w;
+
+	if (!have_info || (!scan_cap && !scan_active))
+		status = "waiting for the boot scan...";
+	else if (!scan_cap)
+		status = "boot scan log unavailable";
+	else if (scan_active)
+		status = "live: boot scan running";
+	else
+		status = "boot scan finished";
+
+	color = scan_active ? (scan_cap ? ui.theme.success : ui.theme.warning) :
+		ui.theme.text_dim;
+
+	ngui_fill_rect(&ui, r, ui.theme.panel);
+	ngui_text(&ui, r.x + 2, r.y + 3, status, color);
+	hint_w = (int)ngui_text_width_ui(&ui, hint);
+	if (hint_w + 120 < r.w)
+		ngui_text(&ui, r.x + r.w - hint_w - 2, r.y + 3, hint,
+			  ui.theme.text_dim);
+}
+
+static void draw(void)
+{
+	struct ngui_rect body, foot;
+	int line_h = ngui_text_line_height(&ui, LINE_PX, 1);
+	unsigned int lines = count_lines();
+	unsigned int pos = 0, idx = 0;
+	int max, y;
+
+	if (line_h < 10)
+		line_h = 10;
+
+	body.x = PAD;
+	body.y = PAD;
+	body.w = ui.w - 2 * PAD;
+	body.h = ui.h - 2 * PAD - FOOT_H;
+	if (body.w < 20)
+		body.w = 20;
+	if (body.h < 20)
+		body.h = 20;
+
+	foot.x = 0;
+	foot.y = ui.h - FOOT_H;
+	foot.w = ui.w;
+	foot.h = FOOT_H;
+
+	ngui_fill_rect(&ui, (struct ngui_rect){ 0, 0, ui.w, ui.h },
+		       ui.theme.bg);
+
+	sc.content_h = (int)lines * line_h;
+	ngui_scroll_begin(&ui, body, &sc);
+	ngui_scroll_wheel(&ui, body, &sc);
+
+	max = sc.content_h - sc.view_h;
+	if (max < 0)
+		max = 0;
+	if (pending_tail && follow)
+		ngui_scroll_to(&sc, max);
+	pending_tail = 0;
+	follow = sc.offset >= max - 1;
+
+	while (pos < text_len) {
+		unsigned int start = pos, end;
+
+		while (pos < text_len && text[pos] != '\n')
+			pos++;
+		end = pos;
+		y = body.y + (int)idx * line_h - sc.offset;
+		if (y + line_h > body.y && y < body.y + body.h) {
+			ngui_text_px(&ui, body.x + 2, y + 1, text + start,
+				     end - start, line_color(text + start,
+							     end - start),
+				     LINE_PX, 0, 0, 1);
+		}
+		idx++;
+		if (pos < text_len && text[pos] == '\n')
+			pos++;
+	}
+	ngui_scroll_end(&ui, body, &sc);
+
+	draw_footer(foot);
+}
+
+static void scroll_keys(void)
+{
+	int k;
+	int max = sc.content_h - sc.view_h;
+	int page = sc.view_h - 22;
+
+	if (page < 22)
+		page = 22;
+	if (max < 0)
+		max = 0;
+
+	while ((k = ngui_key(&ui)) != 0) {
+		int old = sc.offset;
+
+		if (k == NGUI_KEY_ESC)
+			quit = 1;
+		else if (k == NGUI_KEY_PAGE_UP)
+			ngui_scroll_to(&sc, sc.offset - page);
+		else if (k == NGUI_KEY_PAGE_DOWN)
+			ngui_scroll_to(&sc, sc.offset + page);
+		else if (k == NGUI_KEY_UP)
+			ngui_scroll_to(&sc, sc.offset - 20);
+		else if (k == NGUI_KEY_DOWN)
+			ngui_scroll_to(&sc, sc.offset + 20);
+		else if (k == NGUI_KEY_HOME)
+			ngui_scroll_to(&sc, 0);
+		else if (k == NGUI_KEY_END)
+			ngui_scroll_to(&sc, max);
+		if (sc.offset != old)
+			ngui_invalidate(&ui);
+	}
+}
+
+void _start(const char *arg)
+{
+	struct win_info wi;
+	unsigned int sw = 0, sh = 0;
+	unsigned int w = 440, h = 300;
+	unsigned int last_poll;
+
+	(void)arg;
+	if (u_screen_size(&sw, &sh) == 0) {
+		if (sw > 80 && w > sw - 40)
+			w = sw - 40;
+		if (sh > 200 && h > sh - 120)
+			h = sh - 120;
+	}
+	if (w < 260)
+		w = 260;
+	if (h < 180)
+		h = 180;
+	if (u_win_create(w, h, "Boot scan", &wi) != 0) {
+		u_puts("bootscan: no graphics window\n");
+		u_exit(1);
+	}
+	ngui_init(&ui, (unsigned short *)wi.fb, (int)wi.width, (int)wi.height);
+	ngui_font_attach(&ui);
+	sc.hide_bar = 0;
+	last_poll = u_ticks_ms() - POLL_MS;
+
+	for (;;) {
+		unsigned int now = u_ticks_ms();
+
+		if ((int)(now - (last_poll + POLL_MS)) >= 0) {
+			last_poll = now;
+			if (pull()) {
+				pending_tail = 1;
+				ngui_invalidate(&ui);
+			}
+		}
+		if (!ngui_begin(&ui)) {
+			ngui_end_ex(&ui, 0);
+			u_sleep_ms(POLL_MS);
+			continue;
+		}
+		scroll_keys();
+		if (quit)
+			break;
+		draw();
+		ngui_end(&ui);
+		u_sleep_ms(POLL_MS);
+	}
+	u_win_close();
+	u_exit(0);
+}

+ 68 - 11
user/apps/wm/ucmd_wm.c

@@ -66,6 +66,10 @@ static int last_title_id = -1, last_title_x, last_title_y;
 static unsigned int prev_buttons;
 static int full_redraw = 1;
 static int boot_term_spawned;
+static int boot_scan_spawned;
+static int boot_scan_pid;
+static int boot_scan_placed;
+static unsigned int boot_scan_deadline;
 static unsigned int bar_kexec_busy, bar_kexec_progress, bar_kexec_total;
 static int bar_temp_c = -1;
 static int bar_batt_pct = -1;
@@ -145,6 +149,25 @@ static int free_window_slot(void)
 	return 0;
 }
 
+/* Find a window by owner pid without waiting for the cached sync state:
+ * boot ordering needs it before the terminal is spawned. */
+static int window_index_pid(int pid, struct wm_window_info *out)
+{
+	unsigned int i;
+
+	for (i = 0; i < WM_MAX_WINDOWS; i++) {
+		struct wm_window_info info;
+
+		if (u_wm_info(i, &info) == 1 && info.used &&
+		    (int)info.pid == pid) {
+			if (out)
+				*out = info;
+			return (int)i;
+		}
+	}
+	return -1;
+}
+
 static unsigned int rgb16(unsigned int r, unsigned int g, unsigned int b)
 {
 	return (r << 16) | (g << 8) | b;
@@ -1380,18 +1403,52 @@ static void do_update(struct wm_status *st)
 	if (osd_hide && osd_visible)
 		osd_repaint = 1;
 
-	/* Spawn the first terminal once the kernel says the storage scan is
-	 * done, so a shell command can never race the mount table. */
+	/* The boot-scan window is created before the terminal so the terminal
+	 * stays the newest (last) window and keeps the keyboard focus.  Wait
+	 * for the scan window to exist before starting the terminal; a failed
+	 * or wedged helper is bounded so the shell is never held back. */
 	if (st->boot_ready && !boot_term_spawned) {
-		boot_term_spawned = 1;
-		if (!free_window_slot()) {
-			bar_notice("window limit");
-			full_redraw = 1;
-		} else if (u_wm_create_term() < 0) {
-			bar_notice("cannot start term");
-			full_redraw = 1;
-		} else {
-			full_redraw = 1;
+		if (!boot_scan_spawned) {
+			boot_scan_spawned = 1;
+			if (free_window_slot()) {
+				boot_scan_pid = u_spawn("/ramfs/bin/bootscan",
+							"", 0, "/");
+				if (boot_scan_pid > 0)
+					boot_scan_deadline = msg_now + 2000u;
+			}
+			if (boot_scan_pid <= 0)
+				boot_scan_placed = 1;
+		}
+		if (boot_scan_pid > 0 && !boot_scan_placed) {
+			struct wm_window_info wi;
+			int idx = window_index_pid(boot_scan_pid, &wi);
+
+			if (idx >= 0) {
+				int nx = (int)fbw - (int)wi.w - 16;
+				int ny = WM_BAR_H + 8;
+
+				if (nx < 8)
+					nx = 8;
+				u_wm_set_geom((unsigned int)idx, nx, ny);
+				boot_scan_placed = 1;
+			} else if (!u_alive((unsigned int)boot_scan_pid) ||
+				   (int)(msg_now - boot_scan_deadline) >= 0) {
+				if (u_alive((unsigned int)boot_scan_pid))
+					u_kill((unsigned int)boot_scan_pid);
+				boot_scan_placed = 1;
+			}
+		}
+		if (boot_scan_placed) {
+			boot_term_spawned = 1;
+			if (!free_window_slot()) {
+				bar_notice("window limit");
+				full_redraw = 1;
+			} else if (u_wm_create_term() < 0) {
+				bar_notice("cannot start term");
+				full_redraw = 1;
+			} else {
+				full_redraw = 1;
+			}
 		}
 	}
 

+ 12 - 0
user/ucmd_lib.h

@@ -168,6 +168,18 @@ static inline unsigned int u_ticks_ms(void)
 	return (unsigned int)u_syscall0(SYS_GET_TICKS_MS);
 }
 
+/* Boot storage-scan log (the `bootscan` window).  STAT fills the ring
+ * counters; READ copies one SYS_BOOTLOG_CHUNK chunk at absolute offset. */
+static inline int u_bootlog_stat(struct sys_bootlog *out)
+{
+	return u_syscall2(SYS_BOOTLOG, SYS_BOOTLOG_STAT, (int)out);
+}
+
+static inline int u_bootlog_read(unsigned int off, char *buf)
+{
+	return u_syscall3(SYS_BOOTLOG, SYS_BOOTLOG_READ, (int)off, (int)buf);
+}
+
 /* Cursor position of this process's terminal screen (linear cell index);
  * used by `top` to repaint its frame in place. */
 static inline void u_sleep_ms(unsigned int ms)