Skip to content

Instantly share code, notes, and snippets.

@murano500k
Last active October 18, 2016 14:02
Show Gist options
  • Save murano500k/929fb569a5f85b42e927e94015657073 to your computer and use it in GitHub Desktop.
Save murano500k/929fb569a5f85b42e927e94015657073 to your computer and use it in GitHub Desktop.
#! /bin/sh
SIZE_SYSTEM=1024
START_SYSTEM=81937
END_SYSTEM=`echo $START_SYSTEM+$SIZE_SYSTEM*1024 | bc`
END_CACHE=`echo $END_SYSTEM+512*1024 | bc`
echo SIZE_SYSTEM $SIZE_SYSTEM
echo START_SYSTEM $START_SYSTEM
echo END_SYSTEM $END_SYSTEM
echo END_CACHE $END_CACHE
DRIVE=$1
if [[ $DRIVE == *"mmc"* ]]
then
DRIVEPREFIX="${DRIVE}p"
else
DRIVEPREFIX="${DRIVE}"
fi
PATH_TO_IMAGE=$2
umount $DRIVE*
df -Th
sync
TEMP=`parted $DRIVE print all | grep $DRIVE`
TEMP2="${TEMP#*: }"
SIZE="${TEMP2%\.*}"
echo DRIVE $DRIVE
SIZE_DATA=`echo $SIZE-6 | bc`
echo SIZE_DATA $SIZE_DATA
SIZE_KB=`echo $SIZE_DATA*1000000 | bc`
echo SIZE_KB $SIZE_KB
echo PATH_TO_IMAGE $PATH_TO_IMAGE
umount $DRIVE*
sudo dd if=/dev/zero of=$DRIVE bs=1M count=2000
parted $DRIVE --script unit KiB \
mklabel gpt \
mkpart primary fat16 32785 49169 \
mkpart primary fat16 49169 65553 \
mkpart primary fat16 65553 $START_SYSTEM \
mkpart primary ext4 $START_SYSTEM $END_SYSTEM \
mkpart primary ext4 $END_SYSTEM $END_CACHE \
mkpart primary ext4 $END_CACHE $SIZE_KB
umount $DRIVE*
sync
mkfs.vfat -F16 -n "recovery" ${DRIVEPREFIX}1
umount $DRIVE*
mkfs.vfat -F16 -n "boot" ${DRIVEPREFIX}1
umount $DRIVE*
mkfs.vfat -F16 -n "misc" ${DRIVEPREFIX}1
umount $DRIVE*
mkfs.ext4 -L "system" ${DRIVEPREFIX}4
umount $DRIVE*
mkfs.ext4 -L "cache" ${DRIVEPREFIX}5
umount $DRIVE*
mkfs.ext4 -L "data" ${DRIVEPREFIX}6
umount $DRIVE*
sync
parted $DRIVE --script print
./simg2img $PATH_TO_IMAGE/system.img $PATH_TO_IMAGE/raw_system.img
RES="$?"
if [[ $RES != 0 ]];then
sudo apt-get update
sudo apt-get install -y libc++-dev
./simg2img $PATH_TO_IMAGE/system.img $PATH_TO_IMAGE/raw_system.img
fi
dd if=./raw_system.img of=${DRIVEPREFIX}4 bs=4096
exit
#########################
sudo bash -x ./mmcpart-m.sh /dev/mmcblk0 /home/artem/renesas/builds/renesas_301_20160927_full_salvator_h3_userdebug
dd if=./raw_system.img of=/dev/mmcblk0p4 bs=4096
parted /dev/mmcblk0 --script print
sudo umount /dev/mmcblk0*
sudo parted /dev/mmcblk0 --script unit KiB \
mklabel gpt \
mkpart primary fat16 32785 49169 \
mkpart primary ext4 49169 65553 \
mkpart primary ext4 65553 81937 \
mkpart primary ext4 81937 1654801 \
mkpart primary ext4 1654801 2183185 \
mkpart primary ext4 2183185 15000000
sudo mkfs.vfat -F16 "recovery" /dev/mmcblk0p1
sudo umount /dev/mmcblk0*
sudo mkfs.ext4 -L "data" /dev/mmcblk0p6
sudo umount /dev/mmcblk0*
sudo sync
mktable gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk
will be lost. Do you want to continue?
Yes/No? y
(parted) unit KiB
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 32785
End? 49169
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 49169
End? 65553
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) print
Model: UFD 2.0 Silicon-Power16G (scsi)
Disk /dev/sdb: 15730688kiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 32785kiB 49169kiB 16384kiB ext4 primary
2 49169kiB 65553kiB 16384kiB ext4 primary
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 22939
End? ^C
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 65553
End? 22939
Error: Can't have the end before the start! (start sector=131106 length=-85228)
(parted) 81937
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices,
free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 65553
End? 81937
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) print
Model: UFD 2.0 Silicon-Power16G (scsi)
Disk /dev/sdb: 15730688kiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 32785kiB 49169kiB 16384kiB ext4 primary
2 49169kiB 65553kiB 16384kiB ext4 primary
3 65553kiB 81937kiB 16384kiB ext4 primary
(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext4
Start? 81937
End? 1654801
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) print
Model: UFD 2.0 Silicon-Power16G (scsi)
Disk /dev/sdb: 15730688kiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 32785kiB 49169kiB 16384kiB ext4 primary
2 49169kiB 65553kiB 16384kiB ext4 primary
3 65553kiB 81937kiB 16384kiB ext4 primary
4 81937kiB 1654801kiB 1572864kiB ext4 primary
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices,
free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
(parted) quit
Information: You may need to update /etc/fstab.
artem@home:~/Desktop$ umount /dev/sdb*
umount: /dev/sdb: not mounted
umount: /dev/sdb1: not mounted
umount: /dev/sdb2: not mounted
umount: /dev/sdb3: not mounted
umount: /dev/sdb4: not mounted
artem@home:~/Desktop$ sudo parted /dev/sdbError: Could not stat device /dev/sdb - No such file or
directory.
Retry/Cancel? ^C
artem@home:~/Desktop$ sync
artem@home:~/Desktop$ umount /dev/sdb*
umount: /dev/sdb*: No such file or directory
artem@home:~/Desktop$ mkfs.ext4 -L "recovery" /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
The file /dev/sdb1 does not exist and no size was specified.
artem@home:~/Desktop$ mkfs.ext4 -L "boot" /dev/sdb2
mke2fs 1.42.13 (17-May-2015)
The file /dev/sdb2 does not exist and no size was specified.
artem@home:~/Desktop$ mkfs.ext4 -L "misc" /dev/sdb3
mke2fs 1.42.13 (17-May-2015)
The file /dev/sdb3 does not exist and no size was specified.
artem@home:~/Desktop$ sudo sync
artem@home:~/Desktop$ sudo umount /dev/sdb*
umount: /dev/sdb*: mountpoint not found
artem@home:~/Desktop$ sudo mkfs.ext4 -L "recovery" /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
The file /dev/sdb1 does not exist and no size was specified.
artem@home:~/Desktop$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs tmpfs 293M 8.9M 284M 4% /run
/dev/sda5 ext4 20G 5.5G 14G 30% /
tmpfs tmpfs 1.5G 69M 1.4G 5% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/sda1 ext2 504M 150M 330M 32% /boot
/dev/sda4 ext4 143G 134G 2.1G 99% /home
tmpfs tmpfs 293M 72K 293M 1% /run/user/1000
/dev/sdc3 ext4 15M 140K 14M 2% /media/artem/boot
artem@home:~/Desktop$ sudo mkfs.ext4 -L "recovery" /dev/sdc1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: 6cd39b3d-cb4d-48e5-82ae-c05c6a24c6b2
Superblock backups stored on blocks:
8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
artem@home:~/Desktop$ mkfs.ext4 -L "boot" /dev/sdb2
mke2fs 1.42.13 (17-May-2015)
The file /dev/sdb2 does not exist and no size was specified.
artem@home:~/Desktop$ mkfs.ext4 -L "boot" /dev/sdc2
mke2fs 1.42.13 (17-May-2015)
Could not open /dev/sdc2: Permission denied
artem@home:~/Desktop$ sudo mkfs.ext4 -L "recovery" /dev/sdc1
mke2fs 1.42.13 (17-May-2015)
/dev/sdc1 contains a ext4 file system labelled 'recovery'
created on Mon Oct 17 23:25:14 2016
Proceed anyway? (y,n) n
artem@home:~/Desktop$ sudo mkfs.ext4 -L "boot" /dev/sdc2mke2fs 1.42.13 (17-May-2015)
/dev/sdc2 contains a ext4 file system labelled 'recovery'
created on Mon Oct 17 22:30:49 2016
Proceed anyway? (y,n) y
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: fd407714-6b63-47fe-88df-3a3799a03ba0
Superblock backups stored on blocks:
8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
artem@home:~/Desktop$ sudo sync
artem@home:~/Desktop$ sudo umount /dev/sdb*
umount: /dev/sdb*: mountpoint not found
artem@home:~/Desktop$ sudo umount /dev/sdc*
umount: /dev/sdc: not mounted
umount: /dev/sdc1: not mounted
umount: /dev/sdc2: not mounted
umount: /dev/sdc4: not mounted
artem@home:~/Desktop$ sudo mkfs.ext4 -L "recovery" /dev/sdc1
mke2fs 1.42.13 (17-May-2015)
/dev/sdc1 contains a ext4 file system labelled 'recovery'
created on Mon Oct 17 23:25:14 2016
Proceed anyway? (y,n) ^Z
[3]+ Stopped sudo env PATH=$PATH mkfs.ext4 -L "recovery" /dev/sdc1
artem@home:~/Desktop$ ^C
artem@home:~/Desktop$ sudo mkfs.ext4 -L "recovery" /dev/sdc1
mke2fs 1.42.13 (17-May-2015)
/dev/sdc1 contains a ext4 file system labelled 'recovery'
created on Mon Oct 17 23:25:14 2016
Proceed anyway? (y,n) y
artem@home:~/Desktop$ sudo mkfs.ext4 -L "boot" /dev/sdc2
mke2fs 1.42.13 (17-May-2015)
/dev/sdc2 contains a ext4 file system labelled 'boot'
created on Mon Oct 17 23:26:29 2016
Proceed anyway? (y,n) y
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: 55f6d60d-3c15-495c-9a44-5621c77f768d
Superblock backups stored on blocks:
8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
artem@home:~/Desktop$ sudo mkfs.ext4 -L "misc" /dev/sdc3
mke2fs 1.42.13 (17-May-2015)
/dev/sdc3 contains a ext4 file system labelled 'boot'
last mounted on Mon Oct 17 23:22:57 2016
Proceed anyway? (y,n)
artem@home:~/Desktop$ sudo mkfs.ext4 -L "misc" /dev/sdc3
mke2fs 1.42.13 (17-May-2015)
/dev/sdc3 contains a ext4 file system labelled 'boot'
last mounted on Mon Oct 17 23:22:57 2016
Proceed anyway? (y,n) y
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: 7fd34d5d-c185-4729-8c14-7d5c2e485785
Superblock backups stored on blocks:
8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
artem@home:~/Desktop$ sudo mkfs.ext4 -L "system" /dev/sdc4
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 393216 4k blocks and 98304 inodes
Filesystem UUID: f7a66e14-9946-458e-b448-bfec0f42a733
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
artem@home:~/Desktop$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs tmpfs 293M 8.9M 284M 4% /run
/dev/sda5 ext4 20G 5.5G 14G 30% /
tmpfs tmpfs 1.5G 69M 1.4G 5% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/sda1 ext2 504M 150M 330M 32% /boot
/dev/sda4 ext4 143G 134G 2.1G 99% /home
tmpfs tmpfs 293M 72K 293M 1% /run/user/1000
artem@home:~/Desktop$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs tmpfs 293M 8.9M 284M 4% /run
/dev/sda5 ext4 20G 5.5G 14G 30% /
tmpfs tmpfs 1.5G 69M 1.4G 5% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/sda1 ext2 504M 150M 330M 32% /boot
/dev/sda4 ext4 143G 134G 2.1G 99% /home
tmpfs tmpfs 293M 72K 293M 1% /run/user/1000
/dev/sdc2 ext4 15M 140K 14M 2% /media/artem/boot
/dev/sdc1 ext4 15M 140K 14M 2% /media/artem/recovery
/dev/sdc3 ext4 15M 140K 14M 2% /media/artem/misc
artem@home:~/Desktop$ sudo dd if=/home/artem/my/n5radio/aosp_hammerhead-nougat-20160827/system.new.dat of=/dev/sdb5
^C781793+0 records in
781792+0 records out
400277504 bytes (400 MB, 382 MiB) copied, 3.54684 s, 113 MB/s
artem@home:~/Desktop$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.5G 382M 1.1G 27% /dev
tmpfs tmpfs 293M 8.9M 284M 4% /run
/dev/sda5 ext4 20G 5.5G 14G 30% /
tmpfs tmpfs 1.5G 69M 1.4G 5% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/sda1 ext2 504M 150M 330M 32% /boot
/dev/sda4 ext4 143G 134G 2.1G 99% /home
tmpfs tmpfs 293M 72K 293M 1% /run/user/1000
/dev/sdc2 ext4 15M 140K 14M 2% /media/artem/boot
/dev/sdc1 ext4 15M 140K 14M 2% /media/artem/recovery
/dev/sdc3 ext4 15M 140K 14M 2% /media/artem/misc
/dev/sdc4 ext4 1.5G 2.3M 1.4G 1% /media/artem/system
artem@home:~/Desktop$ sudo dd if=/home/artem/my/n5radio/aosp_hammerhead-nougat-20160827/system.new.dat of=/dev/sdb5
xc^C575000+0 records in
574999+0 records out
294399488 bytes (294 MB, 281 MiB) copied, 1.22887 s, 240 MB/s
artem@home:~/Desktop$ ^C
artem@home:~/Desktop$ sudo dd if=/home/artem/my/n5radio/aosp_hammerhead-nougat-20160827/system.new.dat of=/dev/sdc4
#! /bin/sh
parted /dev/sdb --script list
umount /dev/sdb*
dd if=/dev/zero of=/dev/sdb bs=1024 count=1024
sync
parted /dev/sdb --script mklabel gpt
parted /dev/sdb --script mkpart --list
#parted /dev/sdb --script mkpart primary fat32 1MiB 32MiB
parted /dev/sdb --script mkpart primary ext4 32785KiB 49169KiB
parted /dev/sdb --script mkpart primary ext4 50193KiB 66577KiB
parted /dev/sdb --script mkpart primary ext4 67601KiB 83985KiB
parted /dev/sdb --script mkpart primary ext4 85009KiB 1657873KiB
parted /dev/sdb --script mkpart primary ext4 1658897KiB 2183185KiB
parted /dev/sdb --script mkpart primary ext4 2184209KiB 12669969KiB
parted /dev/sdb --script mkpart align-check min 1
sync
umount /dev/sdb*
parted /dev/sdb --script mkpart --list
#mkfs.vfat -F 32 -n "bootloader" /dev/sdb1
sudo sync
sudo umount /dev/sdb*
sudo mkfs.ext4 -L "recovery" /dev/sdc1
sudo mkfs.ext4 -L "boot" /dev/sdc2
sudo mkfs.ext4 -L "misc" /dev/sdc3
sudo mkfs.ext4 -L "system" /dev/sdc4
sudo mkfs.ext4 -L "cache" /dev/sdb
mkfs.ext4 -L "data" /dev/sdb7
sync
umount /dev/sdb*
parted /dev/sdb --script mkpart list
sudo dd if=/home/artem/my/n5radio/aosp_hammerhead-nougat-20160827/system.new.dat of=/dev/sdb5
exit
oem_format=gpt write mmc 1 name=recovery,start=33571840,size=16M
&name=boot,size=16M&name=misc,size=16M&name=system,size=1536M
&name=cache,size=512M&name=data,size=0; mmc dev 1; mmc part;
32785+16*1024
32785+8*1024=57361
2220049+8*1024
1695761+10*1024*1024
49169+16*1024=65553
65553+16*1024=81937
81937+1536*1024=1654801
1654801+512*1024=2179089
2179089
33571840/1024-1024*32
32785-32768
16384
#! /bin/sh
DRIVE=$1
if [[ $DRIVE == *"mmc"* ]]
then
DRIVEPREFIX="${DRIVE}p"
else
DRIVEPREFIX="${DRIVE}"
fi
PATH_TO_IMAGE=$2
TEMP=`parted $DRIVE print all | grep $DRIVE`
TEMP2="${TEMP#*: }"
SIZE="${TEMP2%\.*}"
echo DRIVE $DRIVE
echo SIZE $SIZE
SIZE_KB=`echo $SIZE*1000*1000 | bc`
echo SIZE_KB $SIZE_KB
echo DRIVEPREFIX ${DRIVEPREFIX}7
echo PATH_TO_IMAGE $PATH_TO_IMAGE
df -Th
umount $DRIVE*
sudo dd if=/dev/zero of=$DRIVE bs=2048 count=32
sync
parted $DRIVE --script unit KiB \
mklabel gpt \
mkpart primary ext4 32785 49169 \
mkpart primary ext4 49169 65553 \
mkpart primary ext4 65553 81937 \
mkpart primary ext4 81937 1654801 \
mkpart primary ext4 1654801 2183185 \
mkpart primary ext4 2183185 $SIZE_KB
sync
umount $DRIVE*
mkfs.ext4 -L "recovery" ${DRIVEPREFIX}1
umount $DRIVE*
mkfs.ext4 -L "boot" ${DRIVEPREFIX}2
umount $DRIVE*
mkfs.ext4 -L "misc" ${DRIVEPREFIX}3
umount $DRIVE*
mkfs.ext4 -L "system" ${DRIVEPREFIX}4
umount $DRIVE*
mkfs.ext4 -L "cache" ${DRIVEPREFIX}5
umount $DRIVE*
mkfs.ext4 -L "data" ${DRIVEPREFIX}6
umount $DRIVE*
sync
parted $DRIVE --script print
./simg2img $PATH_TO_IMAGE/system.img $PATH_TO_IMAGE/raw_system.img
dd if=./raw_system.img of=$DRIVE bs=4096
dd if=$ of=$DRIVE5
exit
###########################
###########################
TEMP=parted $DRIVE print all | grep $DRIVE
TEMP2="${WORKD%_not_*}"
TEMP3="${TEMP_STR#*_changes_}"
sudo bash -x ./mmcpart.sh /dev/mmcblk0 /home/artem/renesas/builds/renesas_301_20160927_full_salvator_h3_userdebug
./simg2img /home/artem/renesas/builds/renesas_301_20160927_full_salvator_h3_userdebug/system.img ./raw_system.img
dd if=./raw_system.img of=/dev/mmcblk0p4 bs=4096
sudo apt-get update
sudo apt-get install libc++-dev
parted /dev/mmcblk0 --script print
sudo dd if=/dev/zero of=/dev/mmcblk0 bs=2048 count=32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment