Esempio n. 1
0
static int
szm_do_scale_head_photo(char *in, int in_len, char **out, int *out_len)
{
	int type;
	gdImagePtr im_in;
	*out=NULL;
	*out_len=0;
	type=get_img_type(in, in_len);
	if(type<0)
		return -SZM_ERR_IMGFMT;
	im_in = img_create_func[type](in_len, in);
	if (!im_in)
		return -SZM_ERR_IMGFMT;
	return szm_do_scale_head_photo_internal(im_in, out, out_len, in_len);
}
/**************************************************************************
 *  Check Image Information
 **************************************************************************/
u32 check_imgp (DM_IMAGE_INFO_PACKET * imgp, u32 * pktsz)
{
    print ("\n%s : ------------------ IMG ---------------\n", MOD);
    print ("%s : IMG fmt    = %s   \t type = %s\n", MOD, get_img_fmt (imgp->img_info.img_format),  get_img_type (imgp->img_info.img_type));
    print ("%s : IMG sz     = 0x%x \t addr = 0x%x\n", MOD,(imgp->img_info.img_size), (imgp->img_info.addr_off));
    print ("%s : addr       = 0x%x \t boundary = 0x%x\n", MOD, (imgp->img_info.addr_off), (imgp->img_info.addr_boundary));
    print ("%s : pkt sz     = 0x%x \n", MOD, (imgp->img_info.pkt_size));
    //print ("%s : --------------------------------------\n", MOD);
    print ("%s : IMG range  = 0x%x ~ 0x%x\n", MOD, (imgp->img_info.addr_off), (imgp->img_info.addr_off) + (imgp->img_info.img_size));
    //print ("%s : --------------------------------------\n", MOD);

    // image type is partition table inform
    if (DM_IMG_TYPE_PT_TABLE_INFORM == imgp->img_info.img_type)
    {
        print ("partition table inform\n");
        mt_usbtty_puts (DM_STR_START_REQ);
        handle_pt_cmd ();
        return;
    }
    
    // check image boundary  
    if (g_dl_safe_start_addr > imgp->img_info.addr_off)
    {
        print ("can't flash this image !\n");
        print ("current safe starting address for flashing (0x%x) > current image address (0x%x)\n", g_dl_safe_start_addr, imgp->img_info.addr_off);
        ASSERT (0);
    }

    DM_LOG ("%s : cur safe start addr for flashing (0x%x)\n", MOD, g_dl_safe_start_addr);
    g_dl_safe_start_addr = imgp->img_info.addr_off;

    if (imgp->pattern != DM_IMAGE_INFO_PKT_PATN)
    {
        DM_ASSERT (imgp->pattern == DM_IMAGE_INFO_PKT_PATN);
        dm_ctx.dm_status = DM_STATUS_ERR_ONGOING;
        dm_ctx.dm_err = DM_ERR_WRONG_SEQ;
    }
    // start address offset must be block alignment
    else if (imgp->img_info.addr_off % dm_ctx.block_size)
    {
        DM_ASSERT (imgp->img_info.addr_off % dm_ctx.block_size == 0);
        dm_ctx.dm_status = DM_STATUS_ERR_ONGOING;
        dm_ctx.dm_err = DM_ERR_WRONG_ADDR;
        *pktsz = save_imgp (imgp);
    }
    // packet size must be page size + spare size
    else if (imgp->img_info.pkt_size != dm_ctx.page_size + dm_ctx.spare_size)
    {
        DM_ASSERT (imgp->img_info.pkt_size == dm_ctx.page_size + dm_ctx.spare_size);
        dm_ctx.dm_status = DM_STATUS_ERR_ONGOING;
        dm_ctx.dm_err = DM_ERR_WRONG_PKT_SZ;
        *pktsz = save_imgp (imgp);
    }
    else
    {
        *pktsz = save_imgp (imgp);
         dm_ctx.dm_status = DM_STATUS_SECT_ONGING;
         DM_TIME_BEGIN;
         // erase whole partition to keep data consistent
         force_erase (&imgp->img_info, *pktsz);
         DM_TIME_END_NAND_ERASE;
    }

    return *pktsz;
}