2 # uDPU uses combined ext4 and f2fs partitions.
9 # Check which device is available, depending on the board revision
10 if [ -b "/dev/mmcblk1" ]; then
12 elif [ -b "/dev/mmcblk0" ]; then
15 echo "Cannot detect eMMC flash, aborting.."
21 if grep -q "$1" /proc
/mounts
; then
22 mounted_part
="$(grep -m 1 $1 /proc/mounts | awk '{print $2}')"
24 grep -woq "$mounted_part" /proc
/mounts
&& umount
-l "$mounted_part"
28 udpu_do_part_check
() {
29 local emmc_parts
="1 2 3 4"
32 # Check if the block devices exist
33 for num
in ${emmc_parts}; do
34 [ ! -b ${emmc_dev}p
${num} ] && part_valid
="0"
37 # If partitions are missing create a new partition table
38 if [ "$part_valid" != "1" ]; then
39 printf "Invalid partition table, creating a new one\n"
40 printf "o\nn\np\n1\n\n+256M\nn\np\n2\n\n+256M\nn\np\n3\n\n+1536M\nn\np\n\n\nw\n" | fdisk
-W always
$emmc_dev > /dev
/null
2>&1
42 # Format the /misc part right away as we will need it for the firmware
43 printf "Formating /misc partition, this make take a while..\n"
44 udpu_part_prep
${emmc_dev}p4
45 if mkfs.f2fs
-q -l misc
${emmc_dev}p4
; then
46 printf "/misc partition formated successfully\n"
48 printf "/misc partition formatting failed\n"
53 printf "Partition table looks ok\n"
58 if ! grep -woq /misc
/proc
/mounts
; then
61 # If the mount fails, try to reformat partition
62 # Leaving possiblity for multiple iterations
63 if ! mount
${emmc_dev}p4
/misc
; then
64 printf "Error while mounting /misc, trying to reformat..\n"
67 while [ "$format_count" -lt "1" ]; do
68 udpu_part_prep
${emmc_dev}p4
69 mkfs.f2fs
-q -l misc
${emmc_dev}p4
70 if ! mount
${emmc_dev}p4
/misc
; then
72 printf "Failed while mounting /misc\n"
73 format_count
=$
((format_count
+1))
75 printf "Mounted /misc successfully\n"
83 udpu_do_initial_setup
() {
84 # Prepare /recovery parition
85 udpu_part_prep
${emmc_dev}p2
86 mkfs.ext4
-qF ${emmc_dev}p2
2>&1 /dev
/null
88 # Prepare /boot partition
89 udpu_part_prep
${emmc_dev}p1
90 mkfs.ext4
-qF ${emmc_dev}p1
2>&1 /dev
/null
92 # Prepare /root partition
93 printf "Formating /root partition, this may take a while..\n"
94 udpu_part_prep
${emmc_dev}p3
95 mkfs.f2fs
-q -l rootfs
${emmc_dev}p3
&& printf "/root partition reformated\n"
98 udpu_do_regular_upgrade
() {
99 # Clean /boot partition - mfks.ext4 is not available in chroot
100 grep -woq /boot
/proc
/mounts
&& umount
/boot
102 mount
${emmc_dev}p1
/tmp
/boot
105 # Clean /root partition - mkfs.f2fs is not available in chroot
106 grep -woq /dev
/root
/proc
/mounts
&& umount
/
107 mkdir
-p /tmp
/rootpart
108 mount
${emmc_dev}p3
/tmp
/rootpart
109 rm -rf /tmp
/rootpart
/*
112 platform_do_upgrade_uDPU
() {
115 # Prepare and extract firmware on /misc partition
118 [ -f "/misc/firmware" ] && rm -r /misc
/firmware
119 mkdir
-p /misc
/firmware
120 tar xzf
"$1" -C /misc
/firmware
/
122 udpu_do_regular_upgrade
124 printf "Updating /boot partition\n"
125 if tar xzf
/misc
/firmware
/boot.tgz
-C /tmp
/boot
; then
126 printf "/boot partition updated successfully\n"
128 printf "/boot partition update failed\n"
132 printf "Updating /root partition\n"
133 if tar xzf
/misc
/firmware
/rootfs.tgz
-C /tmp
/rootpart
; then
134 printf "/root partition updated successfully\n"
136 printf "/root partition update failed\n"
140 # Saving configuration files over sysupgrade
141 platform_copy_config_uDPU
144 tmp_parts
=$
(grep "${emmc_dev}" /proc
/mounts |
awk '{print $2}')
145 for part
in ${tmp_parts}; do
147 # Force umount is necessary
148 grep -q "${part}" /proc
/mounts
&& umount
-l "$part"
151 # Sysupgrade complains about /tmp and /dev, so we can detach them here
156 platform_copy_config_uDPU
() {
157 # Config is saved on the /misc partition and copied on the rootfs after the reboot
158 if [ -f "$UPGRADE_BACKUP" ]; then
159 cp -f "$UPGRADE_BACKUP" "/misc/$BACKUP_FILE"