Hsin-Hsiang Hsin-Hsiang - 3 months ago 10
Linux Question

where is the mmc write command data source from?

I am new to the boot loader world, i have a question about when we send a write command how we assign the data source, which is relate to the function argument *src? I traced the source code but i can't find where it assign the data source in c code.

Answer by myself: I found when we do #mmc write 1 0x4 2 the argument means dev # 1, block # 4, count 2 which as below function's argument
mmc->block_dev.block_write(curr_device, blk, cnt, addr);

BUT, i still want to know, is it Is it possible assign a external data source directly?

Is mmc write or mmc read could only write/read from internal memory?

Is it possible assign a external data source, such as from USB port or SD card?

best & regard.

static unsigned long mmc_bwrite(int dev_num, unsigned long start, lbaint_t blkcnt, const void *src){
int err;
struct mmc *mmc = find_mmc_device(dev_num);

if (!mmc) {
printf("MMC Device %d not found\n", dev_num);
return 0;
}

if (blkcnt > 1)
return mmc_bwrite_multi(mmc, start, blkcnt, src);
else if (blkcnt == 1)
return mmc_bwrite_single(mmc, start, src);

return 0;


}

How should i trace code like below?

mmc->block_dev.block_write = mmc_bwrite;

Answer

src is a pointer to a block of memory that is internal to the filesystem, if you wish to stream data from a device to the MMC, then you will need intermediate code to buffer that stream in memory and pass it to the high-level filesystem write function. You should not access mmc_write() directly.

How should i trace code like below?

mmc->block_dev.block_write = mmc_bwrite;

That is merely an assignment, not a function call. mmc_bwrite is a pointer to the function:

mmc_bwrite(int dev_num, unsigned long start, lbaint_t blkcnt, const void *src)

It is a method of hooking the device driver implementation to the filesystem at run-time rather than by static link. Within the filesystem, mmc_bwrite() will be called through mmc->block_dev.block_write rather than directly. So

mmc->block_dev.block_write(curr_device, blk, cnt, addr);

is in fact a call to mmc_bwrite().