* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" // nrf51822-mkit target information const target_cfg_t target_device = { .board_id = "1120", .secret = "xxxxxxxx", .sector_size = 1024, // Assume memory is regions are same size (smallest). Flash algo should ignore requests // when variable sized sectors exist // .sector_cnt = ((.flash_end - .flash_start) / .sector_size); .sector_cnt = (KB(256)/1024), .flash_start = 0, .flash_end = KB(256), .ram_start = 0x20000000, .ram_end = 0x20008000, .disc_size = MB(8) };
* * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" // The file flash_blob.c must only be included in target.c #include "flash_blob.c" // target information target_cfg_t target_device = { .sectors_info = sectors_info, .sector_info_length = (sizeof(sectors_info))/(sizeof(sector_info_t)), .flash_regions[0].start = 0x08000000, .flash_regions[0].end = 0x08000000 + KB(512), .flash_regions[0].flags = kRegionIsDefault, .flash_regions[0].flash_algo = (program_target_t *) &flash, .ram_regions[0].start = 0x20000000, .ram_regions[0].end = 0x20020000, };
void APISelect(void *data) { OPS("### @ API : Accept Success - Thread[%d]", pthread_self()); // struct data qqclient* qq = ((void**)data)[0]; qq->api_select_count ++ ; apiclient* apis = ((void**)data)[1]; int client = apis->sock; pthread_mutex_unlock(&apis->mxsock); // Request char *buffer; NEW(buffer, REQUEST_BUFFER); // Select 模型读取请求 fd_set fdRead; struct timeval fdRTV = {1, 0}; FD_ZERO(&fdRead); FD_SET(client, &fdRead); switch ( select(client, &fdRead, NULL, NULL, &fdRTV) ) { default: if ( FD_ISSET(client, &fdRead) ) { recv(client, buffer, REQUEST_BUFFER, 0); } } if ( strlen(buffer) < 9 ) { OPS("### @ API : Request Unavailable."); DEL(buffer); return; } // Request Test DBG("##### Request Begin #####\n%s\n##### Request End #####\n", buffer); char *http; NEW(http, 16); mid_value(buffer, "GET ", " HTTP/1.1", http, 16); if ( strstr(http, "/v?") >0 ) { // 验证码读取 char *uid, *file; NEW(uid, 18); NEW(file, 32); if ( strstr(http, "&") > 0 ) { mid_value(http, "/v?", "&", uid, 18); } else { mid_value(http, "/v?", NULL, uid, 18); } sprintf(file, "./verify/%s.png", uid); http_send_file(client, file); DEL(uid); DEL(file); DEL(http); DEL(buffer); return; } else if ( strstr(http, "/send?") > 0 ) { // 发送自定义信息 char *msg; NEW(msg, REQUEST_BUFFER); mid_value(buffer, "GET /send?", " HTTP/1.1", msg, REQUEST_BUFFER); api_callback_build("http.send", msg); DEL(msg); http_send(client, "Message Sends OK."); DEL(http); DEL(buffer); return; } else if ( strlen(http) > 0 ) { http_send(client, "QQRobot API Server."); DEL(http); DEL(buffer); return; } DEL(http); char *api; NEW(api, API_BUFFER); mid_value(buffer, "API ", " MOYO/1.1", api, API_BUFFER); if (strlen(api) == 0) { http_send(client, "API IS EMPTY"); DEL(api); DEL(buffer); return; } // API Commands char *response; NEW(response, RESPONSE_BUFFER); // Check SecKey char *seckey; NEW(seckey, 255); mid_value(buffer, "<seckey>", "</seckey>", seckey, 255); if ( strcmp(apis->APISeckey, seckey)!=0 ) { strcat(response, "ACCESS DENIED"); OPS("### @ API : Denied of : %s", api); DEL(seckey); goto API_RESPONSE; } DEL(seckey); // API Runs OPS("### @ API : Command of : %s ...Runs ...", api); // ##### API of login ##### if ( stricmp(api, "login.create")==0 ) { char *uid, *password; NEW(uid, 10); NEW(password, 32); mid_value(buffer, "<uid>", "</uid>", uid, 10); mid_value(buffer, "<password>", "</password>", password, 32); strcat(response, myqq_login(atoi(uid), password)); //printf("Done of %s.\n", api); DEL(uid); DEL(password); } else if ( stricmp(api, "login.destroy")==0 ) { strcat(response, myqq_logout()); //printf("Done of %s.\n", api); } else if ( stricmp(api, "login.verify")==0 ) { char *vcode; NEW(vcode, 4); mid_value(buffer, "<verify>", "</verify>", vcode, 4); if ( qq->process == P_VERIFYING ) { qqclient_verify(qq, vcode); OPS("### @ API : [Input] Verify Code : %s", vcode); strcat(response, myqq_resume_login()); } else { strcat(response, "DONT NEED"); } //printf("Done of %s.\n", api); DEL(vcode); } else if ( stricmp(api, "login.check")==0 ) { strcat(response, myqq_check_login(qq)); //printf("Done of %s.\n", api); } // ##### API of buddy ##### else if ( stricmp(api, "buddy.name")==0 ) { char *uid; NEW(uid, 10); mid_value(buffer, "<uid>", "</uid>", uid, 10); strcat(response, myqq_get_buddy_name(qq, atoi(uid))); //printf("Done of %s.\n", api); DEL(uid); } else if ( stricmp(api, "buddy.send")==0 ) { char *uid, *message; NEW(uid, 10); NEW(message, SEND_MESSAGE_SIZE); mid_value(buffer, "<uid>", "</uid>", uid, 10); mid_value(buffer, "<message>", "</message>", message, SEND_MESSAGE_SIZE); if ( myqq_send_im_to_buddy(qq, atoi(uid), message, 0) ) { strcat(response, "SEND FAILED"); } else { strcat(response, "SEND SUCCESS"); } //printf("Done of %s.\n", api); DEL(uid); DEL(message); } else if ( stricmp(api, "buddy.info")==0 ) { char *uid; NEW(uid, 10); mid_value(buffer, "<uid>", "</uid>", uid, 10); char *info; NEW(info, KB(4)); myqq_get_buddy_info(qq, atoi(uid), info, KB(4)); strcat(response, info); //printf("Done of %s.\n", api); DEL(uid); DEL(info); } else if ( stricmp(api, "buddy.list")==0 ) { char *online; NEW(online, 3); mid_value(buffer, "<online>", "</online>", online, 3); char *info; NEW(info, BUDDY_BUF_SIZE); if ( stricmp(online, "yes")==0 ) { myqq_get_buddy_list(qq, info, BUDDY_BUF_SIZE, 1); } else { myqq_get_buddy_list(qq, info, BUDDY_BUF_SIZE, 0); } strcat(response, info); //printf("Done of %s.\n", api); DEL(online); DEL(info); } // ##### API of qun ##### else if ( stricmp(api, "qun.name")==0 ) { char *gid; NEW(gid, 10); mid_value(buffer, "<gid>", "</gid>", gid, 10); strcat(response, myqq_get_qun_name(qq, atoi(gid))); //printf("Done of %s.\n", api); DEL(gid); } else if ( stricmp(api, "qun.send")==0 ) { char *gid, *message; NEW(gid, 10); NEW(message, SEND_MESSAGE_SIZE); mid_value(buffer, "<gid>", "</gid>", gid, 10); mid_value(buffer, "<message>", "</message>", message, SEND_MESSAGE_SIZE); if ( myqq_send_im_to_qun(qq, atoi(gid), message, 0) ) { strcat(response, "SEND FAILED"); } else { strcat(response, "SEND SUCCESS"); } //printf("Done of %s.\n", api); DEL(gid); DEL(message); } else if ( stricmp(api, "qun.buddy.name")==0 ) { char *gid, *uid; NEW(gid, 10); NEW(uid, 10); mid_value(buffer, "<gid>", "</gid>", gid, 10); mid_value(buffer, "<uid>", "</uid>", uid, 10); strcat(response, myqq_get_qun_member_name(qq, atoi(gid), atoi(uid))); //printf("Done of %s.\n", api); DEL(gid); DEL(uid); } else if ( stricmp(api, "qun.info")==0 ) { char *gid; NEW(gid, 10); mid_value(buffer, "<gid>", "</gid>", gid, 10); char *info; NEW(info, KB(4)); myqq_get_qun_info(qq, atoi(gid), info, KB(4)); strcat(response, info); //printf("Done of %s.\n", api); DEL(gid); DEL(info); } else if ( stricmp(api, "qun.list")==0 ) { char *info; NEW(info, QUN_BUF_SIZE); myqq_get_qun_list(qq, info, QUN_BUF_SIZE); strcat(response, info); //printf("Done of %s.\n", api); DEL(info); } else if ( stricmp(api, "qun.buddy.list")==0 ) { char *gid, *online; NEW(gid, 10); NEW(online, 3); mid_value(buffer, "<gid>", "</gid>", gid, 10); mid_value(buffer, "<online>", "</online>", online, 3); char *info; NEW(info, BUDDY_BUF_SIZE); if ( stricmp(online, "yes")==0 ) { myqq_get_qun_member_list(qq, atoi(gid), info, BUDDY_BUF_SIZE, 1); } else { myqq_get_qun_member_list(qq, atoi(gid), info, BUDDY_BUF_SIZE, 0); } strcat(response, info); //printf("Done of %s.\n", api); DEL(gid); DEL(online); DEL(info); } // ##### API of me ##### else if ( stricmp(api, "me.sleep")==0 ) { char *power; NEW(power, 3); mid_value(buffer, "<power>", "</power>", power, 3); if ( strcmp(power, "on")==0 ) { apis->APISleep = 1; } else { apis->APISleep = 0; } strcat(response, "SWITCH SUCCESS"); //printf("Done of %s.\n", api); DEL(power); } else if ( stricmp(api, "me.list.update")==0 ) { qun_update_all(qq); buddy_update_list(qq); group_update_list(qq); if ( qqclient_wait(qq, 10)<0 ) { strcat(response, "UPDATE FAILED"); } else { strcat(response, "UPDATE SUCCESS"); } //printf("Done of %s.\n", api); } else if ( stricmp(api, "me.autoreply")==0 ) { char *power; NEW(power, 3); mid_value(buffer, "<power>", "</power>", power, 3); if ( strcmp(power, "on")==0 ) { myqq_auto_reply(1); } else { myqq_auto_reply(0); } strcat(response, "SWITCH SUCCESS"); //printf("Done of %s.\n", api); DEL(power); } else if ( stricmp(api, "me.status.update")==0 ) { char *status; NEW(status, 6); mid_value(buffer, "<status>", "</status>", status, 6); if( strcmp( status, "away") == 0 ) qqclient_change_status( qq, QQ_AWAY ); else if( strcmp( status, "online") == 0 ) qqclient_change_status( qq, QQ_ONLINE ); else if( strcmp( status, "hidden") == 0 ) qqclient_change_status( qq, QQ_HIDDEN ); else if( strcmp( status, "killme") == 0 ) qqclient_change_status( qq, QQ_KILLME ); else if( strcmp( status, "busy") == 0 ) qqclient_change_status( qq, QQ_BUSY ); strcat(response, "UPDATE SUCCESS"); //printf("Done of %s.\n", api); DEL(status); } else if ( stricmp(api, "me.buddy.add")==0 ) { char *uid, *message; NEW(uid, 10); NEW(message, 50); mid_value(buffer, "<uid>", "</uid>", uid, 10); mid_value(buffer, "<message>", "</message>", message, 50); qqclient_add(qq, atoi(uid), message); strcat(response, "ADD SUCCESS"); //printf("Done of %s.\n", api); DEL(uid); DEL(message); } else if ( stricmp(api, "me.buddy.del")==0 ) { char *uid; NEW(uid, 10); mid_value(buffer, "<uid>", "</uid>", uid, 10); qqclient_del(qq, atoi(uid)); strcat(response, "DELETE SUCCESS"); //printf("Done of %s.\n", api); DEL(uid); } else { strcat(response, "UNKNOWN API COMMAND"); OPS("### @ API : Command Unknown : %s", api); } API_RESPONSE: // Send send(client, response, strlen(response), 0); // print OPS("### @ API : Command of : %s ...Done.", api); // Response Test DBG("##### Response Begin #####\n%s\n##### Response End #####\n", response); // Close shutdown(client, SD_BOTH); closesocket(client); // Clear DEL(response); //DEL(client); pthread_detach(pthread_self()); }
void prot_user_request_token_reply( struct qqclient* qq, qqpacket* p ) { bytebuffer *buf = p->buf; uchar cmd = get_byte( buf ); get_word( buf ); //0006 uchar verify = get_byte( buf ); if( verify ){ char *url, *data, *session; int datalen = KB(4); DBG("need verifying..."); if( buf->pos == buf->len ) { puts("Verifying code is incorrect!"); return; //verify code wrong. } int len, ret; len = get_word( buf ); if( len >= 128 ){ DBG("url is too long."); return; } NEW( data, datalen ); NEW( url, 128 ); NEW( session, 128 ); get_data( buf, (uchar*)url, len ); ret = http_request( &qq->http_sock, url, session, data, &datalen ); if( ret == 0 ){ char path[PATH_LEN]; sprintf( path, "%s/%u.jpg", qq->verify_dir, qq->number ); FILE *fp; fp = fopen( path, "wb" ); DBG("got png at %s", path ); if( fp ){ fwrite( data, datalen, 1, fp ); fclose( fp ); } strncpy( qq->data.qqsession, session, 127 ); qqclient_set_process( qq, P_VERIFYING ); puts("You need to input the verifying code."); }else{ DBG("http_request failed. ret=%d", ret ); } DEL( data ); DEL( url ); DEL( session ); }else{ get_token( buf, &qq->data.user_token ); qq->data.user_token_time = time(NULL); DBG("got token"); qqbuddy *b = buddy_get( qq, qq->data.operating_number, 0 ); if( b ){ switch( qq->data.operation ){ case OP_ADDBUDDY: if( b->verify_flag == VF_VERIFY ){ prot_buddy_verify_addbuddy( qq, 02, qq->data.operating_number ); }else if( b->verify_flag == VF_OK ){ prot_buddy_verify_addbuddy( qq, 00, qq->data.operating_number ); } break; case OP_DELBUDDY: prot_buddy_del_buddy( qq, qq->data.operating_number ); break; } } } cmd = 0; }
int ft5406_firmware_write_last_data(int fd, const void *buff, size_t size) { struct ft5406_firmware_data_package pkg = { .size = size, .data = (void *) buff }; return ioctl(fd, FT5406_IOCTL_SINGLE_WRITE, &pkg); } int ft5406_firmware_upgrade_fd(int dev_fd, const char *cfgpath) { int ret; char buff[KB(50)] ; ssize_t writelen, bufflen; u8 checksum[2]; bufflen = ft5406_read_firmware_data3(cfgpath, buff, sizeof(buff)) - 2; if (bufflen < 6) { pr_red_info("ft5406_parse_app_file"); return bufflen; } println("bufflen = %" PRINT_FORMAT_SSIZE, bufflen); ret = ft5406_upgrade_enter(dev_fd); if (ret < 0) { pr_red_info("ft5406_upgrade_start"); return ret; } ret = ft5406_erase_app(dev_fd); if (ret < 0) { pr_red_info("ft5406_erase_app"); return ret; } writelen = write(dev_fd, buff, bufflen - 6); if (writelen < 0) { pr_red_info("write"); return writelen; } writelen = ft5406_firmware_write_last_data(dev_fd, buff + writelen, 6); if (writelen < 0) { pr_red_info("ft5406_firmware_write_last_data"); return writelen; } ret = ft5406_read_checksum(dev_fd, checksum); if (ret < 0) { pr_red_info("ft5406_read_checksum"); return ret; } checksum[1] = ft5406_calculate_checksum(buff, bufflen); pr_bold_info("Source checksum = 0x%02x, Dest checksum = 0x%02x", checksum[1], checksum[0]); if (checksum[0] != checksum[1]) { pr_red_info("Checksum do't match"); return -EFAULT; } return ft5406_upgrade_finish(dev_fd); }
int main (int argc,char *argv[]) { const char *progname,*filename = NULL,*device = NULL; int i,flags = FLAG_NONE; size_t result,size,written; struct mtd_info_user mtd; struct erase_info_user erase; struct stat filestat; unsigned char src[BUFSIZE],dest[BUFSIZE]; (progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]); /********************* * parse cmd-line *****************/ for (;;) { int option_index = 0; static const char *short_options = "hvr"; static const struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, {"reboot", no_argument, 0, 'r'}, {0, 0, 0, 0}, }; int c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == EOF) { break; } switch (c) { case 'h': DEBUG("Got FLAG_HELP\n"); showusage (progname,false); break; case 'v': flags |= FLAG_VERBOSE; DEBUG("Got FLAG_VERBOSE\n"); break; case 'r': flags |= FLAG_REBOOT; DEBUG("Got FLAG_REBOOT\n"); break; default: DEBUG("Unknown parameter: %s\n",argv[option_index]); showusage (progname,true); } } if (optind+2 == argc) { flags |= FLAG_FILENAME; filename = argv[optind]; DEBUG("Got filename: %s\n",filename); flags |= FLAG_DEVICE; device = argv[optind+1]; DEBUG("Got device: %s\n",device); } if (progname == NULL || device == NULL) showusage (progname,true); atexit (cleanup); /* get some info about the flash device */ dev_fd = safe_open (device,O_SYNC | O_RDWR); if (ioctl (dev_fd,MEMGETINFO,&mtd) < 0) { DEBUG("ioctl(): %m\n"); log_printf (LOG_ERROR,"This doesn't seem to be a valid MTD flash device!\n"); exit (EXIT_FAILURE); } /* get some info about the file we want to copy */ fil_fd = safe_open (filename,O_RDONLY); if (fstat (fil_fd,&filestat) < 0) { log_printf (LOG_ERROR,"While trying to get the file status of %s: %m\n",filename); exit (EXIT_FAILURE); } /* does it fit into the device/partition? */ if (filestat.st_size > mtd.size) { log_printf (LOG_ERROR,"%s won't fit into %s!\n",filename,device); exit (EXIT_FAILURE); } /***************************************************** * erase enough blocks so that we can write the file * *****************************************************/ #warning "Check for smaller erase regions" erase.start = 0; erase.length = filestat.st_size & ~(mtd.erasesize - 1); if (filestat.st_size % mtd.erasesize) erase.length += mtd.erasesize; if (flags & FLAG_VERBOSE) { /* if the user wants verbose output, erase 1 block at a time and show him/her what's going on */ int blocks = erase.length / mtd.erasesize; erase.length = mtd.erasesize; log_printf (LOG_NORMAL,"Erasing blocks: 0/%d (0%%)",blocks); for (i = 1; i <= blocks; i++) { log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (%d%%)",i,blocks,PERCENTAGE (i,blocks)); if (ioctl (dev_fd,MEMERASE,&erase) < 0) { log_printf (LOG_NORMAL,"\n"); log_printf (LOG_ERROR, "While erasing blocks 0x%.8x-0x%.8x on %s: %m\n", (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device); exit (EXIT_FAILURE); } erase.start += mtd.erasesize; } log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (100%%)\n",blocks,blocks); } else { /* if not, erase the whole chunk in one shot */ if (ioctl (dev_fd,MEMERASE,&erase) < 0) { log_printf (LOG_ERROR, "While erasing blocks from 0x%.8x-0x%.8x on %s: %m\n", (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device); exit (EXIT_FAILURE); } } DEBUG("Erased %u / %luk bytes\n",erase.length,filestat.st_size); /********************************** * write the entire file to flash * **********************************/ if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"Writing data: 0k/%luk (0%%)",KB (filestat.st_size)); size = filestat.st_size; i = BUFSIZE; written = 0; while (size) { if (size < BUFSIZE) i = size; if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"\rWriting data: %dk/%luk (%lu%%)", KB (written + i), KB (filestat.st_size), PERCENTAGE (written + i,filestat.st_size)); /* read from filename */ safe_read (fil_fd,filename,src,i,flags & FLAG_VERBOSE); /* write to device */ result = write (dev_fd,src,i); if (i != result) { if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"\n"); if (result < 0) { log_printf (LOG_ERROR, "While writing data to 0x%.8x-0x%.8x on %s: %m\n", written,written + i,device); exit (EXIT_FAILURE); } log_printf (LOG_ERROR, "Short write count returned while writing to x%.8x-0x%.8x on %s: %d/%lu bytes written to flash\n", written,written + i,device,written + result,filestat.st_size); exit (EXIT_FAILURE); } written += i; size -= i; } if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL, "\rWriting data: %luk/%luk (100%%)\n", KB (filestat.st_size), KB (filestat.st_size)); DEBUG("Wrote %d / %luk bytes\n",written,filestat.st_size); /********************************** * verify that flash == file data * **********************************/ safe_rewind (fil_fd,filename); safe_rewind (dev_fd,device); size = filestat.st_size; i = BUFSIZE; written = 0; if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"Verifying data: 0k/%luk (0%%)",KB (filestat.st_size)); while (size) { if (size < BUFSIZE) i = size; if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL, "\rVerifying data: %dk/%luk (%lu%%)", KB (written + i), KB (filestat.st_size), PERCENTAGE (written + i,filestat.st_size)); /* read from filename */ safe_read (fil_fd,filename,src,i,flags & FLAG_VERBOSE); /* read from device */ safe_read (dev_fd,device,dest,i,flags & FLAG_VERBOSE); /* compare buffers */ if (memcmp (src,dest,i)) { log_printf (LOG_ERROR, "File does not seem to match flash data. First mismatch at 0x%.8x-0x%.8x\n", written,written + i); exit (EXIT_FAILURE); } written += i; size -= i; } if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL, "\rVerifying data: %luk/%luk (100%%)\n", KB (filestat.st_size), KB (filestat.st_size)); DEBUG("Verified %d / %luk bytes\n",written,filestat.st_size); if (flags & FLAG_REBOOT) { log_printf (LOG_NORMAL,"rebooting...\n"); DEBUG("Rebooting now\n"); sleep(1); reboot(RB_AUTOBOOT); } exit (EXIT_SUCCESS); }
/* Tiled memory is good... really, really good... * * Need to make it less likely that we miss out on this - probably * need to move the frontbuffer away from the 'guarenteed' alignment * of the first memory segment, or perhaps allocate a discontigous * framebuffer to get more alignment 'sweet spots'. */ void I810SetTiledMemory(ScrnInfoPtr pScrn, int nr, unsigned int start, unsigned int pitch, unsigned int size) { I810Ptr pI810 = I810PTR(pScrn); I810RegPtr i810Reg = &pI810->ModeReg; uint32_t val; uint32_t fence_mask = 0; if (nr < 0 || nr > 7) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s - fence %d out of range\n", "I810SetTiledMemory", nr); return; } i810Reg->Fence[nr] = 0; fence_mask = ~FENCE_START_MASK; if (start & fence_mask) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s %d: start (%x) is not 512k aligned\n", "I810SetTiledMemory", nr, start); return; } if (start % size) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s %d: start (%x) is not size (%x) aligned\n", "I810SetTiledMemory", nr, start, size); return; } if (pitch & 127) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s %d: pitch (%x) not a multiple of 128 bytes\n", "I810SetTiledMemory", nr, pitch); return; } val = (start | FENCE_X_MAJOR | FENCE_VALID); switch (size) { case KB(512): val |= FENCE_SIZE_512K; break; case MB(1): val |= FENCE_SIZE_1M; break; case MB(2): val |= FENCE_SIZE_2M; break; case MB(4): val |= FENCE_SIZE_4M; break; case MB(8): val |= FENCE_SIZE_8M; break; case MB(16): val |= FENCE_SIZE_16M; break; case MB(32): val |= FENCE_SIZE_32M; break; default: xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s %d: illegal size (0x%x)\n", "I810SetTiledMemory", nr, size); return; } switch (pitch / 128) { case 1: val |= FENCE_PITCH_1; break; case 2: val |= FENCE_PITCH_2; break; case 4: val |= FENCE_PITCH_4; break; case 8: val |= FENCE_PITCH_8; break; case 16: val |= FENCE_PITCH_16; break; case 32: val |= FENCE_PITCH_32; break; default: xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%s %d: illegal size (0x%x)\n", "I810SetTiledMemory", nr, size); return; } i810Reg->Fence[nr] = val; }
/*********************************************************************** * create prx heap from memory container 0("game") ***********************************************************************/ void create_heap(int32_t size) { mc_app = vsh_memory_container_by_id(0); sys_memory_allocate_from_container(KB(size * 64), mc_app, SYS_MEMORY_PAGE_SIZE_64K, &heap_mem); prx_heap = (uint32_t)heap_mem; }
static dma_addr_t i915_stolen_to_dma(struct drm_i915_private *dev_priv) { struct pci_dev *pdev = dev_priv->drm.pdev; struct i915_ggtt *ggtt = &dev_priv->ggtt; struct resource *r; dma_addr_t base; /* Almost universally we can find the Graphics Base of Stolen Memory * at register BSM (0x5c) in the igfx configuration space. On a few * (desktop) machines this is also mirrored in the bridge device at * different locations, or in the MCHBAR. * * On 865 we just check the TOUD register. * * On 830/845/85x the stolen memory base isn't available in any * register. We need to calculate it as TOM-TSEG_SIZE-stolen_size. * */ base = 0; if (INTEL_GEN(dev_priv) >= 3) { u32 bsm; pci_read_config_dword(pdev, INTEL_BSM, &bsm); base = bsm & INTEL_BSM_MASK; } else if (IS_I865G(dev_priv)) { u32 tseg_size = 0; u16 toud = 0; u8 tmp; pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0), I845_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) { switch (tmp & I845_TSEG_SIZE_MASK) { case I845_TSEG_SIZE_512K: tseg_size = KB(512); break; case I845_TSEG_SIZE_1M: tseg_size = MB(1); break; } } pci_bus_read_config_word(pdev->bus, PCI_DEVFN(0, 0), I865_TOUD, &toud); base = (toud << 16) + tseg_size; } else if (IS_I85X(dev_priv)) { u32 tseg_size = 0; u32 tom; u8 tmp; pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0), I85X_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) tseg_size = MB(1); pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 1), I85X_DRB3, &tmp); tom = tmp * MB(32); base = tom - tseg_size - ggtt->stolen_size; } else if (IS_I845G(dev_priv)) { u32 tseg_size = 0; u32 tom; u8 tmp; pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0), I845_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) { switch (tmp & I845_TSEG_SIZE_MASK) { case I845_TSEG_SIZE_512K: tseg_size = KB(512); break; case I845_TSEG_SIZE_1M: tseg_size = MB(1); break; } } pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0), I830_DRB3, &tmp); tom = tmp * MB(32); base = tom - tseg_size - ggtt->stolen_size; } else if (IS_I830(dev_priv)) { u32 tseg_size = 0; u32 tom; u8 tmp; pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0), I830_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) { if (tmp & I830_TSEG_SIZE_1M) tseg_size = MB(1); else tseg_size = KB(512); } pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0), I830_DRB3, &tmp); tom = tmp * MB(32); base = tom - tseg_size - ggtt->stolen_size; } if (base == 0 || add_overflows(base, ggtt->stolen_size)) return 0; /* make sure we don't clobber the GTT if it's within stolen memory */ if (INTEL_GEN(dev_priv) <= 4 && !IS_G33(dev_priv) && !IS_PINEVIEW(dev_priv) && !IS_G4X(dev_priv)) { struct { dma_addr_t start, end; } stolen[2] = { { .start = base, .end = base + ggtt->stolen_size, }, { .start = base, .end = base + ggtt->stolen_size, }, };
* SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" // The file flash_blob.c must only be included in target.c #include "flash_blob.c" // target information target_cfg_t target_device = { .sector_size = 1024, .sector_cnt = (KB(96) / 1024), .flash_start = 0, .flash_end = KB(128), .ram_start = 0x1FFFA000, .ram_end = 0x20012000, .flash_algo = (program_target_t *) &flash, };
unsigned int intel_compute_size(struct intel_screen_private *intel, int w, int h, int bpp, unsigned usage, uint32_t *tiling, int *stride) { int pitch, size; if (*tiling != I915_TILING_NONE) { /* First check whether tiling is necessary. */ pitch = (w * bpp + 7) / 8; pitch = ALIGN(pitch, 64); size = pitch * ALIGN (h, 2); if (INTEL_INFO(intel)->gen < 040) { /* Gen 2/3 has a maximum stride for tiling of * 8192 bytes. */ if (pitch > KB(8)) *tiling = I915_TILING_NONE; /* Narrower than half a tile? */ if (pitch < 256) *tiling = I915_TILING_NONE; /* Older hardware requires fences to be pot size * aligned with a minimum of 1 MiB, so causes * massive overallocation for small textures. */ if (size < 1024*1024/2 && !intel->has_relaxed_fencing) *tiling = I915_TILING_NONE; } else if (!(usage & INTEL_CREATE_PIXMAP_DRI2) && size <= 4096) { /* Disable tiling beneath a page size, we will not see * any benefit from reducing TLB misses and instead * just incur extra cost when we require a fence. */ *tiling = I915_TILING_NONE; } } pitch = (w * bpp + 7) / 8; if (!(usage & INTEL_CREATE_PIXMAP_DRI2) && pitch <= 256) *tiling = I915_TILING_NONE; if (*tiling != I915_TILING_NONE) { int aligned_h, tile_height; if (IS_GEN2(intel)) tile_height = 16; else if (*tiling == I915_TILING_X) tile_height = 8; else tile_height = 32; aligned_h = ALIGN(h, tile_height); *stride = intel_get_fence_pitch(intel, ALIGN(pitch, 512), *tiling); /* Round the object up to the size of the fence it will live in * if necessary. We could potentially make the kernel allocate * a larger aperture space and just bind the subset of pages in, * but this is easier and also keeps us out of trouble (as much) * with drm_intel_bufmgr_check_aperture(). */ size = intel_get_fence_size(intel, *stride * aligned_h); if (size > intel->max_tiling_size) *tiling = I915_TILING_NONE; } if (*tiling == I915_TILING_NONE) { /* We only require a 64 byte alignment for scanouts, but * a 256 byte alignment for sharing with PRIME. */ *stride = ALIGN(pitch, 256); /* Round the height up so that the GPU's access to a 2x2 aligned * subspan doesn't address an invalid page offset beyond the * end of the GTT. */ size = *stride * ALIGN(h, 2); } return size; }
* SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" // The file flash_blob.c must only be included in target.c #include "flash_blob.c" // target information target_cfg_t target_device = { .sector_size = KB(4), .sector_cnt = (MB(8) / KB(4)), .flash_start = 0, .flash_end = MB(8), .ram_start = 0x20000000, .ram_end = 0x20300000, .flash_algo = (program_target_t *) &flash, };
static int ext4_fill_super(struct super_block *sb) { int ret; int group_count; unsigned int bpg; // blocks per groups char buff[KB(1)]; struct ext4_sb_info *e4_sbi; struct ext4_super_block *e4_sb; struct ext4_group_desc *gdt; struct bio *bio; size_t off; bio = bio_alloc(); if (!bio) return -ENOMEM; bio->bdev = sb->s_bdev; bio->sect = 1024 / SECT_SIZE; bio->size = sizeof(buff); bio->data = buff; submit_bio(READ, bio); // TODO: check flags here bio_free(bio); if (ext4_check_fstype(buff, sizeof(struct ext4_super_block)) == false) { GEN_DBG("Invalid EXT4 magic number!\n"); // ((struct ext4_super_block *)buff)->s_magic); ret = -EINVAL; goto L1; } e4_sbi = zalloc(sizeof(*e4_sbi)); if (!e4_sbi) { ret = -ENOMEM; goto L1; } #if 1 // fixme e4_sb = &e4_sbi->e4_sb; memcpy(e4_sb, buff, sizeof(*e4_sb)); #endif sb->s_fs_info = e4_sbi; sb->s_blocksize = 1024 << e4_sb->s_log_block_size; bpg = e4_sb->s_blocks_per_group; group_count = (e4_sb->s_blocks_count_lo + bpg - 1) / bpg; DPRINT("super block information:\n" "label = \"%s\", inode size = %d, block size = %d\n", e4_sb->s_volume_name[0] ? e4_sb->s_volume_name : "<N/A>", e4_sb->s_inode_size, sb->s_blocksize); gdt = malloc(group_count * sizeof(struct ext4_group_desc)); if (NULL == gdt) { ret = -ENOMEM; goto L2; } e4_sbi->gdt = gdt; off = (e4_sb->s_first_data_block + 1) * sb->s_blocksize; __ext4_read_buff(sb, off, gdt, group_count * sizeof(struct ext4_group_desc)); DPRINT("group descrition:\n" "block groups = %d, free blocks = %d, free inodes = %d\n", group_count, gdt->bg_free_blocks_count_lo, gdt->bg_free_inodes_count_lo); return 0; L2: free(e4_sbi); L1: return ret; }
* * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" #include "daplink_addr.h" #include "compiler.h" #include "target_board.h" #include "target_family.h" // Warning - changing the interface start will break backwards compatibility COMPILER_ASSERT(DAPLINK_ROM_IF_START == KB(32)); COMPILER_ASSERT(DAPLINK_ROM_IF_SIZE == KB(95)); // k20dx128 target information target_cfg_t target_device = { .sector_size = 1024, // Assume memory is regions are same size. Flash algo should ignore requests // when variable sized sectors exist // .sector_cnt = ((.flash_end - .flash_start) / .sector_size); .sector_cnt = (DAPLINK_ROM_IF_SIZE / 1024), .flash_start = DAPLINK_ROM_IF_START, .flash_end = DAPLINK_ROM_IF_START + DAPLINK_ROM_IF_SIZE, .ram_start = 0x1fffe000, .ram_end = 0x20002000, // .flash_algo not needed for bootloader };
* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" // atsam3u2c target information const target_cfg_t target_device = { .board_id = "0000", .secret = "xxxxxxxx", .sector_size = 0x1000, // Assume memory is regions are same size. Flash algo should ignore requests // when variable sized sectors exist // .sector_cnt = ((.flash_end - .flash_start) / .sector_size); .sector_cnt = ((KB(128)-KB(32))/0x1000), .flash_start = 0x00080000 + KB(32), .flash_end = 0x00080000 + KB(128), .ram_start = 0x2007C000, .ram_end = 0x20084000 };
.flash_regions[0].start = 0x00014000, #else .flash_regions[0].start = 0x00000000, #endif .flash_regions[0].end = MB(1), .flash_regions[0].flags = kRegionIsDefault, .flash_regions[0].flash_algo = (program_target_t *) &flash_k64, .ram_regions[0].start = 0x20000000, .ram_regions[0].end = 0x20030000, }; target_cfg_t target_device_kw40 = { .sectors_info = sectors_info_kw40, .sector_info_length = (sizeof(sectors_info_kw40))/(sizeof(sectors_info_kw40)), .flash_regions[0].start = 0, .flash_regions[0].end = KB(160), .flash_regions[0].flags = kRegionIsDefault, .flash_regions[0].flash_algo = (program_target_t *) &flash_kw40, .ram_regions[0].start = 0x1FFFF000, .ram_regions[0].end = 0x20004000, }; target_cfg_t target_device_kw41 = { .sectors_info = sectors_info_kw41, .sector_info_length = (sizeof(sectors_info_kw41))/(sizeof(sectors_info_kw41)), .flash_regions[0].start = 0x4000, .flash_regions[0].end = KB(512), .flash_regions[0].flags = kRegionIsDefault, .flash_regions[0].flash_algo = (program_target_t *) &flash_kw41, .ram_regions[0].start = 0x1FFF8000, .ram_regions[0].end = 0x20018000,
* * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "target_config.h" // The file flash_blob.c must only be included in target.c #include "flash_blob.c" // target information target_cfg_t target_device = { .sector_size = KB(4), .sector_cnt = 2048, .flash_start = 0x60000000, .flash_end = 0x60000000 + MB(64), .ram_start = 0x20000000, .ram_end = 0x20000000 + MB(64), .flash_algo = (program_target_t *) &flash, };
static unsigned long i915_stolen_to_physical(struct drm_device *dev) { struct drm_i915_private *dev_priv = to_i915(dev); struct i915_ggtt *ggtt = &dev_priv->ggtt; struct resource *r; u32 base; /* Almost universally we can find the Graphics Base of Stolen Memory * at register BSM (0x5c) in the igfx configuration space. On a few * (desktop) machines this is also mirrored in the bridge device at * different locations, or in the MCHBAR. * * On 865 we just check the TOUD register. * * On 830/845/85x the stolen memory base isn't available in any * register. We need to calculate it as TOM-TSEG_SIZE-stolen_size. * */ base = 0; if (INTEL_INFO(dev)->gen >= 3) { u32 bsm; pci_read_config_dword(dev->pdev, BSM, &bsm); base = bsm & BSM_MASK; } else if (IS_I865G(dev)) { u16 toud = 0; /* * FIXME is the graphics stolen memory region * always at TOUD? Ie. is it always the last * one to be allocated by the BIOS? */ pci_bus_read_config_word(dev->pdev->bus, PCI_DEVFN(0, 0), I865_TOUD, &toud); base = toud << 16; } else if (IS_I85X(dev)) { u32 tseg_size = 0; u32 tom; u8 tmp; pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0), I85X_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) tseg_size = MB(1); pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 1), I85X_DRB3, &tmp); tom = tmp * MB(32); base = tom - tseg_size - ggtt->stolen_size; } else if (IS_845G(dev)) { u32 tseg_size = 0; u32 tom; u8 tmp; pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0), I845_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) { switch (tmp & I845_TSEG_SIZE_MASK) { case I845_TSEG_SIZE_512K: tseg_size = KB(512); break; case I845_TSEG_SIZE_1M: tseg_size = MB(1); break; } } pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0), I830_DRB3, &tmp); tom = tmp * MB(32); base = tom - tseg_size - ggtt->stolen_size; } else if (IS_I830(dev)) { u32 tseg_size = 0; u32 tom; u8 tmp; pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0), I830_ESMRAMC, &tmp); if (tmp & TSEG_ENABLE) { if (tmp & I830_TSEG_SIZE_1M) tseg_size = MB(1); else tseg_size = KB(512); } pci_bus_read_config_byte(dev->pdev->bus, PCI_DEVFN(0, 0), I830_DRB3, &tmp); tom = tmp * MB(32); base = tom - tseg_size - ggtt->stolen_size; } if (base == 0) return 0; /* make sure we don't clobber the GTT if it's within stolen memory */ if (INTEL_INFO(dev)->gen <= 4 && !IS_G33(dev) && !IS_G4X(dev)) { struct { u32 start, end; } stolen[2] = { { .start = base, .end = base + ggtt->stolen_size, }, { .start = base, .end = base + ggtt->stolen_size, }, };
{ struct flash_priv *priv = dev->driver_data; int rc = 0; if (enable) { rc = k_sem_take(&priv->write_lock, K_FOREVER); } else { k_sem_give(&priv->write_lock); } return rc; } #if defined(CONFIG_FLASH_PAGE_LAYOUT) static const struct flash_pages_layout dev_layout = { .pages_count = KB(CONFIG_FLASH_SIZE) / DT_SOC_NV_FLASH_0_ERASE_BLOCK_SIZE, .pages_size = DT_SOC_NV_FLASH_0_ERASE_BLOCK_SIZE, }; static void flash_mcux_pages_layout(struct device *dev, const struct flash_pages_layout **layout, size_t *layout_size) { *layout = &dev_layout; *layout_size = 1; } #endif /* CONFIG_FLASH_PAGE_LAYOUT */ static struct flash_priv flash_data; static const struct flash_driver_api flash_mcux_api = {