rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | #use strict; |
| 4 | use lib "tools/perl"; |
| 5 | use Spreadsheet::ParseExcel; |
| 6 | |
| 7 | # UBI tool |
| 8 | my $MKUBIFS = "tools/ubiimgGen/mkfs.ubifs"; |
| 9 | my $UBINIZE = "tools/ubiimgGen/ubinize"; |
| 10 | |
| 11 | #------------------------------------------------------------ |
| 12 | # global definition |
| 13 | #------------------------------------------------------------ |
| 14 | my $CUSTOMDIR = "$ENV{'WORKDIR'}/custom/$ENV{'PRJ_FILENAME'}"; |
| 15 | my $UBIDIR = "$CUSTOMDIR/build/ubifs"; |
| 16 | my $OUTDIR = "$ENV{'OUTDIR'}"; |
| 17 | my $UBIFSCFGDIR = "$OUTDIR/tmp/ubifs"; |
| 18 | my $IMGDIR = "$ARGV[0]"; |
| 19 | my $PART_NAME = "$ARGV[1]"; |
| 20 | my $BLK_KBSIZE = $ARGV[2]; |
| 21 | my $PAGE_SIZE = $ARGV[3] * 1024; |
| 22 | # use zlib for compression |
| 23 | my $COMP = "zlib"; |
| 24 | |
| 25 | print("$CUSTOMDIR\n"); |
| 26 | print("$UBIDIR\n"); |
| 27 | print("$OUTDIR\n"); |
| 28 | print("$IMGDIR\n"); |
| 29 | print("$PART_NAME\n"); |
| 30 | |
| 31 | my $FileName = "$CUSTOMDIR/build/flash_partition.xls"; |
| 32 | my $parser = Spreadsheet::ParseExcel->new(); |
| 33 | my $workbook = $parser->parse($FileName); |
| 34 | die $parser->error(), ".\n" if ( !defined $workbook ); |
| 35 | my $find = 0; |
| 36 | |
| 37 | #------------------------------------------------------------ |
| 38 | # functions |
| 39 | #------------------------------------------------------------ |
| 40 | sub system_cmd |
| 41 | { |
| 42 | my $cmd = $_[0]; |
| 43 | printf("$cmd\n"); |
| 44 | system($cmd); |
| 45 | } |
| 46 | |
| 47 | #------------------------------------------------------------ |
| 48 | # main function |
| 49 | #------------------------------------------------------------ |
| 50 | # Iterate through all worksheets |
| 51 | for my $worksheet ( $workbook->worksheets() ) { |
| 52 | # Find out the worksheet ranges |
| 53 | my ( $row_min, $row_max ) = $worksheet->row_range(); |
| 54 | my ( $col_min, $col_max ) = $worksheet->col_range(); |
| 55 | |
| 56 | # Scan flash partition |
| 57 | for my $row ( $row_min .. $row_max ) { |
| 58 | next if ($row == 0); |
| 59 | |
| 60 | # Return the cell object at $row and $col |
| 61 | my $name = $worksheet->get_cell($row, 0)->value(); |
| 62 | |
| 63 | # check partition |
| 64 | if ("$name" eq "$PART_NAME") { |
| 65 | my $file = $worksheet->get_cell($row, 1)->value(); |
| 66 | my $len = $worksheet->get_cell($row, 2)->value(); |
| 67 | printf("find ---> partition $name, $file\n"); |
| 68 | |
| 69 | # compute number of blocks in partition |
| 70 | my $ubi_blk_size = $BLK_KBSIZE * 1024 - 2 * $PAGE_SIZE; |
| 71 | my $nr_blk = ($len * 1024) / $BLK_KBSIZE; |
| 72 | system_cmd("$MKUBIFS -F -m $PAGE_SIZE -e $ubi_blk_size -c $nr_blk -r $IMGDIR -o $OUTDIR/${file}_raw.img -x $COMP"); |
| 73 | |
| 74 | # generate cfg and flashed image |
| 75 | if (!-d "$UBIFSCFGDIR") { |
| 76 | printf("create output folder --> $UBIFSCFGDIR\n"); |
| 77 | system_cmd("mkdir -p $UBIFSCFGDIR"); |
| 78 | } |
| 79 | system_cmd("rm -f $UBIFSCFGDIR/$name.ubicfg"); |
| 80 | system_cmd("cp -f $UBIDIR/ubifs_template.ubicfg $UBIFSCFGDIR/$name.ubicfg"); |
| 81 | system_cmd("sed -i \"s|IMG_NAME|$OUTDIR\/${file}_raw.img|g\" $UBIFSCFGDIR/$name.ubicfg"); |
| 82 | system_cmd("sed -i \"s|VOL_NAME|$name|g\" $UBIFSCFGDIR/$name.ubicfg"); |
| 83 | system_cmd("${UBINIZE} -o $OUTDIR/$file -m $PAGE_SIZE -p ${BLK_KBSIZE}KiB -s $PAGE_SIZE -O $PAGE_SIZE $UBIFSCFGDIR/$name.ubicfg"); |
| 84 | system_cmd("rm -f $OUTDIR/${file}_raw.img"); |
| 85 | |
| 86 | # we only need to generate one config file |
| 87 | $find = 1; |
| 88 | last; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if ($find == 1) { |
| 93 | last; |
| 94 | } |
| 95 | } |