Skip to contentSkip to conversation

x86: Various Patches

PATCH New Graeme Russ 3 participants 16 messages Aug 22, 2010 – Aug 23, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86: Various Patches

This is a patch-series I intend to apply to the x86 repository ready for the next merge window.

Patches 1 & 2 are fixes for build breakages caused by non-x86 mainline patches

Patch 3 fixes a cold-boot breakage

Patch 4 removes unmaintained boards

Patch 5 Is a trivial change suggested by Heiko Schocher

The remaining patches are fairly innocuous

#1 lore raw

PATCH 1/13 x86: Fix do_go_exec() - const argv[]

Commit 54841ab50c20d6fa6c9cc3eb826989da3a22d934 made the argv parameter to do_go_exec() const but did not allow for the fact that argv[-1] is set to point to the global data structure and relies on argv being non- const.

With this patch, do_go_exec() creates a new copy of the argv array with an extra element to store global data pointer rather than simply clobbering an arbitrary memory location.

---
 arch/i386/lib/board.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)
arch/i386/lib/board.c +20 -5
index 684cdb8..93f910b 100644
@@ -431,15 +431,30 @@ void hang (void)
 	for (;;);
 }
 
-unsigned long do_go_exec (ulong (*entry)(int, char *[]), int argc, char * const argv[])
+unsigned long do_go_exec (ulong (*entry)(int, char * const []), int argc, char * const argv[])
 {
+	unsigned long ret = 0;
+	char **argv_tmp;
+
 	/*
-	 * x86 does not use a dedicated register to pass the pointer
-	 * to the global_data
+	 * x86 does not use a dedicated register to pass the pointer to
+	 * the global_data, so it is instead passed as argv[-1]. By using
+	 * argv[-1], the called 'Application' can use the contents of
+	 * argv natively. However, to safely use argv[-1] a new copy of
+	 * argv is needed with the extra element
 	 */
-	argv[-1] = (char *)gd;
+	argv_tmp = malloc(sizeof(char *) * (argc + 1));
+
+	if (argv_tmp) {
+		argv_tmp[0] = (char *)gd;
+
+		memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
+
+		ret = (entry) (argc, &argv_tmp[1]);
+		free(argv_tmp);
+	}
 
-	return (entry) (argc, argv);
+	return ret;
 }
 
 void setup_pcat_compatibility(void)
Signature · 1 line
1.7.1.422.g049e9
#2 lore raw

PATCH 2/13 x86: Add do_bdinfo()

In reply to Graeme Russ

x86 failed to compile with a message "a case for this architecture does not exist!" - Add do_bdinfo() for this arch

---
 common/cmd_bdinfo.c |   48 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 45 insertions(+), 3 deletions(-)
common/cmd_bdinfo.c +45 -3
index fbe73f1..fd6a58c 100644
@@ -35,7 +35,7 @@ static void print_num(const char *, ulong);
 static void print_eth(int idx);
 #endif
 
-#ifndef CONFIG_ARM	/* PowerPC and other */
+#if (!defined(CONFIG_ARM) && !defined(CONFIG_X86))
 static void print_lnum(const char *, u64);
 #endif
 
@@ -348,6 +348,45 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	return 0;
 }
 
+#elif defined(CONFIG_X86)
+
+static void print_str(const char *, const char *);
+
+int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	int i;
+	bd_t *bd = gd->bd;
+	char buf[32];
+
+	print_num ("env_t",		(ulong)bd->bi_env);
+	print_num ("boot_params",	(ulong)bd->bi_boot_params);
+	print_num ("bi_memstart",	bd->bi_memstart);
+	print_num ("bi_memsize",	bd->bi_memsize);
+	print_num ("bi_flashstart",	bd->bi_flashstart);
+	print_num ("bi_flashsize",	bd->bi_flashsize);
+	print_num ("bi_flashoffset",	bd->bi_flashoffset);
+	print_num ("bi_sramstart",	bd->bi_sramstart);
+	print_num ("bi_sramsize",	bd->bi_sramsize);
+	print_num ("bi_bootflags",	bd->bi_bootflags);
+	print_str ("cpufreq",		strmhz(buf, bd->bi_intfreq));
+	print_str ("busfreq",		strmhz(buf, bd->bi_busfreq));
+
+	for (i=0; i<CONFIG_NR_DRAM_BANKS; ++i) {
+		print_num("DRAM bank",	i);
+		print_num("-> start",	bd->bi_dram[i].start);
+		print_num("-> size",	bd->bi_dram[i].size);
+	}
+
+#if defined(CONFIG_CMD_NET)
+	print_eth(0);
+	printf ("ip_addr     = %pI4\n", &bd->bi_ip_addr);
+	print_str ("ethspeed",	    strmhz(buf, bd->bi_ethspeed));
+#endif
+	printf ("baudrate    = %d bps\n", bd->bi_baudrate);
+
+	return 0;
+}
+
 #else
  #error "a case for this architecture does not exist!"
 #endif
@@ -372,14 +411,17 @@ static void print_eth(int idx)
 }
 #endif
 
