Ejemplo n.º 1
0
def gen_pmecc_header(page_size, oob_size, ecc_bits, sector_size):
    '''
	generate a pmecc header value, which is 32bits.
	'''
    # print 'page_size: %d, oob_size: %d, ecc_bits: %d, sector_size: %d' \
    #	% (page_size, oob_size, ecc_bits, sector_size)
    nbSectorPerPage = page_size // sector_size
    eccOffset = oob_size - nbSectorPerPage * pmecc_get_ecc_bytes(
        ecc_bits, sector_size)
    #print 'eccOffset = %d, nbSector = %d, nbSectorPerPage = %d' % (eccOffset, nbSectorPerPage, nbSectorPerPage)

    ######## name : value (the excceed field will be ignored)
    #
    # name should be same as .json struct[] array's name.
    maps = {
        "key": 0xc,
        "usePmecc": (ecc_bits > 1),
        "nbSectorPerPage": nbSectorPerPage,
        "spareSize": oob_size,
        "eccBitReq": 2 if ecc_bits < 2 else ecc_bits,
        "sectorSize": sector_size,
        "eccOffset": eccOffset,
    }

    path_list = [
        os.getcwd(),
        os.path.join(os.getcwd(), 'scripts'),
    ]
    for path in path_list:
        fname = os.path.join(path, 'pmecc_head.json')
        if os.path.isfile(fname):
            json_file = open(fname)
            data = json.load(json_file)
            val = bitfieldsparser.convert_bitfield(
                data["pmecc_header"]["struct"], maps)
            #print 'val = 0x%x' % val
            json_file.close()

            return val

    sys.exit('Cannot find pmecc_head.json!')
Ejemplo n.º 2
0
def gen_pmecc_header(page_size, oob_size, ecc_bits, sector_size):
	'''
	generate a pmecc header value, which is 32bits.
	'''
	# print 'page_size: %d, oob_size: %d, ecc_bits: %d, sector_size: %d' \
	#	% (page_size, oob_size, ecc_bits, sector_size)
	nbSectorPerPage = page_size // sector_size
	eccOffset = oob_size - nbSectorPerPage * pmecc_get_ecc_bytes(ecc_bits, sector_size)
	#print 'eccOffset = %d, nbSector = %d, nbSectorPerPage = %d' % (eccOffset, nbSectorPerPage, nbSectorPerPage)

	######## name : value (the excceed field will be ignored)
	#
	# name should be same as .json struct[] array's name.
	maps = {
		"key" : 0xc,
		"usePmecc" : (ecc_bits > 1),
		"nbSectorPerPage" : nbSectorPerPage,
		"spareSize" : oob_size,
		"eccBitReq" : 2 if ecc_bits < 2 else ecc_bits,
		"sectorSize" : sector_size,
		"eccOffset" : eccOffset,
		}

	path_list = [
		os.getcwd(),
		os.path.join(os.getcwd(), 'scripts'),
		]
	for path in path_list:
		fname = os.path.join(path, 'pmecc_head.json')
		if os.path.isfile(fname):
			json_file=open(fname)
			data = json.load(json_file)
			val = bitfieldsparser.convert_bitfield(data["pmecc_header"]["struct"], maps)
			#print 'val = 0x%x' % val
			json_file.close()

			return val

	sys.exit('Cannot find pmecc_head.json!')