From e7ee21085196c5b2f420f04b9ad094351e865fcc Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Wed, 4 Jan 2017 14:19:47 +0900 Subject: [PATCH 02/10] Initial system-rw-update files Add files for system RW update - service files for system-update.target - scripts for system-update services - make_upgrade_image.sh: converts platform image to RW update image Change-Id: I26ee79755cda73fa02e01fcb5316da87cbb123da Signed-off-by: Sunmin Lee --- LICENSE.Apache-2.0 | 204 ++++++++++++++++++++++++++++++++++++ make_upgrade_image.sh | 88 ++++++++++++++++ packaging/system-rw-update.manifest | 5 + packaging/system-rw-update.spec | 42 ++++++++ units/init-update.service | 10 ++ units/offline-update.service | 9 ++ upgrade/update-init.sh | 26 +++++ upgrade/update.sh | 32 ++++++ 8 files changed, 416 insertions(+) create mode 100644 LICENSE.Apache-2.0 create mode 100644 make_upgrade_image.sh create mode 100644 packaging/system-rw-update.manifest create mode 100644 packaging/system-rw-update.spec create mode 100644 units/init-update.service create mode 100644 units/offline-update.service create mode 100755 upgrade/update-init.sh create mode 100755 upgrade/update.sh diff --git a/LICENSE.Apache-2.0 b/LICENSE.Apache-2.0 new file mode 100644 index 0000000..8f17f50 --- /dev/null +++ b/LICENSE.Apache-2.0 @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/make_upgrade_image.sh b/make_upgrade_image.sh new file mode 100644 index 0000000..b6f1433 --- /dev/null +++ b/make_upgrade_image.sh @@ -0,0 +1,88 @@ +#!/bin/sh +# +# make_upgrade_image.sh +# +# Convert Tizen 3.0 platform image to upgrade image (2.4 -> 3.0) + +# For sdb debugging + +sdb_debugging=0 +sdb_rule='SUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="1", RUN+="/usr/bin/direct_set_debug.sh --sdb-set"\nSUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="0", RUN+="/usr/bin/direct_set_debug.sh --sdb-unset"' + +# Back up /home/owner & rpm db +backup () { + echo "Back up home & rpm db" + + local tmp_path=$1 + + umount ${tmp_path} + e2fsck -f rootfs.img + resize2fs rootfs.img 1G + mount rootfs.img ${tmp_path} + + mount system-data.img ${tmp_path}/opt + mount user.img ${tmp_path}/opt/usr + + mkdir ${tmp_path}/usr/share/upgrade/data/home + cp -af ${tmp_path}/opt/usr/home/owner ${tmp_path}/usr/share/upgrade/data/home + + mkdir ${tmp_path}/usr/share/upgrade/data/rpm + cp -af ${tmp_path}/opt/var/lib/rpm/* ${tmp_path}/usr/share/upgrade/data/rpm + + sync + + umount -l ${tmp_path}/opt/usr + umount -l ${tmp_path}/opt + + umount ${tmp_path} + e2fsck -f rootfs.img + resize2fs -M rootfs.img + mount rootfs.img ${tmp_path} +} + +if [ `id -u` -ne 0 ] +then + echo "make_upgrade_image.sh should be executed as root" + exit +fi + +if [ ! $1 ] +then + echo "usage: $0 [tizen-3.0-image(tar.gz)]" + exit +fi + +echo "Decompressing $1" +imgs=`tar zxvf $1` + +tmp_root=`mktemp -d system.XXX` +echo "Mount rootfs.img" +mount rootfs.img ${tmp_root} + +cwd=`pwd` +backup ${cwd}/${tmp_root} + +echo "Make /system-update" +ln -s /usr/share/upgrade/ ${tmp_root}/system-update + +# For sdb debugging +if [ ${sdb_debugging} -eq 1 ] +then + echo "Install sdb rule file" + rule_file="99-sdb-switch.rules" + echo ${sdb_rule} > ${rule_file} + install -m 644 ${rule_file} ${tmp_root}/usr/lib/udev/rules.d + rm ${rule_file} +fi + +sync +umount ${tmp_root} + +upgrade_img=`echo $1 | sed -e 's/\.tar\.gz//'`-upgrade.tar.gz +echo "Compressing upgrade image ${upgrade_img}" +tar zcf ${upgrade_img} dzImage modules.img rootfs.img + +echo "Remove dummies" +rm -rf ${imgs} ${tmp_root} + +echo "Done" diff --git a/packaging/system-rw-update.manifest b/packaging/system-rw-update.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/packaging/system-rw-update.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec new file mode 100644 index 0000000..ad74085 --- /dev/null +++ b/packaging/system-rw-update.spec @@ -0,0 +1,42 @@ +%define debug_package %{nil} + +Name: system-rw-update +Summary: System RW update management +Version: 0.1 +Release: 0 +Group: Base/Startup +License: Apache-2.0 +Source0: %{name}-%{version}.tar.bz2 +Source1001: %{name}.manifest + +%description +This package provides files for RW update +which is implemented by using systemd offline update. + +%prep +%setup -q + +%build +cp %{SOURCE1001} . + +%install +mkdir -p %{buildroot}%{_datadir} +cp -r upgrade %{buildroot}%{_datadir} +mkdir -p %{buildroot}%{_unitdir}/system-update.target.wants +install -m 644 units/init-update.service %{buildroot}%{_unitdir} +install -m 644 units/offline-update.service %{buildroot}%{_unitdir} +#ln -s ../offline-update.service %{buildroot}%{_unitdir}/system-update.target.wants/offline-update.service +ln -s ../init-update.service %{buildroot}%{_unitdir}/system-update.target.wants/init-update.service +ln -s ../getty.target %{buildroot}%{_unitdir}/system-update.target.wants +ln -s ../cynara.socket %{buildroot}%{_unitdir}/system-update.target.wants + +%clean +rm -rf %{buildroot} + +%files +%manifest %{name}.manifest +%license LICENSE.Apache-2.0 +%{_datadir}/upgrade/* +%{_unitdir}/offline-update.service +%{_unitdir}/init-update.service +%{_unitdir}/system-update.target.wants diff --git a/units/init-update.service b/units/init-update.service new file mode 100644 index 0000000..672a76a --- /dev/null +++ b/units/init-update.service @@ -0,0 +1,10 @@ +[Unit] +Description=System update initialize service +DefaultDependencies=no +Requires=sysinit.target +After=sysinit.target +Before=sdbd.service + +[Service] +Type=oneshot +ExecStart=/system-update/update-init.sh diff --git a/units/offline-update.service b/units/offline-update.service new file mode 100644 index 0000000..adc8f12 --- /dev/null +++ b/units/offline-update.service @@ -0,0 +1,9 @@ +[Unit] +Description=System update script service +DefaultDependencies=no +Requires=sysinit.target +After=sysinit.target init-update.service + +[Service] +Type=simple +ExecStart=/system-update/update.sh diff --git a/upgrade/update-init.sh b/upgrade/update-init.sh new file mode 100755 index 0000000..371abfe --- /dev/null +++ b/upgrade/update-init.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# +# RW update initialize script +# +PATH=/bin:/usr/bin:/sbin:/usr/sbin +OWNER_HOME=/opt/usr/home/owner + +USER_DISK=`ls /dev/disk/by-partlabel/ | grep -i user` +USER_MNT=/opt/usr + +# Mount user partition (specific to lazy mount) +mount | grep "$USER_MNT" > /dev/null + +if [ $? != "0" ] +then + /usr/bin/mount PARTLABEL=$USER_DISK $USER_MNT +fi + +# Create home directory +test ! -e /opt/usr/home && mkdir -p /opt/usr/home +chsmack -a "_" /opt/usr/home +cp -af /usr/share/upgrade/data/home/owner /opt/usr/home + +# Copy 3.0 rpm db +rm -rf /var/lib/rpm/* +cp -af /usr/share/upgrade/data/rpm/* /var/lib/rpm diff --git a/upgrade/update.sh b/upgrade/update.sh new file mode 100755 index 0000000..0985749 --- /dev/null +++ b/upgrade/update.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# +# RW update script +# +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +PATCH_DIR=/usr/share/upgrade/scripts +RESULT_FILE=/upgrade_result +RUN=/bin/sh + +# Change to normal mode from next booting +rm /system-update +rm /usr/lib/udev/rules.d/99-sdb-switch.rules + +# Execute update scripts +if [ ! -d ${PATCH_DIR} ] +then + echo "FAIL: Upgrade directory does not exist" > ${RESULT_FILE} +else + PATCHES=`/bin/ls ${PATCH_DIR}` + + for PATCH in ${PATCHES}; do + ${RUN} ${PATCH_DIR}/${PATCH} + done + + sync + + echo "SUCCESS: Upgrade successfully finished" > ${RESULT_FILE} +fi + +# Reboot +reboot -f -- 2.7.4 From 472ccd606d717de6605ed16ca19b15adf00266f8 Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Tue, 18 Jul 2017 09:04:42 +0900 Subject: [PATCH 03/10] Patch for 3.0 to 4.0 From Tizen 4.0, there are some changes in system RW update: - No /system-update link: use /usr/share/upgrade directly - RW update helper macro is introduced - No need to backup home directory Change-Id: Icd49e260674383a5e8c887583d6381180134232c Signed-off-by: Sunmin Lee --- make_upgrade_image.sh | 43 ++++++++++++++++--------- packaging/system-rw-update.spec | 4 +-- units/init-update.service | 2 +- units/offline-update.service | 2 +- upgrade/rw-update-macro.inc | 71 +++++++++++++++++++++++++++++++++++++++++ upgrade/update-init.sh | 27 ++++++---------- upgrade/update.sh | 6 +--- 7 files changed, 113 insertions(+), 42 deletions(-) mode change 100644 => 100755 make_upgrade_image.sh create mode 100755 upgrade/rw-update-macro.inc diff --git a/make_upgrade_image.sh b/make_upgrade_image.sh old mode 100644 new mode 100755 index b6f1433..8a0326c --- a/make_upgrade_image.sh +++ b/make_upgrade_image.sh @@ -2,17 +2,26 @@ # # make_upgrade_image.sh # -# Convert Tizen 3.0 platform image to upgrade image (2.4 -> 3.0) +# Convert Tizen platform image to upgrade image # For sdb debugging -sdb_debugging=0 +sdb_debugging=1 sdb_rule='SUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="1", RUN+="/usr/bin/direct_set_debug.sh --sdb-set"\nSUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="0", RUN+="/usr/bin/direct_set_debug.sh --sdb-unset"' -# Back up /home/owner & rpm db +# Back up data backup () { - echo "Back up home & rpm db" + if [ $# -lt 2 ]; then + echo "No backup data" + return 0 + fi + echo "Back up file at $2" + cat $2 + + # Push data for pre-patch (works in initrd) + local backup_path="/usr/share/upgrade/prepatch/data" + local backup_files="$(cat $2)" local tmp_path=$1 umount ${tmp_path} @@ -23,11 +32,10 @@ backup () { mount system-data.img ${tmp_path}/opt mount user.img ${tmp_path}/opt/usr - mkdir ${tmp_path}/usr/share/upgrade/data/home - cp -af ${tmp_path}/opt/usr/home/owner ${tmp_path}/usr/share/upgrade/data/home - - mkdir ${tmp_path}/usr/share/upgrade/data/rpm - cp -af ${tmp_path}/opt/var/lib/rpm/* ${tmp_path}/usr/share/upgrade/data/rpm + mkdir -p ${tmp_path}/$backup_path + for file in $backup_files; do + cp -afv ${tmp_path}/$file ${tmp_path}/$backup_path + done sync @@ -48,7 +56,7 @@ fi if [ ! $1 ] then - echo "usage: $0 [tizen-3.0-image(tar.gz)]" + echo "usage: $0 [tizen-image-update(tar.gz)]" exit fi @@ -60,10 +68,7 @@ echo "Mount rootfs.img" mount rootfs.img ${tmp_root} cwd=`pwd` -backup ${cwd}/${tmp_root} - -echo "Make /system-update" -ln -s /usr/share/upgrade/ ${tmp_root}/system-update +backup ${cwd}/${tmp_root} $2 # For sdb debugging if [ ${sdb_debugging} -eq 1 ] @@ -80,7 +85,15 @@ umount ${tmp_root} upgrade_img=`echo $1 | sed -e 's/\.tar\.gz//'`-upgrade.tar.gz echo "Compressing upgrade image ${upgrade_img}" -tar zcf ${upgrade_img} dzImage modules.img rootfs.img + +ro_imgs= +for img in ${imgs}; do + if [ "${img}" != "system-data.img" ] && [ "${img}" != "user.img" ]; then + ro_imgs="${ro_imgs} ${img}" + fi +done + +tar zcf ${upgrade_img} ${ro_imgs} echo "Remove dummies" rm -rf ${imgs} ${tmp_root} diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index ad74085..c6da85c 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -2,8 +2,8 @@ Name: system-rw-update Summary: System RW update management -Version: 0.1 -Release: 0 +Version: 0.1.1 +Release: 2 Group: Base/Startup License: Apache-2.0 Source0: %{name}-%{version}.tar.bz2 diff --git a/units/init-update.service b/units/init-update.service index 672a76a..713f9a9 100644 --- a/units/init-update.service +++ b/units/init-update.service @@ -7,4 +7,4 @@ Before=sdbd.service [Service] Type=oneshot -ExecStart=/system-update/update-init.sh +ExecStart=/usr/share/upgrade/update-init.sh diff --git a/units/offline-update.service b/units/offline-update.service index adc8f12..0620853 100644 --- a/units/offline-update.service +++ b/units/offline-update.service @@ -6,4 +6,4 @@ After=sysinit.target init-update.service [Service] Type=simple -ExecStart=/system-update/update.sh +ExecStart=/usr/share/upgrade/update.sh diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc new file mode 100755 index 0000000..00946fb --- /dev/null +++ b/upgrade/rw-update-macro.inc @@ -0,0 +1,71 @@ +#!/bin/sh + +OLD_VER= +NEW_VER= +OLD_REL= +NEW_REL= +OLD_VER_INFO="/inform/version" + +write_version_info() { + OLD_VER=$(cat /etc/config/model-config.xml | grep platform.version \ + | sed -e 's/.*>\(.*\)<.*/\1/') + OLD_REL=$(cat /etc/info.ini | grep Date | sed -e 's/Date=//' -e 's/\_.*//') + echo "OLD_VER=$OLD_VER" > $OLD_VER_INFO + echo "OLD_REL=$OLD_REL" >> $OLD_VER_INFO +} + +get_version_info() { + if [ -f $OLD_VER_INFO ]; then + source $OLD_VER_INFO + fi + NEW_VER=$(cat /etc/config/model-config.xml | grep platform.version \ + | sed -e 's/.*>\(.*\)<.*/\1/') + NEW_REL=$(cat /etc/info.ini | grep Date | sed -e 's/Date=//' -e 's/\_.*//') +} + +restore_backup_file() { + + BACKUP_ZIP="/usr/system/RestoreDir/opt.zip" + REC=0 + DEST="/" + + while [ "$1" != "" ]; do + case $1 in + -r ) + REC=1 + ;; + -d ) + shift + DEST=$1 + ;; + *) + RESTORE_PATH=$1 + ;; + esac + shift + done + + MOD_PATH=$(echo $RESTORE_PATH | sed -e "s/^\///") + + if [ "$REC" = "1" ]; then + REC_FILES=$(unzip -l $BACKUP_ZIP | grep $MOD_PATH | awk '{print $4}') + for REC_FILE in $REC_FILES; do + restore_backup_file $REC_FILE -d $DEST + done + exit + fi + + unzip -nX $BACKUP_ZIP $MOD_PATH -d $DEST + TMP=$(mktemp /tmp/smackinfo.XXXXXX) + PATH_FOR_SMACK=$(echo $MOD_PATH | sed -e "s/\/$//") + if [ "z$DEST" = "z" ]; then + grep $PATH_FOR_SMACK'\ ' /usr/system/RestoreDir/smack_label.txt > $TMP + else + FILE_PATH="$DEST/$PATH_FOR_SMACK" + SMACK_VAL=$(grep $PATH_FOR_SMACK'\ ' /usr/system/RestoreDir/smack_label.txt | \ + awk '{print $2 $3}') + echo "$FILE_PATH $SMACK_VAL" > $TMP + fi + rstsmack $TMP + rm $TMP +} diff --git a/upgrade/update-init.sh b/upgrade/update-init.sh index 371abfe..14cee02 100755 --- a/upgrade/update-init.sh +++ b/upgrade/update-init.sh @@ -3,24 +3,15 @@ # RW update initialize script # PATH=/bin:/usr/bin:/sbin:/usr/sbin -OWNER_HOME=/opt/usr/home/owner +RW_MACRO=/usr/share/upgrade/rw-update-macro.inc -USER_DISK=`ls /dev/disk/by-partlabel/ | grep -i user` -USER_MNT=/opt/usr - -# Mount user partition (specific to lazy mount) -mount | grep "$USER_MNT" > /dev/null - -if [ $? != "0" ] -then - /usr/bin/mount PARTLABEL=$USER_DISK $USER_MNT +if [ -f $RW_MACRO ]; then + source $RW_MACRO + get_version_info fi -# Create home directory -test ! -e /opt/usr/home && mkdir -p /opt/usr/home -chsmack -a "_" /opt/usr/home -cp -af /usr/share/upgrade/data/home/owner /opt/usr/home - -# Copy 3.0 rpm db -rm -rf /var/lib/rpm/* -cp -af /usr/share/upgrade/data/rpm/* /var/lib/rpm +if [ "$NEW_VER" = "4.0" ]; then + # Restore rpm db + rm -rf /var/lib/rpm/* + restore_backup_file -r /opt/var/lib/rpm +fi diff --git a/upgrade/update.sh b/upgrade/update.sh index 0985749..c3dc8e1 100755 --- a/upgrade/update.sh +++ b/upgrade/update.sh @@ -5,13 +5,9 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin PATCH_DIR=/usr/share/upgrade/scripts -RESULT_FILE=/upgrade_result +RESULT_FILE=/opt/data/recovery/rw_result RUN=/bin/sh -# Change to normal mode from next booting -rm /system-update -rm /usr/lib/udev/rules.d/99-sdb-switch.rules - # Execute update scripts if [ ! -d ${PATCH_DIR} ] then -- 2.7.4 From a7e21ee2168075448ebebfe7dff9840128060c0a Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Wed, 19 Jul 2017 10:05:55 +0900 Subject: [PATCH 04/10] Install a rule file for SDB debugging From Tizen 4.0, a rule file for SDB debugging would be installed by default as symlink. SDB debugging feature would be handled by existence of actual path which is installed by udev-sdb-init service. Change-Id: Ic49aa7ea0b099149c288b14d4b825bcd0e6d3dce Signed-off-by: Sunmin Lee --- packaging/system-rw-update.spec | 16 +++++++++++++--- units/udev-sdb-init.service | 8 ++++++++ upgrade/99-sdb-switch.rules | 2 ++ upgrade/install-sdb-rule.sh | 9 +++++++++ upgrade/update.sh | 5 +++++ 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 units/udev-sdb-init.service create mode 100644 upgrade/99-sdb-switch.rules create mode 100755 upgrade/install-sdb-rule.sh diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index c6da85c..191fcdf 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -2,8 +2,8 @@ Name: system-rw-update Summary: System RW update management -Version: 0.1.1 -Release: 2 +Version: 0.1.2 +Release: 3 Group: Base/Startup License: Apache-2.0 Source0: %{name}-%{version}.tar.bz2 @@ -26,10 +26,17 @@ mkdir -p %{buildroot}%{_unitdir}/system-update.target.wants install -m 644 units/init-update.service %{buildroot}%{_unitdir} install -m 644 units/offline-update.service %{buildroot}%{_unitdir} #ln -s ../offline-update.service %{buildroot}%{_unitdir}/system-update.target.wants/offline-update.service -ln -s ../init-update.service %{buildroot}%{_unitdir}/system-update.target.wants/init-update.service +ln -s ../init-update.service %{buildroot}%{_unitdir}/system-update.target.wants ln -s ../getty.target %{buildroot}%{_unitdir}/system-update.target.wants ln -s ../cynara.socket %{buildroot}%{_unitdir}/system-update.target.wants +# SDB debugging +mkdir -p %{buildroot}%{_libdir}/udev/rules.d +ln -s /opt/data/recovery/99-sdb-switch.rules %{buildroot}%{_libdir}/udev/rules.d +install -m 644 units/udev-sdb-init.service %{buildroot}%{_unitdir} +mkdir -p %{buildroot}%{_unitdir}/sysinit.target.wants +ln -s ../udev-sdb-init.service %{buildroot}%{_unitdir}/sysinit.target.wants + %clean rm -rf %{buildroot} @@ -40,3 +47,6 @@ rm -rf %{buildroot} %{_unitdir}/offline-update.service %{_unitdir}/init-update.service %{_unitdir}/system-update.target.wants +%{_unitdir}/udev-sdb-init.service +%{_unitdir}/sysinit.target.wants/* +%{_libdir}/udev/rules.d/* diff --git a/units/udev-sdb-init.service b/units/udev-sdb-init.service new file mode 100644 index 0000000..fc45887 --- /dev/null +++ b/units/udev-sdb-init.service @@ -0,0 +1,8 @@ +[Unit] +Description=Install rule for udev sdb +DefaultDependencies=no +Before=sysinit.target systemd-udevd.service + +[Service] +Type=oneshot +ExecStart=/usr/share/upgrade/install-sdb-rule.sh diff --git a/upgrade/99-sdb-switch.rules b/upgrade/99-sdb-switch.rules new file mode 100644 index 0000000..75238f5 --- /dev/null +++ b/upgrade/99-sdb-switch.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="1", RUN+="/usr/bin/direct_set_debug.sh --sdb-set" +SUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="0", RUN+="/usr/bin/direct_set_debug.sh --sdb-unset" diff --git a/upgrade/install-sdb-rule.sh b/upgrade/install-sdb-rule.sh new file mode 100755 index 0000000..3fac92f --- /dev/null +++ b/upgrade/install-sdb-rule.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +SDB_RULE="99-sdb-switch.rules" +DEST=/opt/data/recovery + +if [ ! -e ${DEST}/${SDB_RULE} ]; then + /bin/mkdir -p ${DEST} + /bin/cp /usr/share/upgrade/${SDB_RULE} ${DEST} +fi diff --git a/upgrade/update.sh b/upgrade/update.sh index c3dc8e1..651f628 100755 --- a/upgrade/update.sh +++ b/upgrade/update.sh @@ -6,6 +6,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin PATCH_DIR=/usr/share/upgrade/scripts RESULT_FILE=/opt/data/recovery/rw_result +SDB_RULE=/opt/data/recovery/99-sdb-switch.rules RUN=/bin/sh # Execute update scripts @@ -24,5 +25,9 @@ else echo "SUCCESS: Upgrade successfully finished" > ${RESULT_FILE} fi +if [ -e ${SDB_RULE} ]; then + rm ${SDB_RULE} +fi + # Reboot reboot -f -- 2.7.4 From a45d39f81e35e9ea1ee576c501fb4036a86367f2 Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Thu, 20 Jul 2017 18:08:26 +0900 Subject: [PATCH 05/10] Udev sdb service should run upgrade mode only Udev rule for SDB connection is required in upgrade only. It should be moved to upgrade target. Change-Id: Ie57d43dd604ce49a92d0c365d91684b5c91b3e27 Signed-off-by: Sunmin Lee --- packaging/system-rw-update.spec | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index 191fcdf..1674e84 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -2,8 +2,8 @@ Name: system-rw-update Summary: System RW update management -Version: 0.1.2 -Release: 3 +Version: 0.1.3 +Release: 4 Group: Base/Startup License: Apache-2.0 Source0: %{name}-%{version}.tar.bz2 @@ -34,8 +34,7 @@ ln -s ../cynara.socket %{buildroot}%{_unitdir}/system-update.target.wants mkdir -p %{buildroot}%{_libdir}/udev/rules.d ln -s /opt/data/recovery/99-sdb-switch.rules %{buildroot}%{_libdir}/udev/rules.d install -m 644 units/udev-sdb-init.service %{buildroot}%{_unitdir} -mkdir -p %{buildroot}%{_unitdir}/sysinit.target.wants -ln -s ../udev-sdb-init.service %{buildroot}%{_unitdir}/sysinit.target.wants +ln -s ../udev-sdb-init.service %{buildroot}%{_unitdir}/system-update.target.wants %clean rm -rf %{buildroot} @@ -48,5 +47,4 @@ rm -rf %{buildroot} %{_unitdir}/init-update.service %{_unitdir}/system-update.target.wants %{_unitdir}/udev-sdb-init.service -%{_unitdir}/sysinit.target.wants/* %{_libdir}/udev/rules.d/* -- 2.7.4 From 8cf31f71a4591a6cabf1e613b8c017e819ef09f1 Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Tue, 1 Aug 2017 18:17:37 +0900 Subject: [PATCH 06/10] Apply platform version path: /opt/etc/version Following is generic mechanism 1. The version file (/opt/etc/version) should be created by RO-updater before updating RO. (if there are already existed, just verify the file or skipping creating file) 2. And then, it should be used by RW upgrade script. 3. And then, it should be updated by RW-updater after upgrade is completed However, this code makes /opt/etc/version file in image creation instead of RO-updater. The reason is for supporting HOME BINARY updater (skipping RO updater) Thus, Follwing is mechanism for HOME BINARY 1. The version file (/opt/etc/version) should be created by image creation. 2. And then, it should be used by RW upgrade script. 3. And then, it should be updated by RW-updater after upgrade is completed Basically, if the file (/opt/etc/version) is not existed in old binary, HOME BINARY updater is not supported. Commented-by: Kunhoon Baik Change-Id: Ie298f3e175b34582ffd38189952a6b125eca7cbe Signed-off-by: Sunmin Lee --- upgrade/record-version.sh | 7 +++++++ upgrade/rw-update-macro.inc | 2 +- upgrade/update.sh | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 upgrade/record-version.sh diff --git a/upgrade/record-version.sh b/upgrade/record-version.sh new file mode 100755 index 0000000..9f74a06 --- /dev/null +++ b/upgrade/record-version.sh @@ -0,0 +1,7 @@ +#!/bin/sh +RW_MACRO=/usr/share/upgrade/rw-update-macro.inc + +if [ -e ${RW_MACRO} ]; then + source ${RW_MACRO} + write_version_info +fi diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc index 00946fb..bd3d3a6 100755 --- a/upgrade/rw-update-macro.inc +++ b/upgrade/rw-update-macro.inc @@ -4,7 +4,7 @@ OLD_VER= NEW_VER= OLD_REL= NEW_REL= -OLD_VER_INFO="/inform/version" +OLD_VER_INFO="/opt/etc/version" write_version_info() { OLD_VER=$(cat /etc/config/model-config.xml | grep platform.version \ diff --git a/upgrade/update.sh b/upgrade/update.sh index 651f628..2654524 100755 --- a/upgrade/update.sh +++ b/upgrade/update.sh @@ -7,6 +7,8 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin PATCH_DIR=/usr/share/upgrade/scripts RESULT_FILE=/opt/data/recovery/rw_result SDB_RULE=/opt/data/recovery/99-sdb-switch.rules +VERSION_FILE=/opt/etc/version +RW_MACRO=/usr/share/upgrade/rw-update-macro.inc RUN=/bin/sh # Execute update scripts @@ -29,5 +31,13 @@ if [ -e ${SDB_RULE} ]; then rm ${SDB_RULE} fi +if [ -e ${VERSION_FILE} ]; then + rm ${VERSION_FILE} + if [ -e ${RW_MACRO} ]; then + source ${RW_MACRO} + write_version_info + fi +fi + # Reboot reboot -f -- 2.7.4 From c4831652d46dd110afdeca88340dd3e851dd8762 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Fri, 4 Aug 2017 17:39:07 +0900 Subject: [PATCH 07/10] Temporary patch for RW updater SDB debugging in the device with SWITCH class and SLP gadget. At this moments, USB SDB debugging feature for RW updater is supported in the device with SWITCH class and SLP gadget. Thus, we need to make a target specific package like system-rw-update-helper-for-XXXX. For generic solution, mini-usb-manager using USB-client HAL should be created for USB SDB debugging feature for RW updater. Anyway, at this moment, it will be created in all device if there are "no such SWITCH rule file" in the device. Change-Id: I1d4dcbed238ca69c46f55162c2c521fcf1188c2c --- make_upgrade_image.sh | 11 ----------- packaging/system-rw-update.spec | 11 ++++++++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/make_upgrade_image.sh b/make_upgrade_image.sh index 8a0326c..c57e978 100755 --- a/make_upgrade_image.sh +++ b/make_upgrade_image.sh @@ -7,7 +7,6 @@ # For sdb debugging sdb_debugging=1 -sdb_rule='SUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="1", RUN+="/usr/bin/direct_set_debug.sh --sdb-set"\nSUBSYSTEM=="switch", ATTR{name}=="usb_cable", ATTR{state}=="0", RUN+="/usr/bin/direct_set_debug.sh --sdb-unset"' # Back up data backup () { @@ -70,16 +69,6 @@ mount rootfs.img ${tmp_root} cwd=`pwd` backup ${cwd}/${tmp_root} $2 -# For sdb debugging -if [ ${sdb_debugging} -eq 1 ] -then - echo "Install sdb rule file" - rule_file="99-sdb-switch.rules" - echo ${sdb_rule} > ${rule_file} - install -m 644 ${rule_file} ${tmp_root}/usr/lib/udev/rules.d - rm ${rule_file} -fi - sync umount ${tmp_root} diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index 1674e84..53c6630 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -31,14 +31,20 @@ ln -s ../getty.target %{buildroot}%{_unitdir}/system-update.target.wants ln -s ../cynara.socket %{buildroot}%{_unitdir}/system-update.target.wants # SDB debugging -mkdir -p %{buildroot}%{_libdir}/udev/rules.d -ln -s /opt/data/recovery/99-sdb-switch.rules %{buildroot}%{_libdir}/udev/rules.d install -m 644 units/udev-sdb-init.service %{buildroot}%{_unitdir} ln -s ../udev-sdb-init.service %{buildroot}%{_unitdir}/system-update.target.wants %clean rm -rf %{buildroot} +%posttrans +if [ -e %{_libdir}/udev/rules.d/99-sdb-switch.rules ]; then + echo "Exist 99-sdb-switch.rules, Skip!" +else + mkdir -p %{_libdir}/udev/rules.d + ln -s /opt/data/recovery/99-sdb-switch.rules %{_libdir}/udev/rules.d +fi + %files %manifest %{name}.manifest %license LICENSE.Apache-2.0 @@ -47,4 +53,3 @@ rm -rf %{buildroot} %{_unitdir}/init-update.service %{_unitdir}/system-update.target.wants %{_unitdir}/udev-sdb-init.service -%{_libdir}/udev/rules.d/* -- 2.7.4 From e18edc03d0d93686fe6d4d028adc24f2b0cd610a Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Fri, 18 Aug 2017 16:52:32 +0900 Subject: [PATCH 08/10] Do not EXIT in rw-update-macro The exit call in RW macro function causes termination of caller script. The restore_backup_file function should be terminated with return. Change-Id: I81e4fdecf4b371ef212f3983d8b856ba2df9ba5c Signed-off-by: Sunmin Lee --- upgrade/rw-update-macro.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upgrade/rw-update-macro.inc b/upgrade/rw-update-macro.inc index bd3d3a6..3c670ab 100755 --- a/upgrade/rw-update-macro.inc +++ b/upgrade/rw-update-macro.inc @@ -52,7 +52,7 @@ restore_backup_file() { for REC_FILE in $REC_FILES; do restore_backup_file $REC_FILE -d $DEST done - exit + return fi unzip -nX $BACKUP_ZIP $MOD_PATH -d $DEST -- 2.7.4 From 1ba9071e6ec75c497f2b16dbabc13d13c19c570b Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Fri, 18 Aug 2017 21:12:16 +0900 Subject: [PATCH 09/10] Update permission of DB directory in init step Change-Id: I942de000ceec9b8c4b84761542c6ae565302c0ad Signed-off-by: Sunmin Lee --- upgrade/update-init.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/upgrade/update-init.sh b/upgrade/update-init.sh index 14cee02..be60406 100755 --- a/upgrade/update-init.sh +++ b/upgrade/update-init.sh @@ -15,3 +15,6 @@ if [ "$NEW_VER" = "4.0" ]; then rm -rf /var/lib/rpm/* restore_backup_file -r /opt/var/lib/rpm fi + +# Permission Update for shared directories +/etc/gumd/useradd.d/91_user-dbspace-permissions.post owner -- 2.7.4 From fbbbbdfb8e2d0d32d1cb25e9d9d812d361dc1399 Mon Sep 17 00:00:00 2001 From: Sunmin Lee Date: Tue, 22 Aug 2017 18:35:20 +0900 Subject: [PATCH 10/10] Specify SmackProcessLabel of udev init service The udev init service which creates rule file doesn't need to be privileged. Specify it to "System" process. Change-Id: Ib4c7f40ec9122d0235bb3191588e0e3b0e604dea Signed-off-by: Sunmin Lee --- packaging/system-rw-update.spec | 4 ++-- units/udev-sdb-init.service | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packaging/system-rw-update.spec b/packaging/system-rw-update.spec index 53c6630..675f16f 100644 --- a/packaging/system-rw-update.spec +++ b/packaging/system-rw-update.spec @@ -2,8 +2,8 @@ Name: system-rw-update Summary: System RW update management -Version: 0.1.3 -Release: 4 +Version: 0.1.4 +Release: 5 Group: Base/Startup License: Apache-2.0 Source0: %{name}-%{version}.tar.bz2 diff --git a/units/udev-sdb-init.service b/units/udev-sdb-init.service index fc45887..893a1fb 100644 --- a/units/udev-sdb-init.service +++ b/units/udev-sdb-init.service @@ -4,5 +4,6 @@ DefaultDependencies=no Before=sysinit.target systemd-udevd.service [Service] +SmackProcessLabel=System Type=oneshot ExecStart=/usr/share/upgrade/install-sdb-rule.sh -- 2.7.4