-#ifndef CONFIG_ARM
+#if (!defined(CONFIG_ARM) && !defined(CONFIG_X86))
 static void print_lnum(const char *name, u64 value)
 {
 	printf ("%-12s= 0x%.8llX\n", name, value);
 }
 #endif
 
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_BLACKFIN)
+#if defined(CONFIG_PPC) || \
+    defined(CONFIG_M68K) || \
+    defined(CONFIG_BLACKFIN) || \
+    defined(CONFIG_X86)
 static void print_str(const char *name, const char *str)
 {
 	printf ("%-12s= %6s MHz\n", name, str);
Signature · 1 line
1.7.1.422.g049e9
#3 lore raw

PATCH 3/13 x86: Fix x86 Cold Boot

In reply to Graeme Russ

Commit 077e1958ca4afe12d88043b123ded058c51b89f7 broke the ability of the x86 port to boot from a cold-reset by removing the initial IDT. Re- instate the initial IDT to allow cold-booting of x86 boards

---
 arch/i386/cpu/start16.S |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/i386/cpu/start16.S +5 -0
index 3e8b2cc..ebe5835 100644
@@ -45,6 +45,7 @@ board_init16_ret:
 	wbinvd
 
 	/* load the temporary Global Descriptor Table */
+o32 cs	lidt	idt_ptr
 o32 cs	lgdt	gdt_ptr
 
 	/* Now, we enter protected mode */
@@ -68,6 +69,10 @@ code32start:
 	.long	_start		/* offset */
 	.word	0x10		/* segment */
 
+idt_ptr:
+	.word	0		/* limit */
+	.long	0		/* base */
+
 /*
  * The following Global Descriptor Table is just enough to get us into
  * 'Flat Protected Mode' - It will be discarded as soon as the final
Signature · 1 line
1.7.1.422.g049e9
#4 lore raw

PATCH 4/13 x86: Remove Unmaintained Boards

In reply to Graeme Russ

The SC520 CDP boards originally implemented by Daniel Engstr??m are now very broken. Attempts to contact Daniel via the email address on the copyright notice have failed. Remove these boards from mainline

---
 MAKEALL                               |    3 -
 board/sc520_cdp/Makefile              |   56 ---
 board/sc520_cdp/config.mk             |   25 -
 board/sc520_cdp/flash.c               |  637 --------------------------
 board/sc520_cdp/flash_old.c           |  458 -------------------
 board/sc520_cdp/sc520_cdp.c           |  396 -----------------
 board/sc520_cdp/sc520_cdp_asm.S       |   85 ----
 board/sc520_cdp/sc520_cdp_asm16.S     |   83 ----
 board/sc520_cdp/sc520_cdp_pci.c       |  271 -----------
 board/sc520_cdp/u-boot.lds            |   91 ----
 board/sc520_spunk/Makefile            |   56 ---
 board/sc520_spunk/config.mk           |   25 -
 board/sc520_spunk/flash.c             |  791 ---------------------------------
 board/sc520_spunk/sc520_spunk.c       |  410 -----------------
 board/sc520_spunk/sc520_spunk_asm.S   |   81 ----
 board/sc520_spunk/sc520_spunk_asm16.S |   83 ----
 board/sc520_spunk/sc520_spunk_pci.c   |  323 --------------
 board/sc520_spunk/u-boot.lds          |   92 ----
 boards.cfg                            |    3 -
 include/configs/sc520_cdp.h           |  220 ---------
 include/configs/sc520_spunk.h         |  250 -----------
 include/configs/sc520_spunk_rel.h     |   32 --
 22 files changed, 0 insertions(+), 4471 deletions(-)
 delete mode 100644 board/sc520_cdp/Makefile
 delete mode 100644 board/sc520_cdp/config.mk
 delete mode 100644 board/sc520_cdp/flash.c
 delete mode 100644 board/sc520_cdp/flash_old.c
 delete mode 100644 board/sc520_cdp/sc520_cdp.c
 delete mode 100644 board/sc520_cdp/sc520_cdp_asm.S
 delete mode 100644 board/sc520_cdp/sc520_cdp_asm16.S
 delete mode 100644 board/sc520_cdp/sc520_cdp_pci.c
 delete mode 100644 board/sc520_cdp/u-boot.lds
 delete mode 100644 board/sc520_spunk/Makefile
 delete mode 100644 board/sc520_spunk/config.mk
 delete mode 100644 board/sc520_spunk/flash.c
 delete mode 100644 board/sc520_spunk/sc520_spunk.c
 delete mode 100644 board/sc520_spunk/sc520_spunk_asm.S
 delete mode 100644 board/sc520_spunk/sc520_spunk_asm16.S
 delete mode 100644 board/sc520_spunk/sc520_spunk_pci.c
 delete mode 100644 board/sc520_spunk/u-boot.lds
 delete mode 100644 include/configs/sc520_cdp.h
 delete mode 100644 include/configs/sc520_spunk.h
 delete mode 100644 include/configs/sc520_spunk_rel.h
MAKEALL +0 -3
index b34ae33..395206a 100755
@@ -818,10 +818,7 @@ LIST_mips_el="			\
 #########################################################################
 
 LIST_I486="		\
-	sc520_cdp	\
 	sc520_eNET	\
-	sc520_spunk	\
-	sc520_spunk_rel	\
 "
 
 LIST_x86="		\
board/sc520_cdp/Makefile deleted +0 -56

56 lines not on this page · raw message

board/sc520_cdp/config.mk deleted +0 -25
deleted file mode 100644
index 2253815..0000000
@@ -1,25 +0,0 @@
-#
-# (C) Copyright 2002
-# Daniel Engstr?m, Omicron Ceti AB, daniel at omicron.se.
-#
-# See file CREDITS for list of people who contributed to this
-# project.
-#
-# 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; either version 2 of
-# the License, or (at your option) any later version.
-#
-# 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
-#
-
-
-TEXT_BASE = 0x387c0000
board/sc520_cdp/flash.c deleted +0 -637

637 lines not on this page · raw message

board/sc520_cdp/flash_old.c deleted +0 -458

458 lines not on this page · raw message

board/sc520_cdp/sc520_cdp.c deleted +0 -396

396 lines not on this page · raw message

board/sc520_cdp/sc520_cdp_asm.S deleted +0 -85

85 lines not on this page · raw message

board/sc520_cdp/sc520_cdp_asm16.S deleted +0 -83

83 lines not on this page · raw message

board/sc520_cdp/sc520_cdp_pci.c deleted +0 -271

271 lines not on this page · raw message

board/sc520_cdp/u-boot.lds deleted +0 -91

91 lines not on this page · raw message

board/sc520_spunk/Makefile deleted +0 -56

56 lines not on this page · raw message

board/sc520_spunk/config.mk deleted +0 -25
deleted file mode 100644
index 2253815..0000000
@@ -1,25 +0,0 @@
-#
-# (C) Copyright 2002
-# Daniel Engstr?m, Omicron Ceti AB, daniel at omicron.se.
-#
-# See file CREDITS for list of people who contributed to this
-# project.
-#
-# 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; either version 2 of
-# the License, or (at your option) any later version.
-#
-# 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
-#
-
-
-TEXT_BASE = 0x387c0000
board/sc520_spunk/flash.c deleted +0 -791

791 lines not on this page · raw message

board/sc520_spunk/sc520_spunk.c deleted +0 -410

16 lines not on this page · raw message

board/sc520_spunk/sc520_spunk_asm.S deleted +0 -81

81 lines not on this page · raw message

board/sc520_spunk/sc520_spunk_asm16.S deleted +0 -83

83 lines not on this page · raw message

board/sc520_spunk/sc520_spunk_pci.c deleted +0 -323

323 lines not on this page · raw message

board/sc520_spunk/u-boot.lds deleted +0 -92

92 lines not on this page · raw message

boards.cfg +0 -3
index 69c6897..fc2e67a 100644

Lines of this file are not shown. View the raw message.

include/configs/sc520_cdp.h deleted +0 -220

220 lines not on this page · raw message

include/configs/sc520_spunk.h deleted +0 -250

250 lines not on this page · raw message

include/configs/sc520_spunk_rel.h deleted +0 -32
deleted file mode 100644
index 2e7a7e1..0000000

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.1.422.g049e9

Part of the diff is not shown here. View the raw message.

#5 lore raw

PATCH 5/13 x86: Make CONFIG_RELOC_FIXUP_WORKS generic for all x86 boards

In reply to Graeme Russ

Relocation is not board-specific fir the x86 architectrure, so CONFIG_RELOC_FIXUP_WORKS can be defined globally in the common.h

---
 arch/i386/include/asm/config.h |    2 ++
 include/configs/eNET.h         |    2 --
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/i386/include/asm/config.h +2 -0
index 049c44e..1952de7 100644
@@ -21,4 +21,6 @@
 #ifndef _ASM_CONFIG_H_
 #define _ASM_CONFIG_H_
 
+#define CONFIG_RELOC_FIXUP_WORKS
+
 #endif
include/configs/eNET.h +0 -2
index 361fe61..04321e1 100644
@@ -29,8 +29,6 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-#define CONFIG_RELOC_FIXUP_WORKS
-
 /*
  * Stuff still to be dealt with -
  */
Signature · 1 line
1.7.1.422.g049e9
#6 lore raw

PATCH 5/13 x86: Make CONFIG_RELOC_FIXUP_WORKS generic for all x86 boards

Hello Graeme,

Quoted 4 lines · Graeme Russ

Relocation is not board-specific fir the x86 architectrure, so CONFIG_RELOC_FIXUP_WORKS can be defined globally in the common.h

Quoted 21 lines
---
 arch/i386/include/asm/config.h |    2 ++
 include/configs/eNET.h         |    2 --
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/i386/include/asm/config.h +2 -0
index 049c44e..1952de7 100644
@@ -21,4 +21,6 @@
 #ifndef _ASM_CONFIG_H_
 #define _ASM_CONFIG_H_
 
+#define CONFIG_RELOC_FIXUP_WORKS
+
 #endif
include/configs/eNET.h +0 -0
index 361fe61..04321e1 100644

include/configs/eNET.h line 34

Quoted 8 lines
include/configs/eNET.h +0 -2
@@ -29,8 +29,6 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-#define CONFIG_RELOC_FIXUP_WORKS
-
 /*
  * Stuff still to be dealt with -
  */

bye,
Heiko

#7 lore raw

PATCH 5/13 x86: Make CONFIG_RELOC_FIXUP_WORKS generic for all x86 boards

In reply to Graeme Russ

Hello.

Quoted 1 line · Graeme Russ

Relocation is not board-specific fir the x86 architectrure, so

    s/fir/for/
Quoted 1 line

CONFIG_RELOC_FIXUP_WORKS can be defined globally in the common.h

You mean config.h?

Quoted 1 line

[...]

arch/i386/include/asm/config.h line 26

Quoted 11 lines
arch/i386/include/asm/config.h +2 -0
index 049c44e..1952de7 100644
@@ -21,4 +21,6 @@
 #ifndef _ASM_CONFIG_H_
 #define _ASM_CONFIG_H_
 
+#define CONFIG_RELOC_FIXUP_WORKS
+
 #endif

WBR, Sergei

#8 lore raw

PATCH 6/13 x86: Use TEXT_BASE in linker scripts

In reply to Graeme Russ

Use TEXT_BASE rather than a hard-coded base address on x86 linker scripts. This will allow any board to define its base link address without having to modify the linker script

---
 board/eNET/u-boot.lds |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
board/eNET/u-boot.lds +4 -4
index 7b0ffaa..d78d75f 100644
@@ -27,7 +27,7 @@ ENTRY(_start)
 
 SECTIONS
 {
-	. = 0x06000000;		/* Location of bootcode in flash */
+	. = TEXT_BASE;		/* Location of bootcode in flash */
 	_i386boot_text_start = .;
 	.text  : { *(.text); }
 
@@ -98,12 +98,12 @@ SECTIONS
 	 * The fff0 offset of resetvec is important, however.
 	 */
 	. = 0xfffffe00;
-	.start32 : AT (0x0603fe00) { *(.start32); }
+	.start32 : AT (TEXT_BASE + 0x3fe00) { *(.start32); }
 
 	. = 0xf800;
-	.start16 : AT (0x0603f800) { *(.start16); }
+	.start16 : AT (TEXT_BASE + 0x3f800) { *(.start16); }
 
 	. = 0xfff0;
-	.resetvec : AT (0x0603fff0) { *(.resetvec); }
+	.resetvec : AT (TEXT_BASE + 0x3fff0) { *(.resetvec); }
 	_i386boot_end = (LOADADDR(.resetvec) + SIZEOF(.resetvec) );
 }
Signature · 1 line
1.7.1.422.g049e9
#9 lore raw

PATCH 7/13 x86: zboot update

In reply to Graeme Russ

The header of recent Linux Kernels includes the size of the image, and therefore is not needed to be passed to zboot. Still process the third parameter (size of image) in the event that an older kernel is being loaded

---
 arch/i386/lib/zimage.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
arch/i386/lib/zimage.c +13 -5
index 89fe015..f279b43 100644
@@ -248,7 +248,8 @@ void boot_zimage(void *setup_base)
 int do_zboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	void *base_ptr;
-	void *bzImage_addr;
+	void *bzImage_addr = NULL;
+	char *s;
 	ulong bzImage_size = 0;
 
 	disable_interrupts();
@@ -256,10 +257,17 @@ int do_zboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	/* Setup board for maximum PC/AT Compatibility */
 	setup_pcat_compatibility();
 
-	/* argv[1] holds the address of the bzImage */
-	bzImage_addr = (void *)simple_strtoul(argv[1], NULL, 16);
+	if (argc >= 2) {
+		/* argv[1] holds the address of the bzImage */
+		bzImage_addr = (void *)simple_strtoul(argv[1], NULL, 16);
+	} else {
+		s = getenv("fileaddr");
+		if (s)
+			bzImage_addr = (void *)simple_strtoul(s, NULL, 16);
+	}
 
-	if (argc == 3)
+	if (argc >= 3)
+		/* argv[2] holds the size of the bzImage */
 		bzImage_size = simple_strtoul(argv[2], NULL, 16);
 
 	/* Lets look for*/
@@ -282,7 +290,7 @@ int do_zboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-	zboot, 3, 0,	do_zboot,
+	zboot, 2, 0,	do_zboot,
 	"Boot bzImage",
 	""
 );
