[coreboot-gerrit] Patch set updated for coreboot: rmodule: use program.ld for linking

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Tue Sep 8 13:59:34 CET 2015


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11517

-gerrit

commit ee5a5279e53ff9c5229ce56651be1e39cc131b04
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Sat Sep 5 12:59:26 2015 -0500

    rmodule: use program.ld for linking
    
    Bring rmodule linking into the common linking method.
    The __rmodule_entry symbol was removed while using
    a more common _start symbol. The rmodtool will honor
    the entry point found within the ELF header. Add
    ENV_RMODULE so that one can distinguish the environment
    when generating linker scripts for rmodules. Lastly,
    directly use program.ld for the rmodule.ld linker script.
    
    BUG=chrome-os-partner:44827
    BRANCH=None
    TEST=Built rambi and analyzed the relocatable ramstage,
         sipi_vector, and smm rmodules.
    
    Change-Id: Iaa499eb229d8171272add9ee6d27cff75e7534ac
    Signed-off-by: Aaron Durbin <adubin at chromium.org>
---
 Makefile.inc                          |   3 +
 src/arch/arm64/include/arch/header.ld |  10 +++-
 src/arch/arm64/stage_entry.S          |   4 +-
 src/arch/x86/c_start.S                |   2 -
 src/arch/x86/include/arch/header.ld   |   2 +-
 src/cpu/x86/Makefile.inc              |   4 +-
 src/cpu/x86/sipi_vector.S             |  10 ++--
 src/cpu/x86/smm/smm_stub.S            |   6 +-
 src/include/memlayout.h               |   4 +-
 src/include/rmodule.h                 |   4 +-
 src/include/rules.h                   |  16 ++++++
 src/lib/program.ld                    |  15 +++--
 src/lib/rmodule.ld                    | 101 ++--------------------------------
 util/cbfstool/rmodule.c               |   8 +--
 14 files changed, 64 insertions(+), 125 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index be6021b..4add195 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -72,6 +72,9 @@ classes-y := ramstage romstage bootblock smm smmstub cpu_microcode libverstage v
 # Add dynamic classes for rmodules
 $(foreach supported_arch,$(ARCH_SUPPORTED), \
 	    $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
+# Provide a macro to determine environment for free standing rmodules.
+$(foreach supported_arch,$(ARCH_SUPPORTED), \
+	$(eval rmodules_$(supported_arch)-generic-ccopts += -D__RMODULE__))
 
 #######################################################################
 # Helper functions for math and various file placement matters.
diff --git a/src/arch/arm64/include/arch/header.ld b/src/arch/arm64/include/arch/header.ld
index fa8fdfa..55b4cb7 100644
--- a/src/arch/arm64/include/arch/header.ld
+++ b/src/arch/arm64/include/arch/header.ld
@@ -17,6 +17,8 @@
  * Foundation, Inc.
  */
 
+#include <rules.h>
+
 /* We use ELF as output format. So that we can debug the code in some form. */
 OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
 OUTPUT_ARCH(aarch64)
@@ -26,7 +28,13 @@ PHDRS
 	to_load PT_LOAD;
 }
 
-#ifdef __BOOTBLOCK__
+#if ENV_BOOTBLOCK
 TARGET(binary)
 #endif
+
+/* secmon uses rmodules */
+#if ENV_RMODULE
+ENTRY(_start)
+#else
 ENTRY(stage_entry)
+#endif
diff --git a/src/arch/arm64/stage_entry.S b/src/arch/arm64/stage_entry.S
index 4e15dbb..dbc6cad 100644
--- a/src/arch/arm64/stage_entry.S
+++ b/src/arch/arm64/stage_entry.S
@@ -136,12 +136,12 @@ ENDPROC(arm64_c_environment)
 	2002:
 .endm
 
-ENTRY(__rmodule_entry)
+ENTRY(_start)
 	split_bsp_path
 	/* Save the arguments to secmon in x25 */
 	mov	x25, x0
 	b	arm64_c_environment
