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中)指定。
- int load_565rle_image(char *fn)
- {
- struct FB fb;
- struct stat s;
- unsigned short *data, *bits, *ptr;
- unsigned count, max;
- int fd;
- if (vt_set_mode(1))
- return -1;
- fd = open(fn, O_RDONLY);
- if (fd < 0) {
- ERROR("cannot open '%s'\n", fn);
- goto fail_restore_text;
- }
- if (fstat(fd, &s) < 0) {
- goto fail_close_file;
- }
- data = mmap(0, s.st_size, PROT_READ, MAP_SHARED, fd, 0);
- if (data == MAP_FAILED)
- goto fail_close_file;
- if (fb_open(&fb))
- goto fail_unmap_data;
- max = fb_width(&fb) * fb_height(&fb);
- ptr = data;
- count = s.st_size;
- bits = fb.bits;
- while (count > 3) {
- unsigned n = ptr[0];
- if (n > max)
- break;
- android_memset16(bits, ptr[1], n << 1);
- bits += n;
- max -= n;
- ptr += 2;
- count -= 4;
- }
- munmap(data, s.st_size);
- fb_update(&fb);
- fb_close(&fb);
- close(fd);
- unlink(fn);
- return 0;
- fail_unmap_data:
- munmap(data, s.st_size);
- fail_close_file:
- close(fd);
- fail_restore_text:
- vt_set_mode(0);
- return -1;
- }