Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:techref:mtd [2018/02/20 18:52] – ↷ Links adapted because of a move operation bobafetthotmaildocs:techref:mtd [2023/03/04 18:00] (current) – typo openwart
Line 1: Line 1:
-| FIXME This page is a Work In Progress. The goal is to make it similar to [[docs:user-guide:additional-software:opkg]] and then link to it as often as possible |+| FIXME This page is a Work In Progress. The goal is to make it similar to [[docs:guide-user:additional-software:opkg]] and then link to it as often as possible |
  
 ====== MTD ====== ====== MTD ======
 ''mtd'' is a utility we use to write to an MTD (Memory Technology Device). Please read the [[#Notes]] to learn more. ''mtd'' is a utility we use to write to an MTD (Memory Technology Device). Please read the [[#Notes]] to learn more.
-cd /tmp 
-wget http://www.example.org/original_firmware.bin 
-mtd -r write /tmp/original_firmware.bin firmware 
- 
- 
 ===== Invocation ===== ===== Invocation =====
 <code> <code>
Line 33: Line 28:
  
 ===== Examples ===== ===== Examples =====
-To write ''linux.trx'' to ''mtd4'' labeled as ''linux'' and reboot afterwards:+Download ''linux.bin'' from Internet (it's not safe to do so, here is for demonstration purpose only), then write ''linux.bin'' to a MTD partition labeled as ''linux'' (could be ''mtd4''and reboot afterwards:
 <code> <code>
-mtd -r write linux.trx linux+cd /tmp 
 +wget http://www.example.org/linux.bin 
 +mtd -r write /tmp/linux.bin linux
 </code> </code>
  
 +===== Example (flash u-boot from OpenWrt) =====
 +
 +Tested  on Marvell EspressoBinBoard based on MVEBU, (see [[https://forum.openwrt.org/t/is-it-possible-to-flash-u-boot-from-openwrt/90284|forum topic]])
 +Download ''flash-image.bin'' for your specific hardware from [[https://downloads.openwrt.org/snapshots/targets/mvebu/cortexa53/|SnapShots]]
 +
 +You can checks your mtd partitions from proc : 
 +<code>
 +root@EBIN:~# cat /proc/mtd 
 +dev:    size   erasesize  name
 +mtd0: 003f0000 00010000 "firmware"
 +mtd1: 00010000 00010000 "u-boot-env"
 +
 +</code>
 +
 +(it's not safe to do so, here is for demonstration purpose only), 
 +
 +then write ''flash-image.bin'' to a MTD partition labeled as ''spi0.0'' (could be ''mtd0'' or ''firmware'') and reboot afterwards :
 +<code>
 +cd /tmp
 +wget https://downloads.openwrt.org/snapshots/targets/mvebu/cortexa53/trusted-firmware-a-espressobin-v7-1gb/flash-image.bin
 +mtd -r write /tmp/flash-image.bin /dev/mtd0
 +</code>
  
 ===== mtd vs dd ===== ===== mtd vs dd =====
 The differences between ''[[http://linux.die.net/man/1/dd|dd]]'' (disc dump) and ''mtd'' are ...  The differences between ''[[http://linux.die.net/man/1/dd|dd]]'' (disc dump) and ''mtd'' are ... 
 TODO TODO
 +
 +===== mtd on vendor-firmware =====
 +''mtd'' can even be used with vendor-firmware, as long as the kernel had mtd-support and not using something "home-brewed". When the vendor is not shipping the binary it can probably transferred via ''scp'', ''netcat'', ''tftp'', ''ftp'', ''http''onto the board. The original binary from the OpenWrt-package might not run on the vendor-os, but linking it static should do the trick. 
 +With OpenWrt-21.02 I was using a small hack to to let the buildroot create a static binary:
 +
 +<code>
 +sed -i -e "s/^LDFLAGS += /LDFLAGS += -static /" package/system/mtd/src/Makefile
 +make package/mtd/compile
 +</code>
 +
 +This patches the mtd source to include the "-static" option when building the binary. This way the binary gets all dependent library-code embedded to make it run itself, as long as the correct CPU-target is used. The new binary can be extracted from the resulting package or just copied from ''build_dir/target-<ARCH>/linux-<TARGET>-<SUBTARGET>/mtd''.
  
 ===== Notes ===== ===== Notes =====
  • Last modified: 2018/02/20 18:52
  • by bobafetthotmail