Hi All,
             Please help me how to flash the ubi image from barebox.
I generated the ubifs image using the mkfs.jffs2, then I created the ubi image using the ubinize. I am trying to flash this ubi image on NAND.

I tried in two ways
1) I flashed the UBI image directly on /dev/nand0.rootfs.bb(erased the partition before flash). 
In this method I am getting the errors like below

Freeing init memory: 152K
[   15.420000] UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 255: 7d6be97d instead of 55424921
[   15.430000] UBI warning: ubi_eba_copy_leb: error 3 while reading VID header back from PEB 255
[   15.510000] UBI: run torture test for PEB 255
[   19.430000] UBI error: torture_peb: read problems on freshly erased PEB 255, must be bad
[   19.440000] UBI error: erase_worker: failed to erase PEB 255, error -5
[   19.440000] UBI: mark PEB 255 as bad
[   19.450000] UBI: 1 PEBs left in the reserve
[   20.690000] UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 254: 7d6be97d instead of 55424921
[   20.700000] UBI warning: ubi_eba_copy_leb: error 3 while reading VID header back from PEB 254
[   20.710000] UBI: run torture test for PEB 254
[   24.630000] UBI error: torture_peb: read problems on freshly erased PEB 254, must be bad
[   24.640000] UBI error: erase_worker: failed to erase PEB 254, error -5
[   24.640000] UBI: mark PEB 254 as bad
[   24.650000] UBI warning: erase_worker: last PEB from the reserved pool was used
[   26.030000] UBI warning: ubi_io_read_vid_hdr: bad magic number at PEB 253: 7d6be97d instead of 55424921
[   26.040000] UBI warning: ubi_eba_copy_leb: error 3 while reading VID header back from PEB 253
[   26.050000] UBI: run torture test for PEB 253
[   29.980000] UBI error: torture_peb: read problems on freshly erased PEB 253, must be bad
[   29.990000] UBI error: erase_worker: failed to erase PEB 253, error -5
[   30.000000] UBI error: erase_worker: no reserved physical eraseblocks
[   30.010000] UBI warning: ubi_ro_mode: switch to read-only mode
[   30.010000] Backtrace:
[   30.010000] [<c000c528>] (dump_backtrace+0x0/0x110) from [<c038df94>] (dump_stack+0x18/0x1c)
[   30.020000]  r6:dfac2b30 r5:dfac2800 r4:fffffffb r3:c04d93dc
[   30.030000] [<c038df7c>] (dump_stack+0x0/0x1c) from [<c023f05c>] (erase_worker+0x55c/0x5c8)
[   30.040000] [<c023eb00>] (erase_worker+0x0/0x5c8) from [<c023f858>] (do_work+0xd8/0x114)
[   30.040000] [<c023f780>] (do_work+0x0/0x114) from [<c02400dc>] (ubi_thread+0x10c/0x19c)
[   30.050000]  r7:00000000 r6:00000000 r5:dfb84000 r4:dfac2800
[   30.060000] [<c023ffd0>] (ubi_thread+0x0/0x19c) from [<c0049f18>] (kthread+0x90/0x98)
[   30.070000] [<c0049e88>] (kthread+0x0/0x98) from [<c002f654>] (do_exit+0x0/0x69c)
[   30.070000]  r6:c002f654 r5:c0049e88 r4:df82ded4
[   30.080000] UBI error: do_work: work failed with error code -5
[   30.080000] UBI error: ubi_thread: ubi_bgt0d: work failed with error code -5

2) I executed the below commands from barebox
#erase /dev/nand0.rootfs.bb
#ubiattach /dev/nand0.rootfs
 After this command it created the /dev/ubi0
#ubimkvol /dev/ubi0 rootfs 0
   After this command it created the /dev/ubi0.rootfs
After these commands I copied the ubifs image on to the /dev/ubi0.rootfs.
 #tftp root.ubifs /dev/ubi0.rootfs
Now I booted the kernel, in this method, I am getting the error like the volume layout not found.

Please tell me which method is correct. If the above two methods are not correct, please suggest me the correct method.

Thanks