void init_alarm_boot_properties() { char *alarm_file = "/proc/sys/kernel/boot_reason"; char buf[BUF_SIZE]; if(read_file2(alarm_file, buf, sizeof(buf))) { /* * Setup ro.alarm_boot value to true when it is RTC triggered boot up * For existing PMIC chips, the following mapping applies * for the value of boot_reason: * * 0 -> unknown * 1 -> hard reset * 2 -> sudden momentary power loss (SMPL) * 3 -> real time clock (RTC) * 4 -> DC charger inserted * 5 -> USB charger insertd * 6 -> PON1 pin toggled (for secondary PMICs) * 7 -> CBLPWR_N pin toggled (for external power supply) * 8 -> KPDPWR_N pin toggled (power key pressed) */ if(buf[0] == '3') property_set("ro.alarm_boot", "true"); else property_set("ro.alarm_boot", "false"); } }
void init_msm_properties(unsigned long msm_id, unsigned long msm_ver, char *board_type) { char platform[PROP_VALUE_MAX]; int rc; unsigned long raw_id = -1; UNUSED(msm_id); UNUSED(msm_ver); UNUSED(board_type); /* set product device & name */ property_set("ro.product.device", "cancro"); property_set("ro.product.name", "cancro"); /* set build fingerprint */ property_set("ro.build.description", "cancro-userdebug 5.1.1 LVY48F 5.9.17 test-keys"); property_set("ro.build.fingerprint", "Xiaomi/cancro/cancro:5.1.1/LVY48F/5.9.17:userdebug/test-keys"); /* get raw ID */ rc = read_file2(RAW_ID_PATH, tmp, sizeof(tmp)); if (rc) { raw_id = strtoul(tmp, NULL, 0); } /* MI 3W */ if (raw_id==1978) { property_set("ro.product.model", "MI 3W"); } else /* MI 4W */ if (raw_id==1974) { property_set("ro.product.model", "MI 4W"); property_set("ro.telephony.default_network", "10"); property_set("ro.ril.def.preferred.network", "10"); property_set("telephony.lteOnGSMDevice", "1"); } else /* MI 4LTE-CU */ if (raw_id==1972) { property_set("ro.product.model", "MI 4LTE"); property_set("ro.product.name", "cancro_wc_lte"); property_set("ro.telephony.default_network", "10"); property_set("ro.ril.def.preferred.network", "10"); property_set("telephony.lteOnGSMDevice", "1"); } /* ??? */ else { property_set("ro.product.model", "MI 3/4"); // this should never happen. } }
void init_msm_properties(unsigned long msm_id, unsigned long msm_ver, char *board_type) { char platform[PROP_VALUE_MAX]; int rc; unsigned long raw_id = -1; UNUSED(msm_id); UNUSED(msm_ver); UNUSED(board_type); property_set("ro.product.device", "cancro"); property_set("ro.product.name", "cancro"); /* get raw ID */ rc = read_file2(RAW_ID_PATH, tmp, sizeof(tmp)); if (rc) { raw_id = strtoul(tmp, NULL, 0); } /* MI 3W */ if (raw_id==1978) { property_set("ro.product.model", "MI 3W"); } else /* MI 4W */ if (raw_id==1974) { property_set("ro.product.model", "MI 4W"); } else /* MI 4LTE-CU */ if (raw_id==1972) { property_set("ro.product.model", "MI 4LTE"); property_set("ro.product.name", "cancro_wc_lte"); } /* ??? */ else { property_set("ro.product.model", "MI 3/4"); // this should never happen. } }
void vendor_load_properties() { int rc; /* Collect MSM info */ rc = read_file2(SOC_ID_PATH1, tmp, sizeof(tmp)); if (!rc) { rc = read_file2(SOC_ID_PATH2, tmp, sizeof(tmp)); } if (rc) { msm_id = strtoul(tmp, NULL, 0); } rc = read_file2(SOC_VER_PATH1, tmp, sizeof(tmp)); if (!rc) { rc = read_file2(SOC_VER_PATH2, tmp, sizeof(tmp)); } if (rc) { msm_ver = strtoul(tmp, NULL, 0); } rc = read_file2(BOARD_TYPE_PATH1, tmp, sizeof(tmp)); if (!rc) { rc = read_file2(BOARD_TYPE_PATH2, tmp, sizeof(tmp)); } if (rc) { sscanf(tmp, STRCONV(BUF_SIZE), board_type); } if (!msm_id) { /* abort */ ERROR("MSM SOC detection failed, skipping MSM initialization\n"); return; } ERROR("Detected MSM SOC ID=%lu SOC VER=%lu BOARD TYPE=%s\n", msm_id, msm_ver, board_type); /* Define MSM family properties */ init_msm_properties(msm_id, msm_ver, board_type); init_alarm_boot_properties(); /*check for coredump*/ check_rlim_action(); /* Set Display Node Permissions */ set_display_node_perms(); }
/** * 返回文件大小 */ int read_file(const char *file, char **buffer) { return read_file2((char*) file, buffer); }
int main(int args_num,char *args[]) { //modify output file name char output[1000]; if(args_num==4){ int i=0; for(i=0;i<strlen(args[3]);i++){ if(args[3][i]=='.'){ output[i]='\0'; break; } output[i]=args[3][i]; } } // open files char *file_dir = malloc(sizeof(char) * 1000); FILE* file1; FILE* file2; FILE* file3; FILE* file4; //open file 1 if(args_num>=2){ getcwd(file_dir,1000); strcat(file_dir,"/"); strcat(file_dir,args[1]); file1=fopen(file_dir,"r"); if(!file1){ getcwd(file_dir,1000); strcat(file_dir,"/a.txt"); file1=fopen(file_dir,"r"); } } else{ getcwd(file_dir,1000); strcat(file_dir,"/a.txt"); file1=fopen(file_dir,"r"); } //open file 2 if(args_num>=3){ getcwd(file_dir,1000); strcat(file_dir,"/"); strcat(file_dir,args[2]); file2=fopen(file_dir,"r"); if(!file2){ getcwd(file_dir,1000); strcat(file_dir,"/b.txt"); file2=fopen(file_dir,"r"); } } else{ getcwd(file_dir,1000); strcat(file_dir,"/b.txt"); file2=fopen(file_dir,"r"); } //open file 3 and 4 if(args_num==4){ getcwd(file_dir,1000); strcat(file_dir,"/"); strcat(file_dir,output); strcat(file_dir,"_1"); file3=fopen(file_dir,"w"); getcwd(file_dir,1000); strcat(file_dir,"/"); strcat(file_dir,output); strcat(file_dir,"_2"); file4 = fopen(file_dir,"w"); if(!file3 || !file4){ getcwd(file_dir,1000); strcat(file_dir,"/c_1.out"); file3=fopen(file_dir,"w"); getcwd(file_dir,1000); strcat(file_dir,"/c_2.out"); file4=fopen(file_dir,"w"); } } else{ getcwd(file_dir,1000); strcat(file_dir,"/c_1.out"); file3=fopen(file_dir,"w"); getcwd(file_dir,1000); strcat(file_dir,"/c_2.out"); file4=fopen(file_dir,"w"); } if(!file1 || !file2){ printf("Error in input files.\n"); exit(0); } //read file 1 read_file1(file1); //read file 2 read_file2(file2); // check for multiplication condition if(m1!=n2){ printf("m1 does not equal n2, can not do multiplication.\n"); exit(0); } //allocate matrix3 and matrix4 matrix_allocate(&matrix3,n1,m2); //method 1 int i,j; pthread_t threads[n1][m2]; clock_t start=clock(); int flag1=1,flag2=1; for(i=0;i<n1;i++){ int return_code= pthread_create(&threads[i][0],NULL,method1,(void *)i); if(return_code){ //error occured creating thread flag1=0; break; } } //join threads to continue with method2 int k; for(k=0;k<i;k++){ pthread_join(threads[k][0],NULL); } //output1 if(flag1){ clock_t mthd1=clock(); printf("Method 1\n"); printf("Number of threads = %d\n",n1); printf("Execution time = %lf milliseconds\n",(double) (mthd1-start)/CLOCKS_PER_SEC*1000.0); write_file(file3); } else printf("Error occured in method 1.\n"); //initialize matrix3 for(i=0;i<n1;i++){ for(j=0;j<m2;j++) matrix3[i][j]=0; } //method 2 clock_t start2 = clock(); for(i=0;i<n1;i++){ for(j=0;j<m2;j++){ int return_code= pthread_create(&threads[i][j],NULL,method2,(void *)(i*m2+j)); if(return_code){ flag2=0; break; } } } int w; for(w=0;w<i;w++){ for(k=0;k<j;k++){ pthread_join(threads[w][k],NULL); } } //output 2 if(flag2){ clock_t mthd2=clock(); printf("Method 2\n"); printf("Number of threads = %d\n",n1*m2); printf("Execution time = %lf milliseconds\n",(double)(mthd2-start2)/CLOCKS_PER_SEC*1000.0); write_file(file4); } else printf("Error occured in method 2.\n"); //close files fclose(file1); fclose(file2); fclose(file3); fclose(file4); return 0; }
/* * Setup Display related nodes & permissions. For HDMI, it can be fb1 or fb2 * Loop through the sysfs nodes and determine the HDMI(dtv panel) */ void set_display_node_perms() { char panel_type[] = "dtv panel"; char buf[BUF_SIZE]; int num; for (num=0; num<=2; num++) { snprintf(tmp,sizeof(tmp),"%sfb%d/msm_fb_type", sys_fb_path, num); if(read_file2(tmp, buf, sizeof(buf))) { if(!strncmp(buf, panel_type, strlen(panel_type))) { // Set appropriate permissions for the nodes snprintf(tmp, sizeof(tmp), "%sfb%d/hpd", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); snprintf(tmp, sizeof(tmp), "%sfb%d/res_info", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); snprintf(tmp, sizeof(tmp), "%sfb%d/vendor_name", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); snprintf(tmp, sizeof(tmp), "%sfb%d/product_description", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); snprintf(tmp, sizeof(tmp), "%sfb%d/video_mode", sys_fb_path, num); setPerms(tmp, 0664); snprintf(tmp, sizeof(tmp), "%sfb%d/format_3d", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/s3d_mode", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/hdcp/tp", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/cec/enable", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/cec/logical_addr", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/cec/rd_msg", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/pa", sys_fb_path, num); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d/cec/wr_msg", sys_fb_path, num); setPerms(tmp, 0600); setOwners(tmp, AID_SYSTEM, AID_SYSTEM); snprintf(tmp, sizeof(tmp), "%sfb%d", dev_fb_path, num); symlink(tmp, DEV_GFX_HDMI); break; } } } // Set the permission for idle_time. snprintf(tmp, sizeof(tmp), "%sfb0/idle_time", sys_fb_path); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); // Set write permission for dynamic_fps node. snprintf(tmp, sizeof(tmp), "%sfb0/dynamic_fps", sys_fb_path); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); // Set permissions for dynamic partial update snprintf(tmp, sizeof(tmp), "%sfb0/dyn_pu", sys_fb_path); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); snprintf(tmp, sizeof(tmp), "%sfb0/modes", sys_fb_path); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); snprintf(tmp, sizeof(tmp), "%sfb0/mode", sys_fb_path); setPerms(tmp, 0664); setOwners(tmp, AID_SYSTEM, AID_GRAPHICS); }