-ENDPROC(__rmodule_entry)
+ENDPROC(_start)
 
 /*
  * Setup SCTLR so that:
diff --git a/src/arch/x86/c_start.S b/src/arch/x86/c_start.S
index 582966b..ad4589a 100644
--- a/src/arch/x86/c_start.S
+++ b/src/arch/x86/c_start.S
@@ -23,8 +23,6 @@ thread_stacks:
 	.code32
 #endif
 	.globl _start
-	.globl __rmodule_entry
-__rmodule_entry:
 _start:
 	cli
 	lgdt	%cs:gdtaddr
diff --git a/src/arch/x86/include/arch/header.ld b/src/arch/x86/include/arch/header.ld
index 55547ad..0262c92 100644
--- a/src/arch/x86/include/arch/header.ld
+++ b/src/arch/x86/include/arch/header.ld
@@ -24,7 +24,7 @@ PHDRS
 	to_load PT_LOAD;
 }
 
-#if ENV_RAMSTAGE
+#if ENV_RAMSTAGE || ENV_RMODULE
 ENTRY(_start)
 #elif ENV_ROMSTAGE
 ENTRY(protected_start)
diff --git a/src/cpu/x86/Makefile.inc b/src/cpu/x86/Makefile.inc
index 9ec0768..e9394b2 100644
--- a/src/cpu/x86/Makefile.inc
+++ b/src/cpu/x86/Makefile.inc
@@ -20,9 +20,9 @@ $(SIPI_DOTO): $(dir $(SIPI_ELF))sipi_vector.rmodules_$(ARCH-ramstage-y).o
 	$(CC_rmodules_$(ARCH-ramstage-y)) $(CFLAGS_rmodules_$(ARCH-ramstage-y)) -nostdlib -r -o $@ $^
 
 ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y)
-$(eval $(call rmodule_link,$(SIPI_ELF), $(SIPI_ELF:.elf=.o), 0,x86_32))
+$(eval $(call rmodule_link,$(SIPI_ELF), $(SIPI_DOTO), 0,x86_32))
 else
-$(eval $(call rmodule_link,$(SIPI_ELF), $(SIPI_ELF:.elf=.o), 0,x86_64))
+$(eval $(call rmodule_link,$(SIPI_ELF), $(SIPI_DOTO), 0,x86_64))
 endif
 
 $(SIPI_BIN): $(SIPI_RMOD)
diff --git a/src/cpu/x86/sipi_vector.S b/src/cpu/x86/sipi_vector.S
index c7b1097..0887b0a 100644
--- a/src/cpu/x86/sipi_vector.S
+++ b/src/cpu/x86/sipi_vector.S
@@ -56,10 +56,8 @@ ap_count:
 
 .text
 .code16
-.global ap_start
-.global __rmodule_entry
-__rmodule_entry:
-ap_start:
+.global _start
+_start:
 	cli
 	xorl	%eax, %eax
 	movl	%eax, %cr3    /* Invalidate TLB*/
@@ -74,9 +72,9 @@ ap_start:
 
 	/* The gdtaddr needs to be releative to the data segment in order
 	 * to properly dereference it. The .text section comes first in an
-	 * rmodule so ap_start can be used as a proxy for the load address. */
+	 * rmodule so _start can be used as a proxy for the load address. */
 	movl	$(gdtaddr), %ebx
-	sub	$(ap_start), %ebx
+	sub	$(_start), %ebx
 
 	data32 lgdt (%ebx)
 
diff --git a/src/cpu/x86/smm/smm_stub.S b/src/cpu/x86/smm/smm_stub.S
index 5fbec28..ead597c 100644
--- a/src/cpu/x86/smm/smm_stub.S
+++ b/src/cpu/x86/smm/smm_stub.S
@@ -59,10 +59,8 @@ fallback_stack_top:
 
 .text
 .code16
