David's route is logical and allows you to get across the border in both directions, but I just don't see any way that's a 5- or 6-week trip. I really encourage you to think of this as the first of several trips to the iberian Peninsula. As you are already aware, there are great destinations in northern Spain in addition to the south and Catalunya. Weather varies a lot across that large country, so I think it makes sense to plan multiple trips with an eye toward optimizing the expected weather. Since you're traveling from late April to early June, it's a great opportunity to see southern Spain, which gets mind-blowingly hot in the summer. Barcelona and Valencia should also be pleasant. To me, northern Spain from the Basque Country across to Galicia (plus also the Pyrenees) is a great summer destination, because if affords a very nice break from the oppressive heat elsewhere in Spain. Even in the summer it can be overcast and rainy, and it doesn't seem to be subject to signficant heat waves--just an occasional day when the temperature might spike for a few hours in the afternoon.
Because of your timing I strongly suggest starting this trip in the south rather than in Barcelona. That way, you'll be out of Andalucia before the really unpleasant heat sets in. I spent 29 days in Andalucia in 2019, beginning on April 9. I had significant rain on a couple days at the beginning of the trip, when I was in Ubeda/Baeza/Jaen, but the weather was pretty great after that. It was warming up noticeably toward the end, though.
I explored flying (from Washington DC) into Seville, Malaga or Granada, but doing that was going to increase my airfare by about $500, so I flew into Madrid, collapsed for the night and caught a bus to Ubeda the next day. (I couldn't count on catching a bus on the day of arrival, and train service to that part of northern Andalucia isn't very useful.) If you wanted to start in Toledo (not in Andalucia, and possible rather cool in April) or in Cordoba you would probably be safe in waiting until on the ground to buy a train ticket for your arrival day. You should do that at the airport train station. The staffed ticket counters at Atocha Station to be avoided at all costs.
Edited to add: The Spanish buses are good, and there's train service as well. (I haven't been to Portugal for about 30 years, but I assume in-country transportation is workable there as well.) The problem is specifically getting across the border. There used to be an overnight train between Madrid and Lisbon, but I believe someone mentioned that it isn't running now. I think there may be a bus from Badajoz across the border. You can also cross in the south (though the Algarve isn't one of my favorite parts of Portugal), and you can cobble together something in the north. Any of those can probably be made to work, but you could end up spending a full day getting from the last place you want to see on the Spanish side of the border to the first place in Portugal. I'd try to avoid doing that twice, if possible.