blob: 8664d95b7833262267602f8bd09ef3f8f000640c [file] [log] [blame]
xiaohu.huangbeee8872024-01-24 19:15:06 +08001#!/bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
8#RTOS root directory
9RTOS_BASE_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..)
10
11TOOL_CHAIN_PATH=$RTOS_BASE_DIR/output/toolchains/gcc-riscv-none/bin
12
13OBJCOPY=$TOOL_CHAIN_PATH/riscv-none-embed-objcopy
14
15FW_ELF=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/$KERNEL/freertos.elf
16FW_HEX=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/$KERNEL/fw.hex
17FW_BIN=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/$KERNEL/fwall.bin
18TARGET=$RTOS_BASE_DIR/output/$ARCH-$BOARD-$PRODUCT/$KERNEL/wifi_fw_w1u.bin
19
20target_size=$((240 * 1024)) # 240kb
21
22$OBJCOPY --gap-fill=0x00 -O ihex $FW_ELF $FW_HEX
23
24$OBJCOPY --gap-fill=0x00 --input-target=ihex --output-target=binary $FW_HEX $TARGET
25
26current_size=$(stat -c %s "$TARGET")
27
28bytes_to_append=$((target_size - current_size))
29
30if [ "$bytes_to_append" -gt 0 ]; then
31 dd if=/dev/zero bs="$bytes_to_append" count=1 >> "$TARGET"
32 echo "File size has been extended to $target_size bytes."
33else
34 echo "File is already at or larger than the target size."
35fi