blob: cc0caf7daa95633d7c02eaeb85838be5c7027322 [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;
6my $CUSTOMDIR;
7my $OUTDIR;
8my $OUTSUBDIR;
9my $TYPE;
10
11if ($#ARGV < 2) {
12 print "Usage: \n";
13 print " cfgGen_module.pl CUSTOMDIR TYPE OUTDIR\n";
14 exit -1;
15}
16
17$CUSTOMDIR = $ARGV[0]."/".$ARGV[1];
18$TYPE = $ARGV[1];
19$OUTDIR = $ARGV[2];
20$OUTSUBDIR = $ARGV[2]."/".$ARGV[1];
21
22if (!-e $CUSTOMDIR) {
23 print $CUSTOMDIR," not exist!\n";
24 exit -1;
25}
26
27if ($TYPE eq "nf") {
28 genall();
29}
30if ($TYPE eq "sf") {
31 genall();
32}
33if ($TYPE eq "bf") {
34 genall();
35}
36
37sub genall {
38 my $FileName = "$CUSTOMDIR/flash_partition.xls";
39 my $parser = Spreadsheet::ParseExcel->new();
40 my $workbook = $parser->parse($FileName);
41
42 die $parser->error(), ".\n" if ( !defined $workbook );
43
44 for my $worksheet ( $workbook->worksheets() ) {
45 if ($worksheet->{Name} =~ m/HOST/) {
46 gen_host_file($worksheet);
47 }
48 if ($worksheet->{Name} =~ m/FDA/) {
49 gen_fda_cfg($worksheet);
50 }
51 if ($worksheet->{Name} =~ m/SPI/) {
52 gen_spi_cfg();
53 }
54 }
55}
56
57sub gen_host_file {
58 my ($worksheet) = @_;
59 my ( $row_min, $row_max ) = $worksheet->row_range();
60 my ( $col_min, $col_max ) = $worksheet->col_range();
61
62 my $FILE = "$OUTSUBDIR/HOST.cfg";
63
64 open (MYFILE, ">$FILE");
65
66 for my $row ( $row_min .. $row_max ) {
67 next if ($row == 0);
68 my ($name, $file, $size, $type);
69 for my $col ( $col_min .. $col_max ) {
70 # Return the cell object at $row and $col
71 my $cell = $worksheet->get_cell( $row, $col );
72 next unless $cell;
73 if ($col == 0) {
74 $name = $cell->value();
75 }
76 if ($col == 1) {
77 $file = $cell->value();
78 }
79 if ($col == 2) {
80 $size = $cell->value();
81 }
82 if ($col == 3) {
83 $type = $cell->value();
84 }
85 }
86
87 my $new_file;
88 my $new_size;
89 if ($type =~ m/yaffs/) {
90 #$new_file = $file;
91 #$new_file =~ s/\..*$/\.oob/;
92 $new_file = lc($name).".oob";
93 $new_size = $size*(1024+32)*(1024+32);
94 system("dd if=/dev/zero bs=$new_size count=1 2>/dev/null | tr '\\000' '\\377' > $OUTSUBDIR/$new_file");
95 if ("$file" ne "__NODL") {
96 system("dd if=$OUTDIR/$file of=$OUTSUBDIR/$new_file conv=notrunc 2>/dev/null");
97 }
98 print MYFILE "name: ", $name, "\n";
99 print MYFILE "file: ", $new_file, "\n";
100 }
101 if ($type =~ m/raw/) {
102 $new_file = lc($name).".raw";
103 $new_size = $size*1024*1024;
104 system("dd if=/dev/zero bs=$new_size count=1 2>/dev/null | tr '\\000' '\\377' > $OUTSUBDIR/$new_file");
105 if ("$file" ne "__NODL") {
106 system("dd if=$OUTDIR/$file of=$OUTSUBDIR/$new_file conv=notrunc 2>/dev/null");
107 }
108 print MYFILE "name: ", $name, "\n";
109 print MYFILE "file: ", $new_file, "\n";
110 }
111 if ($type =~ m/reserved/) {
112 $new_file = lc($name).".raw";
113 $new_size = $size*1024*1024;
114 system("dd if=/dev/zero bs=$new_size count=1 2>/dev/null | tr '\\000' '\\377' > $OUTSUBDIR/$new_file");
115 print MYFILE "name: ", $name, "\n";
116 print MYFILE "file: ", $new_file, "\n";
117 }
118
119 }
120
121 print MYFILE "\n";
122 close (MYFILE);
123}
124
125sub gen_fda_cfg {
126 my ($worksheet) = @_;
127 my ( $row_min, $row_max ) = $worksheet->row_range();
128 my ( $col_min, $col_max ) = $worksheet->col_range();
129
130 my $FILE = "$OUTSUBDIR/FDA.cfg";
131
132 open (MYFILE, ">$FILE");
133 print MYFILE "############################################################################################################\n";
134 print MYFILE "#\n";
135 print MYFILE "# Android Region Setting\n";
136 print MYFILE "#\n";
137 print MYFILE "############################################################################################################\n";
138 print MYFILE "linux_region:\n";
139 print MYFILE " partitions:\n";
140
141 for my $row ( $row_min .. $row_max ) {
142 next if ($row == 0);
143 print MYFILE " - partition:\n";
144 for my $col ( $col_min .. $col_max ) {
145
146 # Return the cell object at $row and $col
147 my $cell = $worksheet->get_cell( $row, $col );
148 next unless $cell;
149
150 if ($col == 0) {
151 print MYFILE " name: ", $cell->value(), "\n";
152 }
153 if ($col == 1) {
154 print MYFILE " file: ", $cell->value(), "\n";
155 my $file = $cell->value();
156 if ( -e "$OUTDIR/$file" ) {
157 system("cp -f $OUTDIR/$file $OUTSUBDIR/");
158 }
159 }
160 if ($col == 2) {
161 print MYFILE " address: ", $cell->value(), "\n";
162 }
163 if ($col == 3) {
164 print MYFILE " type: ", $cell->value(), "\t\t#raw, yaffs, yaffs2\n";
165 }
166 }
167 }
168 print MYFILE "\n";
169 close (MYFILE);
170}
171