15f9996aaSopenharmony_ci#!/bin/bash
25f9996aaSopenharmony_ci#
35f9996aaSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd.
45f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
55f9996aaSopenharmony_ci# you may not use this file except in compliance with the License.
65f9996aaSopenharmony_ci# You may obtain a copy of the License at
75f9996aaSopenharmony_ci#
85f9996aaSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
95f9996aaSopenharmony_ci#
105f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
115f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
125f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135f9996aaSopenharmony_ci# See the License for the specific language governing permissions and
145f9996aaSopenharmony_ci# limitations under the License.
155f9996aaSopenharmony_ciset -e
165f9996aaSopenharmony_ci
175f9996aaSopenharmony_ciOUTPUT_DIR=$1
185f9996aaSopenharmony_ciTYPE=$2
195f9996aaSopenharmony_ci
205f9996aaSopenharmony_ciif [ "${TYPE}" = "veritysetup" ]; then
215f9996aaSopenharmony_ci    veritysetup format ${OUTPUT_DIR}/systemfs_ext4.img ${OUTPUT_DIR}/systemhashfs/system_hashtree\
225f9996aaSopenharmony_ci    --data-block-size=1024 --hash-block-size=1024 > ${OUTPUT_DIR}/system_verityheader
235f9996aaSopenharmony_ci    sed -n "9p" ${OUTPUT_DIR}/system_verityheader | awk '{print $3}' > ${OUTPUT_DIR}/systemhashfs/system_roothash
245f9996aaSopenharmony_cielif [ "${TYPE}" = "addS82ohos" ]; then
255f9996aaSopenharmony_ci    mkdir ${OUTPUT_DIR}/rootfs/systemfs
265f9996aaSopenharmony_ci    mkdir ${OUTPUT_DIR}/rootfs/systemhashfs
275f9996aaSopenharmony_ci    CMD='
285f9996aaSopenharmony_ciif [ ! -e /dev/mmcblk0p6 ]; then
295f9996aaSopenharmony_ciexit 0
305f9996aaSopenharmony_cifi
315f9996aaSopenharmony_cimount -t ext4 -o ro /dev/mmcblk0p6 /systemhashfs
325f9996aaSopenharmony_ci/bin/veritysetup create dm-systemfs /dev/mmcblk0p5 /systemhashfs/system_hashtree $(cat /systemhashfs/system_roothash)
335f9996aaSopenharmony_cimount -t ext4 /dev/dm-0 /systemfs
345f9996aaSopenharmony_ciecho 3840 > /sys/block/dm-0/queue/read_ahead_kb
355f9996aaSopenharmony_ciecho 0 > /sys/module/dm_verity/parameters/prefetch_cluster'
365f9996aaSopenharmony_ci    echo "$CMD" >> ${OUTPUT_DIR}/rootfs/etc/init.d/S82ohos
375f9996aaSopenharmony_cielse
385f9996aaSopenharmony_ci    echo "Unsupported type!" >&2
395f9996aaSopenharmony_cifi
40