-.global smm_handler_start
-.global __rmodule_entry
-__rmodule_entry:
-smm_handler_start:
+.global _start
+_start:
 	movl	$(smm_relocate_gdt), %ebx
 	data32	lgdt (%ebx)
 
diff --git a/src/include/memlayout.h b/src/include/memlayout.h
index d4be3f8..a25e018 100644
--- a/src/include/memlayout.h
+++ b/src/include/memlayout.h
@@ -47,9 +47,9 @@
 #define ARCH_STAGE_HAS_BSS_SECTION 1
 #endif
 
-/* Default is that currently ramstage and smm only has a heap. */
+/* Default is that currently ramstage, smm, and rmodules have a heap. */
 #ifndef ARCH_STAGE_HAS_HEAP_SECTION
-#define ARCH_STAGE_HAS_HEAP_SECTION (ENV_RAMSTAGE || ENV_SMM)
+#define ARCH_STAGE_HAS_HEAP_SECTION (ENV_RAMSTAGE || ENV_SMM || ENV_RMODULE)
 #endif
 
 #define STR(x) #x
diff --git a/src/include/rmodule.h b/src/include/rmodule.h
index 719c6a6..03cdf76 100644
--- a/src/include/rmodule.h
+++ b/src/include/rmodule.h
@@ -73,9 +73,9 @@ struct rmodule {
 };
 
 #if IS_ENABLED(CONFIG_RELOCATABLE_MODULES)
-/* Rmodules have an entry point of named __rmodule_entry. */
+/* Rmodules have an entry point of named _start. */
 #define RMODULE_ENTRY(entry_) \
-	void __rmodule_entry(void *) __attribute__((alias (STRINGIFY(entry_))))
+	void _start(void *) __attribute__((alias (STRINGIFY(entry_))))
 #else
 #define RMODULE_ENTRY(entry_)
 #endif
diff --git a/src/include/rules.h b/src/include/rules.h
index 607d7fc..7523347 100644
--- a/src/include/rules.h
+++ b/src/include/rules.h
@@ -30,6 +30,7 @@
 #define ENV_SMM 0
 #define ENV_SECMON 0
 #define ENV_VERSTAGE 0
+#define ENV_RMODULE 0
 
 #elif defined(__ROMSTAGE__)
 #define ENV_BOOTBLOCK 0
@@ -38,6 +39,7 @@
 #define ENV_SMM 0
 #define ENV_SECMON 0
 #define ENV_VERSTAGE 0
+#define ENV_RMODULE 0
 
 #elif defined(__SMM__)
 #define ENV_BOOTBLOCK 0
@@ -46,6 +48,7 @@
 #define ENV_SMM 1
 #define ENV_SECMON 0
 #define ENV_VERSTAGE 0
+#define ENV_RMODULE 0
 
 #elif defined(__SECMON__)
 #define ENV_BOOTBLOCK 0
@@ -54,6 +57,7 @@
 #define ENV_SMM 0
 #define ENV_SECMON 1
 #define ENV_VERSTAGE 0
+#define ENV_RMODULE 0
 
 #elif defined(__VERSTAGE__)
 #define ENV_BOOTBLOCK 0
@@ -62,6 +66,7 @@
 #define ENV_SMM 0
 #define ENV_SECMON 0
 #define ENV_VERSTAGE 1
+#define ENV_RMODULE 0
 
 #elif defined(__RAMSTAGE__)
 #define ENV_BOOTBLOCK 0
@@ -70,6 +75,16 @@
 #define ENV_SMM 0
 #define ENV_SECMON 0
 #define ENV_VERSTAGE 0
