[FOSS_TLK]kernel: dynamically decide to use cmdline/boot_args
Bootloader passes the boot arguments as cmdline. But since we are adding
support to pass the boot parameters as a structure rather then as cmdline,
we are adding support for both in TLK. Such that TLK can adapt to the
cmdline or structure passed for the boot parameters.
Change-Id: Ib28016b35decd77ebf04b6fdb72a8a264cf27d61
Signed-off-by: Sharif Inamdar <isharif@nvidia.com>
Reviewed-on: http://git-master/r/752878
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Varun Wadekar <vwadekar@nvidia.com>
Tested-by: Varun Wadekar <vwadekar@nvidia.com>
diff --git a/include/kernel/boot_params.h b/include/kernel/boot_params.h
index ed448cf..8aa0482 100644
--- a/include/kernel/boot_params.h
+++ b/include/kernel/boot_params.h
@@ -58,8 +58,22 @@
char encrypted_keys[EKS_MAXIMUM_CODE_SIZE]; // encrypted keys
} key_params;
+/* Structure for boot params */
+typedef struct boot_params {
+ uint32_t version;
+ uint64_t pmem;
+ uint64_t pmem_size;
+ uint64_t emem;
+ uint64_t emem_size;
+ uint32_t chip_uid[4];
+ uint32_t uart_id;
+ uint64_t tsec_carveout;
+ uint64_t tsec_size;
+ uint64_t dtb_load_addr;
+} boot_params_t;
+
void save_boot_params(unsigned int, uint32_t);
-void parse_cmdline(void);
+void get_boot_params(void);
int get_boot_args(task_t *task, uint32_t *args);
#endif
diff --git a/kernel/boot.c b/kernel/boot.c
index 7b7423a..88dcfec 100644
--- a/kernel/boot.c
+++ b/kernel/boot.c
@@ -24,6 +24,8 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
+#include <debug.h>
+#include <err.h>
#include <kernel/boot_params.h>
#include <platform/platform_p.h>
#include <common/ote_nv_uuid.h>
@@ -60,7 +62,7 @@
return offset;
}
-void parse_cmdline(void)
+static int parse_cmdline(void)
{
boot_params *boot_params_ptr = (boot_params*)__bootarg_addr;
char *str;
@@ -79,9 +81,12 @@
if (!boot_params_ptr ||
!boot_params_ptr->param_string[0])
- return;
+ return ERR_INVALID_ARGS;
+ /* Check whether parameters are passed as cmdline or structure */
cmdline_len = boot_params_ptr->param_string_sz;
+ if (cmdline_len == 0)
+ return ERR_NOT_SUPPORTED;
str = boot_params_ptr->param_string;
for (i = 0; i < cmdline_len; i++) {
@@ -143,6 +148,53 @@
cmdline_len -= strlen(str);
str += strlen(str) + 1;
}
+ return NO_ERROR;
+}
+
+static int parse_bootargs(void)
+{
+ boot_params_t *boot_params_ptr = (boot_params*)__bootarg_addr;
+ uint64_t base, size;
+
+ if (!boot_params_ptr || boot_params_ptr->version != 0)
+ return ERR_INVALID_ARGS;
+
+ device_uid[0] = boot_params_ptr->chip_uid[0];
+ device_uid[1] = boot_params_ptr->chip_uid[1];
+ device_uid[2] = boot_params_ptr->chip_uid[2];
+ device_uid[3] = boot_params_ptr->chip_uid[3];
+
+ debug_uart_id = boot_params_ptr->uart_id;
+
+ /* Get DRAM range from the structure passed */
+ base = boot_params_ptr->pmem;
+ size = boot_params_ptr->pmem_size;
+ tz_add_dram_range(base << 20, size << 20);
+
+ if (boot_params_ptr->emem_size != 0) {
+ base = boot_params_ptr->emem;
+ size = boot_params_ptr->emem_size;
+ tz_add_dram_range(base << 20, size << 20);
+ }
+
+ dtb_addr = boot_params_ptr->dtb_load_addr;
+
+ /* Get TSEC range from the structure passed */
+ tsec_carveout_base = boot_params_ptr->tsec_carveout;
+ tsec_carveout_size = boot_params_ptr->tsec_size;
+ tsec_carveout_size <<= 20;
+ tsec_carveout_base <<= 20;
+
+ return NO_ERROR;
+}
+
+void get_boot_params(void)
+{
+ int32_t err = NO_ERROR;
+
+ err = parse_cmdline();
+ if (err)
+ err = parse_bootargs();
}
int get_boot_args(task_t *task, uint32_t *argv)
diff --git a/kernel/main.c b/kernel/main.c
index 2e0a25e..bb2fca3 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -67,8 +67,8 @@
// get us into some sort of thread context
thread_init_early();
- // parse command line arguments
- parse_cmdline();
+ // get boot arguments based on structure passed
+ get_boot_params();
// early arch stuff
arch_early_init();
diff --git a/platform/tegra/common/memory.c b/platform/tegra/common/memory.c
index a0910b6..1a9c728 100644
--- a/platform/tegra/common/memory.c
+++ b/platform/tegra/common/memory.c
@@ -40,13 +40,26 @@
void platform_setup_keys(void)
{
boot_params *boot_params_ptr;
+ boot_params_t *boot_params_ptr_args;
key_params *keys_ptr;
+ int cmdline_len;
uint32_t reg, offset;
extern uint32_t __bootarg_addr;
/* keys immediately follow the boot params in DRAM */
boot_params_ptr = (boot_params *) __bootarg_addr;
- offset = ROUNDUP(boot_params_ptr->param_string_sz, sizeof(uint32_t));
+
+ cmdline_len = boot_params_ptr->param_string_sz;
+
+ /* Check whether parameters are passed as cmdline or structure */
+ if (cmdline_len == 0) {
+ boot_params_ptr_args = (boot_params_t *) __bootarg_addr;
+ offset = sizeof(boot_params_t);
+ keys_ptr = (key_params *)((uintptr_t)boot_params_ptr_args + offset);
+ } else {
+ offset = ROUNDUP(boot_params_ptr->param_string_sz, sizeof(uint32_t));
+ keys_ptr = (key_params *)((uintptr_t)boot_params_ptr->param_string + offset);
+ }
/* ensure TZRAM clock is enabled */
reg = readl(TEGRA_CLK_RESET_BASE + CLK_OUT_ENB_V);
@@ -54,7 +67,6 @@
writel(reg, TEGRA_CLK_RESET_BASE + CLK_OUT_ENB_V);
/* copy keys to TZRAM */
- keys_ptr = (key_params *)((uintptr_t)boot_params_ptr->param_string + offset);
memcpy((void *)TEGRA_TZRAM_BASE,
keys_ptr->encrypted_keys, keys_ptr->encrypted_key_sz);
}