Program FPGA connected to SPI Jetson Nano

Hi! I have a custom carrier board and an FPGA that is connected on SPI0.0 and I need to program it on boot. I have no problem programming it after boot, but I don’t know how to send the bit file and with the help of which driver/file, any ideas how I can do that?

Thanks in advance!

How do you programming it after boot?

Using these functions:

static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
{
	int ret;
	int out_fd;
	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = len,
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	if (mode & SPI_TX_QUAD)
		tr.tx_nbits = 4;
	else if (mode & SPI_TX_DUAL)
		tr.tx_nbits = 2;
	if (mode & SPI_RX_QUAD)
		tr.rx_nbits = 4;
	else if (mode & SPI_RX_DUAL)
		tr.rx_nbits = 2;
	if (!(mode & SPI_LOOP)) {
		if (mode & (SPI_TX_QUAD | SPI_TX_DUAL))
			tr.rx_buf = 0;
		else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL))
			tr.tx_buf = 0;
	}

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1) {
		printf("ioctl error is %d", ret);
		pabort("can't send spi message");
	}
		

	if (verbose)
		hex_dump(tx, len, 32, "TX");

	if (output_file) {
		out_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
		if (out_fd < 0)
			pabort("could not open output file");

		ret = write(out_fd, rx, len);
		if (ret != len)
			pabort("not all bytes written to output file");

		close(out_fd);
	}

	if (verbose || !output_file)
		hex_dump(rx, len, 32, "RX");
}

static void transfer_file(int fd, char *filename)
{
	ssize_t bytes;
	struct stat sb;
	int tx_fd;
	uint8_t *tx;
	uint8_t *rx;
	FILE *bit_file;

	if (stat(filename, &sb) == -1)
		pabort("can't stat input file");

	bit_file = fopen(filename, "rb");
	if (bit_file == NULL)
		pabort("Bit file is empty");

	tx = malloc(sb.st_size + 4);

	fread(&tx[4], sb.st_size, 1, bit_file);
	tx[0] = 0x7A;
	tx[1] = 0x00;
	tx[2] = 0x00;
	tx[3] = 0x00;

	fclose(bit_file);
	
	if (!tx)
		pabort("can't allocate tx buffer");

	rx = malloc(sb.st_size + 4);

	if (!rx)
		pabort("can't allocate rx buffer");

	transfer(fd, tx, rx, sb.st_size + 4);
	free(rx);
	free(tx);
}

I send the activation key and necessary bit stream from a file. This code is taken and modified from spidev_test.c file:

How about running your program at start up?

I will try this, thank you!

At what time in the boot process does the nano use the camera drivers to search for matching cameras?

Not really understand your question.
Maybe you check the kernel message to check if any clue.