
On 25.06.2016 21:04, Mateusz Kulikowski wrote:
Hi Dirk,
On 23.06.2016 13:33, Dirk Behme wrote: [...]
Idea: perhaps after this series is merged we can add 2 new commands to u-boot (SMC/HVC) to play with hypervisors/secure monitors (and perhaps use some simple functionality if needed).
How this should look like?
I thought of something like this (I did such code few times):
u-boot> smc 42 42 42 42 42 42 ret => (0x1, 0x2, 0x3, 0x4)
Could you share any (example?) code you have for such an smc/hvc U-Boot command?
I'm afraid I don't have it anymore :(
SMC call itself is trivial, you can use smc_call @ u-boot: arch/arm/cpu/armv8/fwcall.c (this is code for armv8 in 64-bit mode, but you can easily port it to armv7)
As for adding custom commands - just use any existing as template (sleep may be a good idea :) ).
Anything like below [1]?
Best regards
Dirk
[1]
From f5fb9bdab3054fdc37ca3fed44703f0dc5c8b083 Mon Sep 17 00:00:00 2001 From: Dirk Behme dirk.behme@de.bosch.com Date: Mon, 27 Jun 2016 12:39:35 +0200 Subject: [PATCH] common: Add ARMv8 smc command
Add a command line interface to do ARMv8 secure monitor calls (smc).
Signed-off-by: Dirk Behme dirk.behme@de.bosch.com --- common/Makefile | 2 + common/cmd_armv8svchvc.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-) create mode 100644 common/cmd_armv8svchvc.c
diff --git a/common/Makefile b/common/Makefile index 252fbf1..5a8dad0 100644 --- a/common/Makefile +++ b/common/Makefile @@ -191,6 +191,8 @@ obj-$(CONFIG_CMD_SPL) += cmd_spl.o obj-$(CONFIG_CMD_ZIP) += cmd_zip.o obj-$(CONFIG_CMD_ZFS) += cmd_zfs.o
+obj-$(CONFIG_ARM64) += cmd_armv8svchvc.o + # others obj-$(CONFIG_BOOTSTAGE) += bootstage.o obj-$(CONFIG_CONSOLE_MUX) += iomux.o diff --git a/common/cmd_armv8svchvc.c b/common/cmd_armv8svchvc.c new file mode 100644 index 0000000..6491704 --- /dev/null +++ b/common/cmd_armv8svchvc.c @@ -0,0 +1,60 @@ +/* + * (C) Copyright 2016 + * Robert Bosch Car Multimedia GmbH + * Dirk Behme dirk.behme@de.bosch.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <command.h> + +static int do_smc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct pt_regs regs; + + memset(®s, 0, sizeof(struct pt_regs)); + + switch (argc) { + case 9: + regs.regs[7] = simple_strtoul(argv[8], NULL, 16); + /* fall through */ + case 8: + regs.regs[6] = simple_strtoul(argv[7], NULL, 16); + /* fall through */ + case 7: + regs.regs[5] = simple_strtoul(argv[6], NULL, 16); + /* fall through */ + case 6: + regs.regs[4] = simple_strtoul(argv[5], NULL, 16); + /* fall through */ + case 5: + regs.regs[3] = simple_strtoul(argv[4], NULL, 16); + /* fall through */ + case 4: + regs.regs[2] = simple_strtoul(argv[3], NULL, 16); + /* fall through */ + case 3: + regs.regs[1] = simple_strtoul(argv[2], NULL, 16); + /* fall through */ + case 2: + regs.regs[0] = simple_strtoul(argv[1], NULL, 16); + break; + default: + return CMD_RET_USAGE; + } + + smc_call(®s); + + printf("ret: x0: 0x%016luX\n x1: 0x%016luX\n x2: 0x%016luX x3: 0x%016lX\n", + regs.regs[0], regs.regs[1], regs.regs[2], regs.regs[3]); + + return 0; +} + +U_BOOT_CMD( + smc , 9, 0, do_smc, + "do ARMv8 hypervisor call (SMC)", + "x0 [x1 x2 x3 x4 x5 x6 x7]\n" + " - 8 SMC parameters for the registers x0 - x7" +);