static gboolean monitor_extract_progress(HookInfo* info) { static int stage = EXTRACT_PROGRESS_NONE; int v = 0; switch (stage) { case EXTRACT_PROGRESS_NONE: v = read_progress(PROGRESS_LOG_BASE); if (v != -1) { stage = EXTRACT_PROGRESS_BASE; } return TRUE; case EXTRACT_PROGRESS_BASE: v = read_progress(PROGRESS_LOG_BASE); if (v >= 100) { stage = EXTRACT_PROGRESS_BASE_END; } double ratio = v / 100.0; //extract lang pack use 10% time update_install_progress( info->progress_begin + (info->progress_end - 10 ) * ratio); return TRUE; case EXTRACT_PROGRESS_BASE_END: v = read_progress(PROGRESS_LOG_LANG); if (v != -1) { stage = EXTRACT_PROGRESS_LANG; } return TRUE; case EXTRACT_PROGRESS_LANG: v = read_progress(PROGRESS_LOG_LANG); if (v >= 100) { stage = EXTRACT_PROGRESS_LANG_END; } update_install_progress(info->progress_end - 10 + 10 * ratio); return TRUE; case EXTRACT_PROGRESS_LANG_END: printf("END Monitor_extract_progress\n"); return FALSE; } }
int loadelf_load(char *ch, struct elf_image *img) { unsigned long i, j; struct elf_hdr *ElfHdr = 0; /*elf header struct */ unsigned long p_e_entry; /* elf progamme start address */ unsigned long p_e_phoff; /* Start of program headers */ unsigned short p_e_phentsize; /* Size of program headers */ unsigned short p_e_phnum; /* number of program headers */ struct elf_phdr *ElfPhdr = 0; /* ELF program Header */ struct elf_phdr *phdr = 0; /* ELF program Header */ unsigned char *lptmp; /* load temp address */ WORD brs; unsigned long br; FRESULT res; /* Need to load portions of the ELF file to read metadata. Where should it be loaded? Choose high area of DDR. TODO: Read metadata into SRAM (stack?) instead? */ unsigned char *readbuf = (unsigned char *)0x13000000; img->entry = 0; img->min_addr = (void *) 0xFFFFFFF0; img->max_addr = (void *) 0; /* ELF loader */ /* mount the volume */ lcd_clear(); lcd_print(0, "Pgm load"); lcd_print(1, ch); res = pf_open(ch); if (res != FR_OK) { putstr("ELF not found\n"); lcd_print(1, "not fnd "); return -1; } char str[32]; str[0] = '\0'; _strcat(str, "Open "); _strcat(str, ch); _strcat(str, " OK"); _strcat(str, "\n"); putstr(str); res = pf_lseek(0); if (res != FR_OK) return -1; /* read ELF header length */ pf_lseek(40); //ELF header length stored at 40 res = pf_read(readbuf, 2, &brs); /*read elf magic number */ pf_lseek(0); res = pf_read(readbuf, ((readbuf[0]) << 8) + readbuf[1], &brs); if (res != FR_OK) return -1; ElfHdr = (struct elf_hdr *)readbuf; if ((ElfHdr->e_ident[0] != 0x7f) || (ElfHdr->e_ident[1] != 'E') || (ElfHdr->e_ident[2] != 'L') || (ElfHdr->e_ident[3] != 'F')) return -1; if (ElfHdr->e_type != ET_EXEC) return -1; /* ELF executable programe running start address */ p_e_entry = ElfHdr->e_entry; p_e_phoff = ElfHdr->e_phoff; /*Start of program headers */ p_e_phentsize = ElfHdr->e_phentsize; /*size of program headers */ p_e_phnum = ElfHdr->e_phnum; /*number of program headers */ /* relocate readbuf to avoid conflict */ /* Don't need to play these games as readbuf is now high in DDR memory. if(p_e_entry <= p_e_phentsize + (unsigned)readbuf) { if((p_e_entry - p_e_phentsize) > 0x100000200) readbuf = (unsigned char*)(p_e_entry - p_e_phentsize - 256); else readbuf = (unsigned char*)0x12a00000; }*/ lcd_print(1, "Loading"); /* load all program headers */ pf_lseek(p_e_phoff); res = pf_read_long(readbuf, p_e_phentsize * p_e_phnum, &br); if (res != FR_OK) return -1; /* calculate total in memory size for progress indicator */ unsigned long mem_total = 0; unsigned long mem_progress = 0; ElfPhdr = (struct elf_phdr *)readbuf; for (i = 0; i < p_e_phnum; i++) { if (ElfPhdr[i].p_type == PT_LOAD) { mem_total += ElfPhdr[i].p_memsz; } } /* copy segment section */ for (i = 0; i < p_e_phnum; i++) { /* number of programme header */ phdr = ElfPhdr + i; if (phdr->p_type == PT_LOAD) { /* load to running address */ /* loading */ lptmp = (unsigned char *)phdr->p_paddr; /* assigned physAddr or virtAddr ? */ /* update min and max addresses */ if (img->min_addr > (void*) lptmp) { img->min_addr = lptmp; } if (img->max_addr < (void*)(lptmp + phdr->p_memsz)) { img->max_addr = lptmp + phdr->p_memsz; } if (phdr->p_filesz > 0) { pf_lseek(phdr->p_offset); res = read_progress(lptmp, phdr->p_filesz, &mem_progress, mem_total); if (res != FR_OK) return -1; } /* clean any memory that wasn't loaded */ if (phdr->p_filesz < phdr->p_memsz) { lptmp += phdr->p_filesz; for (j = phdr->p_filesz; j < phdr->p_memsz; j++) { /* clean memory to 0 */ /* TODO: align and write zero ints instead of zero chars */ *lptmp++ = 0; } mem_progress += phdr->p_memsz - phdr->p_filesz; report_load_progress(mem_progress, mem_total); } #ifdef DEBUG printf("loading Segment section No: %lu PhysAdd @ 0x%lX,FileSize=%lu,MemSize=%lu\n", i, phdr->p_paddr, phdr->p_filesz, phdr->p_memsz); #endif } } img->entry = (void *) p_e_entry; return 0; } /* ELF loader */