Android教程:开机Logo


Android系统开机第一个程序的进程是init,它的源码位于system/core/init/init.c,其中函数load_565rle_image负责logo的显示,如果读取成功,就在/dev/graphics/fb0显示图片,如果读取失败,则将/dev/tty0设为文本模式,并打开/dev/tty0并输出android字样。之后会显示android开机动画(其实两张图片做成的效果),logo图片由INIT_IMAGE_FILE(在init.h中)指定。

  1. int load_565rle_image(char *fn)
  2. {
  3.     struct FB fb;
  4.     struct stat s;
  5.     unsigned short *data, *bits, *ptr;
  6.     unsigned count, max;
  7.     int fd;

  8.     if (vt_set_mode(1))
  9.         return -1;

  10.     fd = open(fn, O_RDONLY);
  11.     if (fd < 0) {
  12.         ERROR("cannot open '%s'\n", fn);
  13.         goto fail_restore_text;
  14.     }

  15.     if (fstat(fd, &s) < 0) {
  16.         goto fail_close_file;
  17.     }

  18.     data = mmap(0, s.st_size, PROT_READ, MAP_SHARED, fd, 0);
  19.     if (data == MAP_FAILED)
  20.         goto fail_close_file;

  21.     if (fb_open(&fb))
  22.         goto fail_unmap_data;

  23.     max = fb_width(&fb) * fb_height(&fb);
  24.     ptr = data;
  25.     count = s.st_size;
  26.     bits = fb.bits;
  27.     while (count > 3) {
  28.         unsigned n = ptr[0];
  29.         if (n > max)
  30.             break;
  31.         android_memset16(bits, ptr[1], n << 1);
  32.         bits += n;
  33.         max -= n;
  34.         ptr += 2;
  35.         count -= 4;
  36.     }

  37.     munmap(data, s.st_size);
  38.     fb_update(&fb);
  39.     fb_close(&fb);
  40.     close(fd);
  41.     unlink(fn);
  42.     return 0;

  43. fail_unmap_data:
  44.     munmap(data, s.st_size);
  45. fail_close_file:
  46.     close(fd);
  47. fail_restore_text:
  48.     vt_set_mode(0);
  49.     return -1;
  50. }
  • 1
  • 2
  • 下一页

相关内容