Fix logo_partition_generate

Change-Id: I18ba79807ea302dab97fad5930990d4bedaa8500
diff --git a/mbtk/mbtk_utils_linux/logo_partition.h b/mbtk/mbtk_utils_linux/logo_partition.h
index 6a4b8d3..a084018 100755
--- a/mbtk/mbtk_utils_linux/logo_partition.h
+++ b/mbtk/mbtk_utils_linux/logo_partition.h
@@ -16,10 +16,14 @@
 typedef signed short int16; /* Signed 16 bit value */
 typedef signed char int8; /* Signed 8  bit value */
 
+/* 该变量只在uboot和kernel中加载        分区custom_logo时会使用 */
+/* 与 mbtk_source 无关 */
 #define LOGO_PARTITION_ADDR     0x0A3A0000    // custom_logo 分区的地址
+#define LOGO_PARTITION_NAME     "custom_logo"
 
-#define LOGO_ADDR_START         0x00000400    // 1K
-#define ANIMATION_ADDR_START    0x00080400    // log 不超过 512K
+#define LOGO_SIZE_MAX           0x00080000    // 512K
+#define LOGO_ADDR_START         0x00001000    // 4K (必须为页大小倍数)
+#define ANIMATION_ADDR_START    (LOGO_ADDR_START + LOGO_SIZE_MAX)    // log 不超过 512K
 
 typedef struct {
     uint32 addr;
@@ -33,8 +37,10 @@
     uint32 pic_num;
     uint32 pic_width;
     uint32 pic_height;
-    uint32 frame_rate;
+    uint32 waitting_time;   // 每帧图片之间的等待时间(ms)
+    uint32 frame_show_num;  // 总共显示的帧数
     uint32 bg_rgb;      // 背景色
 } mbtk_animation_header_t;
 
 #endif /* _LOGO_PARTITION_H */
+
diff --git a/mbtk/mbtk_utils_linux/logo_partition_generate.c b/mbtk/mbtk_utils_linux/logo_partition_generate.c
index 3468558..fade677 100755
--- a/mbtk/mbtk_utils_linux/logo_partition_generate.c
+++ b/mbtk/mbtk_utils_linux/logo_partition_generate.c
@@ -48,7 +48,8 @@
     .pic_num = 0,
     .pic_width = 240,
     .pic_height = 320,
-    .frame_rate = 10,
+    .waitting_time = 0,         // ms
+    .frame_show_num = 50,
     .bg_rgb = 0x00000000        // black
 };
 
@@ -64,7 +65,7 @@
 static void help()
 {
     //printf("logo_partition_generate [pic_dir] -a [logo_w] -b [logo_h] -c [logo_bg] -d [anim_num] -e [anim_w] -f [anim_h] -g [anim_rate] -i [anim_bg]\n");
-    printf("logo_partition_generate [pic_dir] -a [logo_bg] -b [anim_rate] -c [anim_bg]\n");
+    printf("logo_partition_generate [pic_dir] -a [logo_bg] -b [waitting_time(ms)] -c [anim_bg] -d [frame_show_num]\n");
 }
 
 static int bmp_read(const char* file_name, uint32 *width, uint32 *height, char *buff, int buff_size)
@@ -103,7 +104,15 @@
 
     // 分配内存并读取像素数据
     fseek(file, file_header.bfOffBits, SEEK_SET);  // 定位到数据区 [[2, 8, 15]]
+#if 0
     fread(buff, 1, data_size, file);
+#else
+    // bmp中y轴是反的,所以从最下面一行开始依次读取一行数据。
+    int line_size = info_header.biWidth * 3;
+    for(int y = info_header.biHeight - 1; y >= 0; y--) {
+        fread(buff + y * line_size, 1, line_size, file);
+    }
+#endif
     fclose(file);
 
     return data_size;
