Skip to content

Commit 548193c

Browse files
jwrdegoedegregkh
authored andcommitted
test_firmware: add support for firmware_request_platform
Add support for testing firmware_request_platform through a new trigger_request_platform trigger. Signed-off-by: Hans de Goede <[email protected]> Acked-by: Luis Chamberlain <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e4c2c0f commit 548193c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

lib/test_firmware.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/delay.h>
2525
#include <linux/kthread.h>
2626
#include <linux/vmalloc.h>
27+
#include <linux/efi_embedded_fw.h>
2728

2829
#define TEST_FIRMWARE_NAME "test-firmware.bin"
2930
#define TEST_FIRMWARE_NUM_REQS 4
@@ -507,6 +508,57 @@ static ssize_t trigger_request_store(struct device *dev,
507508
}
508509
static DEVICE_ATTR_WO(trigger_request);
509510

511+
#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
512+
static ssize_t trigger_request_platform_store(struct device *dev,
513+
struct device_attribute *attr,
514+
const char *buf, size_t count)
515+
{
516+
static const u8 test_data[] = {
517+
0x55, 0xaa, 0x55, 0xaa, 0x01, 0x02, 0x03, 0x04,
518+
0x55, 0xaa, 0x55, 0xaa, 0x05, 0x06, 0x07, 0x08,
519+
0x55, 0xaa, 0x55, 0xaa, 0x10, 0x20, 0x30, 0x40,
520+
0x55, 0xaa, 0x55, 0xaa, 0x50, 0x60, 0x70, 0x80
521+
};
522+
struct efi_embedded_fw efi_embedded_fw;
523+
const struct firmware *firmware = NULL;
524+
char *name;
525+
int rc;
526+
527+
name = kstrndup(buf, count, GFP_KERNEL);
528+
if (!name)
529+
return -ENOSPC;
530+
531+
pr_info("inserting test platform fw '%s'\n", name);
532+
efi_embedded_fw.name = name;
533+
efi_embedded_fw.data = (void *)test_data;
534+
efi_embedded_fw.length = sizeof(test_data);
535+
list_add(&efi_embedded_fw.list, &efi_embedded_fw_list);
536+
537+
pr_info("loading '%s'\n", name);
538+
rc = firmware_request_platform(&firmware, name, dev);
539+
if (rc) {
540+
pr_info("load of '%s' failed: %d\n", name, rc);
541+
goto out;
542+
}
543+
if (firmware->size != sizeof(test_data) ||
544+
memcmp(firmware->data, test_data, sizeof(test_data)) != 0) {
545+
pr_info("firmware contents mismatch for '%s'\n", name);
546+
rc = -EINVAL;
547+
goto out;
548+
}
549+
pr_info("loaded: %zu\n", firmware->size);
550+
rc = count;
551+
552+
out:
553+
release_firmware(firmware);
554+
list_del(&efi_embedded_fw.list);
555+
kfree(name);
556+
557+
return rc;
558+
}
559+
static DEVICE_ATTR_WO(trigger_request_platform);
560+
#endif
561+
510562
static DECLARE_COMPLETION(async_fw_done);
511563

512564
static void trigger_async_request_cb(const struct firmware *fw, void *context)
@@ -903,6 +955,9 @@ static struct attribute *test_dev_attrs[] = {
903955
TEST_FW_DEV_ATTR(trigger_request),
904956
TEST_FW_DEV_ATTR(trigger_async_request),
905957
TEST_FW_DEV_ATTR(trigger_custom_fallback),
958+
#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
959+
TEST_FW_DEV_ATTR(trigger_request_platform),
960+
#endif
906961

907962
/* These use the config and can use the test_result */
908963
TEST_FW_DEV_ATTR(trigger_batched_requests),

0 commit comments

Comments
 (0)