diff mbox

[U-Boot,RFC,3/3] MIPS: bootm.c: integrate QEMU specific functions

Message ID 1357672451-27455-3-git-send-email-juhosg@openwrt.org
State Rejected
Delegated to: Daniel Schwierzeck
Headers show

Commit Message

Gabor Juhos Jan. 8, 2013, 7:14 p.m. UTC
The linux starting code of the qemu specific bootm
implementation is very similar to the one which is
used for regular boards. The preparation code is
different but it makes no sense to keep that in a
separate file.

The pach moves the qemu specific code into bootm.c,
and removes the custom file. This allows to get rid
of some duplicated code, and it collects bootm specific
code into a single file. Additionaly, this allows to use
the prep,go subcommands in qemu as well.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Cc: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
---
This is compile tested only. I don't have suitable kernel
images for mips,mipsel,mips64,mipsel64 systems to try it yet.

-Gabor
---
 arch/mips/lib/Makefile          |    4 --
 arch/mips/lib/bootm.c           |   54 +++++++++++++++++++++++-
 arch/mips/lib/bootm_qemu_mips.c |   88 ---------------------------------------
 3 files changed, 52 insertions(+), 94 deletions(-)
 delete mode 100644 arch/mips/lib/bootm_qemu_mips.c

Comments

Gabor Juhos Jan. 10, 2013, 12:52 p.m. UTC | #1
2013.01.08. 20:14 keltezéssel, Gabor Juhos írta:
> The linux starting code of the qemu specific bootm
> implementation is very similar to the one which is
> used for regular boards. The preparation code is
> different but it makes no sense to keep that in a
> separate file.
> 
> The pach moves the qemu specific code into bootm.c,
> and removes the custom file. This allows to get rid
> of some duplicated code, and it collects bootm specific
> code into a single file. Additionaly, this allows to use
> the prep,go subcommands in qemu as well.
> 
> Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
> Cc: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
> ---
> This is compile tested only. I don't have suitable kernel
> images for mips,mipsel,mips64,mipsel64 systems to try it yet.

Ok, I have tried this with the sample vmlinux image provided here:
ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/

It works as expected:

