armv7: unify stage hand-off routines

This replaces the current stage-specific exit/entry functions with
generic versions. Now all stages compile with stage_entry(), which
is placed at .text.stage_entry.armv7, and stage_exit().

Snow's ramstage files are also updated to avoid build breakage.

Change-Id: I953a2c4b8121bd4b66c3362557997a9ca3aa53b0
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: http://review.coreboot.org/2254
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
David Hendricks 2013-01-31 17:05:50 -08:00 committed by Ronald G. Minnich
parent 79e36d9060
commit 50c0a50ac6
11 changed files with 111 additions and 48 deletions

View File

@ -104,6 +104,14 @@ $(objcbfs)/%.elf: $(objcbfs)/%.debug
$(OBJCOPY) --add-gnu-debuglink=$< $@.tmp $(OBJCOPY) --add-gnu-debuglink=$< $@.tmp
mv $@.tmp $@ mv $@.tmp $@
stages_c = $(src)/arch/armv7/stages.c
stages_o = $(obj)/arch/armv7/stages.o
$(stages_o): $(stages_c)
@printf " CC $(subst $(obj)/,,$(@))\n"
$(CC) -Wa,-acdlns -I. $(INCLUDES) -c -o $@ $< -marm
################################################################################ ################################################################################
# Build the coreboot_ram (stage 2) # Build the coreboot_ram (stage 2)
@ -115,12 +123,12 @@ else
$(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/armv7/coreboot_ram.ld $< $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/armv7/coreboot_ram.ld $<
endif endif
$(objgenerated)/coreboot_ram.o: $$(ramstage-objs) $(LIBGCC_FILE_NAME) $(objgenerated)/coreboot_ram.o: $(stages_o) $$(ramstage-objs) $(LIBGCC_FILE_NAME)
@printf " CC $(subst $(obj)/,,$(@))\n" @printf " CC $(subst $(obj)/,,$(@))\n"
ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
$(LD) -m -m armelf_linux_eabi -r -o $@ --wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3 --wrap __uidiv --wrap __do_div64 --start-group $(ramstage-objs) $(LIBGCC_FILE_NAME) --end-group $(LD) -m -m armelf_linux_eabi -r -o $@ --wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3 --wrap __uidiv --wrap __do_div64 --start-group $(ramstage-objs) $(LIBGCC_FILE_NAME) --end-group
else else
$(CC) $(CFLAGS) -nostdlib -r -o $@ -Wl,--start-group $(ramstage-objs) $(LIBGCC_FILE_NAME) -Wl,--end-group $(CC) $(CFLAGS) -nostdlib -r -o $@ -Wl,--start-group $(stages_o) $(ramstage-objs) $(LIBGCC_FILE_NAME) -Wl,--end-group
endif endif
################################################################################ ################################################################################
@ -239,18 +247,11 @@ $(objgenerated)/bootblock_inc.S: $$(bootblock_inc)
@printf " GEN $(subst $(obj)/,,$(@))\n" @printf " GEN $(subst $(obj)/,,$(@))\n"
printf '$(foreach crt0,$(bootblock_inc),#include "$(crt0)"\n)' > $@ printf '$(foreach crt0,$(bootblock_inc),#include "$(crt0)"\n)' > $@
bootblock_exit_c = $(src)/arch/armv7/bootblock_exit.c
bootblock_exit_o = $(obj)/arch/armv7/bootblock_exit.o
$(bootblock_exit_o): $(bootblock_exit_c)
@printf " CC $(subst $(obj)/,,$(@))\n"
$(CC) -Wa,-acdlns -I. $(INCLUDES) -c -o $@ $< -marm
$(objgenerated)/bootblock.o: $(objgenerated)/bootblock.s $(objgenerated)/bootblock.o: $(objgenerated)/bootblock.s
@printf " CC $(subst $(obj)/,,$(@))\n" @printf " CC $(subst $(obj)/,,$(@))\n"
$(CC) -Wa,-acdlns -c -o $@ $< > $(basename $@).disasm $(CC) -Wa,-acdlns -c -o $@ $< > $(basename $@).disasm
BOOTBLOCK_OBJS = $(objgenerated)/bootblock.o $(bootblock_exit_o) #BOOTBLOCK_OBJS = $(objgenerated)/bootblock.o $(bootblock_exit_o)
$(objgenerated)/bootblock.s: $(objgenerated)/bootblock_inc.S $(obj)/config.h $(obj)/build.h $(objgenerated)/bootblock.s: $(objgenerated)/bootblock_inc.S $(obj)/config.h $(obj)/build.h
@printf " CC $(subst $(obj)/,,$(@))\n" @printf " CC $(subst $(obj)/,,$(@))\n"
@ -262,39 +263,32 @@ $(objgenerated)/bootblock.inc: $(src)/arch/armv7/$(subst ",,$(CONFIG_BOOTBLOCK_S
$< > $(objgenerated)/bootblock.inc.d $< > $(objgenerated)/bootblock.inc.d
$(CC) -c -S $(CFLAGS) -I. $(INCLUDES) $< -o $@ $(CC) -c -S $(CFLAGS) -I. $(INCLUDES) $< -o $@
$(objcbfs)/bootblock.debug: $(BOOTBLOCK_OBJS) $(objgenerated)/bootblock.ld $(objcbfs)/bootblock.debug: $(objgenerated)/bootblock.o $(objgenerated)/bootblock.ld
@printf " LINK $(subst $(obj)/,,$(@))\n" @printf " LINK $(subst $(obj)/,,$(@))\n"
ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
$(LD) -m armelf_linux_eabi -static -o $@.tmp -L$(obj) $< -T $(objgenerated)/bootblock.ld $(LD) -m armelf_linux_eabi -static -o $@.tmp -L$(obj) $< -T $(objgenerated)/bootblock.ld
else else
$(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/bootblock.ld -Wl,--start-group $(BOOTBLOCK_OBJS) $(LIBGCC_FILE_NAME) -Wl,--end-group $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/bootblock.ld -Wl,--start-group $(objgenerated)/bootblock.o $(stages) $(LIBGCC_FILE_NAME) -Wl,--end-group
endif endif
################################################################################ ################################################################################
# Build the romstage # Build the romstage
romstage_main_c = $(src)/arch/armv7/romstage_main.c
romstage_main_o = $(obj)/arch/armv7/romstage_main.o
$(romstage_main_o): $(romstage_main_c)
@printf " CC $(subst $(obj)/,,$(@))\n"
$(CC) -nostdlib -nostartfiles -static -c -o $@ $< -marm
# FIXME(dhendrix): added debug printfs # FIXME(dhendrix): added debug printfs
$(objcbfs)/romstage_null.debug: $$(romstage-objs) $(romstage_main_o) $(objgenerated)/romstage_null.ld $(objcbfs)/romstage_null.debug: $$(romstage-objs) $(stages_o) $(objgenerated)/romstage_null.ld
@printf " LINK $(subst $(obj)/,,$(@))\n" @printf " LINK $(subst $(obj)/,,$(@))\n"
ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
$(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) -T $(objgenerated)/romstage_null.ld $(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) -T $(objgenerated)/romstage_null.ld
else else
$(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_null.ld -Wl,--start-group $(romstage-objs) $(romstage_main_o) $(LIBGCC_FILE_NAME) -Wl,--end-group $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_null.ld -Wl,--start-group $(romstage-objs) $(stages_o) $(LIBGCC_FILE_NAME) -Wl,--end-group
endif endif
$(objcbfs)/romstage_xip.debug: $$(romstage-objs) $(objgenerated)/romstage_xip.ld $(objcbfs)/romstage_xip.debug: $$(romstage-objs) $(objgenerated)/romstage_xip.ld
@printf " LINK $(subst $(obj)/,,$(@))\n" @printf " LINK $(subst $(obj)/,,$(@))\n"
ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
$(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) $(romstage_main_o) -T $(objgenerated)/romstage_xip.ld $(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) $(stages_o) -T $(objgenerated)/romstage_xip.ld
else else
$(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_xip.ld -Wl,--start-group $(romstage-objs) $(romstage_main_o) $(LIBGCC_FILE_NAME) -Wl,--end-group $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_xip.ld -Wl,--start-group $(romstage-objs) $(stages_o) $(LIBGCC_FILE_NAME) -Wl,--end-group
endif endif
$(objgenerated)/romstage_null.ld: $$(ldscripts) $(obj)/ldoptions $(objgenerated)/romstage_null.ld: $$(ldscripts) $(obj)/ldoptions

View File

@ -20,9 +20,11 @@
*/ */
#include <bootblock_common.h> #include <bootblock_common.h>
#include <arch/bootblock_exit.h>
#include <arch/cbfs.h> #include <arch/cbfs.h>
#include <arch/hlt.h> #include <arch/hlt.h>
#include <arch/stages.h>
#include "stages.c"
static int boot_cpu(void) static int boot_cpu(void)
{ {
@ -34,7 +36,7 @@ static int boot_cpu(void)
return 1; return 1;
} }
void main(unsigned long bist) void main(void)
{ {
const char *target1 = "fallback/romstage"; const char *target1 = "fallback/romstage";
unsigned long romstage_entry; unsigned long romstage_entry;
@ -49,6 +51,6 @@ void main(unsigned long bist)
CBFS_DEFAULT_MEDIA, target1); CBFS_DEFAULT_MEDIA, target1);
printk(BIOS_INFO, "bootblock main(): jumping to romstage\n"); printk(BIOS_INFO, "bootblock main(): jumping to romstage\n");
if (romstage_entry) bootblock_exit(romstage_entry); if (romstage_entry) stage_exit(romstage_entry);
hlt(); hlt();
} }

View File

@ -32,6 +32,7 @@ SECTIONS
*/ */
.text : { .text : {
_text = .; _text = .;
*(.text.stage_entry.armv7);
*(.text); *(.text);
*(.text.*); *(.text.*);
. = ALIGN(16); . = ALIGN(16);

View File

@ -1,7 +1,7 @@
/* /*
* This file is part of the coreboot project. * This file is part of the coreboot project.
* *
* Copyright (C) 2012 The ChromiumOS Authors. All rights reserved. * Copyright (C) 2013 The ChromiumOS Authors
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,13 +17,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
void main(void); #ifndef __ARCH_STAGES_H
#define __ARCH_STAGES_H
/* romstage_main is simply a stub to invoke main(), to handle ARM mode switching extern void main(void);
* (ARM/Thumb) properly. */
void romstage_main(void) __attribute__((section(".text.entry.armv7"))); void stage_entry(void) __attribute__((section(".text.stage_entry.armv7")));
void romstage_main(void) void stage_exit(unsigned long);
{
main(); #endif
}

View File

@ -9,8 +9,6 @@ romstage-y += syslib.c
#ramstage-y += printk_init.c #ramstage-y += printk_init.c
#romstage-y += walkcbfs.S #romstage-y += walkcbfs.S
ramstage-y += c_start.S
ramstage-y += div0.c ramstage-y += div0.c
ramstage-y += div64.S ramstage-y += div64.S
ramstage-y += hang_spl.c ramstage-y += hang_spl.c

View File

@ -1,9 +0,0 @@
.section ".text"
.globl _start
_start:
bl _hardwaremain
_hardwaremain: .word hardwaremain
@ .word hardwaremain

View File

@ -38,7 +38,7 @@ SECTIONS
.romtext . : { .romtext . : {
_rom = .; _rom = .;
_start = .; _start = .;
*(.text.entry.armv7); *(.text.stage_entry.armv7);
*(.text.startup); *(.text.startup);
*(.text); *(.text);
} }

45
src/arch/armv7/stages.c Normal file
View File

@ -0,0 +1,45 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* This file contains entry/exit functions for each stage during coreboot
* execution (bootblock entry and ramstage exit will depend on external
* loading.
*
* Unlike other files, this one should be compiled with a -m option to
* specify a pre-determined instruction set. The is to ensure consistency
* in the CPU operating mode (ARM or Thumb) when hand-off between stages
* occurs.
*
* Entry points must be placed at the location the previous stage jumps
* to (the lowest address in the stage image). This is done by giving
* stage_entry() its own section in .text and placing it first in the
* linker script.
*/
#include <arch/stages.h>
void stage_entry(void)
{
main();
}
void stage_exit(unsigned long addr)
{
__attribute__((noreturn)) void (*doit)(void) = (void *)addr;
doit();
}

View File

@ -28,6 +28,7 @@ romstage-y += romstage.c
romstage-y += smdk5250_spl.c romstage-y += smdk5250_spl.c
ramstage-y += smdk5250_spl.c ramstage-y += smdk5250_spl.c
#ramstage-y += mainboard.c #ramstage-y += mainboard.c
ramstage-y += ramstage.c
# romstage-$(CONFIG_CHROMEOS) += chromeos.c # romstage-$(CONFIG_CHROMEOS) += chromeos.c

View File

@ -18,6 +18,7 @@
*/ */
#include <device/device.h> #include <device/device.h>
#include <console/console.h>
// mainboard_enable is executed as first thing after // mainboard_enable is executed as first thing after
// enumerate_buses(). // enumerate_buses().
@ -31,4 +32,3 @@ struct chip_operations mainboard_ops = {
.name = "Samsung/Google ARM ChromeBook", .name = "Samsung/Google ARM ChromeBook",
.enable_dev = mainboard_enable, .enable_dev = mainboard_enable,
}; };

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2013 The ChromeOS Authors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <console/console.h>
void main(void)
{
// volatile unsigned long *pshold = (unsigned long *)0x1004330c;
// *pshold &= ~0x100; /* shut down */
/* FIXME: console_init() seems to cause things to die... Maybe
we need to reset our stack pointer? */
// console_init();
printk(BIOS_INFO, "hello from ramstage\n");
while (1);
}