Signature · 1 line
1.7.1.422.g049e9
#10 lore raw

PATCH 8/13 x86: use gc sections to reduce image size

In reply to Graeme Russ

Follow the discussion of Charles Manning and Mike Frysinger. Using gc_sections helps reduce image size.

---
 arch/i386/config.mk   |    3 +++
 board/eNET/u-boot.lds |   10 +++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)
arch/i386/config.mk +3 -0
index 4b990e0..0e80a1ae 100644
@@ -26,3 +26,6 @@ CROSS_COMPILE ?= i386-linux-
 STANDALONE_LOAD_ADDR = 0x40000
 
 PLATFORM_CPPFLAGS += -DCONFIG_I386 -D__I386__
+
+LDFLAGS += --cref --gc-sections
+PLATFORM_RELFLAGS += -ffunction-sections
board/eNET/u-boot.lds +5 -5
index d78d75f..7b211a8 100644
@@ -77,13 +77,13 @@ SECTIONS
 	_i386boot_bss_size = SIZEOF(.bss);
 
 	/* 16bit realmode trampoline code */
-	.realmode 0x7c0 : AT ( LOADADDR(.rel.dyn) + SIZEOF(.rel.dyn) ) { *(.realmode) }
+	.realmode 0x7c0 : AT ( LOADADDR(.rel.dyn) + SIZEOF(.rel.dyn) ) { KEEP(*(.realmode)) }
 
 	_i386boot_realmode = LOADADDR(.realmode);
 	_i386boot_realmode_size = SIZEOF(.realmode);
 
 	/* 16bit BIOS emulation code (just enough to boot Linux) */