> U-Boot 2013.01-rc2-00139-g926b2e4-dirty (Jan 10 2013 - 13:43:18)
> 
> Board: Qemu -M mips CPU: 24Kf proc_id=0x19300
> DRAM:  128 MiB
> ## Unknown flash on Bank 1 - Size = 0x00000000 = 0 MB
> Flash: 0 Bytes
> *** Warning - bad CRC, using default environment
> 
> In:    serial
> Out:   serial
> Err:   serial
> Net:   NE2000
> Hit any key to stop autoboot:  0 
> qemu-mips # run load_tftp
> Using NE2000 device
> TFTP from server 10.0.2.2; our IP address is 10.0.2.1
> Filename '/initrd.gz'.
> Load address: 0x80800000
> Loading: #################################################################
>          #################################################################
>          #################################################################
>          #################################################################
>          #################################################################
>          #################################################################
>          #################################################################
>          #################################################################
>          #
> done
> Bytes transferred = 2663940 (28a604 hex)
> Using NE2000 device
> TFTP from server 10.0.2.2; our IP address is 10.0.2.1
> Filename 'uImage'.
> Load address: 0x80500000
> Loading: #################################################################
>          #################################################################
>          #################################################################
>          #################################################################
>          ########
> done
> Bytes transferred = 1368045 (14dfed hex)
> qemu-mips # bootm start 0x80500000
> ## Booting kernel from Legacy Image at 80500000 ...
>    Image Name:   Linux 2.6.24.y
>    Created:      2013-01-09  16:27:15 UTC
>    Image Type:   MIPS Linux Kernel Image (gzip compressed)
>    Data Size:    1367981 Bytes = 1.3 MiB
>    Load Address: 80010000
>    Entry Point:  80245650
>    Verifying Checksum ... OK
> qemu-mips # bootm loados
>    Uncompressing Kernel Image ... OK
> qemu-mips # bootm prep
> qemu-mips # bootm go
> 
> Starting kernel ...
> 
> Linux version 2.6.24.7-dirty (j@game.jcrosoft.org) (gcc version 4.2.1) #17 Sat Sep 6 19:31:26 CEST 2008
> console [early0] enabled
> CPU revision is: 00019300 (MIPS 24K)
> FPU revision is: 00000000
> Determined physical RAM map:
>  memory: 08000000 @ 00000000 (usable)
> Initial ramdisk at: 0x80800000 (2663940 bytes)
> Zone PFN ranges:
>   DMA             0 ->     4096
>   Normal       4096 ->    32768
> Movable zone start PFN for each node
> early_node_map[1] active PFN ranges
>     0:        0 ->    32768
> Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
> Kernel command line: root=/dev/ram0 init=/bin/sh console=ttyS0,115200 rd_start=0x80800000 rd_size=0x28A604 ethaddr=52:54:00:12:34:56 panic=1
> Primary instruction cache 2kB, VIPT, 2-way, linesize 16 bytes.
> Primary data cache 2kB, 2-way, VIPT, no aliases, linesize 16 bytes
> Synthesized clear page handler (13 instructions).
> Synthesized copy page handler (22 instructions).
> Synthesized TLB refill handler (20 instructions).
> Synthesized TLB load handler fastpath (32 instructions).
> Synthesized TLB store handler fastpath (32 instructions).
> Synthesized TLB modify handler fastpath (31 instructions).
> Cache parity protection disabled
> PID hash table entries: 512 (order: 9, 2048 bytes)
> Console: colour dummy device 80x25
> Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
> Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
> Memory: 119096k/131072k available (2272k kernel code, 11928k reserved, 483k data, 148k init, 0k highmem)
> Mount-cache hash table entries: 512
> net_namespace: 64 bytes
> NET: Registered protocol family 16
> NET: Registered protocol family 2
> Time: MIPS clocksource has been installed.
> IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
> TCP established hash table entries: 4096 (order: 3, 32768 bytes)
> TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
> TCP: Hash tables configured (established 4096 bind 4096)
> TCP reno registered
> checking if image is initramfs...it isn't (no cpio magic); looks like an initrd
> Freeing initrd memory: 2601k freed
> fuse init (API version 7.9)
> JFS: nTxBlock = 951, nTxLock = 7609
> io scheduler noop registered (default)
> Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing disabled
> serial8250.0: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
> console handover: boot [early0] -> real [ttyS0]
> RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize
> loop: module loaded
> ne.c:v1.10 9/23/94 Donald Becker (becker@scyld.com)
> Last modified Nov 1, 2000 by Paul Gortmaker
> NE*000 ethercard probe at 0x300:52:54:00:12:34:56
> eth0: NE2000 found at 0x300, using IRQ 9.
> Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
> ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
> hdc: QEMU DVD-ROM, ATAPI CD/DVD-ROM drive
> ide1 at 0x170-0x177,0x376 on irq 15
> TCP cubic registered
> NET: Registered protocol family 1
> NET: Registered protocol family 17
> RPC: Registered udp transport module.
> RPC: Registered tcp transport module.
> RAMDISK: Compressed image found at block 0
> VFS: Mounted root (cramfs filesystem) readonly.
> Freeing unused kernel memory: 148k freed
> 
> 
> BusyBox v1.1.3 (Debian 1:1.1.3-3) Built-in shell (ash)
> Enter 'help' for a list of built-in commands.
> 
> /bin/sh: can't access tty; job control turned off
> ~ #
> 

Additionally, I wanted to compile a Linux kernel for mips64/mipsel/mipsel64 to
test these patches on those as well. However when I have tried to configure a
recent kernel I noticed that it has no MIPS QEMU platform. That has been
completely removed from Linux five years ago by:

    commit 302922e5f6901eb6f29c58539631f71b3d9746b8
    Author: Ralf Baechle <ralf@linux-mips.org>
    Date:   Tue Jan 29 10:15:02 2008 +0000

    [MIPS] Qemu: Remove platform.

    The Qemu platform was originally implemented to have an easily supportable
    platform until Qemu reaches a state where it emulates a real world system.
    Since the latest release Qemu is capable of emulating the MIPSsim and
    Malta platforms, so this goal has been reached.  The Qemu plaform is also
    rather underfeatured so less useful than a Malta emulation.

Maybe the qemu_mips specific bootm stuff should be removed completely from U-Boot?

