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 $1 /proc/mounts)" ]; then
22 mounted_part
="$(grep $1 /proc/mounts | awk '{print $2}' | head -1)"
24 [ "$(grep -wo $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 mkfs.f2fs
-q -l misc
${emmc_dev}p4
46 [ $?
-eq 0 ] && printf "/misc partition formated successfully\n" ||
printf "/misc partition formatting failed\n"
50 printf "Partition table looks ok\n"
55 if [ ! "$(grep -wo /misc /proc/mounts)" ]; then
57 mount
${emmc_dev}p4
/misc
59 # If the mount fails, try to reformat partition
60 # Leaving possiblity for multiple iterations
62 printf "Error while mounting /misc, trying to reformat..\n"
65 while [ "$format_count" -lt "1" ]; do
66 udpu_part_prep
${emmc_dev}p4
67 mkfs.f2fs
-q -l misc
${emmc_dev}p4
68 mount
${emmc_dev}p4
/misc
71 printf "Failed while mounting /misc\n"
72 format_count
=$
((format_count
+1))
74 printf "Mounted /misc successfully\n"
82 udpu_do_initial_setup
() {
83 # Prepare /recovery parition
84 udpu_part_prep
${emmc_dev}p2
85 mkfs.ext4
-q ${emmc_dev}p2 |
echo y
&> /dev
/null
87 # Prepare /boot partition
88 udpu_part_prep
${emmc_dev}p1
89 mkfs.ext4
-q ${emmc_dev}p1 |
echo y
&> /dev
/null
91 # Prepare /root partition
92 printf "Formating /root partition, this may take a while..\n"
93 udpu_part_prep
${emmc_dev}p3
94 mkfs.f2fs
-q -l rootfs
${emmc_dev}p3
95 [ $?
-eq 0 ] && printf "/root partition reformated\n"
98 udpu_do_regular_upgrade
() {
99 # Clean /boot partition - mfks.ext4 is not available in chroot
100 [ "$(grep -wo /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 -wo /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 tar xzf
/misc
/firmware
/boot.tgz
-C /tmp
/boot
126 [ $?
-eq 0 ] && printf "/boot partition updated successfully\n" ||
printf "/boot partition update failed\n"
129 printf "Updating /root partition\n"
130 tar xzf
/misc
/firmware
/rootfs.tgz
-C /tmp
/rootpart
131 [ $?
-eq 0 ] && printf "/root partition updated successfully\n" ||
printf "/root partition update failed\n"
134 # Saving configuration files over sysupgrade
135 platform_copy_config_uDPU
138 tmp_parts
=$
(grep "${emmc_dev}" /proc
/mounts |
awk '{print $2}')
139 for part
in ${tmp_parts}; do
141 # Force umount is necessary
142 [ "$(grep "${part}" /proc/mounts)" ] && umount
-l $part
145 # Sysupgrade complains about /tmp and /dev, so we can detach them here
150 platform_copy_config_uDPU
() {
151 # Config is saved on the /misc partition and copied on the rootfs after the reboot
152 if [ -f "/tmp/sysupgrade.tgz" ]; then
153 cp -f /tmp
/sysupgrade.tgz
/misc