diff options
author | Tom Rini <trini@konsulko.com> | 2023-10-24 09:39:52 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-10-24 09:39:52 -0400 |
commit | 5cab3515f8c9796015739c1750b8933291c816be (patch) | |
tree | a661c61e1645b6d26c622b818afd09bacff3624b /test | |
parent | 1b2a3d08c0440db4ee37d748b491673f1db0d384 (diff) | |
parent | d039b1b551e8dbb2c309d35bb19b7866caa4dcc1 (diff) | |
download | u-boot-5cab3515f8c9796015739c1750b8933291c816be.tar.gz u-boot-5cab3515f8c9796015739c1750b8933291c816be.tar.bz2 u-boot-5cab3515f8c9796015739c1750b8933291c816be.zip |
Merge tag 'u-boot-rockchip-20231024' of https://source.denx.de/u-boot/custodians/u-boot-rockchip
- Add Board: rk3588 NanoPC-T6, Orange Pi 5, Orange Pi 5 Plus;
- clk driver fix for rk3568 and rk3588;
- rkmtd cmd support for rockchip nand device;
- dts update and sync from linux;
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/Makefile | 1 | ||||
-rw-r--r-- | test/dm/rkmtd.c | 200 |
2 files changed, 201 insertions, 0 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile index 02c651a786..cb82d839f8 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -100,6 +100,7 @@ obj-$(CONFIG_REMOTEPROC) += remoteproc.o obj-$(CONFIG_DM_RESET) += reset.o obj-$(CONFIG_SYSRESET) += sysreset.o obj-$(CONFIG_DM_REGULATOR) += regulator.o +obj-$(CONFIG_CMD_RKMTD) += rkmtd.o obj-$(CONFIG_DM_RNG) += rng.o obj-$(CONFIG_DM_RTC) += rtc.o obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o diff --git a/test/dm/rkmtd.c b/test/dm/rkmtd.c new file mode 100644 index 0000000000..3c3e8efa92 --- /dev/null +++ b/test/dm/rkmtd.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Test derived from: + * /test/dm/host.c + * Copyright 2022 Google LLC + * Written by Simon Glass <sjg@chromium.org> + * + * Copyright (C) 2023 Johan Jonker <jbx6244@gmail.com> + */ + +#include <common.h> +#include <blk.h> +#include <dm.h> +#include <fs.h> +#include <rkmtd.h> +#include <asm/test.h> +#include <dm/device-internal.h> +#include <dm/test.h> +#include <test/test.h> +#include <test/ut.h> + +#define RW_BUF_SIZE 12 * 512 + +/* Basic test of the RKMTD interface */ +static int dm_test_rkmtd(struct unit_test_state *uts) +{ + struct udevice *dev, *part, *chk, *blk; + char write[RW_BUF_SIZE], read[RW_BUF_SIZE]; + static const char label[] = "test"; + struct rkmtd_dev *plat; + struct blk_desc *desc; + struct sector0 *sec0; + int i; + + ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_RKMTD, &dev)); + ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_PARTITION, &part)); + + ut_assertok(rkmtd_create_device(label, &dev)); + + /* Check that the plat data has been allocated */ + plat = dev_get_plat(dev); + ut_asserteq_str("test", plat->label); + ut_assert(label != plat->label); + + /* Attach RKMTD driver */ + ut_assertok(rkmtd_attach(dev)); + ut_assertok(uclass_first_device_err(UCLASS_RKMTD, &chk)); + ut_asserteq_ptr(chk, dev); + + /* Get RKMTD block device */ + ut_assertok(blk_get_from_parent(dev, &blk)); + ut_assertok(device_probe(blk)); + + /* There should be a GPT partition table in this device */ + ut_asserteq(0, uclass_first_device_err(UCLASS_PARTITION, &part)); + + /* Write a boot block and verify that we get the same data back */ + desc = dev_get_uclass_plat(blk); + ut_asserteq(true, desc->removable); + ut_asserteq(LBA, desc->lba); + + memset(write, '\0', BLK_SIZE); + + for (i = BLK_SIZE; i < sizeof(write); i++) + write[i] = i; + + sec0 = (struct sector0 *)write; + sec0->magic = 0x0FF0AA55; + sec0->rc4_flag = 0; + sec0->boot_code1_offset = 4; + sec0->boot_code2_offset = 4; + sec0->flash_data_size = 4; + sec0->flash_boot_size = 8; + + rkmtd_rc4(write, 512); + ut_asserteq(RK_TAG, sec0->magic); + + ut_asserteq(12, blk_dwrite(desc, 64, 12, write)); + ut_asserteq(12, blk_dread(desc, 64, 12, read)); + ut_asserteq_mem(write, read, RW_BUF_SIZE); + + ut_assertok(rkmtd_detach(dev)); + + ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk)); + ut_assertok(device_unbind(dev)); + + return 0; +} +DM_TEST(dm_test_rkmtd, UT_TESTF_SCAN_FDT); + +/* Reusing the same label should work */ +static int dm_test_rkmtd_dup(struct unit_test_state *uts) +{ + static const char label[] = "test"; + struct udevice *dev, *chk; + + /* Create a RKMTD device with label "test" */ + ut_asserteq(0, uclass_id_count(UCLASS_RKMTD)); + ut_assertok(rkmtd_create_device(label, &dev)); + ut_assertok(rkmtd_attach(dev)); + ut_assertok(uclass_first_device_err(UCLASS_RKMTD, &chk)); + ut_asserteq_ptr(chk, dev); + ut_asserteq(1, uclass_id_count(UCLASS_RKMTD)); + + /* Create another device with the same label (should remove old one) */ + ut_assertok(rkmtd_create_device(label, &dev)); + ut_assertok(rkmtd_attach(dev)); + ut_assertok(uclass_first_device_err(UCLASS_RKMTD, &chk)); + ut_asserteq_ptr(chk, dev); + + /* Make sure there is still only one device */ + ut_asserteq(1, uclass_id_count(UCLASS_RKMTD)); + + return 0; +} +DM_TEST(dm_test_rkmtd_dup, UT_TESTF_SCAN_FDT); + +/* Basic test of the 'rkmtd' command */ +static int dm_test_rkmtd_cmd(struct unit_test_state *uts) +{ + struct udevice *dev, *blk; + struct blk_desc *desc; + + /* First check 'rkmtd info' with binding */ + ut_assertok(run_command("rkmtd info", 0)); + ut_assert_nextline("dev blocks label "); + ut_assert_console_end(); + + /* Bind device 1 */ + ut_assertok(run_commandf("rkmtd bind test1")); + ut_assertok(uclass_first_device_err(UCLASS_RKMTD, &dev)); + ut_assertok(blk_get_from_parent(dev, &blk)); + desc = dev_get_uclass_plat(blk); + + ut_assertok(run_command("rkmtd info", 0)); + ut_assert_nextline("dev blocks label "); + ut_assert_nextline(" 0 609 test1 "); + ut_assert_console_end(); + + /* Bind device 2 */ + ut_assertok(run_commandf("rkmtd bind test2")); + ut_assertok(uclass_next_device_err(&dev)); + ut_assertok(blk_get_from_parent(dev, &blk)); + desc = dev_get_uclass_plat(blk); + + ut_assertok(run_command("rkmtd info", 0)); + ut_assert_nextline("dev blocks label "); + ut_assert_nextline(" 0 609 test1 "); + ut_assert_nextline(" 1 609 test2 "); + ut_assert_console_end(); + + ut_asserteq(1, run_command("rkmtd info test", 0)); + ut_assert_nextline("No such device 'test'"); + ut_assert_console_end(); + + ut_assertok(run_command("rkmtd info test2", 0)); + ut_assert_nextline("dev blocks label "); + ut_assert_nextline(" 1 609 test2 "); + ut_assert_console_end(); + + /* Check 'rkmtd dev' */ + ut_asserteq(1, run_command("rkmtd dev", 0)); + ut_assert_nextline("No current rkmtd device"); + ut_assert_console_end(); + + ut_asserteq(1, run_command("rkmtd dev missing", 0)); + ut_assert_nextline("No such device 'missing'"); + ut_assert_console_end(); + + ut_assertok(run_command("rkmtd dev test2", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("rkmtd dev", 0)); + ut_assert_nextline("Current rkmtd device: 1: test2"); + ut_assert_console_end(); + + /* Try a numerical label */ + ut_assertok(run_command("rkmtd dev 0", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("rkmtd dev", 0)); + ut_assert_nextline("Current rkmtd device: 0: test1"); + ut_assert_console_end(); + + /* Remove one of the bindings */ + ut_assertok(run_commandf("rkmtd unbind test1")); + + /* There should now be no current device */ + ut_asserteq(1, run_command("rkmtd dev", 0)); + ut_assert_nextline("No current rkmtd device"); + ut_assert_console_end(); + + ut_assertok(run_command("rkmtd info", 0)); + ut_assert_nextline("dev blocks label "); + ut_assert_nextline(" 1 609 test2 "); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_rkmtd_cmd, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC); |