-Gabor
Daniel Schwierzeck Jan. 10, 2013, 2:22 p.m. UTC | #2
2013/1/10 Gabor Juhos <juhosg@openwrt.org>:
> 2013.01.08. 20:14 keltezéssel, Gabor Juhos írta:
>> The linux starting code of the qemu specific bootm
>> implementation is very similar to the one which is
>> used for regular boards. The preparation code is
>> different but it makes no sense to keep that in a
>> separate file.
>>
>> The pach moves the qemu specific code into bootm.c,
>> and removes the custom file. This allows to get rid
>> of some duplicated code, and it collects bootm specific
>> code into a single file. Additionaly, this allows to use
>> the prep,go subcommands in qemu as well.
>>
>> Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
>> Cc: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
>> ---
>> This is compile tested only. I don't have suitable kernel
>> images for mips,mipsel,mips64,mipsel64 systems to try it yet.
>
> Ok, I have tried this with the sample vmlinux image provided here:
> ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/
>
> It works as expected:
>
>
> Additionally, I wanted to compile a Linux kernel for mips64/mipsel/mipsel64 to
> test these patches on those as well. However when I have tried to configure a
> recent kernel I noticed that it has no MIPS QEMU platform. That has been
> completely removed from Linux five years ago by:
>
>     commit 302922e5f6901eb6f29c58539631f71b3d9746b8
>     Author: Ralf Baechle <ralf@linux-mips.org>
>     Date:   Tue Jan 29 10:15:02 2008 +0000
>
>     [MIPS] Qemu: Remove platform.
>
>     The Qemu platform was originally implemented to have an easily supportable
>     platform until Qemu reaches a state where it emulates a real world system.
>     Since the latest release Qemu is capable of emulating the MIPSsim and
>     Malta platforms, so this goal has been reached.  The Qemu plaform is also
>     rather underfeatured so less useful than a Malta emulation.
>

yes, I figured that too yesterday while testing.

> Maybe the qemu_mips specific bootm stuff should be removed completely from U-Boot?
>
> -Gabor

I agree. Maybe we should convert the current MIPS Qemu port to MTI
Malta. I have seen
that BareBox already supports Qemu Malta.
For supporting real MTI Malta hardware there is AFAIK some work in progress [1].

[1] http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/140428/focus=140541
Gabor Juhos Jan. 10, 2013, 4:15 p.m. UTC | #3
2013.01.10. 15:22 keltezéssel, Daniel Schwierzeck írta:

> yes, I figured that too yesterday while testing.

:)

>> Maybe the qemu_mips specific bootm stuff should be removed completely from U-Boot?
>>
>> -Gabor
> 
> I agree. Maybe we should convert the current MIPS Qemu port to MTI Malta. 

That is a good idea.

> I have seen that BareBox already supports Qemu Malta.

Yes, although that only supports the UART perperial at the moment.

> For supporting real MTI Malta hardware there is AFAIK some work in progress [1].
> 
> [1] http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/140428/focus=140541

Nice!

-Gabor
diff mbox

Patch

diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile
index 967e98a..a68a564 100644
--- a/arch/mips/lib/Makefile
+++ b/arch/mips/lib/Makefile
@@ -35,11 +35,7 @@  LGOBJS	:= $(addprefix $(obj),$(GLSOBJS))
 SOBJS-y	+=
 
 COBJS-y	+= board.o
-ifeq ($(CONFIG_QEMU_MIPS),y)
-COBJS-y	+= bootm_qemu_mips.o
-else
 COBJS-y	+= bootm.o
-endif
 
 SRCS	:= $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(SOBJS-y) $(COBJS-y))
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index a36154a..71bd456 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -2,6 +2,9 @@ 
  * (C) Copyright 2003
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
+ * (C) Copyright 2008
+ * Jean-Christophe PLAGNIOL-VILLARD <jcplagniol@jcrosoft.com>
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
@@ -33,6 +36,12 @@  DECLARE_GLOBAL_DATA_PTR;
 #define	LINUX_MAX_ENVS		256
 #define	LINUX_MAX_ARGS		256
 
+#ifdef CONFIG_QEMU_MIPS
+#define board_is_mips_qemu	1
+#else
+#define board_is_mips_qemu	0
+#endif
+
 static int linux_argc;
 static char **linux_argv;
 
@@ -43,7 +52,7 @@  static int linux_env_idx;
 static void linux_params_init(ulong start, char *commandline);
 static void linux_env_set(char *env_name, char *env_val);
 
-static void boot_prep_linux(bootm_headers_t *images)
+static void boot_prep_linux_legacy(bootm_headers_t *images)
 {
 	char *commandline = getenv("bootargs");
 	char env_buf[12];
@@ -83,6 +92,44 @@  static void boot_prep_linux(bootm_headers_t *images)
 		linux_env_set("eth1addr", cp);
 }
 
+static void boot_prep_linux_qemu(bootm_headers_t *images)
+{
+	char *bootargs = getenv("bootargs");
+	char *start;
+	uint len;
+
+	gd->bd->bi_boot_params = gd->bd->bi_memstart + (16 << 20) - 256;
+	debug("%-12s= 0x%08lX\n", "boot_params", (ulong)gd->bd->bi_boot_params);
+
+	/* set Magic */
+	*(int32_t *)(gd->bd->bi_boot_params - 4) = 0x12345678;
+	/* set ram_size */
+	*(int32_t *)(gd->bd->bi_boot_params - 8) = gd->ram_size;
+
+	start = (char *)gd->bd->bi_boot_params;
+
+	len = strlen(bootargs);
+
+	strncpy(start, bootargs, len + 1);
+
+	start += len;
+
+	len = images->rd_end - images->rd_start;
+	if (len > 0) {
+		start += sprintf(start, " rd_start=0x%08X rd_size=0x%0X",
+		(uint) UNCACHED_SDRAM(images->rd_start),
+		(uint) len);
+	}
+}
+
+static void boot_prep_linux(bootm_headers_t *images)
+{
+	if (board_is_mips_qemu)
+		boot_prep_linux_qemu(images);
+	else
+		boot_prep_linux_legacy(images);
+}
+
 static void boot_jump_linux(bootm_headers_t *images)
 {
 	void (*theKernel) (int, char **, char **, int *);
@@ -98,7 +145,10 @@  static void boot_jump_linux(bootm_headers_t *images)
 	/* we assume that the kernel is in place */
 	printf("\nStarting kernel ...\n\n");
 
-	theKernel(linux_argc, linux_argv, linux_env, 0);
+	if (board_is_mips_qemu)
+		theKernel(0, NULL, NULL, 0);
+	else
+		theKernel(linux_argc, linux_argv, linux_env, 0);
 }
 
 int do_bootm_linux(int flag, int argc, char * const argv[],
diff --git a/arch/mips/lib/bootm_qemu_mips.c b/arch/mips/lib/bootm_qemu_mips.c
deleted file mode 100644
index a920305..0000000
--- a/arch/mips/lib/bootm_qemu_mips.c
+++ /dev/null
@@ -1,88 +0,0 @@ 
-/*
- * (C) Copyright 2008
- * Jean-Christophe PLAGNIOL-VILLARD <jcplagniol@jcrosoft.com>
- *
- * 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
- *
- */
-
-#include <common.h>
-#include <command.h>
-#include <image.h>
-#include <asm/byteorder.h>
-#include <asm/addrspace.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static void boot_prep_linux_qemu(bootm_headers_t *images)
-{
-	char *bootargs = getenv("bootargs");
-	char *start;
-	uint len;
-
-	gd->bd->bi_boot_params = gd->bd->bi_memstart + (16 << 20) - 256;
-	debug("%-12s= 0x%08lX\n", "boot_params", (ulong)gd->bd->bi_boot_params);
-
-	/* set Magic */
-	*(int32_t *)(gd->bd->bi_boot_params - 4) = 0x12345678;
-	/* set ram_size */
-	*(int32_t *)(gd->bd->bi_boot_params - 8) = gd->ram_size;
-
-	start = (char *)gd->bd->bi_boot_params;
-
-	len = strlen(bootargs);
-
-	strncpy(start, bootargs, len + 1);
-
-	start += len;
-
-	len = images->rd_end - images->rd_start;
-	if (len > 0) {
-		start += sprintf(start, " rd_start=0x%08X rd_size=0x%0X",
-		(uint) UNCACHED_SDRAM(images->rd_start),
-		(uint) len);
-	}
-}
-
-static void boot_jump_linux_qemu(bootm_headers_t *images)
-{
-	void (*theKernel) (int, char **, char **, int *);
-
-	/* find kernel entry point */
-	theKernel = (void (*)(int, char **, char **, int *))images->ep;
-
-	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
-
-	debug("## Transferring control to Linux (at address %08lx) ...\n",
-		(ulong) theKernel);
-
-	/* we assume that the kernel is in place */
-	printf("\nStarting kernel ...\n\n");
-
-	theKernel(0, NULL, NULL, 0);
-}
-
-int do_bootm_linux(int flag, int argc, char * const argv[],
-			bootm_headers_t *images)
-{
-	boot_prep_linux_qemu(images);
-	boot_jump_linux_qemu(images);
-
-	/* does not return */
-	return 1;
-}