On Sat, Mar 17, 2012 at 10:58:05AM +1100, James Cameron wrote:
> On Fri, Mar 16, 2012 at 11:58:51AM -0600, Daniel Drake wrote:
> In OpenFirmware, we might either:
> 
>  * do the resize only if the .zd file requests it, (a new ''resize:''
>    line after ''zblocks-end:''), or

This has been written and tested locally.  The patch is attached for
review.

> Adding resize: to the end of an .zd file does not cause any error on the
> current version of OpenFirmware on XO-1.75, so it can be added now:

I was wrong about this ... in that the zblocks-end: causes the file to
be closed, so the resize: won't be seen in that position.  If it is added
above the zblocks-end: a warning occurs, but the fs-update does complete.

Attached is a revised patch, which places the resize: before
zblocks-end: with a wrapper to prevent warning.  This allows the resize:
request to be added to olpc-os-builder without requiring OpenFirmware
support.

-- 
James Cameron
http://quozl.linux.org.au/
Index: cpu/x86/pc/olpc/via/fsupdate.fth
===================================================================
--- cpu/x86/pc/olpc/via/fsupdate.fth	(revision 2889)
+++ cpu/x86/pc/olpc/via/fsupdate.fth	(working copy)
@@ -63,6 +63,7 @@
    then
 ;
 
+false value fs-update-resize?
 vocabulary nand-commands
 also nand-commands definitions
 
@@ -93,6 +94,47 @@
    fexit
 ;
 
+h# 1be. 2value pt  \ device byte offset to start of partition table
+h# 10 value /pe    \ size of a partition entry
+/pe buffer: pe     \ partition entry buffer
+
+: pe-seek   ( n -- )
+   1- /pe * 0 pt d+                  ( d.pos )
+   " seek" nandih $call-method drop  ( )
+;
+
+: pe-read   ( n -- )  pe-seek  pe /pe " read"  nandih $call-method drop  ;
+: pe-write  ( n -- )  pe-seek  pe /pe " write" nandih $call-method drop  ;
+
+: pe-start@   ( pe -- start )   pe h# 08 + le-l@  ;
+: pe-length@  ( pe -- length )  pe h# 0c + le-l@  ;
+: pe-length!  ( length pe -- )  pe h# 0c + le-l!  ;
+
+: pe-is-set?  ( pe# -- flag )   pe-read  pe-start@ pe-length@ or  ;
+
+: (resize:)  ( -- )
+   4 pe-is-set?  abort" partition 4 is non-zero"
+   3 pe-is-set?  abort" partition 3 is non-zero"
+   " size" nandih $call-method d# 512 um/mod swap drop
+                              ( d-end )
+   2 pe-read                  ( d-end )
+   pe-start@  dup >r          ( d-end p-start )  ( r: p-start )
+   pe-length@ + swap          ( p-end d-end )    ( r: p-start )
+   2dup > abort" partition ends beyond device size"
+   2dup < if                  ( p-end d-end )    ( r: p-start )
+      nip r> - pe-length!     ( )                ( r: )
+      2 pe-write              ( )                ( r: )
+   else                       ( p-end d-end )    ( r: p-start )
+      r> 3drop                ( )                ( r: )
+   then                       ( )                ( r: )
+;
+
+: resize:  ( -- )
+   " write-blocks-end" $call-nand   ( error? )
+   " Write error" ?nand-abort
+   fs-update-resize?  if (resize:) then
+;
+
 : data:  ( "filename" -- )
    safe-parse-word            ( filename$ )
    nb-zd-#sectors  -1 <>  if  ( filename$ )
@@ -240,9 +282,21 @@
 ;
 
 : fs-update  ( "devspec" -- )
+   true to fs-update-resize?
    safe-parse-word $fs-update
 ;
 
+: fs-update-no-resize  ( "devspec" -- )
+   false to fs-update-resize?
+   safe-parse-word $fs-update
+;
+
+: fs-resize  ( -- )
+   open-nand
+   [ also nand-commands ] (resize:) [ previous ]
+   close-nand
+;
+
 : do-fs-update  ( img$ -- )
    tuck  load-base h# c00000 +  swap move  ( len )
    load-base h# c00000 + swap              ( adr len )
>From 778c97e83522c8e6c62e0aa0a4f2413d765c9d13 Mon Sep 17 00:00:00 2001
From: James Cameron <qu...@laptop.org>
Date: Sat, 17 Mar 2012 13:51:27 +1100
Subject: [PATCH] root partition resize after fs-update, #11690

Direct OpenFirmware to resize the root partition just before the end of
the file.  OpenFirmware is to ignore this if fs-update-no-resize is used.
---
 bin/zhashfs.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/bin/zhashfs.c b/bin/zhashfs.c
index dd712ae..eb49549 100644
--- a/bin/zhashfs.c
+++ b/bin/zhashfs.c
@@ -158,6 +158,11 @@ static void read_extents(FILE *infile)
 		process_extent(&fiemap->fm_extents[i]);
 }
 
+void write_end(FILE *file) {
+  LTC_ARGCHK(fputs("[ifdef] resize: resize: [then]\n", file) >= 0);
+  LTC_ARGCHK(fputs("zblocks-end:\n", file) >= 0);
+}
+
 int main(int argc, char **argv)
 {
     char          *fname;
@@ -259,8 +264,8 @@ int main(int argc, char **argv)
     LTC_ARGCHK(readlen == zblocksize);
     write_block(0, buf);
 
-    fprintf(outfile, "zblocks-end:\n");
-    fprintf(zfile,   "zblocks-end:\n");
+    write_end(outfile);
+    write_end(zfile);
 
     fclose(infile);
     fclose(outfile);
-- 
1.7.9.1

_______________________________________________
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel

Reply via email to