Skip to content

Commit

Permalink
arm64: Pass RAM boundary and enable-dcache flag to purgatory
Browse files Browse the repository at this point in the history
When "enable-dcache" is passed to the kexec() command line, kexec-tools
passes this information to purgatory, which in turn enables cache during
sha-256 verification.

RAM boundary which includes all the sections is needed for creating
identity page mapping and to enable d-cache for those areas. Therefore
these informations are passed to purgatory as well.

Signed-off-by: Pratyush Anand <panand@redhat.com>
  • Loading branch information
Pratyush Anand committed Aug 19, 2016
1 parent 272dcac commit 77cb6d4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
6 changes: 5 additions & 1 deletion kexec/arch/arm64/include/arch/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#define OPT_REUSE_CMDLINE ((OPT_MAX)+3)
#define OPT_PORT ((OPT_MAX)+4)
#define OPT_PORT_LSR ((OPT_MAX)+5)
#define OPT_ARCH_MAX ((OPT_MAX)+6)
#define OPT_ENABLE_DCACHE ((OPT_MAX)+6)
#define OPT_ARCH_MAX ((OPT_MAX)+7)

#define KEXEC_ARCH_OPTIONS \
KEXEC_OPTIONS \
{ "append", 1, NULL, OPT_APPEND }, \
{ "command-line", 1, NULL, OPT_APPEND }, \
{ "dtb", 1, NULL, OPT_DTB }, \
{ "enable-dcache", 0, NULL, OPT_ENABLE_DCACHE }, \
{ "initrd", 1, NULL, OPT_INITRD }, \
{ "ramdisk", 1, NULL, OPT_INITRD }, \
{ "reuse-cmdline", 0, NULL, OPT_REUSE_CMDLINE }, \
Expand All @@ -28,6 +30,7 @@ static const char arm64_opts_usage[] __attribute__ ((unused)) =
" --append=STRING Set the kernel command line to STRING.\n"
" --command-line=STRING Set the kernel command line to STRING.\n"
" --dtb=FILE Use FILE as the device tree blob.\n"
" --enable-dcache Enable D-Cache in Purgatory for faster SHA verification.\n"
" --initrd=FILE Use FILE as the kernel initial ramdisk.\n"
" --port=ADDRESS Purgatory output to port ADDRESS.\n"
" --port-lsr=ADDR,VAL Purgatory output port line status address and TX Empty Bit Field.\n"
Expand All @@ -41,6 +44,7 @@ struct arm64_opts {
uint64_t port;
uint64_t port_lsr;
uint8_t port_lsr_val;
uint8_t enable_dcache;
};

extern struct arm64_opts arm64_opts;
Expand Down
16 changes: 16 additions & 0 deletions kexec/arch/arm64/include/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _TYPES_H_
#define _TYPES_H_

#define min(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })

#define max(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })

#endif /* _TYPES_H_ */
24 changes: 23 additions & 1 deletion kexec/arch/arm64/kexec-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "fs2dt.h"
#include "kexec-syscall.h"
#include "arch/options.h"
#include "types.h"

/* Global varables the core kexec routines expect. */

Expand Down Expand Up @@ -136,6 +137,9 @@ int arch_process_options(int argc, char **argv)
arm64_opts.port_lsr_val = strtoul(strtok(NULL, ","),
NULL, 0);
break;
case OPT_ENABLE_DCACHE:
arm64_opts.enable_dcache = 1;
break;
default:
break; /* Ignore core and unknown options. */
}
Expand Down Expand Up @@ -454,14 +458,17 @@ static int setup_2nd_dtb(struct dtb *dtb, char *command_line, int on_crash)
int arm64_load_other_segments(struct kexec_info *info,
uint64_t kernel_entry)
{
int result;
int result, i;
uint64_t dtb_base;
uint64_t image_base;
unsigned long hole_min;
unsigned long hole_max;
unsigned long arm64_ram_start = -1;
unsigned long arm64_ram_end = 0;
uint64_t purgatory_sink;
uint64_t purgatory_sink_lsr;
uint8_t purgatory_sink_lsr_val;
uint8_t purgatory_enable_dcache;
char *initrd_buf = NULL;
struct dtb dtb;
char command_line[COMMAND_LINE_SIZE] = "";
Expand All @@ -479,6 +486,7 @@ int arm64_load_other_segments(struct kexec_info *info,

purgatory_sink_lsr = arm64_opts.port_lsr;
purgatory_sink_lsr_val = arm64_opts.port_lsr_val;
purgatory_enable_dcache = arm64_opts.enable_dcache;

if (arm64_opts.dtb) {
dtb.name = "dtb_2";
Expand Down Expand Up @@ -577,11 +585,25 @@ int arm64_load_other_segments(struct kexec_info *info,
elf_rel_set_symbol(&info->rhdr, "arm64_sink_lsr_val",
&purgatory_sink_lsr_val, sizeof(purgatory_sink_lsr_val));

elf_rel_set_symbol(&info->rhdr, "arm64_enable_dcache",
&purgatory_enable_dcache, sizeof(purgatory_enable_dcache));

elf_rel_set_symbol(&info->rhdr, "arm64_kernel_entry", &kernel_entry,
sizeof(kernel_entry));

elf_rel_set_symbol(&info->rhdr, "arm64_dtb_addr", &dtb_base,
sizeof(dtb_base));
for (i = 0; i < info->nr_segments; i++) {
arm64_ram_start = min(arm64_ram_start,
(unsigned long)info->segment[i].mem);
arm64_ram_end = max(arm64_ram_end,
((unsigned long)info->segment[i].mem +
info->segment[i].memsz));
}
elf_rel_set_symbol(&info->rhdr, "arm64_ram_start",
&arm64_ram_start, sizeof(arm64_ram_start));
elf_rel_set_symbol(&info->rhdr, "arm64_ram_end",
&arm64_ram_end, sizeof(arm64_ram_end));

return 0;
}
Expand Down
9 changes: 9 additions & 0 deletions purgatory/arch/arm64/purgatory-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

#include <stdint.h>
#include <purgatory.h>
#include "cache.h"

/* Symbols set by kexec. */

uint8_t *arm64_sink __attribute__ ((section ("data")));
uint8_t *arm64_sink_lsr __attribute__ ((section ("data")));
uint8_t arm64_sink_lsr_val __attribute__ ((section ("data")));
uint8_t arm64_enable_dcache __attribute__ ((section ("data")));
uint64_t arm64_ram_start __attribute__ ((section ("data")));
uint64_t arm64_ram_end __attribute__ ((section ("data")));
extern void (*arm64_kernel_entry)(uint64_t, uint64_t, uint64_t, uint64_t);
extern uint64_t arm64_dtb_addr;

Expand Down Expand Up @@ -45,10 +49,15 @@ void putchar(int ch)

void post_verification_setup_arch(void)
{
if (arm64_enable_dcache)
disable_dcache(arm64_ram_start, arm64_ram_end);
}

void setup_arch(void)
{
printf("purgatory: entry=%lx\n", (unsigned long)arm64_kernel_entry);
printf("purgatory: dtb=%lx\n", arm64_dtb_addr);

if (arm64_enable_dcache)
enable_dcache(arm64_ram_start, arm64_ram_end, (uint64_t)arm64_sink);
}

0 comments on commit 77cb6d4

Please sign in to comment.