-	.bios 0 : AT ( LOADADDR(.realmode) + SIZEOF(.realmode) ) { *(.bios) }
+	.bios 0 : AT ( LOADADDR(.realmode) + SIZEOF(.realmode) ) { KEEP(*(.bios)) }
 
 	_i386boot_bios = LOADADDR(.bios);
 	_i386boot_bios_size = SIZEOF(.bios);
@@ -98,12 +98,12 @@ SECTIONS
 	 * The fff0 offset of resetvec is important, however.
 	 */
 	. = 0xfffffe00;
-	.start32 : AT (TEXT_BASE + 0x3fe00) { *(.start32); }
+	.start32 : AT (TEXT_BASE + 0x3fe00) { KEEP(*(.start32)); }
 
 	. = 0xf800;
-	.start16 : AT (TEXT_BASE + 0x3f800) { *(.start16); }
+	.start16 : AT (TEXT_BASE + 0x3f800) { KEEP(*(.start16)); }
 
 	. = 0xfff0;
-	.resetvec : AT (TEXT_BASE + 0x3fff0) { *(.resetvec); }
+	.resetvec : AT (TEXT_BASE + 0x3fff0) { KEEP(*(.resetvec)); }
 	_i386boot_end = (LOADADDR(.resetvec) + SIZEOF(.resetvec) );
 }
