SYSTEM_DATA_MNT=opt
USER_MNT=opt/usr
+SCRIPT_NAME="fota-init.sh"
+#------------------------------------------------
+# log msg [file]
+#------------------------------------------------
+log() {
+ # log format: [script_name][tag]actual_log
+ LOG="[${SCRIPT_NAME}]$1"
+ if [ "$2" != "" ]; then
+ echo "$LOG" >> "$2"
+ fi
+ echo "$LOG"
+}
+
#------------------------------------------------
# get partition id
#------------------------------------------------
# handle_no_delta
#------------------------------------------------
handle_no_delta() {
- echo "delta does not exist ..." >> "${INT_LOG_FILE}"
+ log "[Error] delta does not exist ..." "${INT_LOG_FILE}"
echo "${UPI_NO_DELTA_ERROR}" > "${RESULT_FILE}"
}
# handle_no_ua
#------------------------------------------------
handle_no_ua() {
- echo "ua does not exist ..." >> "${INT_LOG_FILE}"
+ log "[Error] ua does not exist ..." "${INT_LOG_FILE}"
echo "${UPI_NO_UA_ERROR}" > "${RESULT_FILE}"
}
# do_fota_update
#------------------------------------------------
do_fota_update() {
- echo "fota update start ..." >> "${INT_LOG_FILE}"
+ log "[Info] fota update start ..." "${INT_LOG_FILE}"
DELTA_DIR=$("$CAT" "${DELTA_PATH_FILE}")
- echo "DELTA_DIR = ${DELTA_DIR}" >> "${INT_LOG_FILE}"
+ log "[Info] DELTA_DIR = ${DELTA_DIR}" "${INT_LOG_FILE}"
RESULT_FILE=${FAKE_ROOT}${FOTA_RESULT_DIR}/result
if [ -e "${RESULT_FILE}" ]; then
do_create_part_table
if [ ! -e "${PART_TBL_PATH}" ]; then
- echo "No partition table" >> "${INT_LOG_FILE}"
+ log "[Error] No partition table" "${INT_LOG_FILE}"
return 1
fi
VERIFY_TOOL=/usr/sbin/img-verifier
if [ -e "${VERIFY_TOOL}" ]; then
if ! "${VERIFY_TOOL}" -i "${DELTA}" -l "/opt/var/log/last_iv.log"; then
- echo "signature verification failed!" >> "${INT_LOG_FILE}"
+ log "[Error] signature verification failed!" "${INT_LOG_FILE}"
return 1
else
- echo "update package verification success"
+ log "[Info] update package verification success"
fi
else
- echo "Warning: No signature verifier... Skip it" >> "${INT_LOG_FILE}"
+ log "[Error] Warning: No signature verifier... Skip it" "${INT_LOG_FILE}"
fi
FOTA_ARG="1"
FOTA_ARG="0"
fi
if ! "${UA}" "${DELTA_DIR}" "${FOTA_TEMP_DIR}" "$FOTA_ARG"; then
- echo "update agent fail!!!" >> "${INT_LOG_FILE}"
+ log "[Error] update agent fail!!!" "${INT_LOG_FILE}"
return 1
else
- echo "update agent success"
+ log "[Info] update agent success"
return 0
fi
for TEST_DIR in "${TEST_DIRS[@]}"; do
if [ ! -e "${TEST_DIR}" ]; then
if "$MKDIR" -p "${TEST_DIR}"; then
- echo "Successfully created <${TEST_DIR}>" >> "${INT_LOG_FILE}"
+ log "[Info] Successfully created <${TEST_DIR}>" "${INT_LOG_FILE}"
else
- echo "Unable to create <${TEST_DIR}>"
+ log "[Error] Unable to create <${TEST_DIR}>"
fi
fi
done
# do_reboot
#------------------------------------------------
do_reboot() {
- echo "Reboot"
+ log "Reboot"
"$SYNC"
"$REBOOT"
while true
check_for_rw_power_fail() {
# Case : Power fail during RW update after RO update
if [ -r "${STATUS_FILE}" ]; then
- echo "${STATUS_FILE} exists" >> "${INT_LOG_FILE}"
- "$CAT" "${STATUS_FILE}" >> "${INT_LOG_FILE}"
+ log "[Info] ${STATUS_FILE} exists" "${INT_LOG_FILE}"
+ log "[Info] Status file: $("$CAT" "${STATUS_FILE}")" "${INT_LOG_FILE}"
"$SYNC"
umount_partitions
exec /sbin/fus_rw-init
#------------------------------------------------
check_for_fota_gui() {
if [ -r "${FOTA_GUI}" ]; then
- echo "GUI Enabled" >> "${INT_LOG_FILE}"
+ log "[Info] GUI Enabled" "${INT_LOG_FILE}"
FOTA_GUI_ENABLE=1
fi
}
if [ -f "${DEBUG_MODE_FILE}" ]; then
DEBUG_MODE_FILE_OWNER=$("${LS}" -l "${DEBUG_MODE_FILE}" | "${CUT}" -d " " -f 3)
if [ "${DEBUG_MODE_FILE_OWNER}" = "0" ]; then
- echo "Enter RO debug mode"
- echo "If you want to continue FOTA, please remove ${DEBUG_MODE_FILE}"
+ log "[Info] Enter RO debug mode"
+ log "[Info] If you want to continue FOTA, please remove ${DEBUG_MODE_FILE}"
# Wait until debug mode file is removed
while [ -f "${DEBUG_MODE_FILE}" ]; do
sleep 3
done
- echo "Debug mode file is removed. Resume FOTA"
+ log "[Info] Debug mode file is removed. Resume FOTA"
else
- echo "Warning: somebody made non-root debug mode file... ignore it"
+ log "[Info] Warning: somebody made non-root debug mode file... ignore it"
fi
fi
}
"$MOUNT" -o remount,ro "${FAKE_ROOT}"
if ! "${VERITY_HANDLER}" "${PART_ROOTFS}"; then
- echo "verity-handler fail!!!"
+ log "[Error] verity-handler fail!!!"
return 1
else
- echo "verity-handler success"
+ log "[Info] verity-handler success"
return 0
fi
else
- echo "Warning: ${VERITYCTL} exists but ${VERITY_HANDLER} does not exists"
+ log "[Error] Warning: ${VERITYCTL} exists but ${VERITY_HANDLER} does not exists"
return 2
fi
else
- echo "verityctl does not exist. Skip hash remaking"
+ log "[Info] verityctl does not exist. Skip hash remaking"
return 0
fi
}
if [ "$fota_result" = "0" ] && [ "$remake_result" = "0" ]; then
exec /sbin/fus_rw-init
else
- echo "Upgrade FAILED"
+ log "[Error] Upgrade FAILED"
do_reboot
fi