+#define ENV_RMODULE 0
+
+#elif defined(__RMODULE__)
+#define ENV_BOOTBLOCK 0
+#define ENV_ROMSTAGE 0
+#define ENV_RAMSTAGE 0
+#define ENV_SMM 0
+#define ENV_SECMON 0
+#define ENV_VERSTAGE 0
+#define ENV_RMODULE 1
 
 #else
 /*
@@ -84,6 +99,7 @@
 #define ENV_SMM 0
 #define ENV_SECMON 0
 #define ENV_VERSTAGE 0
+#define ENV_RMODULE 0
 #endif
 
 /* For romstage and ramstage always build with simple device model, ie.
diff --git a/src/lib/program.ld b/src/lib/program.ld
index 02d017a..43b1fea 100644
--- a/src/lib/program.ld
+++ b/src/lib/program.ld
@@ -33,14 +33,14 @@
 	*(.text);
 	*(.text.*);
 
-#if ENV_RAMSTAGE || ENV_ROMSTAGE
+#if ENV_RAMSTAGE || ENV_ROMSTAGE || ENV_RMODULE
 	ALIGN_COUNTER(ARCH_POINTER_ALIGN_SIZE)
 	SYMBOL_CURRENT_LOC(cbmem_init_hooks)
 	KEEP(*(.rodata.cbmem_init_hooks));
 	SYMBOL_CURRENT_LOC(ecbmem_init_hooks)
 #endif
 
-#if ENV_RAMSTAGE
+#if ENV_RAMSTAGE || ENV_RMODULE
 	ALIGN_COUNTER(ARCH_POINTER_ALIGN_SIZE)
 	SYMBOL_CURRENT_LOC(pci_drivers)
 	KEEP(*(.rodata.pci_driver));
@@ -74,13 +74,20 @@
 .data : {
 	ALIGN_COUNTER(ARCH_CACHELINE_ALIGN_SIZE)
 	SYMBOL_CURRENT_LOC(data)
+
+#if ENV_RMODULE
+	SYMBOL_CURRENT_LOC(rmodule_params)
+	KEEP(*(.module_parameters));
+	SYMBOL_CURRENT_LOC(ermodule_params)
+#endif
+
 	*(.data);
 	*(.data.*);
 
 #ifdef __PRE_RAM__
 	PROVIDE(_preram_cbmem_console = .);
 	PROVIDE(_epreram_cbmem_console = _preram_cbmem_console);
-#elif ENV_RAMSTAGE
+#elif ENV_RAMSTAGE || ENV_RMODULE
 	ALIGN_COUNTER(ARCH_POINTER_ALIGN_SIZE)
 	SYMBOL_CURRENT_LOC(bs_init_begin)
 	KEEP(*(.bs_init));
@@ -111,7 +118,7 @@
 .heap : {
 	ALIGN_COUNTER(ARCH_POINTER_ALIGN_SIZE)
 	SYMBOL_CURRENT_LOC(heap)
-	. += CONFIG_HEAP_SIZE;
+	. += (ENV_RMODULE ? __heap_size : CONFIG_HEAP_SIZE);
 	ALIGN_COUNTER(ARCH_POINTER_ALIGN_SIZE)
 	SYMBOL_CURRENT_LOC(eheap)
 }
diff --git a/src/lib/rmodule.ld b/src/lib/rmodule.ld
index f5d5f06..340fe7a 100644
--- a/src/lib/rmodule.ld
+++ b/src/lib/rmodule.ld
@@ -12,103 +12,14 @@
  * won't be a consistent mapping between the flat blob and the loaded program.
  */
 
