| #!/bin/sh |
| |
| # Get the pnor mtd device number |
| pnor=`grep pnor /proc/mtd |cut -c 4` |
| |
| # Attach the pnor mtd device to ubi |
| ubiattach /dev/ubi_ctrl -m $pnor |
| if [ $? -ne 0 ] |
| then |
| # Check the pnor mtd device is formatted as ubi by reading the first 3 byes, |
| # which should be the ascii chars 'UBI' |
| magic=`hexdump -C -n 3 /dev/mtd$pnor` |
| if [[ $magic == *"UBI"* ]] |
| then |
| # Device already formatted as ubi, ubiattach failed for some other reason |
| exit -1 |
| else |
| # Format device as ubi |
| bios-ubiformat |
| # Retry the ubiattach |
| ubiattach /dev/ubi_ctrl -m $pnor |
| fi |
| fi |