Firefly Open Source Community

Title: Making "snapshot" [Print This Page]

Author: vittly    Time: 11/19/2014 23:55
Title: Making "snapshot"
I've installed you t-firefly ubuntu and have configured it. Is there a way to make my own image of device (boot, kernel, fs ...) as a backup for "may be" situation of system failure?
Author: busybee    Time: 11/20/2014 09:18

This is a brief document about this packing process.


1. Copy following files to your packing directory.

a. Control files
- ATTACHMENT/package-file (describes package content of update.img)
- ATTACHMENT/parameter (parameter for Ubuntu, contains eMMC partition info)
- ATTACHMENT/update-script (not used for Linux, for completion only)
- ATTACHMENT/recovery-script (not used for Linux, for completion only)
- ATTACHMENT/misc-zero.img (boot command, zero will lead to normal boot)

b. RKTools
- RKTools/linux/Linux_Upgrade_Tool_v1.2/rockdev/afptool (RK firmware packing tools)
- RKTools/linux/Linux_Upgrade_Tool_v1.2/rockdev/rkImageMaker (RK image maker)

c. Bootloader and your images
- SDK/RKTools/bootloader/uboot-emmc/RK3288Loader_uboot_V2.17.02.bin, renamed to RKLoader.bin
- Your linux-rootfs.img (ext4 filesystem image, for Linux root)
- Your linux-boot.img (See wiki doc http://wiki.t-firefly.com/index.php/Fir ... _kernel/en to create your own)
- Your resource.img (In SDK/kernel, after successful kernel compilation)

2. do the packing
First, cd to your packing directory. Then run the following commands:

./afptool -pack ./ update_tmp.img
./rkImageMaker -RK32 RKLoader.bin update_tmp.img update.img -os_type:androidos
rm -f update_tmp.img

Now, your update.img is ready to serve.

rk-pack-linux-control-files.zip (1.99 KB, Down times: 12)

Author: tedd77    Time: 12/17/2014 01:44

Hello busybee,

Being a member of Firefly and a support engineer, could you please elaborate more on the procedure?




There are several ambiguous points and some missing files, to start with :




c. Bootloader and your images

- Your linux-rootfs.img (ext4 filesystem image, for Linux root) (What do you mean by Your linux? how can I get it and where from ? especially that I am not using any external storage)
- Your linux-boot.img (See wiki doc [/url][url=http://wiki.t-firefly.com/index.php/Firefly-RK3288/Build_kernel/en]

http://wiki.t-firefly.com/index.php/Fir


... _kernel/en to create your own) (make my own ? but I already have a running system, I am lost here)
- Your resource.img (In SDK/kernel, after successful kernel compilation) (Where from ? and how to?realize?that ?)




Thank you for your earliest reply.



Author: busybee    Time: 12/17/2014 09:39

Hi tedd77. The op topic is making "snapshot", which involves packing all the image files into one big firmware file (update.img).




All my instructions are for those who would like to compile everything from scratch.




- Your linux-rootfs.img (ext4 filesystem image, for Linux root)

See wiki page:?
http://wiki.t-firefly.com/index.php/Fir ... ntu_rfs/en



- Your linux-boot.img and?resource.img?(In SDK/kernel, after successful kernel compilation)





http://wiki.t-firefly.com/index.php/Fir ... _kernel/en






Of course, you can extract those images from our released firmware file.?

Try to run?AndroidTool (
http://wiki.t-firefly.com/index.php/Fir ... lash_Image

),

switch to "Advanced Function" tab, and you'll find the "Unpack" button.

First browse the firmware file and then click "Unpack".






Author: tedd77    Time: 12/17/2014 19:22

Hello busybee,




Thank you. Since I am making a snapshot or an image of an existing running system the procedure are not the same.

The hard time I am having is to figure out the way especially downloading the SDK is not a given task, you would spend days trying to get it as it is slow and not reliable.

Could you please be kind enough to help me get the right detailed procedures? my task is the reverse , it is to make an image from my firefly unit.

It is like making an image of an existing windows computer to apply it later to other machines using GHOST or other image making softwares.




Sorry for the troubles, but this is important for me as well as to others I am sure.
Author: tedd77    Time: 12/19/2014 20:35

Hello busybee,

If Firefly support cannot help, where from can we get it ?

Please let me know if you are willing to support or not! that way I can decide which way to go. Thank you
Author: jas-rk    Time: 12/19/2014 21:06
If it helps you can make a backup of the individual partitions on the eMMC using rkflashkit, some instructions on the wiki . ?It's not exactly the same as making a complete image of the eMMC but you should be able to restore them.
Author: tedd77    Time: 12/20/2014 08:44

jas-rk ,?Thank you, unfortunately the rkflashkit is not detecting my firefly board therefore I am unable to test what you suggested.



Author: busybee    Time: 12/20/2014 11:28

There're many ways of copying out the linux root filesystem.

The easy way, is using rkflashkit or alike to backup the linuxroot partition


Another way,  is copying out the files in linuxroot, by mounting a SD card/usb disk etc:

a. Insert your sd card/usb disk.


b. Check the path (usually under /media/firefly), and cd into that.

    $ cd /media/firefly/your_sd_card


c. Check your rootfs's size:

    $ sudo du -hxs /
    1.8G /

d. Create the ext4fs image file:

    $ sudo dd if=/dev/zero of=new_ubuntu.img bs=1M count=2000

    $ sudo mkfs.ext4 -m0 new_ubuntu.img

NOTE: 1. bs * count should be greater than your size of root partition (add about 200~300M for extra space)

          2. If you're using the vfat filesystem in the sdcard, the vfat has a file limit of 4GiB bytes.


c. Mount the image file:

    $ sudo mkdir -p /mnt/new

    $ sudo mount -o loop new_ubuntu.img /mnt/new


d. Copy files:

    $ sudo cp -ax /  /mnt/new/


e. Umount the image file:

    $ sudo umount /mnt/new


Now your root files are copied into new_ubuntu.img, which can be flashed back later on.

And the first time you flashed the image back, you'd better run a resize2fs on the linuxroot partition:

    $ sudo resize2fs /dev/block/mtd/by-name/system


Author: busybee    Time: 12/20/2014 11:39

For rkflashkit alike tools to work, the device must be set to "upgrade mode".?

?
http://wiki.t-firefly.com/index.php/Fir ... h_image/en

?has the detail.
Author: tedd77    Time: 12/21/2014 06:24

Hello busybee,

Thank you for the instructions.

The results of sudo du -hxs / is 3.2G

I am stuck a the following point : $ sudo mount -o loop new_ubuntu.img /mnt/new

Getting error ?mount: block device /media/firefly/sd31g/new_ubuntu.img is write-protected, mounting read-only
mount: you must specify the filesystem type


The sd card was formatted as file system type=fat32




could you please advice if the command is correct?



Author: tedd77    Time: 12/22/2014 08:07

Hello,

I was able to make the rkflashkit see my device, I can see the following partitions:

resource, boot, misc, backup

I did backup all of them, but re-flashing them to the other board did not seem to make it identical. actually nothing has changed at all.



Author: busybee    Time: 12/22/2014 11:07

Hi tedd77, I've revised the instructions a bit. Please do a mkfs.ext4 before mounting it.


Afer the loop mount, please use a "df -h" command to see if the free space is big enough to hold your Linux rootfs files.


It's best to use rkflashkit to backup in your case.


Here's my output of rkflashkit:

-----------------------8<-------------------8<--------------------------

$ sudo rkflashkit part
Found devices:
0x2207:0x320a

============= 2014-12-22 11:03:55 ============


Loading partition information

PARMxFIRMWARE_VER:4.4.2
MACHINE_MODEL:rk30sdk
MACHINE_ID:007
MANUFACTURER:RK30SDK
MAGIC: 0x5041524B
ATAG: 0x60000800
MACHINE: 3066
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
#KERNEL_IMG: 0x62008000
#FDT_NAME: rk-kernel.dtb
#RECOVER_KEY: 1,1,0,20,0
CMDLINE:console=ttyFIQ0 androidboot.hardware=rk30board androidboot.console=ttyFIQ0 board.ap_has_alsa=0 root=/dev/block/mtd/by-name/linuxroot rw rootfstype=ext4 init=/sbin/init initrd=0x62000000,0x00800000 mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),0x00002000@0x00004000(misc),0x00008000@0x00006000(resource),0x00008000@0x0000e000(kernel),0x00010000@0x00016000(boot),0x00010000@0x00026000(recovery),0x0001a000@0x00036000(backup),0x00040000@0x00050000(cache),0x00002000@0x00090000(kpanic),0x00180000@0x00092000(system),0x00002000@0x00212000(metadata),0x00200000@0x00214000(userdata),0x00620000@0x00414000(linuxroot),-@0x00a34000(user)

Partitions:
uboot        (0x00002000 @ 0x00002000)    4 MiB
misc         (0x00002000 @ 0x00004000)    4 MiB
resource     (0x00008000 @ 0x00006000)   16 MiB
kernel       (0x00008000 @ 0x0000e000)   16 MiB
boot         (0x00010000 @ 0x00016000)   32 MiB
recovery     (0x00010000 @ 0x00026000)   32 MiB
backup       (0x0001a000 @ 0x00036000)   52 MiB
cache        (0x00040000 @ 0x00050000)  128 MiB
kpanic       (0x00002000 @ 0x00090000)    4 MiB
system       (0x00180000 @ 0x00092000)  768 MiB
metadata     (0x00002000 @ 0x00212000)    4 MiB
userdata     (0x00200000 @ 0x00214000) 1024 MiB
linuxroot    (0x00620000 @ 0x00414000) 3136 MiB

-----------------------8<-------------------8<--------------------------


You can see the linuxroot partition above, right ? Then you can backup it by issueing command:


    $ sudo rkflashkit backup @linuxroot  mylinuxroot.img


Author: tedd77    Time: 12/22/2014 17:17

hello busybee,


thank you, I will try again to do the image using your method.

as for the rkflashkit the only partitions I can see are resource, boot, misc, and backup.

============= 2014-12-22 10:11:54 ============


    Loading partition information

    PARM FIRMWARE_VER:4.4.2
    MACHINE_MODEL:rk30sdk
    MACHINE_ID:007
    MANUFACTURER:RK30SDK
    MAGIC: 0x5041524B
    ATAG: 0x60000800
    MACHINE: 3066
    CHECK_MASK: 0x80
    PWR_HLD: 0,0,A,0,1
    #KERNEL_IMG: 0x62008000
    #FDT_NAME: rk-kernel.dtb
    #RECOVER_KEY: 1,1,0,20,0
    CMDLINE:console=ttyFIQ0,115200 root=/dev/block/mtd/by-name/linuxroot rw rootfstype=ext4 init=/sbin/init initrd=0x62000000,0x00800000 mtdparts=rk29xxnand:0x00008000@0x00002000(resource),0x00008000@0x0000A000(boot),0x00002000@0x00012000(misc),0x0001a000@0x00014000(backup),-@0x0002e000(linuxroot)

Partitions:
resource     (0x00008000 @ 0x00002000)   16 MiB
boot         (0x00008000 @ 0x0000a000)   16 MiB
misc         (0x00002000 @ 0x00012000)    4 MiB
backup       (0x0001a000 @ 0x00014000)   52 MiB

-----------------------

Although the linuxroot is stated in the CMDLINE however I cannot see in the form of a partition in order to be able to backup.


I am using the rkflashkit present under the git clone https://github.com/linuxerwang/rkflashkit

Best regards


Author: tedd77    Time: 12/23/2014 01:07

hello busybee,




I did the image as per your instructions, when trying to flash with androidtool I get loading firmware failed.

Unless there is another tool to flash back to the board the image we created it not suitable .




I hope my experience will benefit other members.

Please look into it and advise with proper remedie.



Author: busybee    Time: 12/23/2014 09:41

Woud you please post the AndroidTool snapshot with failure message?




I personally like to flash individual image with rkflashkit:




sudo rkflashkit flash @linuxroot ?your_linux_root.img




or launch its friendly GUI:

sudo rkflashkit

select the partition and image file and flash.



Author: tedd77    Time: 12/24/2014 02:09

Hello busybee,




Please find attached the screenshots, as I mentionned in an earlier post I do not see all partitions.

1. Screeshot of the error for the command sudo rkflashkit @linuxroot my_image_path_and_name

2. the sudo rkflashkit part






Author: busybee    Time: 12/24/2014 14:33
Ahha, you're using the pure Ubuntu firmware. That's the reason you don't have the system partitiion etc.

The correctly flash command is (fixed in my previous post):

sudo rkflashkit flash @linuxroot your_linux_root.img

and you can get the usage by:

rkflashkit help



Author: tedd77    Time: 12/25/2014 09:41

Hello busybee,




Attached is the screenshot, yet the command is producing errors.

Yes I am using the ubuntu image only on my firefly board.

The linuxroot is still not recognized.



Author: busybee    Time: 12/26/2014 16:02




Sorry, tedd77, I though it just worked, but it didn't.

Especially I've been using rkflashkit and never met your problem.

I did not notice your linuxroot partition is special, in that the size is ommited ('-'), which means to use rest of the storage.

(I spent most of my time in dual firmware.)




But rkflashkit already has the solution, you can specify "SIZE@OFFSET(PART)" instead of "@PART", like:

sudo rkflashkit flash 0x202000@0x0002e000(linuxroot) linux-rootfs-ubuntu-14.04.img reboot




The size and offset are both using units of sector (512 bytes).

Since it is error-proned, I write a script named "flash-linux-root" to do this.

Please save the attachment file "flash-linux-root.txt" as "flash-linux-root.sh", and do a chmod before use:

chmod 755 flash-linux-root.sh




Then run it:

./flash-linux-root.sh /path/to/your/linux-rootfs-ubuntu-14.04.img 0x0002e000




This is my output of running this:

$ ~/flash-linux-root.sh linux-rootfs-ubuntu-14.04.img 0x0002e000
About to run:
sudo rkflashkit flash 0x202000@0x0002e000(linuxroot) linux-rootfs-ubuntu-14.04.img reboot
Press enter to continue...
Found devices:
0x2207:0x320a
[('202000', '0x0002e000')]
============= 2014-12-26 15:49:17 ============

Writing file linux-rootfs-ubuntu-14.04.img to partition 0x00202000@0x0002E000
writing flash memory at offset 0x0002e000
.....




Hope it finally helps. Thanks.






Author: tedd77    Time: 12/26/2014 18:46

Hello busybee,




Thank you for the prompt reply, could you please attach the script file ? you missed to attach it to your post.

And where from to get linux-rootfs-ubuntu-14.04.img ?
Author: tedd77    Time: 12/27/2014 04:11

Hello busybee,




Assume I will be obliged to use the dualboot image in order to overcome the issue of backup.

How can I have the linuxroot partition size as large as 8Gbytes? I tried to look on ways to enlarge it with no luck.

If I can do that then I guess my issue of backing and restoring the partitions will be straight forward.



Author: busybee    Time: 12/29/2014 10:18

Annoying forum attachment which won't accept *.txt, *.sh, except .zip file.




Please uncompress the zip file first.
Author: tedd77    Time: 12/30/2014 09:10

Hello busybee,




Thank you , it is working now. great script.




Best regards




Welcome Firefly Open Source Community (https://bbs.t-firefly.com/) Powered by Discuz! X3.1