static int get_off_size(int argc, char *argv[], loff_t *off, loff_t *size) { if (argc >= 1) { if (!(str2longlong(argv[0], (unsigned long long*)off))) { store_msg("'%s' is not a number\n", argv[0]); return -1; } } else { *off = 0; *size = 0; } if (argc >= 2) { if (!(str2longlong(argv[1], (unsigned long long *)size))) { store_msg("'%s' is not a number\n", argv[1]); return -1; } }else{ *size = 0; } store_dbg("offset 0x%llx, size 0x%llx", *off, *size); return 0; }
void cmn_err (int level, char *s, ...) { char tmp[1024], *a[6]; va_list ap; int i, n = 0; va_start (ap, s); for (i = 0; i < strlen (s); i++) if (s[i] == '%') n++; for (i = 0; i < n && i < 6; i++) a[i] = va_arg (ap, char *); for (i = n; i < 6; i++) a[i] = NULL; strcpy (tmp, "osscore: "); sprintf (tmp + strlen (tmp), s, a[0], a[1], a[2], a[3], a[4], a[5], NULL, NULL, NULL, NULL); if (level == CE_PANIC) panic (tmp); printf ("%s", tmp); #if 0 /* This may cause a crash under SMP */ if (sound_started) store_msg (tmp); #endif va_end (ap); }
static int do_store_rom_protect(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { #if defined(CONFIG_AML_NAND) char *cmd = NULL; char str[128]; char *area = argv[2]; #endif if (argc < 3)return CMD_RET_USAGE; if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf rom_protect %s", area); store_dbg("command: %s", str); int ret = run_command(str, 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } #else return -1; #endif } return CMD_RET_SUCCESS; }
static int do_store_disprotect(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { char *area; area = argv[2]; if (strcmp(area, "key") == 0) { MsgP("disprotect key\n"); info_disprotect |= DISPROTECT_KEY; _info_disprotect_back_before_mmcinfo1 |= DISPROTECT_KEY; } if (strcmp(area, "fbbt") == 0) { store_msg("disprotect fbbt"); info_disprotect |= DISPROTECT_FBBT; } if (strcmp(area, "hynix") == 0) { store_msg("disprotect hynix"); info_disprotect |= DISPROTECT_HYNIX; } return 0; }
long do_msgrcv(int msqid, long *pmtype, void __user *mtext, size_t msgsz, long msgtyp, int msgflg) { struct msg_queue *msq; struct msg_msg *msg; int mode; struct ipc_namespace *ns; if (msqid < 0 || (long) msgsz < 0) return -EINVAL; mode = convert_mode(&msgtyp, msgflg); ns = current->nsproxy->ipc_ns; msq = msg_lock_check(ns, msqid); if (IS_ERR(msq)) return PTR_ERR(msq); for (;;) { struct msg_receiver msr_d; struct list_head *tmp; msg = ERR_PTR(-EACCES); if (ipcperms(&msq->q_perm, S_IRUGO)) goto out_unlock; msg = ERR_PTR(-EAGAIN); tmp = msq->q_messages.next; while (tmp != &msq->q_messages) { struct msg_msg *walk_msg; walk_msg = list_entry(tmp, struct msg_msg, m_list); if (testmsg(walk_msg, msgtyp, mode) && !security_msg_queue_msgrcv(msq, walk_msg, current, msgtyp, mode)) { msg = walk_msg; if (mode == SEARCH_LESSEQUAL && walk_msg->m_type != 1) { msg = walk_msg; msgtyp = walk_msg->m_type - 1; } else { msg = walk_msg; break; } } tmp = tmp->next; } if (!IS_ERR(msg)) { /* * Found a suitable message. * Unlink it from the queue. */ if ((msgsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) { msg = ERR_PTR(-E2BIG); goto out_unlock; } list_del(&msg->m_list); msq->q_qnum--; msq->q_rtime = get_seconds(); msq->q_lrpid = task_tgid_vnr(current); msq->q_cbytes -= msg->m_ts; atomic_sub(msg->m_ts, &ns->msg_bytes); atomic_dec(&ns->msg_hdrs); ss_wakeup(&msq->q_senders, 0); msg_unlock(msq); break; } /* No message waiting. Wait for a message */ if (msgflg & IPC_NOWAIT) { msg = ERR_PTR(-ENOMSG); goto out_unlock; } list_add_tail(&msr_d.r_list, &msq->q_receivers); msr_d.r_tsk = current; msr_d.r_msgtype = msgtyp; msr_d.r_mode = mode; if (msgflg & MSG_NOERROR) msr_d.r_maxsize = INT_MAX; else msr_d.r_maxsize = msgsz; msr_d.r_msg = ERR_PTR(-EAGAIN); current->state = TASK_INTERRUPTIBLE; msg_unlock(msq); schedule(); /* Lockless receive, part 1: * Disable preemption. We don't hold a reference to the queue * and getting a reference would defeat the idea of a lockless * operation, thus the code relies on rcu to guarantee the * existance of msq: * Prior to destruction, expunge_all(-EIRDM) changes r_msg. * Thus if r_msg is -EAGAIN, then the queue not yet destroyed. * rcu_read_lock() prevents preemption between reading r_msg * and the spin_lock() inside ipc_lock_by_ptr(). */ rcu_read_lock(); /* Lockless receive, part 2: * Wait until pipelined_send or expunge_all are outside of * wake_up_process(). There is a race with exit(), see * ipc/mqueue.c for the details. */ msg = (struct msg_msg*)msr_d.r_msg; while (msg == NULL) { cpu_relax(); msg = (struct msg_msg *)msr_d.r_msg; } /* Lockless receive, part 3: * If there is a message or an error then accept it without * locking. */ if (msg != ERR_PTR(-EAGAIN)) { rcu_read_unlock(); break; } /* Lockless receive, part 3: * Acquire the queue spinlock. */ ipc_lock_by_ptr(&msq->q_perm); rcu_read_unlock(); /* Lockless receive, part 4: * Repeat test after acquiring the spinlock. */ msg = (struct msg_msg*)msr_d.r_msg; if (msg != ERR_PTR(-EAGAIN)) goto out_unlock; list_del(&msr_d.r_list); if (signal_pending(current)) { msg = ERR_PTR(-ERESTARTNOHAND); out_unlock: msg_unlock(msq); break; } } if (IS_ERR(msg)) return PTR_ERR(msg); msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz; *pmtype = msg->m_type; if (store_msg(mtext, msg, msgsz)) msgsz = -EFAULT; free_msg(msg); return msgsz; }
int do_store(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { int i, init_flag=0,dev, ret = 0; uint64_t addr; loff_t off=0, size=0; char *cmd, *s, *area; char str[128]; unsigned char *tmp_buf= NULL; if (argc < 2) goto usage; cmd = argv[1]; if (strcmp(cmd, "erase") == 0){ area = argv[2]; if(strcmp(area, "boot") == 0){ if(POR_NAND_BOOT()){ off = simple_strtoul(argv[3], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); store_dbg("NAND BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); ret = run_command("amlnf deverase boot 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } return ret; }else if(POR_SPI_BOOT()){ off = simple_strtoul(argv[3], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); store_dbg("SPI BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); ret = run_command("sf probe 2",0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0 0x%x", CONFIG_ENV_IN_SPI_OFFSET);//store erase boot shoould NOT erase ENV in flash! ret = run_command(str,0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if(POR_EMMC_BOOT()){ off = simple_strtoul(argv[3], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); store_dbg("MMC BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); sprintf(str, "mmc erase bootloader"); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for(i=0; i<2; i++){ //switch to boot partition here sprintf(str, "mmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret == -1){ //store_msg("mmc cmd %s failed \n",cmd); return 0; } else if(ret != 0){ store_msg("mmc cmd %s failed",cmd); //return -1; goto E_SWITCH_BACK; } //erase boot partition sprintf(str, "mmc erase bootloader"); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); //return -1; goto E_SWITCH_BACK; } } E_SWITCH_BACK: //switch back to urs partition sprintf(str, "mmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); return 0; } } else if(strcmp(area, "data") == 0){ if(POR_NAND_BOOT()){ store_dbg("NAND BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); ret = run_command("amlnf deverase data 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase code 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase cache 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } return ret; } else if(POR_SPI_BOOT()){ store_dbg("SPI BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); ret = run_command("amlnf deverase data 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase code 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase cache 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); off = size =0; ret = run_command("mmc erase 1",0); // whole if(ret != 0){ store_msg("mmc cmd %s failed ",cmd); return -1; } } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); off = size =0; ret = run_command("mmc erase 1",0); //whole if(ret != 0){ store_msg("mmc cmd %s failed ",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); return 0; } } else { goto usage; } } else if(strcmp(cmd, "read") == 0){ if (argc < 6) goto usage; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (get_off_size(argc - 4, argv + 4, &off, &size) != 0) goto usage; store_dbg("addr = %llx off= 0x%llx size=0x%llx",addr,off,size); if((POR_NAND_BOOT())){ sprintf(str, "amlnf read_byte %s 0x%llx 0x%llx 0x%llx",s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } return ret; }else if((POR_SPI_BOOT())){ if(device_boot_flag == SPI_NAND_FLAG){ sprintf(str, "amlnf read_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed \n",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); sprintf(str, "mmc read %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } } return ret; } else if(POR_EMMC_BOOT()) { store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "mmc read %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "write") == 0){ if (argc < 6) goto usage; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (get_off_size(argc - 4, argv + 4, &off, &size) != 0) goto usage; if((POR_NAND_BOOT())){ sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } }else if((POR_SPI_BOOT())){ if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed \n",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); sprintf(str, "mmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } } } else if(POR_EMMC_BOOT()) { store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "mmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return 0; } return ret; } else if(strcmp(cmd, "rom_write") == 0){ if (argc < 5) goto usage; addr = (ulong)simple_strtoul(argv[2], NULL, 16); if (get_off_size(argc - 3, argv + 3, &off, &size) != 0) goto usage; if(POR_NAND_BOOT()){ sprintf(str, "amlnf rom_write 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if (POR_SPI_BOOT()){ ret = run_command("sf probe 2",0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0x%llx 0x%llx ", off, size); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf write 0x%llx 0x%llx 0x%llx ",addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); tmp_buf= (unsigned char *)addr; #ifndef CONFIG_AML_SECU_BOOT_V2 #ifdef MMC_UBOOT_CLEAR_MBR //modify the 55 AA info for emmc uboot _mbrFlag[0] = tmp_buf[510]; _mbrFlag[1] = tmp_buf[511]; tmp_buf[510]=0; tmp_buf[511]=0; #endif #endif// #if defined(CONFIG_AML_SECU_BOOT_V2) sprintf(str, "mmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for(i=0; i<2; i++){ //switch to boot partition here sprintf(str, "mmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret == -1){ //store_msg("mmc cmd %s failed \n",cmd); ret = 0; return ret; } else if(ret != 0){ store_msg("mmc cmd %s failed",cmd); //return -1; goto W_SWITCH_BACK; } //write uboot to boot partition sprintf(str, "mmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); //return -1; goto W_SWITCH_BACK; } } W_SWITCH_BACK: //switch back to urs partition sprintf(str, "mmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "rom_read") == 0){ if (argc < 5) goto usage; addr = (ulong)simple_strtoul(argv[2], NULL, 16); if (get_off_size(argc - 3, argv + 3, &off, &size) != 0) goto usage; if(POR_NAND_BOOT()){ sprintf(str, "amlnf rom_read 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if (POR_SPI_BOOT()){ ret = run_command("sf probe 2",0); if(ret != 0){ return -1; } sprintf(str, "sf read 0x%llx 0x%llx 0x%llx ",addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if (POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "mmc read bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); tmp_buf= (unsigned char *)addr; ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for(i=0; i<2; i++){ //switch to boot partition here sprintf(str, "mmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret == -1){ //store_msg("mmc cmd %s failed \n",cmd); return 0; } else if(ret != 0){ store_msg("mmc cmd %s failed",cmd); goto R_SWITCH_BACK; //return -1; } //write uboot to boot partition sprintf(str, "mmc read bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); //return -1; goto R_SWITCH_BACK; } } R_SWITCH_BACK: //switch back to urs partition sprintf(str, "mmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #endif #ifndef CONFIG_AML_SECU_BOOT_V2 #ifdef MMC_UBOOT_CLEAR_MBR tmp_buf[510]= _mbrFlag[0]; tmp_buf[511]= _mbrFlag[1]; #endif #endif// #ifndef CONFIG_AML_SECU_BOOT_V2 return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return 0; } } else if (strcmp(cmd, "rom_protect") == 0){ if (argc < 3) goto usage; area = argv[2]; if(POR_NAND_BOOT()){ sprintf(str, "amlnf rom_protect %s", area); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; } } else if (strcmp(cmd, "scrub") == 0){ off = (ulong)simple_strtoul(argv[2], NULL, 16); sprintf(str, "amlnf scrub %d", off); if((POR_NAND_BOOT()) ){ ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } }else if(POR_SPI_BOOT()){ if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } ret = run_command("sf probe 2", 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmc erase whole",0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } } }else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); device_boot_flag = EMMC_BOOT_FLAG; ret = run_command("mmcinfo 1", 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ MsgP("mmc key\n"); run_command("mmc key", 0); } MsgP("mmc erase 1"); ret = run_command("mmc erase 1", 0); } return ret; } else if(strcmp(cmd, "init") == 0){ init_flag = (argc > 2) ? (int)simple_strtoul(argv[2], NULL, 16) : 0; store_dbg("init_flag %d",init_flag); if(POR_NAND_BOOT()){ if((init_flag >=STORE_BOOT_ERASE_PROTECT_CACHE)&&(init_flag <=STORE_BOOT_SCRUB_ALL)){ sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",0); printf("command: %s -> %d\n", str, init_flag); device_boot_flag = NAND_BOOT_FLAG; ret = run_command(str, 0); if(ret != 0){ #if 0 if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } if(ret){ store_msg("nand cmd %s failed,ret=%d ",cmd,ret); return -1; } return 0; #else return -1; #endif } return ret; } else if(POR_SPI_BOOT()) { if(device_boot_flag == -1) { ret = run_command("sf probe 2", 0); if(ret){ store_msg(" cmd %s failed \n",cmd); return -1; } if((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)){ sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); /*nand erase!*/ sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",0); printf("command: %s -> %d\n", str, init_flag); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret < 0)//fail to init NAND flash { store_msg("nand cmd %s failed \n",cmd); device_boot_flag = SPI_EMMC_FLAG; store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmcinfo 1", 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -2; } if(init_flag == STORE_BOOT_ERASE_PROTECT_CACHE){ // OTA upgrade protect cache store_msg("mmc erase non_cache \n"); ret = run_command("mmc erase non_cache", 0); }else if(init_flag >= STORE_BOOT_ERASE_ALL){ // erase all except reserved area if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ MsgP("mmc key;\n"); run_command("mmc key", 0); } MsgP("mmc erase 1 \n"); ret = run_command("mmc erase 1", 0); } return 0; } else if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ #if 0 sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); #else return -1; #endif } device_boot_flag = SPI_NAND_FLAG; return 0; } if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); if((init_flag >=STORE_BOOT_ERASE_PROTECT_CACHE)&&(init_flag <=STORE_BOOT_SCRUB_ALL)){ sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",0); store_dbg("command: %s", str); ret = run_command(str, 0); #if 0 if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } #else if(ret == NAND_INIT_FAILED){ return -1; } #endif if((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)){ ret = run_command("sf probe 2", 0); sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmcinfo 1", 0); if(init_flag == STORE_BOOT_ERASE_PROTECT_CACHE){ // OTA upgrade protect cache store_msg("mmc erase non_cache \n"); ret = run_command("mmc erase non_cache", 0); }else if(init_flag == STORE_BOOT_ERASE_ALL){ // erase all except reserved area if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ run_command("mmc key", 0); } MsgP("mmc erase 1 \n"); ret = run_command("mmc erase 1", 0); } if((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)){ ret = run_command("sf probe 2", 0); sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } } if(ret != 0){ store_msg("cmd %s failed \n",cmd); return -1; } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); device_boot_flag = EMMC_BOOT_FLAG; ret = run_command("mmcinfo 1", 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } if(init_flag == STORE_BOOT_ERASE_PROTECT_CACHE){ // OTA upgrade protect cache ret = run_command("mmc erase non_cache", 0); }else if(init_flag >= STORE_BOOT_ERASE_ALL){ // erase all except reserved area if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ MsgP("mmc key\n"); run_command("mmc key", 0); } MsgP("mmc erase 1"); ret = run_command("mmc erase 1", 0); } return ret; }else{ store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "size") == 0){ if (argc < 4) goto usage; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if(POR_NAND_BOOT()){ sprintf(str, "amlnf size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if(POR_SPI_BOOT()){ if(device_boot_flag == SPI_NAND_FLAG){ sprintf(str, "amlnf size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("MMC , %s %d ",__func__,__LINE__); sprintf(str, "mmc size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); return -1; } } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC , %s %d ",__func__,__LINE__); sprintf(str, "mmc size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); return -1; } return ret; } else if(POR_CARD_BOOT()){ store_dbg("CARD BOOT , %s %d ",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "disprotect") == 0){ area = argv[2]; if(strcmp(area, "key") == 0){ MsgP("disprotect key\n"); info_disprotect |= DISPROTECT_KEY; _info_disprotect_back_before_mmcinfo1 |= DISPROTECT_KEY; } if(strcmp(area, "secure") == 0){ store_msg("disprotect secure"); info_disprotect |= DISPROTECT_SECURE; } if(strcmp(area, "fbbt") == 0){ store_msg("disprotect fbbt"); info_disprotect |= DISPROTECT_FBBT; } if(strcmp(area, "hynix") == 0){ store_msg("disprotect hynix"); info_disprotect |= DISPROTECT_HYNIX; } return 0; } else if(strcmp(cmd, "exit") == 0){ if(POR_NAND_BOOT()){ ret = run_command("amlnf exit", 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } } return 0; } else{ goto usage; } return ret; usage: cmd_usage(cmdtp); return 1; }
asmlinkage long sys_msgrcv (int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg) { struct msg_queue *msq; struct msg_receiver msr_d; struct list_head* tmp; struct msg_msg* msg, *found_msg; int err; int mode; if (msqid < 0 || (long) msgsz < 0) return -EINVAL; mode = convert_mode(&msgtyp,msgflg); msq = msg_lock(msqid); if(msq==NULL) return -EINVAL; retry: err = -EIDRM; if (msg_checkid(msq,msqid)) goto out_unlock; err=-EACCES; if (ipcperms (&msq->q_perm, S_IRUGO)) goto out_unlock; tmp = msq->q_messages.next; found_msg=NULL; while (tmp != &msq->q_messages) { msg = list_entry(tmp,struct msg_msg,m_list); if(testmsg(msg,msgtyp,mode)) { found_msg = msg; if(mode == SEARCH_LESSEQUAL && msg->m_type != 1) { found_msg=msg; msgtyp=msg->m_type-1; } else { found_msg=msg; break; } } tmp = tmp->next; } if(found_msg) { msg=found_msg; if ((msgsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) { err=-E2BIG; goto out_unlock; } list_del(&msg->m_list); msq->q_qnum--; msq->q_rtime = CURRENT_TIME; msq->q_lrpid = current->pid; msq->q_cbytes -= msg->m_ts; atomic_sub(msg->m_ts,&msg_bytes); atomic_dec(&msg_hdrs); ss_wakeup(&msq->q_senders,0); msg_unlock(msqid); out_success: msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz; if (put_user (msg->m_type, &msgp->mtype) || store_msg(msgp->mtext, msg, msgsz)) { msgsz = -EFAULT; } free_msg(msg); return msgsz; } else { struct msg_queue *t; /* no message waiting. Prepare for pipelined * receive. */ if (msgflg & IPC_NOWAIT) { err=-ENOMSG; goto out_unlock; } list_add_tail(&msr_d.r_list,&msq->q_receivers); msr_d.r_tsk = current; msr_d.r_msgtype = msgtyp; msr_d.r_mode = mode; if(msgflg & MSG_NOERROR) msr_d.r_maxsize = INT_MAX; else msr_d.r_maxsize = msgsz; msr_d.r_msg = ERR_PTR(-EAGAIN); current->state = TASK_INTERRUPTIBLE; msg_unlock(msqid); schedule(); current->state = TASK_RUNNING; /* This introduces a race so we must always take the slow path msg = (struct msg_msg*) msr_d.r_msg; if(!IS_ERR(msg)) goto out_success; */ t = msg_lock(msqid); if(t==NULL) msqid=-1; msg = (struct msg_msg*)msr_d.r_msg; if(!IS_ERR(msg)) { /* our message arived while we waited for * the spinlock. Process it. */ if(msqid!=-1) msg_unlock(msqid); goto out_success; } err = PTR_ERR(msg); if(err == -EAGAIN) { if(msqid==-1) BUG(); list_del(&msr_d.r_list); if (signal_pending(current)) err=-EINTR; else goto retry; } } out_unlock: if(msqid!=-1) msg_unlock(msqid); return err; }
static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { uint64_t addr; loff_t off=0, size=0; char *cmd = NULL; char str[128]; int ret = 0; int i = 0; cpu_id_t cpu_id = get_cpu_id(); if (argc < 5) return CMD_RET_USAGE; addr = (ulong)simple_strtoul(argv[2], NULL, 16); if (get_off_size(argc - 3, (char **)(argv + 3), &off, &size) != 0) return CMD_RET_FAILURE; if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf rom_write 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if ((device_boot_flag==SPI_EMMC_FLAG)||(device_boot_flag==SPI_NAND_FLAG)){ ret = run_command("sf probe 2",0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0x%llx 0x%llx ", off, size); ret = run_command(str, 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf write 0x%llx 0x%llx 0x%llx ",addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); #ifndef CONFIG_AML_SECU_BOOT_V2 #ifdef MMC_UBOOT_CLEAR_MBR //modify the 55 AA info for emmc uboot unsigned char *tmp_buf= (unsigned char *)addr; _mbrFlag[0] = tmp_buf[510]; _mbrFlag[1] = tmp_buf[511]; tmp_buf[510]=0; tmp_buf[511]=0; #endif #endif// #if defined(CONFIG_AML_SECU_BOOT_V2) if (cpu_id.family_id >= MESON_CPU_MAJOR_ID_GXL) off += 512; sprintf(str, "amlmmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for (i=0; i<2; i++) { //switch to boot partition here sprintf(str, "amlmmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret == -1) { //store_msg("mmc cmd %s failed \n",cmd); ret = 0; return ret; } else if(ret != 0){ store_msg("amlmmc cmd %s failed",cmd); //return -1; goto W_SWITCH_BACK; } //write uboot to boot partition sprintf(str, "amlmmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); //return -1; goto W_SWITCH_BACK; } } W_SWITCH_BACK: //switch back to urs partition sprintf(str, "amlmmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return 0; } }
static int do_store_scrub(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { int ret = 0; loff_t off=0; char *cmd = NULL; char str[128]; off = (ulong)simple_strtoul(argv[2], NULL, 16); sprintf(str, "amlnf scrub %d", (int)off); if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } } else if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); #if defined(CONFIG_AML_NAND) ret = run_command(str, 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } #endif ret = run_command("sf probe 2", 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("amlmmc erase whole",0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); device_boot_flag = EMMC_BOOT_FLAG; run_command("mmc dev 1", 0); ret = run_command("mmcinfo", 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } if (_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY) { MsgP("mmc key\n"); run_command("mmc key", 0); } MsgP("amlmmc erase 1"); ret = run_command("amlmmc erase 1", 0); } return ret; }
static int do_store_erase(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { int i, ret = 0; loff_t size=0; char *cmd = NULL, *area; char str[128]; loff_t off; if (argc < 3) return CMD_RET_USAGE; off = off; area = argv[2]; if (strcmp(area, "boot") == 0) { off = argc > 3 ? simple_strtoul(argv[3], NULL, 16) : 0; size = argc > 4 ? simple_strtoul(argv[4], NULL, 16) : 0x60000; if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) store_dbg("NAND BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); ret = run_command("amlnf deverase boot 0",0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } return ret; }else if((device_boot_flag==SPI_EMMC_FLAG)||(device_boot_flag==SPI_NAND_FLAG)){ store_dbg("SPI BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); ret = run_command("sf probe 2",0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0 0x%x", CONFIG_ENV_IN_SPI_OFFSET);//store erase boot shoould NOT erase ENV in flash! ret = run_command(str,0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if(device_boot_flag == EMMC_BOOT_FLAG){ store_dbg("MMC BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); sprintf(str, "amlmmc erase bootloader"); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for (i=0; i<2; i++) { //switch to boot partition here sprintf(str, "amlmmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret == -1) { //store_msg("mmc cmd %s failed \n",cmd); return 0; } else if(ret != 0){ store_msg("amlmmc cmd %s failed",cmd); //return -1; goto E_SWITCH_BACK; } //erase boot partition sprintf(str, "amlmmc erase bootloader"); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed",cmd); //return -1; goto E_SWITCH_BACK; } } E_SWITCH_BACK: //switch back to urs partition sprintf(str, "amlmmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); return 0; } } else if (strcmp(area, "data") == 0){ if (device_boot_flag == NAND_BOOT_FLAG) { store_dbg("NAND BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); #if defined(CONFIG_AML_NAND) ret = run_command("amlnf deverase data 0",0); if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase code 0",0); if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase cache 0",0); if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } #endif return ret; } else if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); #if defined(CONFIG_AML_NAND) ret = run_command("amlnf deverase data 0",0); if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase code 0",0); if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase cache 0",0); if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } #endif return ret; } else if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); off = size =0; ret = run_command("mmc erase 1",0); // whole if (ret != 0) { store_msg("mmc cmd %s failed ",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); off = size =0; ret = run_command("amlmmc erase 1",0); //whole if (ret != 0) { store_msg("amlmmc cmd %s failed ",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); return 0; } } else if (strcmp(area, "key") == 0){ if (device_boot_flag == EMMC_BOOT_FLAG) { sprintf(str, "emmc erase key"); ret = run_command(str, 0); if (ret != 0) { store_msg("emmc cmd %s failed",cmd); return CMD_RET_USAGE; } } else if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf key_erase"); ret = run_command(str, 0); if (ret != 0) { store_msg("emmc cmd %s failed",cmd); return CMD_RET_USAGE; } #endif } } else if (strcmp(area, "dtb") == 0) { if (device_boot_flag == EMMC_BOOT_FLAG) { sprintf(str, "emmc erase dtb"); ret = run_command(str, 0); if (ret != 0) { store_msg("emmc cmd %s failed",cmd); return CMD_RET_USAGE; } } else if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf dtb_erase"); ret = run_command(str, 0); if (ret != 0) { store_msg("emmc cmd %s failed",cmd); return CMD_RET_USAGE; } #endif } } return 0; }
static int do_store_size(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { int ret = 0; uint64_t addr; char *cmd = NULL, *s = NULL; char str[128]; if (argc < 4) return CMD_RET_USAGE; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_NAND_FLAG){ #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("MMC , %s %d ",__func__,__LINE__); sprintf(str, "amlmmc size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC , %s %d ",__func__,__LINE__); sprintf(str, "amlmmc size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag==CARD_BOOT_FLAG){ store_dbg("CARD BOOT , %s %d ",__func__,__LINE__); return CMD_RET_FAILURE; } return CMD_RET_FAILURE; }
static int do_store_init(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { int i, init_flag=0, ret = 0; char *cmd = ""; char str[128]; init_flag = (argc > 2) ? (int)simple_strtoul(argv[2], NULL, 16) : 0; store_dbg("init_flag %d",init_flag); if (device_boot_flag == _AML_DEVICE_BOOT_FLAG_DEFAULT ) { i = get_device_boot_flag(); if (i) { MsgP("ERR:FAILED in get_device_boot_flag\n"); return __LINE__; } } switch (device_boot_flag) { #if defined(CONFIG_AML_NAND) case NAND_BOOT_FLAG: { if ((init_flag >=STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <=STORE_BOOT_SCRUB_ALL)) { sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",1); printf("command: %s <- %d\n", str, init_flag); device_boot_flag = NAND_BOOT_FLAG; ret = run_command(str, 0); if (ret != 0) { #if 0 if ((ret == NAND_INIT_FAILED) && (init_flag == STORE_BOOT_ERASE_ALL)) { sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } if (ret) { store_msg("nand cmd %s failed,ret=%d ",cmd,ret); return -1; } return 0; #else return -1; #endif } return ret; } break; #endif case EMMC_BOOT_FLAG: { store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); device_boot_flag = EMMC_BOOT_FLAG; sprintf(str, "mmc dev %d", CONFIG_SYS_MMC_ENV_DEV); run_command(str,0); ret = run_command("mmcinfo", 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } if (init_flag == STORE_BOOT_ERASE_PROTECT_CACHE) { // OTA upgrade protect cache ret = run_command("amlmmc erase non_cache", 0); }else if(init_flag >= STORE_BOOT_ERASE_ALL){ // erase all except reserved area if (_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY) { MsgP("amlmmc key\n"); run_command("amlmmc key", 0); } sprintf(str, "amlmmc erase %d", CONFIG_SYS_MMC_ENV_DEV); MsgP("amlmmc erase %d", CONFIG_SYS_MMC_ENV_DEV); ret = run_command(str, 0); } return ret; } break; case SPI_EMMC_FLAG: case SPI_NAND_FLAG: { /* if (device_boot_flag == -1) { ret = run_command("sf probe 2", 0); if (ret) { store_msg(" cmd %s failed \n",cmd); return -1; } if ((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)) { sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } sprintf(str, "amlnf init %d ",init_flag); store_dbg("command: %s", str); ret = run_command(str, 0); if (ret < 0) //fail to init NAND flash { store_msg("nand cmd %s failed \n",cmd); device_boot_flag = SPI_EMMC_FLAG; store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmcinfo 1", 0); if (ret != 0) { store_msg("mmc cmd %s failed \n",cmd); return -2; } if (init_flag == STORE_BOOT_ERASE_PROTECT_CACHE) { // OTA upgrade protect cache store_msg("mmc erase non_cache \n"); ret = run_command("mmc erase non_cache", 0); }else if(init_flag >= STORE_BOOT_ERASE_ALL){ // erase all except reserved area if (_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY) { MsgP("mmc key;\n"); run_command("mmc key", 0); } MsgP("mmc erase 1 \n"); ret = run_command("mmc erase 1", 0); } return 0; } else if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } device_boot_flag = SPI_NAND_FLAG; return 0; } */ if (device_boot_flag == SPI_NAND_FLAG) { store_dbg("spi+nand , %s %d ",__func__,__LINE__); #if defined(CONFIG_AML_NAND) if ((init_flag >=STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <=STORE_BOOT_SCRUB_ALL)) { sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",1); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = NAND_INIT_FAILED; #endif #if 0 if ((ret == NAND_INIT_FAILED) && (init_flag == STORE_BOOT_ERASE_ALL)) { sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } #else if (ret == NAND_INIT_FAILED) { return -1; } #endif if ((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)) { ret = run_command("sf probe 2", 0); sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } } if (device_boot_flag == SPI_EMMC_FLAG) { store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmcinfo 1", 0); if (init_flag == STORE_BOOT_ERASE_PROTECT_CACHE) { // OTA upgrade protect cache store_msg("amlmmc erase non_cache \n"); ret = run_command("amlmmc erase non_cache", 0); }else if(init_flag == STORE_BOOT_ERASE_ALL){ // erase all except reserved area if (_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY) { run_command("mmc key", 0); } MsgP("amlmmc erase 1 \n"); ret = run_command("amlmmc erase 1", 0); } if ((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)) { ret = run_command("sf probe 2", 0); sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } } if (ret != 0) { store_msg("cmd %s failed \n",cmd); return -1; } return ret; } default: store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return CMD_RET_FAILURE; } return 0; }
static int do_store_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { uint64_t addr; loff_t off=0, size=0; char *cmd = NULL; char str[128]; int ret = 0; char * s = argv[2]; if (argc < 6) return CMD_RET_USAGE; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (get_off_size(argc - 4, (char **)(argv + 4), &off, &size) != 0) return CMD_RET_FAILURE; if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed \n",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); sprintf(str, "amlmmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "amlmmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return CMD_RET_FAILURE; } return ret; }
asmlinkage long sys_msgrcv (int msqid, struct msgbuf __user *msgp, size_t msgsz, long msgtyp, int msgflg) { struct msg_queue *msq; struct msg_receiver msr_d; struct list_head* tmp; struct msg_msg* msg, *found_msg; int err; int mode; if (msqid < 0 || (long) msgsz < 0) return -EINVAL; mode = convert_mode(&msgtyp,msgflg); msq = msg_lock(msqid); if(msq==NULL) return -EINVAL; retry: err = -EIDRM; if (msg_checkid(msq,msqid)) goto out_unlock; err=-EACCES; if (ipcperms (&msq->q_perm, S_IRUGO)) goto out_unlock; tmp = msq->q_messages.next; found_msg=NULL; while (tmp != &msq->q_messages) { msg = list_entry(tmp,struct msg_msg,m_list); if(testmsg(msg,msgtyp,mode) && !security_msg_queue_msgrcv(msq, msg, current, msgtyp, mode)) { found_msg = msg; if(mode == SEARCH_LESSEQUAL && msg->m_type != 1) { found_msg=msg; msgtyp=msg->m_type-1; } else { found_msg=msg; break; } } tmp = tmp->next; } if(found_msg) { msg=found_msg; if ((msgsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) { err=-E2BIG; goto out_unlock; } list_del(&msg->m_list); msq->q_qnum--; msq->q_rtime = get_seconds(); msq->q_lrpid = current->tgid; msq->q_cbytes -= msg->m_ts; atomic_sub(msg->m_ts,&msg_bytes); atomic_dec(&msg_hdrs); ss_wakeup(&msq->q_senders,0); msg_unlock(msq); out_success: msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz; if (put_user (msg->m_type, &msgp->mtype) || store_msg(msgp->mtext, msg, msgsz)) { msgsz = -EFAULT; } free_msg(msg); return msgsz; } else { /* no message waiting. Prepare for pipelined * receive. */ if (msgflg & IPC_NOWAIT) { err=-ENOMSG; goto out_unlock; } list_add_tail(&msr_d.r_list,&msq->q_receivers); msr_d.r_tsk = current; msr_d.r_msgtype = msgtyp; msr_d.r_mode = mode; if(msgflg & MSG_NOERROR) msr_d.r_maxsize = INT_MAX; else msr_d.r_maxsize = msgsz; msr_d.r_msg = ERR_PTR(-EAGAIN); current->state = TASK_INTERRUPTIBLE; msg_unlock(msq); schedule(); /* * The below optimisation is buggy. A sleeping thread that is * woken up checks if it got a message and if so, copies it to * userspace and just returns without taking any locks. * But this return to user space can be faster than the message * send, and if the receiver immediately exits the * wake_up_process performed by the sender will oops. */ #if 0 msg = (struct msg_msg*) msr_d.r_msg; if(!IS_ERR(msg)) goto out_success; #endif msq = msg_lock(msqid); msg = (struct msg_msg*)msr_d.r_msg; if(!IS_ERR(msg)) { /* our message arived while we waited for * the spinlock. Process it. */ if(msq) msg_unlock(msq); goto out_success; } err = PTR_ERR(msg); if(err == -EAGAIN) { if(!msq) BUG(); list_del(&msr_d.r_list); if (signal_pending(current)) err=-EINTR; else goto retry; } } out_unlock: if(msq) msg_unlock(msq); return err; }