Welcome! Log In Create A New Profile

Advanced

Restore to mtd partitions

Posted by abp 
abp
Restore to mtd partitions
September 26, 2019 04:34PM
Hi
I have some files and I want to write in mtd partitions.

My files name are:
- BOOT.bin
- devicetree.dtb
- rootfs.jffs2
- uImage

How can I do it?
These images has a .sh file to install.
here is the code:

if [ -e BOOT.bin ]; then
        flash_erase /dev/mtd0 0x0 0x80 >/dev/null 2>&1
        nandwrite -p -s 0x0 /dev/mtd0 ./BOOT.bin >/dev/null 2>&1
        rm -rf BOOT.bin
    fi

    if [ -e devicetree.dtb ]; then
        flash_erase /dev/mtd0 0x1020000 0x1 >/dev/null 2>&1
        nandwrite -p -s 0x1020000 /dev/mtd0 ./devicetree.dtb >/dev/null 2>&1
        rm devicetree.dtb
    fi

    if [ -e uImage ]; then 
      flash_erase /dev/mtd0 0x1100000 0x40 >/dev/null 2>&1
      nandwrite -p -s 0x1100000 /dev/mtd0 ./uImage >/dev/null 2>&1
      rm uImage
    fi

    if [ -e rootfs.jffs2 ]; then
      if [ -f /dev/mtd3 ];then
          flash_erase /dev/mtd2 0x0 0x1E0 >/dev/null 2>&1
      else
          flash_erase /dev/mtd2 0x0 0x280 >/dev/null 2>&1
      fi
      nandwrite -p -s 0x0 /dev/mtd2 ./rootfs.jffs2 >/dev/null 2>&1
      rm rootfs.jffs2
    fi

When I want to run "flash_erase /dev/mtd0 0x0 0x80"
I get this error:

libmtd: error!: "/dev/mtd0" is not a character device
flash_erase: error!: mtd_get_dev_info failed

How can I do it?
thanks
Re: Restore to mtd partitions
September 26, 2019 08:52PM
abp Wrote:
-------------------------------------------------------
> Hi
> I have some files and I want to write in mtd
> partitions.
>
> My files name are:
> - BOOT.bin
> - devicetree.dtb
> - rootfs.jffs2
> - uImage
>
> How can I do it?
> These images has a .sh file to install.
> here is the code:
>
>
> if [ -e BOOT.bin ]; then
>         flash_erase /dev/mtd0 0x0 0x80 >/dev/null
> 2>&1
>         nandwrite -p -s 0x0 /dev/mtd0 ./BOOT.bin
> >/dev/null 2>&1
>         rm -rf BOOT.bin
>     fi
> 
>     if [ -e devicetree.dtb ]; then
>         flash_erase /dev/mtd0 0x1020000 0x1
> >/dev/null 2>&1
>         nandwrite -p -s 0x1020000 /dev/mtd0
> ./devicetree.dtb >/dev/null 2>&1
>         rm devicetree.dtb
>     fi
> 
>     if [ -e uImage ]; then 
>       flash_erase /dev/mtd0 0x1100000 0x40
> >/dev/null 2>&1
>       nandwrite -p -s 0x1100000 /dev/mtd0 ./uImage
> >/dev/null 2>&1
>       rm uImage
>     fi
> 
>     if [ -e rootfs.jffs2 ]; then
>       if [ -f /dev/mtd3 ];then
>           flash_erase /dev/mtd2 0x0 0x1E0
> >/dev/null 2>&1
>       else
>           flash_erase /dev/mtd2 0x0 0x280
> >/dev/null 2>&1
>       fi
>       nandwrite -p -s 0x0 /dev/mtd2 ./rootfs.jffs2
> >/dev/null 2>&1
>       rm rootfs.jffs2
>     fi
>
>
> When I want to run "flash_erase /dev/mtd0 0x0
> 0x80"
> I get this error:
>
>
> libmtd: error!: "/dev/mtd0" is not a character
> device
> flash_erase: error!: mtd_get_dev_info failed
>
>
> How can I do it?
> thanks

Which box is it? Please post a boot log, or dmesg.

And then in Debian, Arch, ... whichever Linux distro you are running in this box:

