From patchwork Mon Jan 19 20:41:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1642 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768855371; bh=3uPT8B2ACpijpOHZKiq8UgLvOSAJbvHdoNmdOCANKcQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=fD7RJna6Lf7yWMTxsOYgK3XNw7tXCYVEx5DYSuMCTB4DDyge/HC2hS01TcX1EfDRQ d8B745RywFBYG9Nh6WOsweu2alNOHw9qfDrvQraDl8M6jpqq0diokxDLY5hgF4AU7B tz+cnEKBp3un6EWbuxCnPCu0ypNc3e/OUXKv/1+9/Zh5b4aioo85vU7BuUcYTGYEjV rSlfWZLqgBz29bGrrYaR+/ChERMGsJPY0EwDk2jf2VKX6D11J9vxZv2liknYcm/ynN YE6TnSoXZfw/vbnh0iEayxwGkwVctcpZWpvrXYJdsv51IQTvriVBCRHHXWDHuLRXQW TOnQOF1GgKy6Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EC25469504 for ; Mon, 19 Jan 2026 13:42:51 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 05VlGgwnorBw for ; Mon, 19 Jan 2026 13:42:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768855371; bh=3uPT8B2ACpijpOHZKiq8UgLvOSAJbvHdoNmdOCANKcQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=fD7RJna6Lf7yWMTxsOYgK3XNw7tXCYVEx5DYSuMCTB4DDyge/HC2hS01TcX1EfDRQ d8B745RywFBYG9Nh6WOsweu2alNOHw9qfDrvQraDl8M6jpqq0diokxDLY5hgF4AU7B tz+cnEKBp3un6EWbuxCnPCu0ypNc3e/OUXKv/1+9/Zh5b4aioo85vU7BuUcYTGYEjV rSlfWZLqgBz29bGrrYaR+/ChERMGsJPY0EwDk2jf2VKX6D11J9vxZv2liknYcm/ynN YE6TnSoXZfw/vbnh0iEayxwGkwVctcpZWpvrXYJdsv51IQTvriVBCRHHXWDHuLRXQW TOnQOF1GgKy6Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DB07A694CE for ; Mon, 19 Jan 2026 13:42:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768855370; bh=pK/MMt5oUdGmhXY9eyTkowZIHFMpsEfQ35W8FlbTZoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A4LmjO56jVmM9hdQH5w2+nFM1A8PobhLZsQzP9qlzmHYiaRKOEVrXQ1UHhvYVAW2d /xeCHINaKtGlYC/TA8QjTdcNGKCcj+Yewdn6BrzvFOgRwQ+kvLy38sKULG3ak7MDxA lTb4ybWO4b0GtGxRPXfHFb3m0q1YKKf7iRCluzhmHYIL5homTtlfLJ1yyld1ppGK99 qahxYOsWg9ZHD4zIx6Iwsr0vb5zE6BPSqul8C6hTY2WPkin0USf6Tq32b4uU2X8IAg CWgsLrVfkFo/yqJFaro6UcQu7qgkA/99aYvyqiR9FebEc4IsEywVMtdu9005aI1GbT cOSxXEGMKWrpQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D7C2C694CE; Mon, 19 Jan 2026 13:42:50 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id xkPDcMWiKbUj; Mon, 19 Jan 2026 13:42:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768855365; bh=Nif0oYZDB9arwCOoCWjotbCz0qDONoY2qfIb8zsxl5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hf6Rvv0ER2SNMMOyjxFGEfUaN9tbhQfrlgRMmVkDw0TCJlBcDoS+xlf1yCiNZGna0 qELNbyx4sBvDa9uYb9UkBc2omIfnjKn12RGJMxt54/aSnrJocHM5LclaHCRK5FVP2i 0E0iEeD8Yo21OutG6ms5ejOSHmDUP5ks/mMnZhBgt0FsHqBN/hvmjiVFUnoycl5dxz ouAC+Q1bfXPstXhEY5KQFVUdctFaRXgjPLCUx+LMj+fV87KEmF9+QQ7ECrrQaoznGN m2ySTMGMHGmxIw5ikSD6NizDZKxcc0XSdbU/wdx9r7a2tLmH/YWQUiGvH4oP2L8LDH 28HGX6rCw/kzQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9CF2B693E3; Mon, 19 Jan 2026 13:42:45 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 19 Jan 2026 13:41:05 -0700 Message-ID: <20260119204130.3972647-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119204130.3972647-1-sjg@u-boot.org> References: <20260119204130.3972647-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NTZUPN666WSLXTXASLIHDHTEQGXQAYNX X-Message-ID-Hash: NTZUPN666WSLXTXASLIHDHTEQGXQAYNX X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/27] sandbox: Allow grid size to be specified in 'sb grid' command List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add an optional second parameter to 'sb grid' to specify the grid size in pixels. For example, 'sb grid 1 14' enables a 20-pixel (0x14) grid. The default remains 10 pixels when no size is specified. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- arch/sandbox/cpu/sdl.c | 11 +++++++---- arch/sandbox/include/asm/sdl_sync.h | 2 ++ arch/sandbox/include/asm/state.h | 1 + cmd/sb.c | 6 ++++-- doc/develop/expo.rst | 4 ++++ doc/usage/cmd/sb.rst | 7 ++++--- drivers/video/sandbox_sdl.c | 1 + test/cmd/sb.c | 11 +++++++++++ 8 files changed, 34 insertions(+), 9 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index 4a98d920c9f..f2cc4bbd041 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -311,16 +311,19 @@ static int copy_to_texture(void *lcd_base, const struct vid_bbox *damage) return 0; } -static void draw_grid(void) +static void draw_grid(int size) { int x, y; + if (!size) + size = 0x20; + SDL_SetRenderDrawColor(sdl.renderer, 192, 192, 192, SDL_ALPHA_OPAQUE); - for (x = 0; x < sdl.vis_width; x += 10) + for (x = 0; x < sdl.vis_width; x += size) SDL_RenderDrawLine(sdl.renderer, x, 0, x, sdl.vis_height - 1); - for (y = 0; y < sdl.vis_height; y += 10) + for (y = 0; y < sdl.vis_height; y += size) SDL_RenderDrawLine(sdl.renderer, 0, y, sdl.vis_width - 1, y); } @@ -345,7 +348,7 @@ int sandbox_sdl_sync(void *lcd_base, const struct vid_bbox *damage, } if (opts && opts->draw_grid) - draw_grid(); + draw_grid(opts->grid_size); /* * On some machines this does not appear. Draw an empty rectangle which diff --git a/arch/sandbox/include/asm/sdl_sync.h b/arch/sandbox/include/asm/sdl_sync.h index 78f4233e056..81b28ff61e5 100644 --- a/arch/sandbox/include/asm/sdl_sync.h +++ b/arch/sandbox/include/asm/sdl_sync.h @@ -13,9 +13,11 @@ * struct sandbox_sdl_sync_opts - Options for sandbox_sdl_sync() * * @draw_grid: Draw a grid overlay on the display + * @grid_size: Grid size in pixels (0 for default of 0x20) */ struct sandbox_sdl_sync_opts { bool draw_grid; + int grid_size; }; #endif diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 31766a6e7ea..001d780aec8 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -180,6 +180,7 @@ struct sandbox_state { bool quiet_vidconsole; /* Don't use vidconsole for stdout */ bool disable_mcheck; /* Disable mcheck heap protection */ bool show_grid; /* Show grid overlay on video */ + int grid_size; /* Grid size in pixels (0 for default) */ int video_test; /* ms to wait before next assert */ const char *video_frames_dir; /* Directory to write video frames */ int video_frame_count; /* Number of frames written */ diff --git a/cmd/sb.c b/cmd/sb.c index 55a4b5b447f..dcf7ec9d0b4 100644 --- a/cmd/sb.c +++ b/cmd/sb.c @@ -106,6 +106,8 @@ static int do_sb_grid(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; state->show_grid = hextoul(argv[1], NULL); + if (argc >= 3) + state->grid_size = hextoul(argv[2], NULL); return 0; } @@ -160,7 +162,7 @@ static int do_sb_devoff(struct cmd_tbl *cmdtp, int flag, int argc, U_BOOT_LONGHELP(sb, "devoff - Disable device from device tree node\n" "sb devon - Enable device from device tree node\n" - "sb grid <0|1> - Enable/disable grid overlay on video\n" + "sb grid <0|1> [] - Enable/disable grid overlay on video\n" "sb handoff - Show handoff data received from SPL\n" "sb map - Show mapped memory\n" "sb state - Show sandbox state"); @@ -168,7 +170,7 @@ U_BOOT_LONGHELP(sb, U_BOOT_CMD_WITH_SUBCMDS(sb, "Sandbox status commands", sb_help_text, U_BOOT_SUBCMD_MKENT(devoff, 2, 1, do_sb_devoff), U_BOOT_SUBCMD_MKENT(devon, 2, 1, do_sb_devon), - U_BOOT_SUBCMD_MKENT(grid, 2, 1, do_sb_grid), + U_BOOT_SUBCMD_MKENT(grid, 3, 1, do_sb_grid), U_BOOT_SUBCMD_MKENT(handoff, 1, 1, do_sb_handoff), U_BOOT_SUBCMD_MKENT(map, 1, 1, do_sb_map), U_BOOT_SUBCMD_MKENT(state, 1, 1, do_sb_state)); diff --git a/doc/develop/expo.rst b/doc/develop/expo.rst index ca83b403621..fc642ed3696 100644 --- a/doc/develop/expo.rst +++ b/doc/develop/expo.rst @@ -797,6 +797,10 @@ For example, to watch an expo test render with a visible display:: ./u-boot -T -l -V 500 --video_frames /tmp/good -c "ut bootstd expo_render_image" +The :doc:`../usage/cmd/sb` ``grid`` subcommand can be used to overlay a grid on +the display, to help with checking alignment of objects. The grid size defaults +to 0x20 pixels but can be specified as a parameter. + This will write each asserted expo frame to ``/tmp/good/frame0.bmp``, ``/tmp/good/frame1.bmp``, etc. diff --git a/doc/usage/cmd/sb.rst b/doc/usage/cmd/sb.rst index ee72ecd0db9..08f8f87f88f 100644 --- a/doc/usage/cmd/sb.rst +++ b/doc/usage/cmd/sb.rst @@ -13,7 +13,7 @@ Synopsis sb devoff sb devon - sb grid <0|1> + sb grid <0|1> [] sb handoff sb map sb state @@ -45,8 +45,9 @@ sb grid ~~~~~~~ This enables or disables a grid overlay on the video display. When enabled, -a 10-pixel grid is drawn over the display, which is useful for debugging UI -layout and alignment. Use ``sb grid 1`` to enable and ``sb grid 0`` to disable. +a grid is drawn over the display, which is useful for debugging UI layout and +alignment. Use ``sb grid 1`` to enable and ``sb grid 0`` to disable. An +optional second parameter specifies the grid size in pixels (default 0x20). sb handoff ~~~~~~~~~~ diff --git a/drivers/video/sandbox_sdl.c b/drivers/video/sandbox_sdl.c index 4785185dd70..6fc71bc9cb9 100644 --- a/drivers/video/sandbox_sdl.c +++ b/drivers/video/sandbox_sdl.c @@ -149,6 +149,7 @@ static int sandbox_sdl_video_sync(struct udevice *vid, uint flags) sizeof(plat->last_sync_damage)); opts.draw_grid = state->show_grid; + opts.grid_size = state->grid_size; return sandbox_sdl_sync(uc_priv->fb, damage, &opts); } diff --git a/test/cmd/sb.c b/test/cmd/sb.c index 4ce8a8c4215..b1fbddac449 100644 --- a/test/cmd/sb.c +++ b/test/cmd/sb.c @@ -130,6 +130,7 @@ static int dm_test_sb_grid(struct unit_test_state *uts) /* Ensure grid is initially off */ state->show_grid = false; + state->grid_size = 0; /* Enable grid */ ut_assertok(run_command("sb grid 1", 0)); @@ -141,6 +142,16 @@ static int dm_test_sb_grid(struct unit_test_state *uts) ut_assert_console_end(); ut_asserteq(false, state->show_grid); + /* Enable grid with custom size (0x14 = 20 decimal) */ + ut_assertok(run_command("sb grid 1 14", 0)); + ut_assert_console_end(); + ut_asserteq(true, state->show_grid); + ut_asserteq(0x14, state->grid_size); + + /* Clean up */ + state->show_grid = false; + state->grid_size = 0; + return 0; } DM_TEST(dm_test_sb_grid, UTF_CONSOLE);