Welcome to the Linux Foundation Forum!

Mount image file to partitions

Hi

I downloaded a device firmware.
Like this:
zetnu.xilinx-201907311618-autofreq-user-Update2UBI-NF-sig.tar.gz

I extract above file and file content is these files:

  • BOOT.bin
  • devicetree.dtb
  • rootfs.jffs2
  • uImage

Next to this files, was a file yo install.
This file:
runme.sh

This file content is this:
`
#!/bin/sh -e

  1. path=$(pwd)
  2. cp_config="all"
  3. if [ ! -d /mnt/upgrade ];
  4. then
  5. mkdir /mnt/upgrade
  6. fi
  7.  
  8. if [ -e /usr/bin/ctrl_bd ]; then
  9. ret=`cat /usr/bin/ctrl_bd | grep "XILINX" | wc -l`
  10. else
  11. ret=0
  12. fi
  13.  
  14. if [ $ret -eq 1 ];then
  15. cd ./xilinx
  16.  
  17. if [ -e /dev/ubi_ctrl ];then
  18.  
  19. if [ ! -d /mnt/config ];then
  20. mkdir /mnt/config
  21. fi
  22. ubiattach /dev/ubi_ctrl -m 2
  23. mount -t ubifs ubi1:rootfs /mnt/config
  24. if [ ! -d /mnt/config/home/usr_config ];then
  25. mkdir /mnt/config/home/usr_config
  26. fi
  27.  
  28. if [ `ls /mnt/config/home/usr_config | wc -l` -gt 1 ];then
  29. cp_config="all" #cp -r /config/* /mnt/config/home/usr_config/
  30. else
  31. cp_config="mac" #cp -r /config/mac /mnt/config/home/usr_config/
  32. fi
  33.  
  34. umount /mnt/config
  35. ubidetach -d 1 /dev/ubi_ctrl
  36. fi
  37.  
  38. if [ -e BOOT.bin ]; then
  39. flash_erase /dev/mtd0 0x0 0x80 >/dev/null 2>&1
  40. nandwrite -p -s 0x0 /dev/mtd0 ./BOOT.bin >/dev/null 2>&1
  41. rm -rf BOOT.bin
  42. fi
  43.  
  44. if [ -e devicetree.dtb ]; then
  45. flash_erase /dev/mtd0 0x1020000 0x1 >/dev/null 2>&1
  46. nandwrite -p -s 0x1020000 /dev/mtd0 ./devicetree.dtb >/dev/null 2>&1
  47. rm devicetree.dtb
  48. fi
  49.  
  50. if [ -e uImage ]; then
  51. flash_erase /dev/mtd0 0x1100000 0x40 >/dev/null 2>&1
  52. nandwrite -p -s 0x1100000 /dev/mtd0 ./uImage >/dev/null 2>&1
  53. rm uImage
  54. fi
  55.  
  56. if [ -e rootfs.jffs2 ]; then
  57. if [ -f /dev/mtd3 ];then
  58. flash_erase /dev/mtd2 0x0 0x1E0 >/dev/null 2>&1
  59. else
  60. flash_erase /dev/mtd2 0x0 0x280 >/dev/null 2>&1
  61. fi
  62. nandwrite -p -s 0x0 /dev/mtd2 ./rootfs.jffs2 >/dev/null 2>&1
  63. rm rootfs.jffs2
  64. fi
  65.  
  66. if [ -e /dev/ubi_ctrl ];then
  67. if [ ! -d /mnt/config ];then
  68. mkdir /mnt/config
  69. fi
  70. ubiattach /dev/ubi_ctrl -m 2
  71. mount -t ubifs ubi1:rootfs /mnt/config
  72. if [ ! -d /mnt/config/home/usr_config ];then
  73. mkdir /mnt/config/home/usr_config
  74. fi
  75. if [ $cp_config == "all" ];then
  76. cp -r /config/* /mnt/config/home/usr_config/
  77. if [ -e ../lighttpd-htdigest.user ]; then
  78. line1=`cat ../lighttpd-htdigest.user | wc -c`
  79. if [ $line1 != "0" ]; then
  80. cp -r ../lighttpd-htdigest.user /mnt/config/home/usr_config/lighttpd-htdigest.user
  81. if [ -e ../shadow ]; then
  82. line2=`cat ../shadow | wc -c`
  83. if [ $line2 != "0" ]; then
  84. cp /etc/shadow /mnt/config/home/usr_config/shadow
  85. old_shd=`sed -n '1p' /mnt/config/home/usr_config/shadow`
  86. o1=`echo ${old_shd:5}`
  87. o2=${o1#*:}
  88.  
  89. new_shd=`cat ../shadow`
  90. n1=$new_shd":"$o2
  91.  
  92. sed -i '1d' /mnt/config/home/usr_config/shadow
  93. sed -i "1i $(echo $n1)" /mnt/config/home/usr_config/shadow
  94. fi
  95. fi
  96. fi
  97. fi
  98. else
  99. cp -r /config/mac /mnt/config/home/usr_config/
  100. fi
  101. sync
  102. umount /mnt/config
  103. ubidetach -d 1 /dev/ubi_ctrl
  104. fi
  105.  
  106. if [ -e /dev/ubi_ctrl ];then
  107. ubiattach /dev/ubi_ctrl -m 2
  108. mount -t ubifs ubi1:rootfs /mnt/upgrade
  109.  
  110. cd /mnt/upgrade/upgrade
  111. rm -rf /mnt/upgrade/upgrade/*
  112. cd $path
  113.  
  114. if [ -e ./xilinx/angstrom_rootfs.jffs2 ];then
  115. cp -rf ./xilinx/angstrom_rootfs.jffs2 /mnt/upgrade/upgrade
  116. if [ -f /dev/mtd3 ];then
  117. flash_erase /dev/mtd3 0 0xa0 >/dev/null 2>&1
  118. fi
  119. fi
  120. flash_erase /dev/mtd0 0x1040000 0x1 >/dev/null 2>&1
  121. nandwrite -p -s 0x1040000 /dev/mtd0 ./xilinx/upgrade-marker.bin >/dev/null 2>&1
  122.  
  123. sync
  124.  
  125. umount /mnt/upgrade
  126. ubidetach -d 1 /dev/ubi_ctrl
  127. fi
  128. else
  129. echo "this is not for c5"
  130. fi
  131.  
  132. rm -rf *.tar.gz
  133.  
  134.  
  135. #/sbin/reboot -f &

`

Above code used nandwrite to write in a device.

Now, I want to mount these images to a directory or partitions. and add or change somethings to these images. next write again to images.

How can I do it?
Step 1, I just want to mount and read file and directories.

Please help me.

Thanks

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training