-BASE_ADDRESS = 0x00000;
-
-ENTRY(__rmodule_entry);
+#include <memlayout.h>
+#include <arch/header.ld>
 
 SECTIONS
 {
-	. = BASE_ADDRESS;
-
-	.payload :  {
-		/* C code of the module. */
-		_program = .;
-		*(.text._start);
-		*(.text.stage_entry);
-		*(.text);
-		*(.text.*);
-		/* C read-only data. */
-		. = ALIGN(16);
-
-#if IS_ENABLED(CONFIG_COVERAGE)
-		__CTOR_LIST__ = .;
-		*(.ctors);
-		LONG(0);
-		LONG(0);
-		__CTOR_END__ = .;
-#endif
-
-		/* The driver sections are to allow linking coreboot's
-		 * ramstage with the rmodule linker. Any changes made in
-		 * ramstage.ld should be made here as well. */
-		. = ALIGN(8);
-		_pci_drivers = . ;
-		KEEP(*(.rodata.pci_driver));
-		_epci_drivers = . ;
-		. = ALIGN(8);
-		_cpu_drivers = . ;
-		KEEP(*(.rodata.cpu_driver));
-		_ecpu_drivers = . ;
-		. = ALIGN(8);
-		_bs_init_begin = .;
-		KEEP(*(.bs_init));
-		LONG(0);
-		LONG(0);
-		_bs_init_end = .;
-		_cbmem_init_hooks = .;
-		KEEP(*(.rodata.cbmem_init_hooks));
-		_ecbmem_init_hooks = .;
-
-		. = ALIGN(8);
-
-		*(.rodata);
-		*(.rodata.*);
-		. = ALIGN(8);
-
-		/* The parameters section can be used to pass parameters
-		 * to a module, however there has to be an prior agreement
-		 * on how to interpret the parameters. */
-		_module_params_begin = .;
-		KEEP(*(.module_parameters));
-		_module_params_end = .;
-		. = ALIGN(8);
-
-		/* Data section. */
-		. = ALIGN(64);	/* Mirror cache line alignment from ramstage. */
-		_sdata = .;
-		*(.data);
-		*(.data.*);
-		. = ALIGN(8);
-		_edata = .;
-
-		. = ALIGN(8);
-	}
-
-	.bss (NOLOAD) : {
-		/* C uninitialized data of the module. */
-		_bss = .;
-		*(.bss);
-		*(.bss.*)
-		*(.sbss)
-		*(.sbss.*)
-		*(COMMON);
-		. = ALIGN(8);
-		_ebss = .;
-
-		/*
-		 * Place the heap after BSS. The heap size is passed in by
-		 * by way of ld --defsym=__heap_size=<>
-		 */
-		_heap = .;
-		. = . + __heap_size;
-		_eheap = .;
-		_eprogram = .;
-	}
+	SET_COUNTER(rmodule, 0x00000000)
 
-	/DISCARD/ : {
-		/* Drop unnecessary sections. */
-		*(.eh_frame);
-		*(.note);
-		*(.note.*);
-	}
+	/* program.ld is directly included because there's no one particular
+	 * class that rmodule is used on. */
+	#include <lib/program.ld>
 }
diff --git a/util/cbfstool/rmodule.c b/util/cbfstool/rmodule.c
index f93f4f6..c35eff7 100644
--- a/util/cbfstool/rmodule.c
+++ b/util/cbfstool/rmodule.c
@@ -402,11 +402,11 @@ static int populate_program_info(struct rmod_context *ctx)
 		break;
 	}
 
-	if (populate_sym(ctx, "_module_params_begin", &ctx->parameters_begin,
+	if (populate_sym(ctx, "_rmodule_params", &ctx->parameters_begin,
 	                 nsyms, strtab))
 		return -1;
 
-	if (populate_sym(ctx, "_module_params_end", &ctx->parameters_end,
+	if (populate_sym(ctx, "_ermodule_params", &ctx->parameters_end,
 	                 nsyms, strtab))
 		return -1;
 
@@ -416,8 +416,8 @@ static int populate_program_info(struct rmod_context *ctx)
 	if (populate_sym(ctx, "_ebss", &ctx->bss_end, nsyms, strtab))
 		return -1;
 
-	if (populate_sym(ctx, "__rmodule_entry", &ctx->entry, nsyms, strtab))
-		return -1;
+	/* Honor the entry point within the ELF header. */
+	ctx->entry = ehdr->e_entry;
 
 	/* Link address is the virtual address of the program segment. */
 	ctx->link_addr = ctx->phdr->p_vaddr;



More information about the coreboot-gerrit mailing list