blob: f2498a2eabdd43ea84ffff5d187b9dc5cf64f7eb [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/usr/bin/perl -w
2
3#use strict;
4use lib "tools/perl";
5use Spreadsheet::ParseExcel;
6
7# UBI tool
8my $MKUBIFS = "tools/ubiimgGen/mkfs.ubifs";
9my $UBINIZE = "tools/ubiimgGen/ubinize";
10
11#------------------------------------------------------------
12# global definition
13#------------------------------------------------------------
14my $CUSTOMDIR = "$ENV{'WORKDIR'}/custom/$ENV{'PRJ_FILENAME'}";
15my $UBIDIR = "$CUSTOMDIR/build/ubifs";
16my $OUTDIR = "$ENV{'OUTDIR'}";
17my $UBIFSCFGDIR = "$OUTDIR/tmp/ubifs";
18my $IMGDIR = "$ARGV[0]";
19my $PART_NAME = "$ARGV[1]";
20my $BLK_KBSIZE = $ARGV[2];
21my $PAGE_SIZE = $ARGV[3] * 1024;
22# use zlib for compression
23my $COMP = "zlib";
24
25print("$CUSTOMDIR\n");
26print("$UBIDIR\n");
27print("$OUTDIR\n");
28print("$IMGDIR\n");
29print("$PART_NAME\n");
30
31my $FileName = "$CUSTOMDIR/build/flash_partition.xls";
32my $parser = Spreadsheet::ParseExcel->new();
33my $workbook = $parser->parse($FileName);
34die $parser->error(), ".\n" if ( !defined $workbook );
35my $find = 0;
36
37#------------------------------------------------------------
38# functions
39#------------------------------------------------------------
40sub 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
51for 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}