cat /proc/mtd
cat /etc/fw_env.config
fw_printenv

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
abp
Re: Restore to mtd partitions
September 27, 2019 05:05AM
Thanks for reply
I solved above problem.

Now how can I view content?
Can I view directory and folders in images files? or /dev/mtd0 content?
Re: Restore to mtd partitions
September 27, 2019 05:00PM
abp,

> Now how can I view content?
> Can I view directory and folders in images files?
> or /dev/mtd0 content?

You did not answer my quesions above, so it is a little bit diffifult to show you how.

In Linux you could mount the file system which is currently on a flash partition. Some flash partitions don't have any file sysem.

These are raw images

- BOOT.bin
- devicetree.dtb
- uImage

This has JFFS2 file system on it

- rootfs.jffs2

To mount rootfs.jffs2 image as a disk partition, you need the host Linux kernel that has builtin supports for JFFS2 (such as this). And then use a couple commands to prepare and mount that. After is is mounted, it is just like any USB/HDD drive partition.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Restore to mtd partitions
September 27, 2019 08:00PM
Mount JFFS2 file system from Linux.

This requires that the kernel has these capabilities:

- JFFS2 supports, either as a builtin or loadable kernel module.
- mtdblock supports, either as a builtin or loadable kernel module.

Assuming mtd2 contains a JFFS2 file system.
mkdir /tmp/pogoroot
mknod /dev/mtdblock2 b 31 2
mount -t jffs2 -o ro /dev/mtdblock2 /tmp/pogoroot/

And then you can cd to it as a normal partition:

cd /tmp/pogoroot/

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 2 time(s). Last edit at 09/27/2019 08:03PM by bodhi.
abp
Re: Restore to mtd partitions
September 28, 2019 02:03AM
Thanks, bodhi

Can I message you in Whatsapp or Telegram or Skype? Please

Because I need to do it fastly.
Thanks
Re: Restore to mtd partitions
September 28, 2019 09:57PM
abp Wrote:
-------------------------------------------------------
> Thanks, bodhi
>
> Can I message you in Whatsapp or Telegram or
> Skype? Please
>
> Because I need to do it fastly.
> Thanks

Please post your questions here. I will do my best to answer promptly!

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 09/28/2019 09:58PM by bodhi.
abp
Re: Restore to mtd partitions
September 29, 2019 03:48AM
Thanks
I want to mount these image to my ubuntu (My system) and next view image content and directories and folders.

How can I do it?

Next to these files, was an install file (.sh file)

I attached this file.

Please help me to do it.

Thanks
Attachments:
open | download - runme.sh (4 KB)
Re: Restore to mtd partitions
September 29, 2019 05:30AM
abp,

> I want to mount these image to my ubuntu (My
> system) and next view image content and
> directories and folders.

Usually, on Ubuntu system you would have JFFS2 configured in as loadable module. To verify this take several steps.

You need to figure out which config file is appropriate to look at:

uname -a

And assuming that your current Ubuntu kernel is
4.15.0-52-generic
Then you would do:
grep -i jffs2 /boot/config-4.15.0-52-generic
And the output would say something like:

CONFIG_JFFS2_FS=m
....
...

Now knowing that JFFS2 is a loadable module in your Ubuntu kernel, you would modprobe it:

modprobe jffs2
And then verify that it was loaded:

lsmod | grep -i jffs2

And then mount the mtd like I've showed before.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 09/29/2019 05:31AM by bodhi.
abp
Re: Restore to mtd partitions
September 29, 2019 06:03AM
When I run this command: (uname -a)
I get this message:
Linux abp-pc 5.0.0-29-generic #31~18.04.1-Ubuntu SMP Thu Sep 12 18:29:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

and when I run (grep -i jffs2 /boot/config-4.15.0-52-generic) I get this message:
grep: /boot/config-4.15.0-52-generic: No such file or directory

What is the problem? please



Edited 1 time(s). Last edit at 09/29/2019 06:08AM by abp.
Re: Restore to mtd partitions
September 29, 2019 01:47PM
Linux abp-pc 5.0.0-29-generic #31~18.04.1-Ubuntu SMP Thu Sep 12 18:29:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Means your kernel is 5.0.0-29-generic. So the command is

grep -i jffs2 /boot/config-5.0.0-29-generic

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: