Module Name:    src
Committed By:   phx
Date:           Sun Mar 13 15:23:43 UTC 2011

Modified Files:
        src/sys/arch/sandpoint/stand/altboot: README.altboot entry.S main.c
            version

Log Message:
With the new boot argument "altboot" the program can replace itself with a
new binary while running.
The default boot path was changed from nfs: to wd0:.
Bumped altboot version to 1.7.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/sandpoint/stand/altboot/README.altboot
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/sandpoint/stand/altboot/entry.S
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/sandpoint/stand/altboot/main.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/sandpoint/stand/altboot/version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sandpoint/stand/altboot/README.altboot
diff -u src/sys/arch/sandpoint/stand/altboot/README.altboot:1.1 src/sys/arch/sandpoint/stand/altboot/README.altboot:1.2
--- src/sys/arch/sandpoint/stand/altboot/README.altboot:1.1	Sun Jan 23 01:05:30 2011
+++ src/sys/arch/sandpoint/stand/altboot/README.altboot	Sun Mar 13 15:23:43 2011
@@ -1,6 +1,6 @@
 /// notes about altboot ///
 
-$NetBSD: README.altboot,v 1.1 2011/01/23 01:05:30 nisimura Exp $
+$NetBSD: README.altboot,v 1.2 2011/03/13 15:23:43 phx Exp $
 
 Altboot is a functional bridge to fill the gap between a NAS product
 custom bootloader and the NetBSD kernel startup environment.  Altboot
@@ -17,7 +17,7 @@
   targets to make it possible having common NetBSD kernels for them.
 - builds and hands a bootinfo list to the NetBSD kernel.
 
-Altboot is known working on two models.
+Altboot is known working on at least three models.
 - KuroBox with a popular U-Boot as the replacement of vendor proprietary
 
    U-Boot 1.1.4 LiSt 2.1.0 (Sep 21 2006 - 00:22:56) LinkStation / KuroBox
@@ -26,6 +26,10 @@
 
    PPCBoot 2.0.0 (Mar  1 2005 - 15:31:41)
 
+- D-Link DSM-G600 with heavily restricted vendor custom U-Boot
+
+   U-Boot 0.2.0 (May 26 2005 - 19:38:32)
+
 The standard use of altboot is to invoke it with a short script from
 U-Boot/PPCboot, where the altboot image is stored in an unoccupied 128KB
 section of the target's HW NOR flash.  Combined with standard
@@ -45,4 +49,3 @@
 - preloaded kernel module names (under development).
 
                              ### ### ###
-

Index: src/sys/arch/sandpoint/stand/altboot/entry.S
diff -u src/sys/arch/sandpoint/stand/altboot/entry.S:1.2 src/sys/arch/sandpoint/stand/altboot/entry.S:1.3
--- src/sys/arch/sandpoint/stand/altboot/entry.S:1.2	Sat Feb 26 20:11:24 2011
+++ src/sys/arch/sandpoint/stand/altboot/entry.S	Sun Mar 13 15:23:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: entry.S,v 1.2 2011/02/26 20:11:24 phx Exp $ */
+/* $NetBSD: entry.S,v 1.3 2011/03/13 15:23:43 phx Exp $ */
 
 #include <powerpc/psl.h>
 #include <powerpc/spr.h>
@@ -24,25 +24,12 @@
 	 * U-Boot/PPCBoot forgets to flush the cache when using the "bootm"
 	 * command, so we have to do that now.
 	 */
-	lis	3,_start@ha
-	addi	3,3,_start@l
-	andi.	3,3,~31@l
-	lis	4,(_edata+31)@ha
-	addi	4,4,(_edata+31)@l
-	mr	5,3
-10:
-	dcbst	0,5
-	addi	5,5,32
-	cmplw	5,4
-	ble	10b
-	sync
-11:
-	icbi	0,3
-	addi	3,3,32
-	cmplw	3,4
-	ble	11b
-	sync
-	isync
+	lis	11,_start@ha
+	addi	11,11,_start@l
+	andi.	11,11,~31@l
+	lis	12,(_edata+31)@ha
+	addi	12,12,(_edata+31)@l
+	bl	syncicache
 
 	mfspr	11,SPR_HID0
 	andi.	0,11,HID0_DCE
