All binaries provided in a delta have to be statically linked.
Linking statically with libblkid turned out to be very difficult.
blkid-print functionality is replaced by calling blkid.
Change-Id: I6793b30f73b9b7323ce66e1a2eaba03a461c3717
ADD_SUBDIRECTORY(src/img-verifier)
ADD_SUBDIRECTORY(src/upgrade-apply)
ADD_SUBDIRECTORY(src/upgrade-apply-deltafs)
-ADD_SUBDIRECTORY(src/blkid-print)
ADD_SUBDIRECTORY(data)
ADD_SUBDIRECTORY(scripts/rw-upgrade)
ADD_SUBDIRECTORY(src/dynamic-partitions)
/bin/findmnt
/bin/dd
/bin/grep
-/bin/blkid-print
/usr/sbin/parse-dynparts
/bin/resize-dynparts
/bin/copy-blockdev
%{_bindir}/upgrade-apply
%{_bindir}/verity_handler
%{_bindir}/upgrade-apply-deltafs
-%{_bindir}/blkid-print
# Image verifier
%{_sbindir}/img-verifier
%attr(755,root,root) %{img_verifier_root_ca_dir}
UPGRADE_SUPPORT_SCRIPT_NAMES=("upgrade-prepare-partitions.sh" "upgrade-trigger.sh" \
"upgrade-partial.sh" "upgrade-fota.sh")
-if [ -z "$BLKID_PRINT" ]; then
- BLKID_PRINT="/usr/bin/blkid-print"
-fi
-
if [ -z "$RESIZE_DYNPARTS" ]; then
RESIZE_DYNPARTS="/bin/resize-dynparts"
fi
fi
}
+get_partition_path() {
+ local device=$1
+ local part_name=$2
+ local suffix=$3
+
+ if [ -z "${device}" ] || [ -z "${part_name}" ] || [ -z "${suffix}" ]; then
+ echo ""
+ fi
+
+ /usr/sbin/blkid -t PARTLABEL="${part_name}_${suffix}" -o device -l "${device}"
+}
+
check_if_super() {
- if SUPERFS="$( ("$BLKID_PRINT" "$EMMC_DEVICE" super a) 2>/dev/null)"; then
+ if SUPERFS="$(get_partition_path "$EMMC_DEVICE" super a)"; then
local MAPPED_DEVICES=""
MAPPED_DEVICES=$(dmsetup ls)
NEXT_PARTITION="/dev/mapper/${partition_name}_${NEXT_AB}"
NEXT_PARTITION_SIZE="$(blockdev --getsize64 $NEXT_PARTITION)"
else
- if ! CURRENT_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$partition_name" "$CURRENT_AB")"; then
+ if ! CURRENT_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$partition_name" "$CURRENT_AB")"; then
log "[Error] Unable to find: $partition_name current partition on $EMMC_DEVICE device on $CURRENT_AB slot"
check_optional_partition "$partition_name" 1
continue
CURRENT_PARTITION_SIZE="$(calculate_size $CURRENT_PARTITION)"
- if ! NEXT_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$partition_name" "$NEXT_AB")"; then
+ if ! NEXT_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$partition_name" "$NEXT_AB")"; then
log "[Error] Unable to find: $partition_name next partition on $EMMC_DEVICE device on $NEXT_AB slot"
check_optional_partition "$partition_name" 1
continue
NEXT_PARTITION="/dev/mapper/${PART_NAME}_${NEXT_AB}"
CURR_PARTITION="/dev/mapper/${PART_NAME}_${CURRENT_AB}"
else
- NEXT_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$PART_NAME" "$NEXT_AB")"
- CURR_PARTITION="$("$BLKID_PRINT" "$EMMC_DEVICE" "$PART_NAME" "$CURRENT_AB")"
+ NEXT_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$PART_NAME" "$NEXT_AB")"
+ CURR_PARTITION="$(get_partition_path "$EMMC_DEVICE" "$PART_NAME" "$CURRENT_AB")"
fi
log "[Info] Flashing $DELTA_NAME... to $NEXT_PARTITION, Delta type: ${TYPE_S[0]}"
local DST="$2"
local MOUNT_OPTIONS="$3"
local SRC
- if ! SRC="$("$BLKID_PRINT" "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB")"; then
+ if ! SRC="$(get_partition_path "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB")"; then
log "[Error] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
return 1
fi
+++ /dev/null
-INCLUDE(FindPkgConfig)
-
-pkg_check_modules(blkid_pkgs REQUIRED blkid)
-SET(BLKIDSRCS blkid-print.c)
-SET(BLKIDEXENAME "blkid-print")
-
-FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-ADD_EXECUTABLE(${BLKIDEXENAME} ${BLKIDSRCS})
-TARGET_LINK_LIBRARIES(${BLKIDEXENAME} ${blkid_pkgs_LDFLAGS})
-INSTALL(TARGETS ${BLKIDEXENAME} DESTINATION ${BINDIR})
+++ /dev/null
-/*
- * tota-ua
- *
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include "blkid-api.h"
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-blkid_partlist get_part_list(char *device_name, blkid_probe *pr) {
- assert(pr);
-
- *pr = blkid_new_probe_from_filename(device_name);
- if (*pr == NULL)
- return NULL;
- blkid_partlist ls = blkid_probe_get_partitions(*pr);
- return ls;
-}
-
-int get_part_number_by_name(blkid_partlist ls, const char *part_name, const char *new_slot) {
- int nparts = blkid_partlist_numof_partitions(ls);
- char part_name_with_slot[MAX_PARTNAME_LEN];
- int found_part_n = -1;
-
- if (snprintf(part_name_with_slot, MAX_PARTNAME_LEN, "%s_%s", part_name, new_slot) < 0) {
- return -1;
- }
-
- for (int it = 0; it < nparts; ++it) {
- blkid_partition part = blkid_partlist_get_partition(ls, it);
- const char *p;
-
- p = blkid_partition_get_name(part);
- if (!p)
- continue;
-
- if (found_part_n < 0 && strncmp(p, part_name, strlen(part_name)+1) == 0)
- found_part_n = it + 1;
- else if (strncmp(p, part_name_with_slot, strlen(part_name_with_slot)+1) == 0)
- found_part_n = it + 1;
- }
- if (found_part_n >= 0)
- return found_part_n;
-
- // nothing found
- return -1;
-}
-
+++ /dev/null
-/*
- * tota-ua
- *
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#pragma once
-#include <blkid/blkid.h>
-
-#ifndef MAX_PARTNAME_LEN
-#define MAX_PARTNAME_LEN 10000
-#endif
-blkid_partlist get_part_list(char *device_name, blkid_probe *pr);
-int get_part_number_by_name(blkid_partlist ls, const char *part_name, const char *new_slot);
+++ /dev/null
-/*
- * tota-ua
- *
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include <stdlib.h>
-#include "blkid-api.h"
-
-#define ARRAY_LEN(arr) sizeof(arr)/sizeof(arr[0])
-
-void usage(const char* msg) {
- if (msg) {
- fprintf(stderr, "%s\n", msg);
- }
- fprintf(stderr, "USAGE: blkid-print device_name partition_label suffix [verbose]\n"
- "device_name: block device e.g. /dev/mmcblk0\n"
- "partition_label: partiton label to search for e.g. rootfs,ramdisk etc.\n"
- "suffix: a|b partiton slot\n"
- "verbose: optional, prints part_nr: part_nr (part_label): part_path instead of part_path only\n");
-}
-
-blkid_partition partition_for(char *device_name, char *part_name, char *new_slot) {
- char part_name_with_slot[MAX_PARTNAME_LEN];
- int found_part_n = -1;
- if (!device_name || !part_name || !new_slot){
- fprintf(stderr, "partition_for: one or more argument is NULL\n");
- return NULL;
- }
- if (snprintf(part_name_with_slot, MAX_PARTNAME_LEN, "%s_%s", part_name, new_slot) < 0) {
- return NULL;
- }
- blkid_probe pr = blkid_new_probe_from_filename(device_name);
- if (pr == NULL) {
- fprintf(stderr, "ERROR: blkid error for %s\n", device_name);
- usage(NULL);
- return NULL;
- }
- blkid_partlist ls = blkid_probe_get_partitions(pr);
- if (!ls) {
- fprintf(stderr, "ERROR: unable to probe partitions.\n");
- blkid_free_probe(pr);
- return NULL;
- }
- int nparts = blkid_partlist_numof_partitions(ls);
- if (nparts == -1) {
- fprintf(stderr, "ERROR: unable to get partition count\n");
- blkid_free_probe(pr);
- return NULL;
- }
-
-
- for (int i = 0; i < nparts; i++) {
- blkid_partition part = blkid_partlist_get_partition(ls, i);
- const char *p;
-
- p = blkid_partition_get_name(part);
- if (!p)
- continue;
-
- if (found_part_n < 0 && strncmp(p, part_name, strlen(part_name)+1) == 0)
- found_part_n = i;
- else if (strncmp(p, part_name_with_slot, strlen(part_name_with_slot)+1) == 0)
- found_part_n = i;
- }
-
- blkid_free_probe(pr);
- if (found_part_n >= 0) {
- blkid_partition par = blkid_partlist_get_partition(ls, found_part_n);
- return par;
- }
- return NULL;
-}
-
-const char *get_part_label(blkid_partlist ls, int part_nr) {
- blkid_partition part = blkid_partlist_get_partition(ls, part_nr);
- return blkid_partition_get_name(part);
-}
-
-int main(int argc, char *argv[]) {
- char device_name_path[PATH_MAX];
- if (argc < 4 || argc > 5 || (argc == 5 && strcmp(argv[4], "verbose")) ) {
- usage("Please specify correct argument number\n");
- return 1;
- }
-
- int verbose = (argc == 5) ? 1 : 0;
-
- char *device_name = realpath(argv[1], device_name_path);
- if (!device_name) {
- fprintf(stderr, "ERROR: Unable to determine realpath for: %s\n", argv[1]);
- usage(NULL);
- return 1;
- }
- char *partition_label = argv[2];
- char *suffix = argv[3];
- blkid_partition part = partition_for(device_name, partition_label, suffix);
- if (part == NULL) {
- fprintf(stderr, "ERROR: Partition '%s' not found.\n", partition_label);
- return 2;
- }
- int part_nr = blkid_partition_get_partno(part);
- if (part_nr < 0) {
- fprintf(stderr, "ERROR: Partition '%s' not found", partition_label);
- return 3;
- }
- const char *part_label = blkid_partition_get_name(part);
- char part_path[PATH_MAX];
- // /dev/sda1 /dev/vda1 vs /dev/mmcblk0p1 /dev/nvme0n1p1
- // no_separator vs "p" separator
- if (strncmp("/dev/sd", device_name, ARRAY_LEN("/dev/sd") - 1) == 0 ||
- strncmp("/dev/vd", device_name, ARRAY_LEN("/dev/vd") - 1) == 0)
- snprintf(part_path, PATH_MAX, "%s%d", device_name, part_nr);
- else
- snprintf(part_path, PATH_MAX, "%sp%d", device_name, part_nr);
-
- if (verbose)
- printf("part_nr: %d (%s): %s\n", part_nr, part_label, part_path);
- else
- printf("%s\n", part_path);
- return 0;
-}