Files
OpenCellular/chip/g/loader/setup.c
Vadim Bendebury 725bef1b3b cr50: RO Loader implementation
This code is a port of the sample loader application included in the
FPGA update. Only the pieces relevant to straight verification and
boot were ported.

The loader generates a hash, inputs to which are the image body, state
of fuses and state of flash INFO region, and the output is the value,
which will unlock the region for execution, if it is correct.

Only one image load is attempted, the image is supposed to be located
in the flash at the offset of CONFIG_RW_MEM_OFF.

BRANCH=none
BUG=chrome-os-partner:43025
TEST=with the rest of the patches applied the RO image successfully
     verifies and starts up the RW image.

Change-Id: I26e1fbdaeb8b23d519c1a328526a3422231bb322
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/311316
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2015-11-10 06:54:43 -08:00

55 lines
1.5 KiB
C

/* Copyright 2015 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "debug_printf.h"
#include "link_defs.h"
#include "registers.h"
#include "setup.h"
/* Is there a system wide function for this? */
void halt(void)
{
while (1)
;
}
void checkBuildVersion(void)
{
uint32_t last_sync = GREG32(SWDP, P4_LAST_SYNC);
if (last_sync == GC_SWDP_P4_LAST_SYNC_DEFAULT)
return;
debug_printf("compiled for %u, not willing to run on %u\n",
GC_SWDP_P4_LAST_SYNC_DEFAULT, last_sync);
halt();
}
void unlockFlashForRW(void)
{
uint32_t text_end = ((uint32_t)(&__ro_end) +
(uint32_t)(&__data_end) -
(uint32_t)(&__data_start) +
CONFIG_FLASH_BANK_SIZE)
& ~(CONFIG_FLASH_BANK_SIZE - 1);
GREG32(GLOBALSEC, FLASH_REGION1_BASE_ADDR) = text_end;
GREG32(GLOBALSEC, FLASH_REGION1_SIZE) =
CONFIG_FLASH_SIZE - text_end - 1;
GWRITE_FIELD(GLOBALSEC, FLASH_REGION1_CTRL, EN, 1);
GWRITE_FIELD(GLOBALSEC, FLASH_REGION1_CTRL, RD_EN, 1);
GWRITE_FIELD(GLOBALSEC, FLASH_REGION1_CTRL, WR_EN, 0);
}
void disarmRAMGuards(void)
{
GWRITE_FIELD(GLOBALSEC, CPU0_D_REGION0_CTRL, EN, 1);
GWRITE_FIELD(GLOBALSEC, CPU0_D_REGION0_CTRL, RD_EN, 1);
GWRITE_FIELD(GLOBALSEC, CPU0_D_REGION0_CTRL, WR_EN, 1);
GWRITE_FIELD(GLOBALSEC, CPU0_D_REGION1_CTRL, EN, 1);
GWRITE_FIELD(GLOBALSEC, CPU0_D_REGION1_CTRL, RD_EN, 1);
GWRITE_FIELD(GLOBALSEC, CPU0_D_REGION1_CTRL, WR_EN, 1);
}