# Collect a set of files from the rootfs and "pack" it to UserDef. Each file # consists of # # 4 bytes: file size S (little endian) # S bytes: file data # 1 byte: length L of the file name # 1 byte: '=' (ignored) # L bytes: file name # 0..3 bytes: padding (with 0) to get a 32-bit alignment for the next size # # The sequence ends if a file size of 0 is found. # List of files to load; it is OK if a file does not exist setenv path "/root" setenv files "file1 file2 file3" # Mount the rootfs ubi part TargetFS ubifsmount ubi0:rootfs # Save loadaddr setenv start $loadaddr setenv current $loadaddr # If a file exists, store its information at $current, then increment position # and pad with zeroes. For storing the file name, env export is used. This # stores a name=value pair. The name is 'x' and is overwritten by the file # name length afterwards, but this explains why the '=' remains visible. for i in $files; do setexpr data $current + 4 if ubifsload $data $path/$i; then # Successful loading sets $filesize, store as size S mw.l $current $filesize setexpr current $data + $filesize # Set file name; the local variable i can not be exported, so copy to # regular environment variable x first setenv x "$i" env export -b $current x # Find terminating zero and compute file name length setenv fname $current while itest.b *$current != 0; do setexpr current $current + 1 done # Write file name length L (counted without the leading "x=") setexpr length $current - $fname setexpr length $length - 2 mw.b $fname $length # Align $current to next 32 bit boundary, pad with zeroes while setexpr t $current \& 3 itest $t != 0 do mw.b $current 0 setexpr current $current + 1 done fi done # Add final size 0 to indicate end of list mw.l $current 0 setexpr current $current + 4 # Restore loadaddr setenv loadaddr $start # Save file collection to UserDef setexpr size $current - $start nand erase.part UserDef nand write . UserDef $size