@@ -200,7 +209,7 @@
 /*
 *
 * logo_partition_generate [pic_dir] -a [logo_w] -b [logo_h] -c [logo_bg] -d [anim_num] -e [anim_w] -f [anim_h] -g [anim_rate] -i [anim_bg]
-* logo_partition_generate [pic_dir] -a [logo_bg] -b [anim_rate] -c [anim_bg]
+* logo_partition_generate [pic_dir] -a [logo_bg] -b [waitting_time(ms)] -c [anim_bg] -d [frame_show_num]
 */
 int main(int argc, char *argv[])
 {
@@ -218,7 +227,7 @@
         return -1;
     }
 
-    while((ch = getopt(argc, argv, "a:b:c:"))!= -1){
+    while((ch = getopt(argc, argv, "a:b:c:d:"))!= -1){
         switch(ch)
         {
 #if 0
@@ -281,19 +290,27 @@
 #else
             case 'a':
                 temp_int = (uint32)strtoul(optarg, NULL, 0); // 自动识别
-                logo_header.bg_rgb = temp_int & 0x00FFFFFF;
+                logo_header.bg_rgb = temp_int << 8;
                 break;
             case 'b':
                 temp_int = (uint32)atoi(optarg);
                 if(temp_int > 0) {
-                    animation_header.frame_rate = temp_int;
+                    animation_header.waitting_time = temp_int;
                 } else {
-                    printf("animation frame_rate error.");
+                    printf("animation waitting_time error.");
                 }
                 break;
             case 'c':
                 temp_int = (uint32)strtoul(optarg, NULL, 0); // 自动识别
-                animation_header.bg_rgb = temp_int & 0x00FFFFFF;
+                animation_header.bg_rgb = temp_int << 8;
+                break;
+            case 'd':
+                temp_int = (uint32)atoi(optarg);
+                if(temp_int > 0) {
+                    animation_header.frame_show_num = temp_int;
+                } else {
+                    printf("animation frame_show_num error.");
+                }
                 break;
 #endif
             default:
@@ -303,8 +320,8 @@
     }
 
     printf("Before Logo : addr - 0x%x, w - %d, h - %d, bg - 0x%06x\n", logo_header.addr ,logo_header.pic_width, logo_header.pic_height, logo_header.bg_rgb);
-    printf("Before Anim : addr - 0x%x, w - %d, h - %d, bg - 0x%06x, num - %d, frame_rate - %d\n", animation_header.addr ,animation_header.pic_width, animation_header.pic_height, animation_header.bg_rgb,
-                    animation_header.pic_num, animation_header.frame_rate);
+    printf("Before Anim : addr - 0x%x, w - %d, h - %d, bg - 0x%06x, num - %d, waitting_time(ms) - %d, frame_show_num - %d\n", animation_header.addr ,animation_header.pic_width, animation_header.pic_height, animation_header.bg_rgb,
+                    animation_header.pic_num, animation_header.waitting_time, animation_header.frame_show_num);
 
     int fd = open(out_bin, O_WRONLY | O_TRUNC | O_CREAT, 0644);
     if(fd < 0) {
@@ -329,8 +346,8 @@
     }
 
     printf("After Logo : addr - 0x%x, w - %d, h - %d, bg - 0x%06x\n", logo_header.addr ,logo_header.pic_width, logo_header.pic_height, logo_header.bg_rgb);
-    printf("After Anim : addr - 0x%x, w - %d, h - %d, bg - 0x%06x, num - %d, frame_rate - %d\n", animation_header.addr ,animation_header.pic_width, animation_header.pic_height, animation_header.bg_rgb,
-                    animation_header.pic_num, animation_header.frame_rate);
+    printf("After Anim : addr - 0x%x, w - %d, h - %d, bg - 0x%06x, num - %d, waitting_time(ms) - %d, frame_show_num - %d\n", animation_header.addr ,animation_header.pic_width, animation_header.pic_height, animation_header.bg_rgb,
+                    animation_header.pic_num, animation_header.waitting_time, animation_header.frame_show_num);
 
     printf("Success generate logo_partition bin:%s\n", out_bin);
     close(fd);