Signature · 1 line
1.7.1.422.g049e9
#11 lore raw

PATCH 9/13 x86: Move loading of GTD to C code

In reply to Graeme Russ

Linux has C macros and code to load the GTD after switching to Protected Mode. Using these greatly simplifies the assembler code

---
 arch/i386/cpu/cpu.c   |   57 +++++++++++++++++++++++++++++
 arch/i386/cpu/start.S |   96 -------------------------------------------------
 2 files changed, 57 insertions(+), 96 deletions(-)
arch/i386/cpu/cpu.c +57 -0
index bd6aced..ae40384 100644
@@ -37,6 +37,61 @@
 #include <command.h>
 #include <asm/interrupt.h>
 
+/* Constructor for a conventional segment GDT (or LDT) entry */
+/* This is a macro so it can be used in initializers */
+#define GDT_ENTRY(flags, base, limit)			\
+	((((base)  & 0xff000000ULL) << (56-24)) |	\
+	 (((flags) & 0x0000f0ffULL) << 40) |		\
+	 (((limit) & 0x000f0000ULL) << (48-16)) |	\
+	 (((base)  & 0x00ffffffULL) << 16) |		\
+	 (((limit) & 0x0000ffffULL)))
+
+/* Simple and small GDT entries for booting only */
+
+#define GDT_ENTRY_32BIT_CS	2
+#define GDT_ENTRY_32BIT_DS	(GDT_ENTRY_32BIT_CS + 1)
+#define GDT_ENTRY_16BIT_CS	(GDT_ENTRY_32BIT_DS + 1)
+#define GDT_ENTRY_16BIT_DS	(GDT_ENTRY_16BIT_CS + 1)
+
+/*
+ * Set up the GDT
+ */
+
+struct gdt_ptr {
+	u16 len;
+	u32 ptr;
+} __attribute__((packed));
+
+static void reload_gdt(void)
+{
+	/* There are machines which are known to not boot with the GDT
+	   being 8-byte unaligned.  Intel recommends 16 byte alignment. */
+	static const u64 boot_gdt[] __attribute__((aligned(16))) = {
+		/* CS: code, read/execute, 4 GB, base 0 */
+		[GDT_ENTRY_32BIT_CS] = GDT_ENTRY(0xc09b, 0, 0xfffff),
+		/* DS: data, read/write, 4 GB, base 0 */
+		[GDT_ENTRY_32BIT_DS] = GDT_ENTRY(0xc093, 0, 0xfffff),
+		/* 16-bit CS: code, read/execute, 64 kB, base 0 */
+		[GDT_ENTRY_16BIT_CS] = GDT_ENTRY(0x109b, 0, 0x0ffff),
+		/* 16-bit DS: data, read/write, 64 kB, base 0 */
+		[GDT_ENTRY_16BIT_DS] = GDT_ENTRY(0x1093, 0, 0x0ffff),
+	};
+	static struct gdt_ptr gdt;
+
+	gdt.len = sizeof(boot_gdt)-1;
+	gdt.ptr = (u32)&boot_gdt;
+
+	asm volatile("lgdtl %0\n" \
+		     "movl $((2+1)*8), %%ecx\n" \
+		     "movl %%ecx, %%ds\n" \
+		     "movl %%ecx, %%es\n" \
+		     "movl %%ecx, %%fs\n" \
+		     "movl %%ecx, %%gs\n" \
+		     "movl %%ecx, %%ss" \
+		     : : "m" (gdt) : "ecx");
+}
+
+
 int cpu_init_f(void)
 {
 	/* initialize FPU, reset EM, set MP and NE */
@@ -51,6 +106,8 @@ int cpu_init_f(void)
 
 int cpu_init_r(void)
 {
+	reload_gdt();
+
 	/* Initialize core interrupt and exception functionality of CPU */
 	cpu_init_interrupts ();
 	return 0;
arch/i386/cpu/start.S +0 -96

105 lines not on this page · raw message

Signature · 1 line
1.7.1.422.g049e9
#12 lore raw

PATCH 10/13 x86: Coding Style Cleanup

In reply to Graeme Russ

Perform some basic code cleanups of the x86 files

---
 arch/i386/cpu/sc520/sc520.c     |   54 ++--
 arch/i386/cpu/sc520/sc520_asm.S |  642 +++++++++++++++++++--------------------
 arch/i386/cpu/start.S           |   30 +-
 arch/i386/cpu/start16.S         |    9 +-
 4 files changed, 362 insertions(+), 373 deletions(-)
arch/i386/cpu/sc520/sc520.c +28 -26
index 519bfd8..7acd471 100644
@@ -41,7 +41,8 @@ volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000;
 
 void init_sc520(void)
 {
-	/* Set the UARTxCTL register at it's slower,
+	/*
+	 * Set the UARTxCTL register at it's slower,
 	 * baud clock giving us a 1.8432 MHz reference
 	 */
 	writeb(0x07, &sc520_mmcr->uart1ctl);
@@ -50,25 +51,30 @@ void init_sc520(void)
 	/* first set the timer pin mapping */
 	writeb(0x72, &sc520_mmcr->clksel);	/* no clock frequency selected, use 1.1892MHz */
 
-	/* enable PCI bus arbitrer */
-	writeb(0x02, &sc520_mmcr->sysarbctl);	/* enable concurrent mode */
+	/* enable PCI bus arbiter (concurrent mode) */
+	writeb(0x02, &sc520_mmcr->sysarbctl);
 
-	writeb(0x1f, &sc520_mmcr->sysarbmenb);	/* enable external grants */
-	writeb(0x04, &sc520_mmcr->hbctl);	/* enable posted-writes */
+	/* enable external grants */
+	writeb(0x1f, &sc520_mmcr->sysarbmenb);
+
+	/* enable posted-writes */
+	writeb(0x04, &sc520_mmcr->hbctl);
 
 	if (CONFIG_SYS_SC520_HIGH_SPEED) {
-		writeb(0x02, &sc520_mmcr->cpuctl);	/* set it to 133 MHz and write back */
+		/* set it to 133 MHz and write back */
+		writeb(0x02, &sc520_mmcr->cpuctl);
 		gd->cpu_clk = 133000000;
 		printf("## CPU Speed set to 133MHz\n");
 	} else {
-		writeb(0x01, &sc520_mmcr->cpuctl);	/* set it to 100 MHz and write back */
+		/* set it to 100 MHz and write back */
+		writeb(0x01, &sc520_mmcr->cpuctl);
 		printf("## CPU Speed set to 100MHz\n");
 		gd->cpu_clk = 100000000;
 	}
 
 
 	/* wait at least one millisecond */
-	asm("movl	$0x2000,%%ecx\n"
+	asm("movl	$0x2000, %%ecx\n"
 	    "0:		pushl %%ecx\n"
 	    "popl	%%ecx\n"
 	    "loop 0b\n": : : "ecx");
@@ -107,15 +113,15 @@ unsigned long init_sc520_dram(void)
 
 	/* set SDRAM speed here */
 
-	refresh_rate/=78;
-	if (refresh_rate<=1) {
-		val = 0;  /* 7.8us */
-	} else if (refresh_rate==2) {
-		val = 1;  /* 15.6us */
-	} else if (refresh_rate==3 || refresh_rate==4) {
-		val = 2;  /* 31.2us */
+	refresh_rate /= 78;
+	if (refresh_rate <= 1) {
+		val = 0;	/* 7.8us */
+	} else if (refresh_rate == 2) {
+		val = 1;	/* 15.6us */
+	} else if (refresh_rate == 3 || refresh_rate == 4) {
+		val = 2;	/* 31.2us */
 	} else {
-		val = 3;  /* 62.4us */
+		val = 3;	/* 62.4us */
 	}
 
 	tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
@@ -124,9 +130,9 @@ unsigned long init_sc520_dram(void)
 	val = readb(&sc520_mmcr->drctmctl) & 0xf0;
 
 	if (cas_precharge_delay==3) {
-		val |= 0x04;   /* 3T */
+		val |= 0x04;	/* 3T */
 	} else if (cas_precharge_delay==4) {
-		val |= 0x08;   /* 4T */
+		val |= 0x08;	/* 4T */
 	} else if (cas_precharge_delay>4) {
 		val |= 0x0c;
 	}
@@ -139,8 +145,10 @@ unsigned long init_sc520_dram(void)
 	writeb(val, &c520_mmcr->drctmctl);
 #endif
 
-	/* We read-back the configuration of the dram
-	 * controller that the assembly code wrote */
+	/*
+	 * We read-back the configuration of the dram
+	 * controller that the assembly code wrote
+	 */
 	dram_ctrl = readl(&sc520_mmcr->drcbendadr);
 
 	bd->bi_dram[0].start = 0;
@@ -148,7 +156,6 @@ unsigned long init_sc520_dram(void)
 		/* bank 0 enabled */
 		dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
 		bd->bi_dram[0].size = bd->bi_dram[1].start;
-
 	} else {
 		bd->bi_dram[0].size = 0;
 		bd->bi_dram[1].start = bd->bi_dram[0].start;
@@ -179,11 +186,6 @@ unsigned long init_sc520_dram(void)
 	} else {
 		bd->bi_dram[3].size = 0;
 	}
-
-
-#if 0
-	printf("Configured %d bytes of dram\n", dram_present);
-#endif
 	gd->ram_size = dram_present;
 
 	return dram_present;
arch/i386/cpu/sc520/sc520_asm.S +314 -328

725 lines not on this page · raw message

arch/i386/cpu/start.S +15 -15
index 3cea04b..f67a1b7 100644
@@ -45,7 +45,7 @@ _i386boot_start:
 
 	/* Turn of cache (this might require a 486-class CPU) */
 	movl	%cr0, %eax
-	orl	$0x60000000,%eax
+	orl	$0x60000000, %eax
 	movl	%eax, %cr0
 	wbinvd
 
@@ -54,13 +54,13 @@ _i386boot_start:
 _start:
 	/* This is the 32-bit cold-reset entry point */
 
-	movl    $0x18,%eax	/* Load our segement registes, the
+	movl	$0x18, %eax	/* Load our segement registes, the
 				 * gdt have already been loaded by start16.S */
-	movw    %ax,%fs
-	movw	%ax,%ds
-	movw    %ax,%gs
-	movw    %ax,%es
-	movw    %ax,%ss
+	movw	%ax, %fs
+	movw	%ax, %ds
+	movw	%ax, %gs
+	movw	%ax, %es
+	movw	%ax, %ss
 
 	/* Clear the interupt vectors */
 	lidt	blank_idt_ptr
@@ -79,7 +79,7 @@ _start:
 	 * to store the return address */
 
 	/* Early platform init (setup gpio, etc ) */
-	mov     $early_board_init_ret, %ebp
+	mov	$early_board_init_ret, %ebp
 	jmp	early_board_init
 early_board_init_ret:
 
@@ -92,12 +92,12 @@ early_board_init_ret:
 
 	/* size memory */
 	mov	$mem_init_ret, %ebp
-	jmp     mem_init
+	jmp	mem_init
 mem_init_ret:
 
 	/* fetch memory size (into %eax) */
 	mov	$get_mem_size_ret, %ebp
-	jmp     get_mem_size
+	jmp	get_mem_size
 get_mem_size_ret:
 
 	/* Check we have enough memory for stack */
@@ -113,7 +113,7 @@ get_mem_size_ret:
 	jmp	die
 mem_ok:
 	/* Set stack pointer to upper memory limit*/
-	movl    %eax, %esp
+	movl	%eax, %esp
 
 	/* indicate progress */
 	movw	$0x02, %ax
@@ -150,12 +150,12 @@ stack_ok:
 	wbinvd
 
 	/* Get upper memory limit */
-	movl %esp, %ecx
-	subl $CONFIG_SYS_STACK_SIZE, %ecx
+	movl	%esp, %ecx
+	subl	$CONFIG_SYS_STACK_SIZE, %ecx
 
 	/* Create a Stack Frame */
-	pushl %ebp
-	movl %esp, %ebp
+	pushl	%ebp
+	movl	%esp, %ebp
 
 	/* stack_limit parameter */
 	pushl	%ecx
arch/i386/cpu/start16.S +5 -4
index ebe5835..2a5cca9 100644
@@ -31,7 +31,8 @@
 .code16
 .globl start16
 start16:
-	/* First we let the BSP do some early initialization
+	/*
+	 * First we let the BSP do some early initialization
 	 * this code have to map the flash to its final position
 	 */
 	mov	$board_init16_ret, %bp
@@ -40,7 +41,7 @@ board_init16_ret:
 
 	/* Turn of cache (this might require a 486-class CPU) */
 	movl	%cr0, %eax
-	orl	$0x60000000,%eax
+	orl	$0x60000000, %eax
 	movl	%eax, %cr0
 	wbinvd
 
@@ -50,7 +51,7 @@ o32 cs	lgdt	gdt_ptr
 
 	/* Now, we enter protected mode */
 	movl	%cr0, %eax
-	orl	$1,%eax
+	orl	$1, %eax
 	movl	%eax, %cr0
 
 	/* Flush the prefetch queue */
@@ -61,7 +62,7 @@ ff:
 
 	/* Finally jump to the 32bit initialization code */
 	movw	$code32start, %ax
-	movw	%ax,%bp
+	movw	%ax, %bp
 o32 cs	ljmp	*(%bp)
 
 	/* 48-bit far pointer */
Signature · 1 line
1.7.1.422.g049e9
#13 lore raw

PATCH 11/13 eNET: Add eNET_RAM_config

In reply to Graeme Russ

This patch allows configuration of the eNET board for generation of a U-Boot image which can be loaded into RAM (using tftp for example). Executing the image loaded into RAM is very similar to a cold-boot (the image is relocated to upper memory etc). This allows very rapid development and testing of new features without needing to burn Boot-ROMs

---
 Makefile             |   12 ++++++++++++
 board/eNET/config.mk |    7 ++++++-
 boards.cfg           |    1 -
 3 files changed, 18 insertions(+), 2 deletions(-)
Makefile +12 -0
index 4f1cb1b..972c6aa 100644
@@ -2428,6 +2428,18 @@ espt_config  :   unconfig
 	@echo "#define CONFIG_ESPT 1" > $(obj)include/config.h
 	@$(MKCONFIG) -a $@ sh sh4 espt
 
+#========================================================================
+# x86
+#========================================================================
+eNET_config	\
+eNET_RAM_config	:	unconfig
+	@if [ "$(findstring RAM,$@)" ]; then					\
+		echo "TEXT_BASE = 0x06000000" > $(obj)board/eNET/config.tmp;	\
+	else									\
+		echo "TEXT_BASE = 0x38040000" > $(obj)board/eNET/config.tmp;	\
+	fi
+	@$(MKCONFIG) eNET i386 i386 eNET - sc520
+
 #########################################################################
 #########################################################################
 
board/eNET/config.mk +6 -1
index 63a58fd..2c0b514 100644
@@ -21,7 +21,12 @@
 # MA 02111-1307 USA
 #
 
-TEXT_BASE = 0x06000000
+sinclude $(OBJTREE)/board/$(BOARDDIR)/config.tmp
+
+ifndef TEXT_BASE
+ TEXT_BASE = 0x38040000
+endif
+
 CFLAGS_common/dlmalloc.o += -Wa,--no-warn -fno-strict-aliasing
 PLATFORM_RELFLAGS += -fvisibility=hidden
 PLATFORM_CPPFLAGS += -fno-dwarf2-cfi-asm
boards.cfg +0 -1
index fc2e67a..3f6d2040 100644
@@ -70,7 +70,6 @@ gcplus		arm	sa1100
 lart		arm	sa1100
 shannon		arm	sa1100
 mimc200		avr32	at32ap		-		mimc		at32ap700x
-eNET		i386	i386		-		-		sc520
 idmr		m68k	mcf52x2
 TASREG		m68k	mcf52x2		tasreg		esd
 M5272C3		m68k	mcf52x2		m5272c3		freescale
Signature · 1 line
1.7.1.422.g049e9
#14 lore raw

PATCH 12/13 eNET: Fix eNET Interrupt Setup for Linux

In reply to Graeme Russ

Fix minor issues with the configuration of the hardware interrupts for Linux when booting the eNET board

---
 board/eNET/eNET.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
board/eNET/eNET.c +9 -6
index 7f0e257..700a31e 100644
@@ -204,10 +204,18 @@ void setup_pcat_compatibility()
 	 */
 	writew(0x0000,&sc520_mmcr->intpinpol);
 
-	/* Set PIT 0 -> IRQ0, RTC -> IRQ8, FP error -> IRQ13 */
+	/*
+	 * PIT 0 -> IRQ0
+	 * RTC -> IRQ8
+	 * FP error -> IRQ13
+	 * UART1 -> IRQ4
+	 * UART2 -> IRQ3
+	 */
 	writeb(SC520_IRQ0, &sc520_mmcr->pit_int_map[0]);
 	writeb(SC520_IRQ8, &sc520_mmcr->rtcmap);
 	writeb(SC520_IRQ13, &sc520_mmcr->ferrmap);
+	writeb(SC520_IRQ4, &sc520_mmcr->uart_int_map[0]);
+	writeb(SC520_IRQ3, &sc520_mmcr->uart_int_map[1]);
 
 	/* Disable all other interrupt sources */
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[0]);
@@ -215,11 +223,6 @@ void setup_pcat_compatibility()
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[2]);
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[1]);
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[2]);
-	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[0]);	/* disable PCI INT A */
-	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[1]);	/* disable PCI INT B */
-	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[2]);	/* disable PCI INT C */
-	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[3]);	/* disable PCI INT D */
-	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->dmabcintmap);		/* disable DMA INT */
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->ssimap);
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wdtmap);
 	writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wpvmap);
