| #!/usr/bin/perl -w |
| |
| #use strict; |
| use lib "tools/perl"; |
| use Spreadsheet::ParseExcel; |
| |
| # UBI tool |
| my $MKUBIFS = "tools/ubiimgGen/mkfs.ubifs"; |
| my $UBINIZE = "tools/ubiimgGen/ubinize"; |
| |
| #------------------------------------------------------------ |
| # global definition |
| #------------------------------------------------------------ |
| my $CUSTOMDIR = "$ENV{'WORKDIR'}/custom/$ENV{'PRJ_FILENAME'}"; |
| my $UBIDIR = "$CUSTOMDIR/build/ubifs"; |
| my $OUTDIR = "$ENV{'OUTDIR'}"; |
| my $UBIFSCFGDIR = "$OUTDIR/tmp/ubifs"; |
| my $IMGDIR = "$ARGV[0]"; |
| my $PART_NAME = "$ARGV[1]"; |
| my $BLK_KBSIZE = $ARGV[2]; |
| my $PAGE_SIZE = $ARGV[3] * 1024; |
| # use zlib for compression |
| my $COMP = "zlib"; |
| |
| print("$CUSTOMDIR\n"); |
| print("$UBIDIR\n"); |
| print("$OUTDIR\n"); |
| print("$IMGDIR\n"); |
| print("$PART_NAME\n"); |
| |
| my $FileName = "$CUSTOMDIR/build/flash_partition.xls"; |
| my $parser = Spreadsheet::ParseExcel->new(); |
| my $workbook = $parser->parse($FileName); |
| die $parser->error(), ".\n" if ( !defined $workbook ); |
| my $find = 0; |
| |
| #------------------------------------------------------------ |
| # functions |
| #------------------------------------------------------------ |
| sub system_cmd |
| { |
| my $cmd = $_[0]; |
| printf("$cmd\n"); |
| system($cmd); |
| } |
| |
| #------------------------------------------------------------ |
| # main function |
| #------------------------------------------------------------ |
| # Iterate through all worksheets |
| for my $worksheet ( $workbook->worksheets() ) { |
| # Find out the worksheet ranges |
| my ( $row_min, $row_max ) = $worksheet->row_range(); |
| my ( $col_min, $col_max ) = $worksheet->col_range(); |
| |
| # Scan flash partition |
| for my $row ( $row_min .. $row_max ) { |
| next if ($row == 0); |
| |
| # Return the cell object at $row and $col |
| my $name = $worksheet->get_cell($row, 0)->value(); |
| |
| # check partition |
| if ("$name" eq "$PART_NAME") { |
| my $file = $worksheet->get_cell($row, 1)->value(); |
| my $len = $worksheet->get_cell($row, 2)->value(); |
| printf("find ---> partition $name, $file\n"); |
| |
| # compute number of blocks in partition |
| my $ubi_blk_size = $BLK_KBSIZE * 1024 - 2 * $PAGE_SIZE; |
| my $nr_blk = ($len * 1024) / $BLK_KBSIZE; |
| system_cmd("$MKUBIFS -F -m $PAGE_SIZE -e $ubi_blk_size -c $nr_blk -r $IMGDIR -o $OUTDIR/${file}_raw.img -x $COMP"); |
| |
| # generate cfg and flashed image |
| if (!-d "$UBIFSCFGDIR") { |
| printf("create output folder --> $UBIFSCFGDIR\n"); |
| system_cmd("mkdir -p $UBIFSCFGDIR"); |
| } |
| system_cmd("rm -f $UBIFSCFGDIR/$name.ubicfg"); |
| system_cmd("cp -f $UBIDIR/ubifs_template.ubicfg $UBIFSCFGDIR/$name.ubicfg"); |
| system_cmd("sed -i \"s|IMG_NAME|$OUTDIR\/${file}_raw.img|g\" $UBIFSCFGDIR/$name.ubicfg"); |
| system_cmd("sed -i \"s|VOL_NAME|$name|g\" $UBIFSCFGDIR/$name.ubicfg"); |
| system_cmd("${UBINIZE} -o $OUTDIR/$file -m $PAGE_SIZE -p ${BLK_KBSIZE}KiB -s $PAGE_SIZE -O $PAGE_SIZE $UBIFSCFGDIR/$name.ubicfg"); |
| system_cmd("rm -f $OUTDIR/${file}_raw.img"); |
| |
| # we only need to generate one config file |
| $find = 1; |
| last; |
| } |
| } |
| |
| if ($find == 1) { |
| last; |
| } |
| } |