@@ -169,6 +156,46 @@
 	bctr
 
 /*
+ * newaltboot(argc, argv, altboot_base, altboot_len)
+ * To be executed in a safe memory region. Copies the new altboot from
+ * altboot_base to 0x1000000 and starts it there.
+ */
+	.globl	newaltboot
+newaltboot:
+	lis	7,0x1000000@h
+	mr	11,7
+	subi	7,7,4
+	subi	5,5,4
+	add	12,11,6
+	addi	6,6,3
+	srawi	6,6,2
+	mtctr	6
+1:	lwzu	8,4(5)
+	stwu	8,4(7)
+	bdnz+	1b
+	mtctr	11
+	addi	12,12,31
+	bl	syncicache
+	bctr
+syncicache:
+/* r11=start, r12=end, r10=scratch */
+	mr	10,11
+2:	dcbst	0,10
+	addi	10,10,32
+	cmplw	10,12
+	ble	2b
+	sync
+3:	icbi	0,11
+	addi	11,11,32
+	cmplw	11,12
+	ble	3b
+	sync
+	isync
+	blr
+	.globl	newaltboot_end
+newaltboot_end:
+
+/*
  * reverse endian access to mimic outw/outl/inw/inl
  */
 	.globl out16rb

Index: src/sys/arch/sandpoint/stand/altboot/main.c
diff -u src/sys/arch/sandpoint/stand/altboot/main.c:1.11 src/sys/arch/sandpoint/stand/altboot/main.c:1.12
--- src/sys/arch/sandpoint/stand/altboot/main.c:1.11	Sun Mar 13 01:56:21 2011
+++ src/sys/arch/sandpoint/stand/altboot/main.c	Sun Mar 13 15:23:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.11 2011/03/13 01:56:21 phx Exp $ */
+/* $NetBSD: main.c,v 1.12 2011/03/13 15:23:43 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -54,7 +54,8 @@
 	{ "quiet",	AB_QUIET },
 	{ "verb",	AB_VERBOSE },
 	{ "silent",	AB_SILENT },
-	{ "debug",	AB_DEBUG }
+	{ "debug",	AB_DEBUG },
+	{ "altboot",	-1 }
 };
 
 void *bootinfo; /* low memory reserved to pass bootinfo structures */
@@ -89,7 +90,9 @@
 int module_open(struct boot_module *);
 
 void main(int, char **, char *, char *);
+
 extern char bootprog_name[], bootprog_rev[];
+extern char newaltboot[], newaltboot_end[];
 
 struct pcidev lata[2];
 struct pcidev lnif[1];
@@ -104,7 +107,7 @@
 static int parse_cmdline(char **, int, char *, char *);
 static int is_space(char);
 
-#define	BNAME_DEFAULT "nfs:"
+#define	BNAME_DEFAULT "wd0:"
 #define MAX_ARGS 10
 
 void
@@ -113,6 +116,7 @@
 	struct brdprop *brdprop;
 	unsigned long marks[MARK_MAX];
 	char *new_argv[MAX_ARGS];
+	ssize_t len;
 	int n, i, fd, howto;
 	char *bname;
 
@@ -232,7 +236,22 @@
 	}
 	printf("loading \"%s\" ", bi_path.bootpath);
 	marks[MARK_START] = 0;
-	if (fdloadfile(fd, marks, LOAD_KERNEL) < 0)
+
+	if (howto == -1) {
+		/* load another altboot binary and replace ourselves */
+		len = read(fd, (void *)0x100000, 0x1000000 - 0x100000);
+		if (len == -1)
+			goto loadfail;
+		close(fd);
+		netif_shutdown_all();
+
+		memcpy((void *)0xf0000, newaltboot,
+		    newaltboot_end - newaltboot);
+		__syncicache((void *)0xf0000, newaltboot_end - newaltboot);
+		printf("Restarting...\n");
+		run((void *)1, argv, (void *)0x100000, (void *)len,
+		    (void *)0xf0000);
+	} else if (fdloadfile(fd, marks, LOAD_KERNEL) < 0)
 		goto loadfail;
 	close(fd);
 

Index: src/sys/arch/sandpoint/stand/altboot/version
diff -u src/sys/arch/sandpoint/stand/altboot/version:1.3 src/sys/arch/sandpoint/stand/altboot/version:1.4
--- src/sys/arch/sandpoint/stand/altboot/version:1.3	Sat Feb 26 20:11:24 2011
+++ src/sys/arch/sandpoint/stand/altboot/version	Sun Mar 13 15:23:43 2011
@@ -6,3 +6,6 @@
 1.4:	load kernels from local disk
 1.5:	altboot is the new name as this is capable of handling net & dsk.
 1.6:	build altboot.img to fake a Linux kernel module, supports bootargs
+1.7:	ST1023/IP1000A driver, load kernels from memory (mem:), possibility
+	to replace altboot with a new version while running, interactive
+	mode, default boot path is now wd0:netbsd in multiuser mode

Reply via email to