rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #! /bin/sh |
| 2 | |
| 3 | PROJECT=$1 |
| 4 | OUT=$2 |
| 5 | BOOTDEV_TYPE=$3 |
| 6 | SCATTER_SRC=$4 |
| 7 | NAND_CHIP_NAME=$5 |
| 8 | NAND_HEADER_VERSION=$6 |
| 9 | HEADER_LK_MERGE=$7 |
| 10 | |
| 11 | |
| 12 | if [ ! -e ${PROJECT}/gen-partitions.ini ]; then |
| 13 | echo ERROR: can not find $1 |
| 14 | exit 1 |
| 15 | fi |
| 16 | |
| 17 | mkdir -p ${OUT} |
| 18 | cat ${PROJECT}/gen-partitions.ini | while read p s m t |
| 19 | do |
| 20 | if [ "$t" = "" ]; then |
| 21 | if [ "${BOOTDEV_TYPE}" = "nand" ]; then |
| 22 | if [ "${HEADER_LK_MERGE}" = "yes" ]; then |
| 23 | python3 scripts/gen-partition-nand_merge.py ${PROJECT}/$p ${PROJECT}/$s ${OUT}/$m |
| 24 | else |
| 25 | python3 scripts/gen-partition-nand.py ${PROJECT}/$p ${PROJECT}/$s ${OUT}/$m |
| 26 | fi |
| 27 | else |
| 28 | python3 ${SCATTER_SRC}/gen-partition.py ${PROJECT}/$p ${PROJECT}/$s ${OUT}/$m |
| 29 | fi |
| 30 | else |
| 31 | if [ "${BOOTDEV_TYPE}" = "nand" ]; then |
| 32 | if [ "${HEADER_LK_MERGE}" = "yes" ]; then |
| 33 | python3 scripts/gen-partition-nand_merge.py ${PROJECT}/$p ${PROJECT}/$s ${OUT}/$m ${OUT}/$t |
| 34 | else |
| 35 | python3 scripts/gen-partition-nand.py ${PROJECT}/$p ${PROJECT}/$s ${OUT}/$m ${OUT}/$t |
| 36 | fi |
| 37 | else |
| 38 | python3 ${SCATTER_SRC}/gen-partition.py ${PROJECT}/$p ${PROJECT}/$s ${OUT}/$m ${OUT}/$t |
| 39 | fi |
| 40 | fi |
| 41 | |
| 42 | if [ "${BOOTDEV_TYPE}" = "nand" ]; then |
| 43 | if [ "${NAND_HEADER_VERSION}" = "2.0" ]; then |
| 44 | if [ "$m" = "MBR_NAND" ]; then |
| 45 | python3 -B ${PWD}/tools/nand-utils/gen_nand_header.py ${NAND_CHIP_NAME} ${OUT}/$m |
| 46 | fi |
| 47 | elif [ "${NAND_HEADER_VERSION}" = "1.1" ]; then |
| 48 | lk_start=$(grep 'name="bl2"' ${PROJECT}/$p | grep -o 'start="[0-9]*"' | grep -o [0-9]*) |
| 49 | if [ "${lk_start}" = "" ]; then |
| 50 | echo ERROR: can not find UBOOT in ${PROJECT}/$p |
| 51 | exit 1 |
| 52 | fi |
| 53 | temp_header_file="temp_nand_header.bin" |
| 54 | python3 -B ${PWD}/tools/nand-utils/gen_nand_header_v11.py ${NAND_CHIP_NAME} ${lk_start} ${OUT}/${temp_header_file} |
| 55 | cat ${OUT}/$m >> ${OUT}/${temp_header_file} |
| 56 | rm ${OUT}/$m |
| 57 | mv ${OUT}/${temp_header_file} ${OUT}/$m |
| 58 | elif [ "${NAND_HEADER_VERSION}" = "1.2" ]; then |
| 59 | temp_header_file="temp_nand_header.bin" |
| 60 | python3 -B ${PWD}/tools/nand-utils/gen_nand_header_v12.py ${NAND_CHIP_NAME} ${OUT}/${temp_header_file} |
| 61 | dd if=${OUT}/${temp_header_file} of=${OUT}/$m conv=notrunc |
| 62 | rm ${OUT}/${temp_header_file} |
| 63 | elif [ "${NAND_HEADER_VERSION}" = "1.3" ]; then |
| 64 | preloader_start=$(grep 'name="preloader"' ${PROJECT}/$p | grep -o 'start="[0-9]*"' | grep -o [0-9]*) |
| 65 | if [ "${preloader_start}" = "" ]; then |
| 66 | echo ERROR: can not find preloader in ${PROJECT}/$p |
| 67 | exit 1 |
| 68 | fi |
| 69 | temp_header_file="temp_nand_header.bin" |
| 70 | python3 -B ${PWD}/tools/nand-utils/gen_nand_header_v13.py ${NAND_CHIP_NAME} ${preloader_start} ${OUT}/${temp_header_file} |
| 71 | cat ${OUT}/$m >> ${OUT}/${temp_header_file} |
| 72 | rm ${OUT}/$m |
| 73 | mv ${OUT}/${temp_header_file} ${OUT}/$m |
| 74 | elif [ "${NAND_HEADER_VERSION}" = "1.4" ]; then |
| 75 | temp_header_file="temp_nand_header.bin" |
| 76 | python -B ${PWD}/tools/nand-utils/gen_nand_header_v14.py ${NAND_CHIP_NAME} ${OUT}/${temp_header_file} |
| 77 | dd if=${OUT}/${temp_header_file} of=${OUT}/$m conv=notrunc |
| 78 | rm ${OUT}/${temp_header_file} |
| 79 | elif [ "${NAND_HEADER_VERSION}" = "3.0" ]; then |
| 80 | if [ "$m" = "MBR_NAND" ]; then |
| 81 | python -B ${PWD}/tools/nand-utils/gen_nand_header_mt2731.py ${NAND_CHIP_NAME} ${OUT}/$m |
| 82 | fi |
| 83 | elif [ "${NAND_HEADER_VERSION}" = "4.0" ]; then |
| 84 | if [ "$m" = "MBR_NAND" ]; then |
| 85 | python3 -B ${PWD}/tools/nand-utils/gen_nand_header_v4.py ${NAND_CHIP_NAME} ${OUT}/$m |
| 86 | fi |
| 87 | elif [ "${NAND_HEADER_VERSION}" = "5.0" ]; then |
| 88 | if [ "$m" = "MBR_NAND" ]; then |
| 89 | python -B ${PWD}/tools/nand-utils/gen_nand_header_mt2735_hsm.py ${NAND_CHIP_NAME} ${OUT}/$m |
| 90 | fi |
| 91 | else |
| 92 | if [ "${NAND_CHIP_NAME}" = "" ]; then |
| 93 | echo ERROR: please check NAND_CHIP_NAME ${NAND_CHIP_NAME} |
| 94 | exit 2 |
| 95 | fi |
| 96 | |
| 97 | PAGE_SIZE=$(grep -o '^'${NAND_CHIP_NAME}' [0-9]*' nand-setting.txt | grep -o '[0-9]*$') |
| 98 | LBS=$(grep -o 'lbs="[0-9]*"' ${PROJECT}/$p | grep -o [0-9]*) |
| 99 | if [ "${PAGE_SIZE}" != "${LBS}" ]; then |
| 100 | echo ERROR: PAGE_SIZE ${PAGE_SIZE} of NAND ${NAND_CHIP_NAME} != LBS ${LBS} of partition table ${PROJECT}/$p |
| 101 | exit 3 |
| 102 | fi |
| 103 | |
| 104 | LK1=$(grep 'name="LK1"' ${PROJECT}/$p | grep -o 'start="[0-9]*"' | grep -o [0-9]*) |
| 105 | if [ "${LK1}" = "" ]; then |
| 106 | echo ERROR: can not find LK1 in ${PROJECT}/$p |
| 107 | exit 4 |
| 108 | fi |
| 109 | |
| 110 | LK2=$(grep 'name="LK2"' ${PROJECT}/$p | grep -o 'start="[0-9]*"' | grep -o [0-9]*) |
| 111 | if [ "${LK2}" = "" ]; then |
| 112 | echo ERROR: can not find LK2 in ${PROJECT}/$p |
| 113 | exit 5 |
| 114 | fi |
| 115 | |
| 116 | python3 scripts/dev-info-hdr-tool.py ${BOOTDEV_TYPE} ${OUT}/$m ${OUT}/$m ${NAND_CHIP_NAME} ${LK1} ${LK2} |
| 117 | fi |
| 118 | fi |
| 119 | done |