Signature · 1 line
1.7.1.422.g049e9
#15 lore raw

PATCH 13/13 x86: Add RTC support to eNET

In reply to Graeme Russ

The SC520 has an inbuilt MC146818 - Enable it for the eNET board

---
 drivers/rtc/mc146818.c |    6 ++++++
 include/configs/eNET.h |    2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/rtc/mc146818.c +6 -0
index ac4eb6a..155034f 100644
@@ -31,6 +31,12 @@
 #include <command.h>
 #include <rtc.h>
 
+#ifdef __I386__
+#include <asm/io.h>
+#define in8(p) inb(p)
+#define out8(p,v) outb(v,p)
+#endif
+
 #if defined(CONFIG_CMD_DATE)
 
 static uchar rtc_read  (uchar reg);
include/configs/eNET.h +2 -0
index 04321e1..ca130c3 100644
@@ -33,6 +33,7 @@
  * Stuff still to be dealt with -
  */
 #define CONFIG_RTC_MC146818
+#define CONFIG_SYS_ISA_IO_BASE_ADDRESS	0
 
 /*
  * High Level Configuration Options
@@ -92,6 +93,7 @@
 #define CONFIG_CMD_BDI		/* bdinfo			*/
 #define CONFIG_CMD_BOOTD	/* bootd			*/
 #define CONFIG_CMD_CONSOLE	/* coninfo			*/
+#define CONFIG_CMD_DATE
 #define CONFIG_CMD_ECHO		/* echo arguments		*/
 #define CONFIG_CMD_FLASH	/* flinfo, erase, protect	*/
 #define CONFIG_CMD_FPGA		/* FPGA configuration Support	*/
Signature · 1 line
1.7.1.422.g049e9