Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Shirisha G <shirisha@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: linux-kselftest@vger.kernel.org, maddy@linux.ibm.com,
	venkat88@linux.ibm.com, shirisha@linux.ibm.com
Subject: [PATCH 5/7] Subject: [PATCH] selftests/powerpc: Add RTAS firmware flash interface test
Date: Fri, 18 Sep 2026 10:52:40 +0530	[thread overview]
Message-ID: <20260918052321.932660-5-shirisha@linux.ibm.com> (raw)
In-Reply-To: <20260918052321.932660-1-shirisha@linux.ibm.com>

Add kselftest for the RTAS firmware flash interface on pseries/PowerVM
systems. This test validates the existence and accessibility of the
firmware flash and update proc entries, while safely rejecting invalid
data. It does not perform actual firmware updates.

The test verifies:
- Existence of `/proc/ppc64/rtas/firmware_flash` interface
- Ability to open and read the flash interface
- Rejection of invalid image writes (requires root)
- Accessibility of `/proc/ppc64/rtas/firmware_update` status
- Safe validation subset without triggering real updates

Signed-off-by: Shirisha G <shirisha@linux.ibm.com>
---
 .../selftests/powerpc/rtas/rtas_flash_test.c  | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/rtas_flash_test.c

diff --git a/tools/testing/selftests/powerpc/rtas/rtas_flash_test.c b/tools/testing/selftests/powerpc/rtas/rtas_flash_test.c
new file mode 100644
index 000000000000..7f7c90447e9c
--- /dev/null
+++ b/tools/testing/selftests/powerpc/rtas/rtas_flash_test.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * RTAS Firmware Flash Test (Safe Subset)
+ * Copyright (C) 2026 IBM Corporation
+ *
+ * WARNING: This test only validates the interface with invalid data.
+ * It does NOT perform actual firmware updates.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include "utils.h"
+
+#define FLASH_PROC "/proc/ppc64/rtas/firmware_flash"
+#define UPDATE_PROC "/proc/ppc64/rtas/firmware_update"
+
+int main(void)
+{
+	int fd;
+	char invalid_data[256];
+	ssize_t ret;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify flash interface exists */
+	SKIP_IF(access(FLASH_PROC, F_OK) != 0);
+
+	/* Test 2: Verify we can open the interface */
+	fd = open(FLASH_PROC, O_RDONLY);
+	if (fd >= 0) {
+		close(fd);
+		printf("Flash interface is readable\n");
+	}
+
+	/* Test 3: Test invalid image rejection (requires root) */
+	if (geteuid() == 0) {
+		fd = open(FLASH_PROC, O_WRONLY);
+		if (fd >= 0) {
+			/* Write invalid data - should be rejected */
+			memset(invalid_data, 0xFF, sizeof(invalid_data));
+			ret = write(fd, invalid_data, sizeof(invalid_data));
+			
+			/* We expect this to fail or be rejected */
+			if (ret < 0) {
+				printf("Invalid image correctly rejected (errno=%d)\n", errno);
+			} else {
+				printf("WARNING: Write accepted (may need validation)\n");
+			}
+			close(fd);
+		}
+	} else {
+		printf("Skipping write test (requires root)\n");
+	}
+
+	/* Test 4: Check update status interface */
+	if (access(UPDATE_PROC, R_OK) == 0) {
+		fd = open(UPDATE_PROC, O_RDONLY);
+		if (fd >= 0) {
+			char status[256];
+			ret = read(fd, status, sizeof(status) - 1);
+			if (ret > 0) {
+				status[ret] = '\0';
+				printf("Update status: %s\n", status);
+			}
+			close(fd);
+		}
+	}
+
+	printf("RTAS flash test passed (safe subset)\n");
+	return 0;
+}
-- 
2.43.5


  parent reply	other threads:[~2026-09-18  5:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  5:22 [PATCH 1/7] Subject: [PATCH] selftests/powerpc: Add RTAS real-time clock test Shirisha G
2026-09-18  5:22 ` [PATCH 2/7] Subject: [PATCH] selftests/powerpc: Add NVRAM access test Shirisha G
2026-09-18  5:22 ` [PATCH 3/7] Subject: [PATCH] selftests/powerpc: Add RTAS /proc interface test Shirisha G
2026-09-18  5:22 ` [PATCH 4/7] Subject: [PATCH] selftests/powerpc: Add FADump sysfs " Shirisha G
2026-09-18  5:22 ` Shirisha G [this message]
2026-09-18  5:22 ` [PATCH 6/7] Subject: [PATCH] selftests/powerpc: Add common test utilities header Shirisha G
2026-09-18  5:22 ` [PATCH 7/7] Subject: [PATCH] selftests/powerpc/rtas: consolidate TEST_GEN_PROGS definitions Shirisha G

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918052321.932660-5-shirisha@linux.ibm.com \
    --to=shirisha@linux.ibm.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=venkat88@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox